コード例 #1
0
ファイル: AttributeMapperTest.cs プロジェクト: apkd/LiteDB
        public void AttributeMapper_Test()
        {
            var mapper = new BsonMapper();

            var c0 = new AttrCustomer
            {
                MyPK = 1,
                NameCustomer = "J",
                Address = new AttrAddress { AddressPK = 5, Street = "R" },
                Ignore = true,
                Addresses = new List<AttrAddress>()
                {
                    new AttrAddress { AddressPK = 3 },
                    new AttrAddress { AddressPK = 4 }
                }
            };

            var j0 = JsonSerializer.Serialize(mapper.ToDocument(c0));

            var c1 = mapper.ToObject<AttrCustomer>(JsonSerializer.Deserialize(j0).AsDocument);

            Assert.AreEqual(c0.MyPK, c1.MyPK);
            Assert.AreEqual(c0.NameCustomer, c1.NameCustomer);
            Assert.AreEqual(false, c1.Ignore);
            Assert.AreEqual(c0.Address.AddressPK, c1.Address.AddressPK);
            Assert.AreEqual(c0.Addresses[0].AddressPK, c1.Addresses[0].AddressPK);
            Assert.AreEqual(c0.Addresses[1].AddressPK, c1.Addresses[1].AddressPK);
        }
コード例 #2
0
        public void AttributeMapper_Test()
        {
            var mapper = new BsonMapper();

            var c0 = new AttrCustomer
            {
                MyPK         = 1,
                NameCustomer = "J",
                Address      = new AttrAddress {
                    AddressPK = 5, Street = "R"
                },
                Ignore    = true,
                Addresses = new List <AttrAddress>()
                {
                    new AttrAddress {
                        AddressPK = 3
                    },
                    new AttrAddress {
                        AddressPK = 4
                    }
                }
            };

            var j0 = JsonSerializer.Serialize(mapper.ToDocument(c0));

            var c1 = mapper.ToObject <AttrCustomer>(JsonSerializer.Deserialize(j0).AsDocument);

            Assert.AreEqual(c0.MyPK, c1.MyPK);
            Assert.AreEqual(c0.NameCustomer, c1.NameCustomer);
            Assert.AreEqual(false, c1.Ignore);
            Assert.AreEqual(c0.Address.AddressPK, c1.Address.AddressPK);
            Assert.AreEqual(c0.Addresses[0].AddressPK, c1.Addresses[0].AddressPK);
            Assert.AreEqual(c0.Addresses[1].AddressPK, c1.Addresses[1].AddressPK);
        }