Skip to content

Commit 91f770a

Browse files
committed
Add failing SortedList serialization and deserialization tests.
1 parent b3c7e17 commit 91f770a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

source/MongoDB.Tests/UnitTests/Serialization/SerializationFactoryTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,33 @@ public void CanDeserializeIntGenericDictionaryWithComplexType()
203203
Assert.IsTrue(prop.Dict[2].Name == "b");
204204
}
205205

206+
public class SortedListDictionary
207+
{
208+
public SortedList<string, int> Property { get; set; }
209+
}
210+
211+
[Test]
212+
public void CanSerializeSortedListDictionary()
213+
{
214+
var expectedBson = Serialize<Document>(new Document("Property", new Document { { "key1", 10 }, { "key2", 20 } }));
215+
var obj = new SortedListDictionary { Property = new SortedList<string, int> { { "key1", 10 }, { "key2", 20 } } };
216+
var bson = Serialize<GenericDictionary>(obj);
217+
Assert.AreEqual(expectedBson, bson);
218+
}
219+
220+
[Test]
221+
public void CanDeserializeSortedListDictionary()
222+
{
223+
var bson = Serialize<Document>(new Document("Property", new Document { { "key1", 10 }, { "key2", 20 } }));
224+
var prop = Deserialize<SortedListDictionary>(bson);
225+
226+
Assert.IsNotNull(prop);
227+
Assert.IsNotNull(prop.Property);
228+
Assert.AreEqual(2, prop.Property.Count);
229+
Assert.Contains(new KeyValuePair<string, int>("key1", 10), prop.Property);
230+
Assert.Contains(new KeyValuePair<string, int>("key2", 20), prop.Property);
231+
}
232+
206233
public class HashSetHelper
207234
{
208235
public HashSet<string> Property { get; set; }

0 commit comments

Comments
 (0)