namespace MongoDB.Bson.FSharp.Tests open System open System.Linq open System.Collections.Generic open MongoDB.Bson open MongoDB.Bson.Serialization open MongoDB.Bson.Serialization.Attributes open NUnit.Framework [] type C() = let mutable _p : string = null member x.P with public get() : string = _p and public set(value) = _p <- value type T() = let mutable _id : IDictionary = null member x.ID with public get() : IDictionary = _id and public set(value) = _id <- value [] type DictionaryGenericSerializerTests() = [] member this.TestDictOperatorSerialization() = let id = [ "A" :> obj, C (P = "x") :> obj] |> dict let o = new T(ID = id) let json = BsonExtensionMethods.ToJson(o) let rep = "{ 'A' : { '_t' : 'DictionaryGenericSerializers.C', 'P' : 'x' } }" let expected = "{ 'ID' : #R }".Replace("#R", rep).Replace("'", "\"") Assert.AreEqual(expected, json); let bson = BsonExtensionMethods.ToBson(o) let rehydrated = BsonSerializer.Deserialize(bson) Assert.IsInstanceOf>(rehydrated.ID); Assert.IsTrue(Enumerable.SequenceEqual(bson, rehydrated.ToBson()));