Example #1
0
        public void SerializePrivateSettersNoConstructor()
        {
            var obj = new PrivateSettersNoConstructor();

            obj.Set(
                Guid.NewGuid().ToString(),
                43,
                new SubClass {
                Name = "Hello, world!"
            },
                new List <double> {
                0.3, -20.3, 321.2
            });
            var collection = database.GetCollection <PrivateSettersNoConstructor>(nameof(PrivateSettersNoConstructor));

            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));
        }
Example #2
0
        public void SerializePrivateSettersNoConstructor()
        {
            var obj = new PrivateSettersNoConstructor();

            obj.Set(
                Guid.NewGuid().ToString(),
                43,
                new SubClass {
                Name = "Hello, world!"
            },
                new List <double> {
                0.3, -20.3, 321.2
            });
            var json            = JsonConvert.SerializeObject(obj);
            var deserializedObj = JsonConvert.DeserializeObject <PrivateSettersNoConstructor>(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));
        }