Skip to content

Commit d06d817

Browse files
authored
CSHARP-5782: Add .NET10 to unittests and smoke tests (#1827)
* CSHARP-5782: Add .NET10 to unittests and smoke tests
1 parent 71233ea commit d06d817

File tree

21 files changed

+187
-41
lines changed

21 files changed

+187
-41
lines changed

evergreen/evergreen.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,20 +1111,31 @@ tasks:
11111111
- func: configure-framework
11121112
vars:
11131113
FRAMEWORK: net472
1114+
DOTNET_SDK_VERSION: 10.0
11141115
- func: run-unit-tests
11151116

11161117
- name: unit-tests-netstandard21
11171118
commands:
11181119
- func: configure-framework
11191120
vars:
11201121
FRAMEWORK: netstandard2.1
1122+
DOTNET_SDK_VERSION: 10.0
11211123
- func: run-unit-tests
11221124

11231125
- name: unit-tests-net60
11241126
commands:
11251127
- func: configure-framework
11261128
vars:
11271129
FRAMEWORK: net6.0
1130+
DOTNET_SDK_VERSION: 10.0
1131+
- func: run-unit-tests
1132+
1133+
- name: unit-tests-net100
1134+
commands:
1135+
- func: configure-framework
1136+
vars:
1137+
FRAMEWORK: net10.0
1138+
DOTNET_SDK_VERSION: 10.0
11281139
- func: run-unit-tests
11291140

11301141
- name: test-net472
@@ -1654,6 +1665,7 @@ tasks:
16541665
- func: configure-framework
16551666
vars:
16561667
FRAMEWORK: net472
1668+
DOTNET_SDK_VERSION: 10.0
16571669
- func: bootstrap-mongo-orchestration
16581670
- func: run-smoke-tests
16591671

@@ -1665,6 +1677,7 @@ tasks:
16651677
- func: configure-framework
16661678
vars:
16671679
FRAMEWORK: netcoreapp3.1
1680+
DOTNET_SDK_VERSION: 10.0
16681681
- func: bootstrap-mongo-orchestration
16691682
- func: run-smoke-tests
16701683

@@ -1676,6 +1689,7 @@ tasks:
16761689
- func: configure-framework
16771690
vars:
16781691
FRAMEWORK: net5.0
1692+
DOTNET_SDK_VERSION: 10.0
16791693
- func: bootstrap-mongo-orchestration
16801694
- func: run-smoke-tests
16811695

@@ -1687,6 +1701,7 @@ tasks:
16871701
- func: configure-framework
16881702
vars:
16891703
FRAMEWORK: net6.0
1704+
DOTNET_SDK_VERSION: 10.0
16901705
- func: bootstrap-mongo-orchestration
16911706
- func: run-smoke-tests
16921707

@@ -1698,6 +1713,19 @@ tasks:
16981713
- func: configure-framework
16991714
vars:
17001715
FRAMEWORK: net8.0
1716+
DOTNET_SDK_VERSION: 10.0
1717+
- func: bootstrap-mongo-orchestration
1718+
- func: run-smoke-tests
1719+
1720+
- name: test-smoke-tests-net100
1721+
depends_on:
1722+
- name: push-packages-myget
1723+
variant: ".push-packages-myget"
1724+
commands:
1725+
- func: configure-framework
1726+
vars:
1727+
FRAMEWORK: net10.0
1728+
DOTNET_SDK_VERSION: 10.0
17011729
- func: bootstrap-mongo-orchestration
17021730
- func: run-smoke-tests
17031731

@@ -2380,6 +2408,7 @@ buildvariants:
23802408
- name: unit-tests-net472
23812409
- name: unit-tests-netstandard21
23822410
- name: unit-tests-net60
2411+
- name: unit-tests-net100
23832412

23842413
- name: unit-tests-ubuntu
23852414
display_name: Unit Tests on Ubuntu
@@ -2389,6 +2418,7 @@ buildvariants:
23892418
tasks:
23902419
- name: unit-tests-netstandard21
23912420
- name: unit-tests-net60
2421+
- name: unit-tests-net100
23922422

23932423
- name: unit-tests-macos
23942424
display_name: Unit Tests on MacOs
@@ -2398,6 +2428,7 @@ buildvariants:
23982428
tasks:
23992429
- name: unit-tests-netstandard21
24002430
- name: unit-tests-net60
2431+
- name: unit-tests-net100
24012432

24022433
- name: unit-tests-macos-arm
24032434
display_name: Unit Tests on MacOs Arm
@@ -2406,6 +2437,7 @@ buildvariants:
24062437
OS: "macos-14-arm64"
24072438
tasks:
24082439
- name: unit-tests-net60
2440+
- name: unit-tests-net100
24092441

24102442
- matrix_name: stable-api-tests
24112443
matrix_spec: { version: ["5.0", "6.0", "7.0", "8.0", "rapid", "latest"], topology: ["standalone", "sharded-cluster"], auth: "auth", ssl: "nossl", os: "windows-64" }
@@ -2778,6 +2810,7 @@ buildvariants:
27782810
- name: test-smoke-tests-net50
27792811
- name: test-smoke-tests-net60
27802812
- name: test-smoke-tests-net80
2813+
- name: test-smoke-tests-net100
27812814
rules:
27822815
- if: { version: "*", topology: "*", ssl: "*", os: ["ubuntu-2004", "macos-14"] }
27832816
then:

evergreen/install-dotnet.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ if [ -n "$FRAMEWORK" ]; then
1313
RUNTIME_VERSION="6.0"
1414
elif [ "$FRAMEWORK" = "net8.0" ]; then
1515
RUNTIME_VERSION="8.0"
16+
elif [ "$FRAMEWORK" = "net10.0" ]; then
17+
RUNTIME_VERSION="10.0"
1618
elif [ "$FRAMEWORK" = "netstandard2.1" ]; then
1719
RUNTIME_VERSION="3.1"
1820
elif [ "$FRAMEWORK" = "netcoreapp3.1" ]; then

evergreen/run-smoke-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fi
1010

1111
. ./evergreen/append-myget-package-source.sh
1212

13+
export ADD_NET10_TFM="1" # Remove after cake removal
1314
export DRIVER_PACKAGE_VERSION="${DRIVER_PACKAGE_VERSION}"
1415
./evergreen/compile-sources.sh "$SMOKE_TESTS_PROJECT"
1516

evergreen/run-unit-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ if [ "$FRAMEWORK" = "netstandard2.1" ]; then
77
FRAMEWORK="netcoreapp3.1"
88
fi
99

10+
export ADD_NET10_TFM="1" # Remove after cake removal
1011
./evergreen/compile-sources.sh
1112
dotnet test -c Release --no-build --filter "Category!=Integration" -f "$FRAMEWORK" --results-directory ./build/test-results --logger "junit;verbosity=detailed;LogFileName=TEST-{assembly}.xml;FailureBodyFormat=Verbose" --logger "console;verbosity=detailed"

src/MongoDB.Bson/BsonExtensionMethods.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,41 @@ public static BsonDocument ToBsonDocument<TNominalType>(
131131
/// <param name="configurator">The serialization context configurator.</param>
132132
/// <param name="args">The serialization args.</param>
133133
/// <returns>A BsonDocument.</returns>
134-
/// <exception cref="System.ArgumentNullException">nominalType</exception>
135-
/// <exception cref="System.ArgumentException">serializer</exception>
136134
public static BsonDocument ToBsonDocument(
137135
this object obj,
138136
Type nominalType,
139137
IBsonSerializer serializer = null,
140138
Action<BsonSerializationContext.Builder> configurator = null,
139+
BsonSerializationArgs args = default(BsonSerializationArgs)) =>
140+
ToBsonDocument(obj, nominalType, BsonDocumentWriterSettings.Defaults, serializer, configurator, args);
141+
142+
internal static BsonDocument ToBsonDocument<TNominalType>(
143+
this TNominalType obj,
144+
BsonDocumentWriterSettings bsonDocumentWriterSettings,
145+
IBsonSerializer serializer = null,
146+
Action<BsonSerializationContext.Builder> configurator = null,
147+
BsonSerializationArgs args = default) =>
148+
ToBsonDocument(obj, typeof(TNominalType), bsonDocumentWriterSettings, serializer, configurator, args);
149+
150+
internal static BsonDocument ToBsonDocument(
151+
this object obj,
152+
Type nominalType,
153+
BsonDocumentWriterSettings bsonDocumentWriterSettings,
154+
IBsonSerializer serializer = null,
155+
Action<BsonSerializationContext.Builder> configurator = null,
141156
BsonSerializationArgs args = default(BsonSerializationArgs))
142157
{
143158
if (nominalType == null)
144159
{
145-
throw new ArgumentNullException("nominalType");
160+
throw new ArgumentNullException(nameof(nominalType));
146161
}
147162
args.SetOrValidateNominalType(nominalType, "nominalType");
148163

164+
if (bsonDocumentWriterSettings == null)
165+
{
166+
throw new ArgumentNullException(nameof(bsonDocumentWriterSettings));
167+
}
168+
149169
if (obj == null)
150170
{
151171
return null;
@@ -175,11 +195,11 @@ public static BsonDocument ToBsonDocument(
175195

176196
// otherwise serialize into a new BsonDocument
177197
var document = new BsonDocument();
178-
using (var bsonWriter = new BsonDocumentWriter(document))
179-
{
180-
var context = BsonSerializationContext.CreateRoot(bsonWriter, configurator);
181-
serializer.Serialize(context, args, obj);
182-
}
198+
using var bsonWriter = new BsonDocumentWriter(document, bsonDocumentWriterSettings);
199+
200+
var context = BsonSerializationContext.CreateRoot(bsonWriter, configurator);
201+
serializer.Serialize(context, args, obj);
202+
183203
return document;
184204
}
185205

tests/BuildProps/Tests.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<PropertyGroup>
99
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
1010
<TargetFrameworks Condition="'$(IsWindows)'=='true'">$(TargetFrameworks);net472</TargetFrameworks>
11+
<TargetFrameworks Condition="'$(ADD_NET10_TFM)'=='1'">$(TargetFrameworks);net10.0</TargetFrameworks>
1112
<IsPackable>false</IsPackable>
1213
<SignAssembly>true</SignAssembly>
1314
<AssemblyOriginatorKeyFile>..\..\MongoDB.Driver.snk</AssemblyOriginatorKeyFile>

tests/MongoDB.Bson.Tests/IO/BsonStreamAdapterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public void Read_should_throw_when_subject_is_disposed()
599599
var count = 2;
600600
subject.Dispose();
601601

602-
Action action = () => subject.Read(buffer, offset, count);
602+
Action action = () => _ = subject.Read(buffer, offset, count);
603603

604604
action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("BsonStreamAdapter");
605605
}

tests/MongoDB.Bson.Tests/IO/ByteBufferStreamTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public void Read_should_throw_when_buffer_is_null()
362362
{
363363
var subject = CreateSubject();
364364

365-
Action action = () => subject.Read(null, 0, 0);
365+
Action action = () => _ = subject.Read(null!, 0, 0);
366366

367367
action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("buffer");
368368
}
@@ -379,7 +379,7 @@ public void Read_should_throw_when_count_is_out_of_range(int destinationSize, in
379379
var subject = CreateSubject();
380380
var destination = new byte[destinationSize];
381381

382-
Action action = () => subject.Read(destination, offset, count);
382+
Action action = () => _ = subject.Read(destination, offset, count);
383383

384384
action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("count");
385385
}
@@ -394,7 +394,7 @@ public void Read_should_throw_when_offset_is_out_of_range(int destinationSize, i
394394
var subject = CreateSubject();
395395
var destination = new byte[destinationSize];
396396

397-
Action action = () => subject.Read(destination, offset, 0);
397+
Action action = () => _ = subject.Read(destination, offset, 0);
398398

399399
action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("offset");
400400
}
@@ -405,7 +405,7 @@ public void Read_should_throw_when_subject_is_disposed()
405405
var subject = CreateDisposedSubject();
406406
var destination = new byte[1];
407407

408-
Action action = () => subject.Read(destination, 0, 1);
408+
Action action = () => _ = subject.Read(destination, 0, 1);
409409

410410
action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("ByteBufferStream");
411411
}

tests/MongoDB.Bson.Tests/Serialization/BsonClassMapTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,9 @@ private BsonClassMap WithKnownTypes(BsonClassMap classMap, List<Type> value)
681681

682682
private BsonClassMap Clone(BsonClassMap classMap)
683683
{
684+
#pragma warning disable SYSLIB0050
684685
var clone = (BsonClassMap)FormatterServices.GetUninitializedObject(classMap.GetType());
686+
#pragma warning restore SYSLIB0050
685687
Reflector.SetFieldValue(clone, "_baseClassMap", Reflector.GetFieldValue(classMap, "_baseClassMap"));
686688
Reflector.SetFieldValue(clone, "_classType", Reflector.GetFieldValue(classMap, "_classType"));
687689
Reflector.SetFieldValue(clone, "_creator", Reflector.GetFieldValue(classMap, "_creator"));

tests/MongoDB.Bson.Tests/Serialization/BsonMemberMapTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,9 @@ private BsonMemberMap CreateBsonMemberMap()
411411

412412
private BsonMemberMap Clone(BsonMemberMap memberMap)
413413
{
414+
#pragma warning disable SYSLIB0050
414415
var clone = (BsonMemberMap)FormatterServices.GetUninitializedObject(memberMap.GetType());
416+
#pragma warning restore SYSLIB0050
415417
Reflector.SetFieldValue(clone, "_classMap", Reflector.GetFieldValue(memberMap, "_classMap"));
416418
Reflector.SetFieldValue(clone, "_defaultValue", Reflector.GetFieldValue(memberMap, "_defaultValue"));
417419
Reflector.SetFieldValue(clone, "_defaultValueCreator", Reflector.GetFieldValue(memberMap, "_defaultValueCreator"));

0 commit comments

Comments
 (0)