public void Map_TestMappingCommonlyNamedProperties()
        {
            var expected = new SaleItem
            {
                Description = "Test SaleItem",
                Id = 1,
                Weight = 3.4
            };

            var actual = Yam<SaleItem, Product>.Map(expected);

            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(0, actual.ShippingWeight);
        }
        public void Map_TestMappingUsingConstantExpressions()
        {
            var expected = new SaleItem
            {
                Description = "Test SaleItem",
                Id = 1,
                Weight = 3.4
            };

            var actual = Yam<SaleItem, Product>
                .Use(saleItem => 42, product => product.ShippingWeight)
                .Map(expected);

            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(42, actual.ShippingWeight);
        }
        public void Map_CreatesAMap_AndAddsItToTheYam()
        {
            var map = Yam.GetMap<SaleItem, Product>();
            Assert.IsNull(map);

            var expected = new SaleItem
            {
                Description = "Test SaleItem",
                Id = 1,
                Weight = 3.4
            };

            Yam<SaleItem, Product>.Map(expected);

            map = Yam.GetMap<SaleItem, Product>();
            Assert.IsNotNull(map);
        }
示例#4
0
        public void Map_TestMappingPropertiesThatAreGenericLists_WhenAMappingForThoseDataTypesExists()
        {
            SaleItem saleItem1 = new SaleItem { Description = "SaleItem 1", Id = 1, Weight = 3.5 };
            SaleItem saleItem2 = new SaleItem { Description = "SaleItem 2", Id = 2, Weight = 4.7 };
            List<SaleItem> saleItems = new List<SaleItem> { saleItem1, saleItem2 };
            Order order = new Order { Items = saleItems };

            Yam.CreateMap(typeof(Order), typeof(Invoice));
            Yam.CreateMap(typeof(SaleItem), typeof(Product));
            Yam.AddPropertyMap(typeof(SaleItem), typeof(Product), "Weight", "ShippingWeight");

            Invoice invoice = (Invoice)Yam.Map(order, typeof(Invoice));

            Assert.AreEqual(order.Items.Count, invoice.Items.Count);
            foreach (var item in order.Items)
                Assert.IsNotNull(invoice.Items.FirstOrDefault(it => it.Description == item.Description && it.Id == item.Id && it.ShippingWeight == item.Weight));
        }