diff --git a/src/MongoDB.Bson/Exceptions/BsonException.cs b/src/MongoDB.Bson/Exceptions/BsonException.cs
index ca2db03a717..a8e6ea21121 100644
--- a/src/MongoDB.Bson/Exceptions/BsonException.cs
+++ b/src/MongoDB.Bson/Exceptions/BsonException.cs
@@ -66,6 +66,7 @@ public BsonException(string format, params object[] args)
///
/// The SerializationInfo.
/// The StreamingContext.
+ [Obsolete("Legacy serialization support APIs are obsolete: SYSLIB0051")]
public BsonException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
diff --git a/src/MongoDB.Bson/Exceptions/BsonInternalException.cs b/src/MongoDB.Bson/Exceptions/BsonInternalException.cs
index 150fc8f05f0..c0a0a665615 100644
--- a/src/MongoDB.Bson/Exceptions/BsonInternalException.cs
+++ b/src/MongoDB.Bson/Exceptions/BsonInternalException.cs
@@ -56,6 +56,7 @@ public BsonInternalException(string message, Exception innerException)
///
/// The SerializationInfo.
/// The StreamingContext.
+ [Obsolete("Legacy serialization support APIs are obsolete: SYSLIB0051")]
public BsonInternalException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
diff --git a/src/MongoDB.Bson/Exceptions/BsonSerializationException.cs b/src/MongoDB.Bson/Exceptions/BsonSerializationException.cs
index 4ac318ebe53..f64d9997659 100644
--- a/src/MongoDB.Bson/Exceptions/BsonSerializationException.cs
+++ b/src/MongoDB.Bson/Exceptions/BsonSerializationException.cs
@@ -56,6 +56,7 @@ public BsonSerializationException(string message, Exception innerException)
///
/// The SerializationInfo.
/// The StreamingContext.
+ [Obsolete("Legacy serialization support APIs are obsolete: SYSLIB0051")]
public BsonSerializationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
diff --git a/src/MongoDB.Bson/Exceptions/DuplicateBsonMemberMapAttributeException.cs b/src/MongoDB.Bson/Exceptions/DuplicateBsonMemberMapAttributeException.cs
index caefa7ec10f..eb1df083179 100644
--- a/src/MongoDB.Bson/Exceptions/DuplicateBsonMemberMapAttributeException.cs
+++ b/src/MongoDB.Bson/Exceptions/DuplicateBsonMemberMapAttributeException.cs
@@ -48,6 +48,7 @@ public DuplicateBsonMemberMapAttributeException(string message, Exception inner)
///
/// The info.
/// The context.
+ [Obsolete("Legacy serialization support APIs are obsolete: SYSLIB0051")]
protected DuplicateBsonMemberMapAttributeException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
diff --git a/src/MongoDB.Bson/Exceptions/TruncationException.cs b/src/MongoDB.Bson/Exceptions/TruncationException.cs
index dcb6d1327ab..d455a0ce7e0 100644
--- a/src/MongoDB.Bson/Exceptions/TruncationException.cs
+++ b/src/MongoDB.Bson/Exceptions/TruncationException.cs
@@ -56,6 +56,7 @@ public TruncationException(string message, Exception innerException)
///
/// The SerializationInfo.
/// The StreamingContext.
+ [Obsolete("Legacy serialization support APIs are obsolete: SYSLIB0051")]
public TruncationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
diff --git a/src/MongoDB.Bson/Serialization/BsonDeserializationArgs.cs b/src/MongoDB.Bson/Serialization/BsonDeserializationArgs.cs
index d9fb8b6c654..e210a598262 100644
--- a/src/MongoDB.Bson/Serialization/BsonDeserializationArgs.cs
+++ b/src/MongoDB.Bson/Serialization/BsonDeserializationArgs.cs
@@ -14,7 +14,6 @@
*/
using System;
-using MongoDB.Bson.IO;
namespace MongoDB.Bson.Serialization
{
@@ -23,27 +22,9 @@ namespace MongoDB.Bson.Serialization
///
public struct BsonDeserializationArgs
{
- // private fields
- private Type _nominalType;
-
- // constructors
- private BsonDeserializationArgs(
- Type nominalType)
- {
- _nominalType = nominalType;
- }
-
- // public properties
///
/// Gets or sets the nominal type.
///
- ///
- /// The nominal type.
- ///
- public Type NominalType
- {
- get { return _nominalType; }
- set { _nominalType = value; }
- }
+ public Type NominalType { get; set; }
}
}
diff --git a/src/MongoDB.Bson/Serialization/BsonSerializationInfo.cs b/src/MongoDB.Bson/Serialization/BsonSerializationInfo.cs
index 01a5b9315de..ff3237d9711 100644
--- a/src/MongoDB.Bson/Serialization/BsonSerializationInfo.cs
+++ b/src/MongoDB.Bson/Serialization/BsonSerializationInfo.cs
@@ -28,7 +28,7 @@ public class BsonSerializationInfo
{
#region static
///
- /// Creates a new instance of the BsonSerializationinfo class with an element path instead of an element name.
+ /// Creates a new instance of the BsonSerializationInfo class with an element path instead of an element name.
///
/// The element path.
/// The serializer.
diff --git a/src/MongoDB.Bson/Serialization/Serializers/NullableSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/NullableSerializer.cs
index 8740bdd3a9b..bef79d7f2b2 100644
--- a/src/MongoDB.Bson/Serialization/Serializers/NullableSerializer.cs
+++ b/src/MongoDB.Bson/Serialization/Serializers/NullableSerializer.cs
@@ -40,6 +40,11 @@ public static class NullableSerializer
/// A NullableSerializer
public static IBsonSerializer Create(IBsonSerializer valueSerializer)
{
+ if (valueSerializer == null)
+ {
+ throw new ArgumentNullException(nameof(valueSerializer));
+ }
+
var valueType = valueSerializer.ValueType;
var nullableSerializerType = typeof(NullableSerializer<>).MakeGenericType(valueType);
return (IBsonSerializer)Activator.CreateInstance(nullableSerializerType, valueSerializer);
diff --git a/tests/MongoDB.Bson.Tests/Exceptions/BsonExceptionTests.cs b/tests/MongoDB.Bson.Tests/Exceptions/BsonExceptionTests.cs
new file mode 100644
index 00000000000..14287e70916
--- /dev/null
+++ b/tests/MongoDB.Bson.Tests/Exceptions/BsonExceptionTests.cs
@@ -0,0 +1,53 @@
+/* Copyright 2010-present MongoDB Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using FluentAssertions;
+using Xunit;
+
+namespace MongoDB.Bson.Tests.Exceptions
+{
+ public class BsonExceptionTests
+ {
+ [Fact]
+ public void constructor_with_format_and_args_should_format_message_correctly()
+ {
+ // Act
+ var exception = new BsonException("Error code: {0}, message: {1}", 123, "Test error");
+
+ // Assert
+ exception.Message.Should().Be("Error code: 123, message: Test error");
+ }
+
+ [Fact]
+ public void constructor_with_format_and_args_should_handle_empty_args()
+ {
+ // Act
+ var exception = new BsonException("Simple message");
+
+ // Assert
+ exception.Message.Should().Be("Simple message");
+ }
+
+ [Fact]
+ public void constructor_with_format_and_args_should_handle_null_args()
+ {
+ // Act
+ var exception = new BsonException("Message with {0}", (object)null);
+
+ // Assert
+ exception.Message.Should().Be("Message with ");
+ }
+ }
+}
diff --git a/tests/MongoDB.Bson.Tests/Exceptions/BsonInternalExceptionTests.cs b/tests/MongoDB.Bson.Tests/Exceptions/BsonInternalExceptionTests.cs
new file mode 100644
index 00000000000..fce871f8b4b
--- /dev/null
+++ b/tests/MongoDB.Bson.Tests/Exceptions/BsonInternalExceptionTests.cs
@@ -0,0 +1,74 @@
+/* Copyright 2010-present MongoDB Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using FluentAssertions;
+using Xunit;
+
+namespace MongoDB.Bson.Tests.Exceptions
+{
+ public class BsonInternalExceptionTests
+ {
+ [Fact]
+ public void constructor_should_initialize_empty_instance()
+ {
+ // Act
+ var exception = new BsonInternalException();
+
+ // Assert
+ exception.Message.Should().Be("Exception of type 'MongoDB.Bson.BsonInternalException' was thrown.");
+ exception.InnerException.Should().BeNull();
+ }
+
+ [Fact]
+ public void constructor_should_initialize_instance_with_message()
+ {
+ // Arrange
+ var message = "Test internal exception message";
+
+ // Act
+ var exception = new BsonInternalException(message);
+
+ // Assert
+ exception.Message.Should().Be(message);
+ exception.InnerException.Should().BeNull();
+ }
+
+ [Fact]
+ public void constructor_should_initialize_instance_with_message_and_inner_exception()
+ {
+ // Arrange
+ var message = "Test internal exception message";
+ var innerException = new Exception("Inner exception message");
+
+ // Act
+ var exception = new BsonInternalException(message, innerException);
+
+ // Assert
+ exception.Message.Should().Be(message);
+ exception.InnerException.Should().BeSameAs(innerException);
+ }
+
+ [Fact]
+ public void should_inherit_from_bson_exception()
+ {
+ // Act
+ var exception = new BsonInternalException();
+
+ // Assert
+ exception.Should().BeAssignableTo();
+ }
+ }
+}
diff --git a/tests/MongoDB.Bson.Tests/Exceptions/BsonSerializationExceptionTests.cs b/tests/MongoDB.Bson.Tests/Exceptions/BsonSerializationExceptionTests.cs
new file mode 100644
index 00000000000..4c0fac93c66
--- /dev/null
+++ b/tests/MongoDB.Bson.Tests/Exceptions/BsonSerializationExceptionTests.cs
@@ -0,0 +1,39 @@
+/* Copyright 2010-present MongoDB Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using FluentAssertions;
+using Xunit;
+
+namespace MongoDB.Bson.Tests.Exceptions
+{
+ public class BsonSerializationExceptionTests
+ {
+ [Fact]
+ public void Constructor_with_message_and_inner_exception_should_initialize_properties()
+ {
+ // Arrange
+ var message = "Test error message";
+ var innerException = new ArgumentException("Inner exception message");
+
+ // Act
+ var exception = new BsonSerializationException(message, innerException);
+
+ // Assert
+ exception.Message.Should().Be(message);
+ exception.InnerException.Should().BeSameAs(innerException);
+ }
+ }
+}
diff --git a/tests/MongoDB.Bson.Tests/IO/DateTimeJsonTokenTests.cs b/tests/MongoDB.Bson.Tests/IO/DateTimeJsonTokenTests.cs
new file mode 100644
index 00000000000..66f24afb62d
--- /dev/null
+++ b/tests/MongoDB.Bson.Tests/IO/DateTimeJsonTokenTests.cs
@@ -0,0 +1,69 @@
+/* Copyright 2010-present MongoDB Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using FluentAssertions;
+using MongoDB.Bson.IO;
+using Xunit;
+
+namespace MongoDB.Bson.Tests.IO
+{
+ public class DateTimeJsonTokenTests
+ {
+ [Fact]
+ public void Constructor_should_initialize_token_with_provided_values()
+ {
+ // Arrange
+ var lexeme = "ISODate(\"2023-01-01T00:00:00Z\")";
+ var value = new BsonDateTime(new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc));
+
+ // Act
+ var token = new DateTimeJsonToken(lexeme, value);
+
+ // Assert
+ token.Lexeme.Should().Be(lexeme);
+ token.Type.Should().Be(JsonTokenType.DateTime);
+ }
+
+ [Fact]
+ public void Constructor_should_set_token_type_to_DateTime()
+ {
+ // Arrange
+ var lexeme = "ISODate(\"2023-01-01T00:00:00Z\")";
+ var value = new BsonDateTime(new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc));
+
+ // Act
+ var token = new DateTimeJsonToken(lexeme, value);
+
+ // Assert
+ token.Type.Should().Be(JsonTokenType.DateTime);
+ }
+
+ [Fact]
+ public void DateTimeValue_should_return_provided_value()
+ {
+ // Arrange
+ var lexeme = "ISODate(\"2023-01-01T00:00:00Z\")";
+ var value = new BsonDateTime(new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc));
+ var token = new DateTimeJsonToken(lexeme, value);
+
+ // Act
+ var result = token.DateTimeValue;
+
+ // Assert
+ result.Should().Be(value);
+ }
+ }
+}
diff --git a/tests/MongoDB.Bson.Tests/IO/ObjectIdJsonTokenTests.cs b/tests/MongoDB.Bson.Tests/IO/ObjectIdJsonTokenTests.cs
new file mode 100644
index 00000000000..093457728cd
--- /dev/null
+++ b/tests/MongoDB.Bson.Tests/IO/ObjectIdJsonTokenTests.cs
@@ -0,0 +1,68 @@
+/* Copyright 2010-present MongoDB Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using FluentAssertions;
+using MongoDB.Bson.IO;
+using Xunit;
+
+namespace MongoDB.Bson.Tests.IO
+{
+ public class ObjectIdJsonTokenTests
+ {
+ [Fact]
+ public void Constructor_should_initialize_token_with_provided_values()
+ {
+ // Arrange
+ var lexeme = "ObjectId(\"507f1f77bcf86cd799439011\")";
+ var value = new ObjectId("507f1f77bcf86cd799439011");
+
+ // Act
+ var token = new ObjectIdJsonToken(lexeme, value);
+
+ // Assert
+ token.Lexeme.Should().Be(lexeme);
+ token.Type.Should().Be(JsonTokenType.ObjectId);
+ }
+
+ [Fact]
+ public void Constructor_should_set_token_type_to_ObjectId()
+ {
+ // Arrange
+ var lexeme = "ObjectId(\"507f1f77bcf86cd799439011\")";
+ var value = new ObjectId("507f1f77bcf86cd799439011");
+
+ // Act
+ var token = new ObjectIdJsonToken(lexeme, value);
+
+ // Assert
+ token.Type.Should().Be(JsonTokenType.ObjectId);
+ }
+
+ [Fact]
+ public void ObjectIdValue_should_return_provided_value()
+ {
+ // Arrange
+ var lexeme = "ObjectId(\"507f1f77bcf86cd799439011\")";
+ var value = new ObjectId("507f1f77bcf86cd799439011");
+ var token = new ObjectIdJsonToken(lexeme, value);
+
+ // Act
+ var result = token.ObjectIdValue;
+
+ // Assert
+ result.Should().Be(value);
+ }
+ }
+}
diff --git a/tests/MongoDB.Bson.Tests/ObjectModel/BsonJavaScriptTests.cs b/tests/MongoDB.Bson.Tests/ObjectModel/BsonJavaScriptTests.cs
new file mode 100644
index 00000000000..b79c3cade87
--- /dev/null
+++ b/tests/MongoDB.Bson.Tests/ObjectModel/BsonJavaScriptTests.cs
@@ -0,0 +1,387 @@
+/* Copyright 2010-present MongoDB Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using FluentAssertions;
+using MongoDB.Shared;
+using Xunit;
+
+namespace MongoDB.Bson.Tests.ObjectModel
+{
+ public class BsonJavaScriptTests
+ {
+ [Fact]
+ public void BsonType_should_return_JavaScript()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+ var subject = new BsonJavaScript(code);
+
+ // Act
+ var result = subject.BsonType;
+
+ // Assert
+ result.Should().Be(BsonType.JavaScript);
+ }
+
+ [Fact]
+ public void Code_should_return_code_provided_in_constructor()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+ var subject = new BsonJavaScript(code);
+
+ // Act
+ var result = subject.Code;
+
+ // Assert
+ result.Should().Be(code);
+ }
+
+ [Fact]
+ public void CompareTo_BsonJavaScript_should_return_0_when_codes_are_equal()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+ var subject = new BsonJavaScript(code);
+ var other = new BsonJavaScript(code);
+
+ // Act
+ var result = subject.CompareTo(other);
+
+ // Assert
+ result.Should().Be(0);
+ }
+
+ [Fact]
+ public void CompareTo_BsonJavaScript_should_return_1_when_other_is_null()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("function() { return 1; }");
+
+ // Act
+ var result = subject.CompareTo((BsonJavaScript)null);
+
+ // Assert
+ result.Should().Be(1);
+ }
+
+ [Fact]
+ public void CompareTo_BsonJavaScript_should_return_negative_when_this_code_is_less_than_other_code()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("a");
+ var other = new BsonJavaScript("b");
+
+ // Act
+ var result = subject.CompareTo(other);
+
+ // Assert
+ result.Should().BeLessThan(0);
+ }
+
+ [Fact]
+ public void CompareTo_BsonJavaScript_should_return_positive_when_this_code_is_greater_than_other_code()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("b");
+ var other = new BsonJavaScript("a");
+
+ // Act
+ var result = subject.CompareTo(other);
+
+ // Assert
+ result.Should().BeGreaterThan(0);
+ }
+ [Fact]
+ public void CompareTo_BsonValue_should_compare_code_when_other_is_BsonJavaScript()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("a");
+ BsonValue other = new BsonJavaScript("b");
+
+ // Act
+ var result = subject.CompareTo(other);
+
+ // Assert
+ result.Should().BeLessThan(0);
+ }
+
+ [Fact]
+ public void CompareTo_BsonValue_should_return_1_when_other_is_null()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("function() { return 1; }");
+
+ // Act
+ var result = subject.CompareTo((BsonValue)null);
+
+ // Assert
+ result.Should().Be(1);
+ }
+ [Fact]
+ public void CompareTo_BsonValue_should_use_CompareTypeTo_when_other_is_not_BsonJavaScript()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("function() { return 1; }");
+ var other = new BsonInt32(1);
+
+ // Act
+ var result = subject.CompareTo(other);
+
+ // Assert
+ result.Should().NotBe(0);
+ // The actual comparison result depends on BsonType enum values
+ }
+
+ [Fact]
+ public void Constructor_should_initialize_Code_property()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+
+ // Act
+ var subject = new BsonJavaScript(code);
+
+ // Assert
+ subject.Code.Should().Be(code);
+ }
+
+ [Fact]
+ public void Constructor_should_throw_when_code_is_null()
+ {
+ // Arrange & Act
+ Action act = () => new BsonJavaScript(null);
+
+ // Assert
+ act.ShouldThrow()
+ .And.ParamName.Should().Be("code");
+ }
+
+ [Fact]
+ public void Create_should_map_value_to_BsonJavaScript()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+
+ // Act
+ var result = BsonJavaScript.Create(code);
+
+ // Assert
+ result.Should().NotBeNull();
+ result.Code.Should().Be(code);
+ }
+
+ [Fact]
+ public void Create_should_throw_when_value_is_null()
+ {
+ // Act
+ Action act = () => BsonJavaScript.Create(null);
+
+ // Assert
+ act.ShouldThrow()
+ .And.ParamName.Should().Be("value");
+ }
+
+ [Fact]
+ public void Equality_operator_should_return_false_when_codes_are_not_equal()
+ {
+ // Arrange
+ var lhs = new BsonJavaScript("function() { return 1; }");
+ var rhs = new BsonJavaScript("function() { return 2; }");
+
+ // Act
+ var result = lhs == rhs;
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equality_operator_should_return_true_when_codes_are_equal()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+ var lhs = new BsonJavaScript(code);
+ var rhs = new BsonJavaScript(code);
+
+ // Act
+ var result = lhs == rhs;
+
+ // Assert
+ result.Should().BeTrue();
+ }
+
+ [Fact]
+ public void Equals_BsonJavaScript_should_return_false_when_codes_are_not_equal()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("function() { return 1; }");
+ var other = new BsonJavaScript("function() { return 2; }");
+
+ // Act
+ var result = subject.Equals(other);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_BsonJavaScript_should_return_false_when_other_is_different_type()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("function() { return 1; }");
+ var other = new BsonJavaScriptWithScope("function() { return 1; }", new BsonDocument());
+
+ // Act
+ var result = subject.Equals(other);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_BsonJavaScript_should_return_false_when_other_is_null()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("function() { return 1; }");
+
+ // Act
+ var result = subject.Equals((BsonJavaScript)null);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_BsonJavaScript_should_return_true_when_codes_are_equal()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+ var subject = new BsonJavaScript(code);
+ var other = new BsonJavaScript(code);
+
+ // Act
+ var result = subject.Equals(other);
+
+ // Assert
+ result.Should().BeTrue();
+ }
+ [Fact]
+ public void Equals_object_should_return_false_when_other_is_not_BsonJavaScript()
+ {
+ // Arrange
+ var subject = new BsonJavaScript("function() { return 1; }");
+ object other = "function() { return 1; }";
+
+ // Act
+ var result = subject.Equals(other);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_object_should_return_true_when_other_is_BsonJavaScript_with_equal_code()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+ var subject = new BsonJavaScript(code);
+ object other = new BsonJavaScript(code);
+
+ // Act
+ var result = subject.Equals(other);
+
+ // Assert
+ result.Should().BeTrue();
+ }
+ [Fact]
+ public void GetHashCode_should_return_combination_of_BsonType_and_code_hash_codes()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+ var subject = new BsonJavaScript(code);
+
+ // Calculate expected hash code using same algorithm as in the class
+ int expectedHash = 17;
+ expectedHash = 37 * expectedHash + Hasher.GetHashCode(BsonType.JavaScript);
+ expectedHash = 37 * expectedHash + code.GetHashCode();
+
+ // Act
+ var result = subject.GetHashCode();
+
+ // Assert
+ result.Should().Be(expectedHash);
+ }
+
+ [Fact]
+ public void Implicit_conversion_from_string_should_create_BsonJavaScript_instance()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+
+ // Act
+ BsonJavaScript result = code;
+
+ // Assert
+ result.Should().NotBeNull();
+ result.Code.Should().Be(code);
+ }
+
+ [Fact]
+ public void Inequality_operator_should_return_false_when_codes_are_equal()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+ var lhs = new BsonJavaScript(code);
+ var rhs = new BsonJavaScript(code);
+
+ // Act
+ var result = lhs != rhs;
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Inequality_operator_should_return_true_when_codes_are_not_equal()
+ {
+ // Arrange
+ var lhs = new BsonJavaScript("function() { return 1; }");
+ var rhs = new BsonJavaScript("function() { return 2; }");
+
+ // Act
+ var result = lhs != rhs;
+
+ // Assert
+ result.Should().BeTrue();
+ }
+
+ [Fact]
+ public void ToString_should_return_formatted_string_representation()
+ {
+ // Arrange
+ var code = "function() { return 1; }";
+ var subject = new BsonJavaScript(code);
+ var expected = $"new BsonJavaScript(\"{code}\")";
+
+ // Act
+ var result = subject.ToString();
+
+ // Assert
+ result.Should().Be(expected);
+ }
+ }
+}
diff --git a/tests/MongoDB.Bson.Tests/ObjectModel/BsonJavaScriptWithScopeTests.cs b/tests/MongoDB.Bson.Tests/ObjectModel/BsonJavaScriptWithScopeTests.cs
new file mode 100644
index 00000000000..91ead7e9ec7
--- /dev/null
+++ b/tests/MongoDB.Bson.Tests/ObjectModel/BsonJavaScriptWithScopeTests.cs
@@ -0,0 +1,452 @@
+/* Copyright 2010-present MongoDB Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using FluentAssertions;
+using Xunit;
+
+namespace MongoDB.Bson.Tests.ObjectModel
+{
+ public class BsonJavaScriptWithScopeTests
+ {
+ [Fact]
+ public void BsonType_should_return_JavaScriptWithScope()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope(code, scope);
+
+ // Act
+ var result = subject.BsonType;
+
+ // Assert
+ result.Should().Be(BsonType.JavaScriptWithScope);
+ }
+
+ [Fact]
+ public void Clone_should_create_shallow_copy()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope(code, scope);
+
+ // Act
+ var result = subject.Clone();
+
+ // Assert
+ result.Should().NotBeSameAs(subject);
+ result.Should().BeOfType();
+ var clone = (BsonJavaScriptWithScope)result;
+ clone.Code.Should().Be(subject.Code);
+ clone.Scope.Should().NotBeSameAs(subject.Scope);
+ clone.Scope["x"].Should().Be(1);
+ clone.Scope["y"].Should().Be(2);
+ }
+
+ [Fact]
+ public void CompareTo_BsonJavaScriptWithScope_should_compare_code_first_then_scope()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 2 }, { "y", 3 } };
+ var subject1 = new BsonJavaScriptWithScope("a", scope1);
+ var subject2 = new BsonJavaScriptWithScope("b", scope1);
+ var subject3 = new BsonJavaScriptWithScope("a", scope2);
+
+ // Act
+ var result1 = subject1.CompareTo(subject2); // code comparison: a < b
+ var result2 = subject2.CompareTo(subject1); // code comparison: b > a
+ var result3 = subject1.CompareTo(subject3); // same code, different scope
+ var result4 = subject1.CompareTo(subject1); // same instance
+
+ // Assert
+ result1.Should().BeLessThan(0);
+ result2.Should().BeGreaterThan(0);
+ result3.Should().BeLessThan(0); // scope1 < scope2
+ result4.Should().Be(0);
+ }
+
+ [Fact]
+ public void CompareTo_BsonJavaScriptWithScope_should_return_1_when_other_is_null()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope(code, scope);
+ BsonJavaScriptWithScope other = null;
+
+ // Act
+ var result = subject.CompareTo(other);
+
+ // Assert
+ result.Should().Be(1);
+ }
+
+ [Fact]
+ public void CompareTo_BsonValue_should_return_1_when_other_is_null()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope(code, scope);
+ BsonValue other = null;
+
+ // Act
+ var result = subject.CompareTo(other);
+
+ // Assert
+ result.Should().Be(1);
+ }
+
+ [Fact]
+ public void CompareTo_BsonValue_should_use_CompareTo_when_other_is_BsonJavaScriptWithScope()
+ {
+ // Arrange
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope("a", scope);
+ BsonValue other = new BsonJavaScriptWithScope("b", scope);
+
+ // Act
+ var result = subject.CompareTo(other);
+
+ // Assert
+ result.Should().BeLessThan(0);
+ }
+
+ [Fact]
+ public void CompareTo_BsonValue_should_use_CompareTypeTo_when_other_is_not_BsonJavaScriptWithScope()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope(code, scope);
+ var other = new BsonInt32(1);
+
+ // Act
+ var result = subject.CompareTo(other);
+
+ // Assert
+ // BsonJavaScriptWithScope has a higher BsonType enum value than BsonInt32
+ result.Should().BeGreaterThan(0);
+ }
+
+ [Fact]
+ public void Constructor_should_initialize_instance()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+
+ // Act
+ var result = new BsonJavaScriptWithScope(code, scope);
+
+ // Assert
+ result.Code.Should().Be(code);
+ result.Scope.Should().BeSameAs(scope);
+ }
+
+ [Fact]
+ public void Constructor_should_throw_when_scope_is_null()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ BsonDocument scope = null;
+
+ // Act
+ Action act = () => new BsonJavaScriptWithScope(code, scope);
+
+ // Assert
+ act.ShouldThrow()
+ .And.ParamName.Should().Be("scope");
+ }
+
+ [Fact]
+ public void DeepClone_should_create_deep_copy()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ var nestedDoc = new BsonDocument { { "a", 3 } };
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 }, { "z", nestedDoc } };
+ var subject = new BsonJavaScriptWithScope(code, scope);
+
+ // Act
+ var result = subject.DeepClone();
+
+ // Assert
+ result.Should().NotBeSameAs(subject);
+ result.Should().BeOfType();
+ var clone = (BsonJavaScriptWithScope)result;
+ clone.Code.Should().Be(subject.Code);
+ clone.Scope.Should().NotBeSameAs(subject.Scope);
+ clone.Scope["x"].Should().Be(1);
+ clone.Scope["y"].Should().Be(2);
+ clone.Scope["z"].Should().NotBeSameAs(nestedDoc);
+ clone.Scope["z"].AsBsonDocument["a"].Should().Be(3);
+
+ // Modify the nested document to ensure deep clone
+ nestedDoc["a"] = 4;
+ clone.Scope["z"].AsBsonDocument["a"].Should().Be(3); // Should still be 3
+ }
+
+ [Fact]
+ public void Equality_operator_should_handle_null()
+ {
+ // Arrange
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope("code", scope);
+ BsonJavaScriptWithScope nullValue = null;
+
+ // Act
+ var resultLeftNull = nullValue == subject;
+ var resultRightNull = subject == nullValue;
+
+ // Assert
+ resultLeftNull.Should().BeFalse();
+ resultRightNull.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equality_operator_should_return_false_when_not_equal()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 1 }, { "y", 3 } };
+ var subject1 = new BsonJavaScriptWithScope("code", scope1);
+ var subject2 = new BsonJavaScriptWithScope("code", scope2);
+ var subject3 = new BsonJavaScriptWithScope("different", scope1);
+
+ // Act
+ var resultDifferentScope = subject1 == subject2;
+ var resultDifferentCode = subject1 == subject3;
+
+ // Assert
+ resultDifferentScope.Should().BeFalse();
+ resultDifferentCode.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equality_operator_should_return_true_when_equal()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject1 = new BsonJavaScriptWithScope("code", scope1);
+ var subject2 = new BsonJavaScriptWithScope("code", scope2);
+
+ // Act
+ var result = subject1 == subject2;
+
+ // Assert
+ result.Should().BeTrue();
+ }
+ [Fact]
+ public void Equals_BsonJavaScriptWithScope_should_return_false_when_not_equal()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 1 }, { "y", 3 } };
+ var subject1 = new BsonJavaScriptWithScope("code", scope1);
+ var subject2 = new BsonJavaScriptWithScope("code", scope2);
+ var subject3 = new BsonJavaScriptWithScope("different", scope1);
+
+ // Act
+ var resultDifferentScope = subject1.Equals(subject2);
+ var resultDifferentCode = subject1.Equals(subject3);
+
+ // Assert
+ resultDifferentScope.Should().BeFalse();
+ resultDifferentCode.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_BsonJavaScriptWithScope_should_return_false_when_other_is_null()
+ {
+ // Arrange
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope("code", scope);
+ BsonJavaScriptWithScope other = null;
+
+ // Act
+ var result = subject.Equals(other);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_BsonJavaScriptWithScope_should_return_true_when_equal()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject1 = new BsonJavaScriptWithScope("code", scope1);
+ var subject2 = new BsonJavaScriptWithScope("code", scope2);
+
+ // Act
+ var result = subject1.Equals(subject2);
+
+ // Assert
+ result.Should().BeTrue();
+ }
+ [Fact]
+ public void Equals_object_should_return_false_when_other_is_different_type()
+ {
+ // Arrange
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope("code", scope);
+ object other = "not a BsonJavaScriptWithScope";
+
+ // Act
+ var result = subject.Equals(other);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_object_should_return_false_when_other_is_null()
+ {
+ // Arrange
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope("code", scope);
+ object other = null;
+
+ // Act
+ var result = subject.Equals(other);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_object_should_return_true_when_equal()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject1 = new BsonJavaScriptWithScope("code", scope1);
+ object subject2 = new BsonJavaScriptWithScope("code", scope2);
+
+ // Act
+ var result = subject1.Equals(subject2);
+
+ // Assert
+ result.Should().BeTrue();
+ }
+ [Fact]
+ public void GetHashCode_should_return_different_values_for_unequal_instances()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 1 }, { "y", 3 } };
+ var subject1 = new BsonJavaScriptWithScope("code", scope1);
+ var subject2 = new BsonJavaScriptWithScope("code", scope2);
+ var subject3 = new BsonJavaScriptWithScope("different", scope1);
+
+ // Act
+ var hashCode1 = subject1.GetHashCode();
+ var hashCode2 = subject2.GetHashCode();
+ var hashCode3 = subject3.GetHashCode();
+
+ // Assert
+ hashCode1.Should().NotBe(hashCode2);
+ hashCode1.Should().NotBe(hashCode3);
+ }
+
+ [Fact]
+ public void GetHashCode_should_return_same_value_for_equal_instances()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject1 = new BsonJavaScriptWithScope("code", scope1);
+ var subject2 = new BsonJavaScriptWithScope("code", scope2);
+
+ // Act
+ var hashCode1 = subject1.GetHashCode();
+ var hashCode2 = subject2.GetHashCode();
+
+ // Assert
+ hashCode1.Should().Be(hashCode2);
+ }
+ [Fact]
+ public void Inequality_operator_should_return_false_when_equal()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject1 = new BsonJavaScriptWithScope("code", scope1);
+ var subject2 = new BsonJavaScriptWithScope("code", scope2);
+
+ // Act
+ var result = subject1 != subject2;
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Inequality_operator_should_return_true_when_not_equal()
+ {
+ // Arrange
+ var scope1 = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var scope2 = new BsonDocument { { "x", 1 }, { "y", 3 } };
+ var subject1 = new BsonJavaScriptWithScope("code", scope1);
+ var subject2 = new BsonJavaScriptWithScope("code", scope2);
+ var subject3 = new BsonJavaScriptWithScope("different", scope1);
+
+ // Act
+ var resultDifferentScope = subject1 != subject2;
+ var resultDifferentCode = subject1 != subject3;
+
+ // Assert
+ resultDifferentScope.Should().BeTrue();
+ resultDifferentCode.Should().BeTrue();
+ }
+
+ [Fact]
+ public void Scope_property_should_return_the_scope()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope(code, scope);
+
+ // Act
+ var result = subject.Scope;
+
+ // Assert
+ result.Should().BeSameAs(scope);
+ }
+
+ [Fact]
+ public void ToString_should_return_formatted_string()
+ {
+ // Arrange
+ var code = "function() { return x + y; }";
+ var scope = new BsonDocument { { "x", 1 }, { "y", 2 } };
+ var subject = new BsonJavaScriptWithScope(code, scope);
+ var expectedString = "new BsonJavaScript(\"function() { return x + y; }\", { \"x\" : 1, \"y\" : 2 })";
+
+ // Act
+ var result = subject.ToString();
+
+ // Assert
+ result.Should().Be(expectedString);
+ }
+ }
+}
diff --git a/tests/MongoDB.Bson.Tests/ObjectModel/BsonSymbolTests.cs b/tests/MongoDB.Bson.Tests/ObjectModel/BsonSymbolTests.cs
new file mode 100644
index 00000000000..0908958e698
--- /dev/null
+++ b/tests/MongoDB.Bson.Tests/ObjectModel/BsonSymbolTests.cs
@@ -0,0 +1,285 @@
+/* Copyright 2010-present MongoDB Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using FluentAssertions;
+using Xunit;
+
+namespace MongoDB.Bson.Tests.ObjectModel
+{
+ public class BsonSymbolTests
+ {
+ [Fact]
+ public void BsonType_should_return_Symbol()
+ {
+ // Arrange
+ var symbol = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var bsonType = symbol.BsonType;
+
+ // Assert
+ bsonType.Should().Be(BsonType.Symbol);
+ }
+
+ [Fact]
+ public void CompareTo_BsonSymbol_should_compare_names()
+ {
+ // Arrange
+ var symbol1 = BsonSymbolTable.Lookup("abc");
+ var symbol2 = BsonSymbolTable.Lookup("def");
+ var symbol3 = BsonSymbolTable.Lookup("abc");
+
+ // Act
+ var result1 = symbol1.CompareTo(symbol2);
+ var result2 = symbol2.CompareTo(symbol1);
+ var result3 = symbol1.CompareTo(symbol3);
+
+ // Assert
+ result1.Should().BeLessThan(0);
+ result2.Should().BeGreaterThan(0);
+ result3.Should().Be(0);
+ }
+
+ [Fact]
+ public void CompareTo_BsonSymbol_should_return_1_when_other_is_null()
+ {
+ // Arrange
+ var symbol = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var result = symbol.CompareTo((BsonSymbol)null);
+
+ // Assert
+ result.Should().Be(1);
+ }
+
+ [Fact]
+ public void CompareTo_BsonValue_should_compare_names_when_other_is_BsonString()
+ {
+ // Arrange
+ var symbol = BsonSymbolTable.Lookup("abc");
+ var bsonString = new BsonString("def");
+
+ // Act
+ var result = symbol.CompareTo(bsonString);
+
+ // Assert
+ result.Should().BeLessThan(0);
+ }
+
+ [Fact]
+ public void CompareTo_BsonValue_should_compare_names_when_other_is_BsonSymbol()
+ {
+ // Arrange
+ var symbol1 = BsonSymbolTable.Lookup("abc");
+ var symbol2 = BsonSymbolTable.Lookup("def");
+ BsonValue value2 = symbol2;
+
+ // Act
+ var result = symbol1.CompareTo(value2);
+
+ // Assert
+ result.Should().BeLessThan(0);
+ }
+ [Fact]
+ public void CompareTo_BsonValue_should_return_1_when_other_is_null()
+ {
+ // Arrange
+ var symbol = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var result = symbol.CompareTo((BsonValue)null);
+
+ // Assert
+ result.Should().Be(1);
+ }
+
+ [Fact]
+ public void CompareTo_BsonValue_should_use_CompareTypeTo_when_other_is_different_BsonType()
+ {
+ // Arrange
+ var symbol = BsonSymbolTable.Lookup("abc");
+ var int32 = new BsonInt32(123);
+
+ // Act
+ var result = symbol.CompareTo(int32);
+
+ // Assert
+ // Symbol's enum value is greater than Int32's enum value
+ result.Should().BeGreaterThan(0);
+ }
+ [Fact]
+ public void Create_should_map_value_to_BsonSymbol()
+ {
+ // Arrange
+ var value = "test";
+
+ // Act
+ var symbol = BsonSymbol.Create(value);
+
+ // Assert
+ symbol.Should().NotBeNull();
+ symbol.Name.Should().Be(value);
+ }
+
+ [Fact]
+ public void Create_should_throw_when_value_is_null()
+ {
+ // Act
+ Action act = () => BsonSymbol.Create(null);
+
+ // Assert
+ act.ShouldThrow()
+ .And.ParamName.Should().Be("value");
+ }
+
+ [Fact]
+ public void Equality_operator_should_return_true_when_symbols_are_same_instance()
+ {
+ // Arrange
+ var symbol1 = BsonSymbolTable.Lookup("test");
+ var symbol2 = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var result = symbol1 == symbol2;
+
+ // Assert
+ result.Should().BeTrue();
+ }
+
+ [Fact]
+ public void Equals_BsonSymbol_should_return_false_when_other_is_null()
+ {
+ // Arrange
+ var symbol = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var result = symbol.Equals((BsonSymbol)null);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_BsonSymbol_should_return_true_when_symbols_are_same_instance()
+ {
+ // Arrange
+ var symbol1 = BsonSymbolTable.Lookup("test");
+ var symbol2 = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var result = symbol1.Equals(symbol2);
+
+ // Assert
+ result.Should().BeTrue();
+ }
+ [Fact]
+ public void Equals_object_should_return_false_when_other_is_different_type()
+ {
+ // Arrange
+ var symbol = BsonSymbolTable.Lookup("test");
+ object other = "test";
+
+ // Act
+ var result = symbol.Equals(other);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_object_should_return_false_when_other_is_null()
+ {
+ // Arrange
+ var symbol = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var result = symbol.Equals(null);
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Equals_object_should_return_true_when_other_is_same_symbol()
+ {
+ // Arrange
+ var symbol1 = BsonSymbolTable.Lookup("test");
+ object symbol2 = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var result = symbol1.Equals(symbol2);
+
+ // Assert
+ result.Should().BeTrue();
+ }
+ [Fact]
+ public void GetHashCode_should_return_same_value_for_same_symbol()
+ {
+ // Arrange
+ var symbol1 = BsonSymbolTable.Lookup("test");
+ var symbol2 = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var hashCode1 = symbol1.GetHashCode();
+ var hashCode2 = symbol2.GetHashCode();
+
+ // Assert
+ hashCode1.Should().Be(hashCode2);
+ }
+
+ [Fact]
+ public void Implicit_operator_string_to_BsonSymbol_should_lookup_symbol()
+ {
+ // Arrange
+ string symbolName = "test";
+
+ // Act
+ BsonSymbol symbol = symbolName;
+
+ // Assert
+ symbol.Should().NotBeNull();
+ symbol.Name.Should().Be(symbolName);
+ }
+
+ [Fact]
+ public void Inequality_operator_should_return_false_when_symbols_are_same_instance()
+ {
+ // Arrange
+ var symbol1 = BsonSymbolTable.Lookup("test");
+ var symbol2 = BsonSymbolTable.Lookup("test");
+
+ // Act
+ var result = symbol1 != symbol2;
+
+ // Assert
+ result.Should().BeFalse();
+ }
+ [Fact]
+ public void ToString_should_return_name()
+ {
+ // Arrange
+ var symbolName = "test";
+ var symbol = BsonSymbolTable.Lookup(symbolName);
+
+ // Act
+ var result = symbol.ToString();
+
+ // Assert
+ result.Should().Be(symbolName);
+ }
+ }
+}
diff --git a/tests/MongoDB.Bson.Tests/ObjectModel/BsonTypeMapperOptionsTests.cs b/tests/MongoDB.Bson.Tests/ObjectModel/BsonTypeMapperOptionsTests.cs
new file mode 100644
index 00000000000..48b8670d362
--- /dev/null
+++ b/tests/MongoDB.Bson.Tests/ObjectModel/BsonTypeMapperOptionsTests.cs
@@ -0,0 +1,289 @@
+/* Copyright 2010-present MongoDB Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using FluentAssertions;
+using Xunit;
+
+namespace MongoDB.Bson.Tests.ObjectModel
+{
+ public class BsonTypeMapperOptionsTests
+ {
+ [Fact]
+ public void Clone_should_create_independent_copy_with_same_values()
+ {
+ // Arrange
+ var original = new BsonTypeMapperOptions
+ {
+ DuplicateNameHandling = DuplicateNameHandling.ThrowException,
+ MapBsonArrayTo = typeof(object[]),
+ MapBsonDocumentTo = typeof(Dictionary),
+ MapOldBinaryToByteArray = true
+ };
+
+ // Act
+ var clone = original.Clone();
+
+ // Assert
+ clone.Should().NotBeSameAs(original);
+ clone.DuplicateNameHandling.Should().Be(original.DuplicateNameHandling);
+ clone.MapBsonArrayTo.Should().Be(original.MapBsonArrayTo);
+ clone.MapBsonDocumentTo.Should().Be(original.MapBsonDocumentTo);
+ clone.MapOldBinaryToByteArray.Should().Be(original.MapOldBinaryToByteArray);
+ clone.IsFrozen.Should().BeFalse();
+ }
+
+ [Fact]
+ public void Constructor_should_initialize_default_values()
+ {
+ // Act
+ var options = new BsonTypeMapperOptions();
+
+ // Assert
+ options.DuplicateNameHandling.Should().Be(DuplicateNameHandling.Overwrite);
+ options.MapBsonArrayTo.Should().Be(typeof(List