Пример #1
0
 public IEnumerable <IProduct> Resolve(ProductComplexViewModel source, Package destination, IEnumerable <IProduct> destMember, ResolutionContext context)
 {
     if (source.Parts != null)
     {
         source.Parts.ToList().ForEach(x => destination.Add(context.Mapper.Map <IProduct>(x)));
     }
     //return destination.Parts;
     return(null);
 }
Пример #2
0
        public void MappingPackage_IsWorkingProperly()
        {
            string pack  = "Pack";
            string prod1 = "Prod1";
            string prod2 = "Prod2";

            var req = new ProductComplexViewModel
            {
                Code  = pack,
                Type  = "Type0",
                Parts = new List <ProductViewModel>
                {
                    new ProductViewModel
                    {
                        Code = prod1,
                        Type = "Type1",
                    },
                    new ProductViewModel
                    {
                        Code = prod2,
                        Type = "Type2",
                    },
                }
            };

            var mapper = GetRepository <IMapper>();

            var reqModel = mapper.Map <IProduct>(req);

            Assert.IsTrue(reqModel is IPackage);

            IPackage reqPackage = (IPackage)reqModel;

            Assert.IsTrue(reqPackage?.Code == req.Code);
            Assert.IsTrue(reqPackage?.Type == req.Type);
            Assert.IsTrue(reqPackage?.Parts.ToList().Count == 2);
            Assert.IsTrue(reqPackage?.Parts.ToList()[0].Code == prod1);
            Assert.IsTrue(reqPackage?.Parts.ToList()[1].Code == prod2);
        }