Skip to content

test: Migrate legacy MongoDB tests to ConsoleMF. #3055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 27, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@
<!-- MySql.Data .NET/Core references -->
<PackageReference Include="MySql.Data" Version="6.10.7" Condition="'$(TargetFramework)' == 'net8.0'" />

<!-- mongocsharpdriver Legacy MongoDB driver references -->
<PackageReference Include="mongocsharpdriver" Version="1.10.0" Condition="'$(TargetFramework)' == 'net462'" />

<!-- MongoDB.Driver .NET Framework references -->
<!-- 2.3.0 is the oldest version we support, 2.17.1 is the newest version as of October 2022 -->
<PackageReference Include="MongoDB.Driver" Version="2.3.0" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="MongoDB.Driver" Version="2.14.1" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="MongoDB.Driver" Version="2.3.0" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="MongoDB.Driver" Version="2.17.1" Condition="'$(TargetFramework)' == 'net48'" />

<!-- MongoDB.Driver .NET/Core references -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0


using MongoDB.Bson;

namespace MultiFunctionApplicationHelpers.NetStandardLibraries.MongoDB
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

// 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
#if NET462
// 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
#if NET471
#define MONGODRIVER2_3
#endif

Expand All @@ -11,6 +11,9 @@
#define MONGODRIVER2_8_1
#endif

// net462 has the legacy MongoDB client
#if !NET462

using System.Collections.Generic;
using System.Linq;
using MongoDB.Driver;
Expand Down Expand Up @@ -561,7 +564,7 @@ public async Task<long> CountAsync()
#pragma warning restore CS0618 // Type or member is obsolete
#endif

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

// EstimatedDocumentCount{Async} did not exist in driver version 2.3 which is bound to net462 in MultiFunctionApplicationHelpers.csproj
// EstimatedDocumentCount{Async} did not exist in driver version 2.3 which is bound to net471 in MultiFunctionApplicationHelpers.csproj
#if !MONGODRIVER2_3
[LibraryMethod]
[Transaction]
Expand Down Expand Up @@ -1048,7 +1051,7 @@ public int CreateOne()
{
var document = new CustomMongoDbEntity { Id = new ObjectId(), Name = "" };
Collection.InsertOne(document);
#if NET462
#if MONGODRIVER2_3
Collection.Indexes.CreateOne(Builders<CustomMongoDbEntity>.IndexKeys.Ascending(k => k.Name));
#else
Collection.Indexes.CreateOne(new CreateIndexModel<CustomMongoDbEntity>(Builders<CustomMongoDbEntity>.IndexKeys.Ascending(k => k.Name)));
Expand All @@ -1063,7 +1066,7 @@ public async Task<int> CreateOneAsync()
{
var document = new CustomMongoDbEntity { Id = new ObjectId(), Name = "" };
await Collection.InsertOneAsync(document);
#if NET462
#if MONGODRIVER2_3
await Collection.Indexes.CreateOneAsync(Builders<CustomMongoDbEntity>.IndexKeys.Ascending(k => k.Name));
#else
await Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomMongoDbEntity>(Builders<CustomMongoDbEntity>.IndexKeys.Ascending(k => k.Name)));
Expand Down Expand Up @@ -1256,3 +1259,5 @@ private void DropCollection(string collectionName)
}

}

#endif
Loading
Loading