Beispiel #1
0
        public void SerializePublicSettersNoConstructor()
        {
            var obj = new PublicSettersNoConstructor
            {
                Id       = Guid.NewGuid().ToString(),
                Number   = 43,
                SubClass = new SubClass {
                    Name = "Hello, world!"
                },
                Values = new List <double> {
                    0.3, -20.3, 321.2
                }
            };
            var collection = database.GetCollection <PublicSettersNoConstructor>(nameof(PublicSettersNoConstructor));

            collection.InsertOne(obj);
            var deserializedObj = collection.Find(x => x.Id == obj.Id).FirstOrDefault();

            Assert.That(deserializedObj, Is.Not.Null);
            Assert.That(deserializedObj.Id, Is.EqualTo(obj.Id));
            Assert.That(deserializedObj.Number, Is.EqualTo(obj.Number));
            CollectionAssert.AreEqual(obj.Values, deserializedObj.Values);
            Assert.That(deserializedObj.SubClass, Is.Not.Null);
            Assert.That(deserializedObj.SubClass.Name, Is.EqualTo(obj.SubClass.Name));
        }
Beispiel #2
0
        public void SerializePublicSettersNoConstructor()
        {
            var obj = new PublicSettersNoConstructor
            {
                Id       = Guid.NewGuid().ToString(),
                Number   = 43,
                SubClass = new SubClass {
                    Name = "Hello, world!"
                },
                Values = new List <double> {
                    0.3, -20.3, 321.2
                }
            };
            var json            = JsonConvert.SerializeObject(obj);
            var deserializedObj = JsonConvert.DeserializeObject <PublicSettersNoConstructor>(json);

            Assert.That(deserializedObj, Is.Not.Null);
            Assert.That(deserializedObj.Id, Is.EqualTo(obj.Id));
            Assert.That(deserializedObj.Number, Is.EqualTo(obj.Number));
            CollectionAssert.AreEqual(obj.Values, deserializedObj.Values);
            Assert.That(deserializedObj.SubClass, Is.Not.Null);
            Assert.That(deserializedObj.SubClass.Name, Is.EqualTo(obj.SubClass.Name));
        }