Esempio n. 1
0
        public void SerializeNoSettersOneToOneConstructorAndPartialConstructor()
        {
            var obj = new NoSettersOneToOneConstructorAndPartialConstructor(
                Guid.NewGuid().ToString(),
                43,
                new List <double> {
                0.3, -20.3, 321.2
            },
                new SubClass {
                Name = "Hello, world!"
            });
            var json            = JsonConvert.SerializeObject(obj);
            var deserializedObj = JsonConvert.DeserializeObject <NoSettersOneToOneConstructorAndPartialConstructor>(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));
        }
Esempio n. 2
0
        public void SerializeNoSettersOneToOneConstructorAndPartialConstructor()
        {
            var obj = new NoSettersOneToOneConstructorAndPartialConstructor(
                Guid.NewGuid().ToString(),
                43,
                new List <double> {
                0.3, -20.3, 321.2
            },
                new SubClass {
                Name = "Hello, world!"
            });
            var collection = database.GetCollection <NoSettersOneToOneConstructorAndPartialConstructor>(nameof(NoSettersOneToOneConstructorAndPartialConstructor));

            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));
        }