Skip to content

Commit 2fad2b2

Browse files
authored
test: Migrate legacy MongoDB tests to ConsoleMF. (#3055)
1 parent ae1a436 commit 2fad2b2

25 files changed

Lines changed: 476 additions & 1785 deletions

tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/MultiFunctionApplicationHelpers.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@
6767
<!-- MySql.Data .NET/Core references -->
6868
<PackageReference Include="MySql.Data" Version="6.10.7" Condition="'$(TargetFramework)' == 'net8.0'" />
6969

70+
<!-- mongocsharpdriver Legacy MongoDB driver references -->
71+
<PackageReference Include="mongocsharpdriver" Version="1.10.0" Condition="'$(TargetFramework)' == 'net462'" />
72+
7073
<!-- MongoDB.Driver .NET Framework references -->
7174
<!-- 2.3.0 is the oldest version we support, 2.17.1 is the newest version as of October 2022 -->
72-
<PackageReference Include="MongoDB.Driver" Version="2.3.0" Condition="'$(TargetFramework)' == 'net462'" />
73-
<PackageReference Include="MongoDB.Driver" Version="2.14.1" Condition="'$(TargetFramework)' == 'net471'" />
75+
<PackageReference Include="MongoDB.Driver" Version="2.3.0" Condition="'$(TargetFramework)' == 'net471'" />
7476
<PackageReference Include="MongoDB.Driver" Version="2.17.1" Condition="'$(TargetFramework)' == 'net48'" />
7577

7678
<!-- MongoDB.Driver .NET/Core references -->

tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/NetStandardLibraries/MongoDB/CustomMongoDbEntity.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2020 New Relic, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
54
using MongoDB.Bson;
65

76
namespace MultiFunctionApplicationHelpers.NetStandardLibraries.MongoDB

tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/NetStandardLibraries/MongoDB/MongoDBDriverExerciser.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2020 New Relic, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
// Several methods exercised here do not exist in MongoDB.Driver version 2.3 which is the oldest we support on .NET Framework. It is bound to the net462 TFM in MultiFunctionApplicationHelpers.csproj
5-
#if NET462
4+
// Several methods exercised here do not exist in MongoDB.Driver version 2.3 which is the oldest we support on .NET Framework. It is bound to the net471 TFM in MultiFunctionApplicationHelpers.csproj
5+
#if NET471
66
#define MONGODRIVER2_3
77
#endif
88

@@ -11,6 +11,9 @@
1111
#define MONGODRIVER2_8_1
1212
#endif
1313

14+
// net462 has the legacy MongoDB client
15+
#if !NET462
16+
1417
using System.Collections.Generic;
1518
using System.Linq;
1619
using MongoDB.Driver;
@@ -561,7 +564,7 @@ public async Task<long> CountAsync()
561564
#pragma warning restore CS0618 // Type or member is obsolete
562565
#endif
563566

564-
// CountDocuments{Async} did not exist in driver version 2.3 which is bound to net462 in MultiFunctionApplicationHelpers.csproj
567+
// CountDocuments{Async} did not exist in driver version 2.3 which is bound to net471 in MultiFunctionApplicationHelpers.csproj
565568
#if !MONGODRIVER2_3
566569
[LibraryMethod]
567570
[Transaction]
@@ -610,7 +613,7 @@ public async Task<IAsyncCursor<string>> DistinctAsync()
610613
return await Collection.DistinctAsync<string>("Name", filter);
611614
}
612615

613-
// EstimatedDocumentCount{Async} did not exist in driver version 2.3 which is bound to net462 in MultiFunctionApplicationHelpers.csproj
616+
// EstimatedDocumentCount{Async} did not exist in driver version 2.3 which is bound to net471 in MultiFunctionApplicationHelpers.csproj
614617
#if !MONGODRIVER2_3
615618
[LibraryMethod]
616619
[Transaction]
@@ -1048,7 +1051,7 @@ public int CreateOne()
10481051
{
10491052
var document = new CustomMongoDbEntity { Id = new ObjectId(), Name = "" };
10501053
Collection.InsertOne(document);
1051-
#if NET462
1054+
#if MONGODRIVER2_3
10521055
Collection.Indexes.CreateOne(Builders<CustomMongoDbEntity>.IndexKeys.Ascending(k => k.Name));
10531056
#else
10541057
Collection.Indexes.CreateOne(new CreateIndexModel<CustomMongoDbEntity>(Builders<CustomMongoDbEntity>.IndexKeys.Ascending(k => k.Name)));
@@ -1063,7 +1066,7 @@ public async Task<int> CreateOneAsync()
10631066
{
10641067
var document = new CustomMongoDbEntity { Id = new ObjectId(), Name = "" };
10651068
await Collection.InsertOneAsync(document);
1066-
#if NET462
1069+
#if MONGODRIVER2_3
10671070
await Collection.Indexes.CreateOneAsync(Builders<CustomMongoDbEntity>.IndexKeys.Ascending(k => k.Name));
10681071
#else
10691072
await Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomMongoDbEntity>(Builders<CustomMongoDbEntity>.IndexKeys.Ascending(k => k.Name)));
@@ -1256,3 +1259,5 @@ private void DropCollection(string collectionName)
12561259
}
12571260

12581261
}
1262+
1263+
#endif

0 commit comments

Comments
 (0)