コード例 #1
0
        public void Mapping_With_AutoMapper_Profiles()
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <ColorReceiptProfile>();
            });
            var mapper = configuration.CreateMapper();

            ColorReceiptViewModel vm = new ColorReceiptViewModel {
                Id = 1
            };
            ColorReceiptModel model = mapper.Map <ColorReceiptModel>(vm);

            Assert.Equal(vm.Id, model.Id);
        }
コード例 #2
0
        public virtual void ValidateVM()
        {
            var dbContext       = DbContext(GetCurrentMethod());
            var serviceProvider = GetServiceProviderMock(dbContext).Object;

            ColorReceiptFacade facade = new ColorReceiptFacade(serviceProvider, dbContext);

            var data = new ColorReceiptViewModel()
            {
                ColorCode         = "test",
                Remark            = "test",
                Cloth             = "test",
                ColorReceiptItems = new List <ColorReceiptItemViewModel>()
                {
                    new ColorReceiptItemViewModel()
                }
            };

            System.ComponentModel.DataAnnotations.ValidationContext validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            var response = data.Validate(validationContext);

            Assert.NotEmpty(response);
            data.ColorName    = "test";
            validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response          = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.Technician = new TechnicianViewModel()
            {
                Name      = "a",
                IsDefault = true
            };
            validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response          = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.ChangeTechnician = true;
            validationContext     = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.NewTechnician = "test";
            data.Type          = "type";
            validationContext  = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response           = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.ColorReceiptItems = new List <ColorReceiptItemViewModel>();
            validationContext      = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.ColorReceiptItems = new List <ColorReceiptItemViewModel>()
            {
                new ColorReceiptItemViewModel()
                {
                    Product = new Lib.ViewModels.Integration.Master.ProductIntegrationViewModel()
                    {
                        Id   = 1,
                        Code = "code",
                        Name = "name"
                    },
                    Quantity = 1001
                }
            };
            validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response          = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.ColorReceiptItems = new List <ColorReceiptItemViewModel>()
            {
                new ColorReceiptItemViewModel()
                {
                    Product = new Lib.ViewModels.Integration.Master.ProductIntegrationViewModel()
                    {
                        Id   = 1,
                        Code = "code",
                        Name = "name"
                    },
                    Quantity = 3
                }
            };
            validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response          = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.DyeStuffReactives = new List <ColorReceiptDyeStuffReactiveViewModel>();
            validationContext      = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.DyeStuffReactives = new List <ColorReceiptDyeStuffReactiveViewModel>()
            {
                new ColorReceiptDyeStuffReactiveViewModel()
                {
                },
                new ColorReceiptDyeStuffReactiveViewModel()
                {
                    Name     = "air",
                    Quantity = -1
                }
            };
            validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response          = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.DyeStuffReactives = new List <ColorReceiptDyeStuffReactiveViewModel>()
            {
                new ColorReceiptDyeStuffReactiveViewModel()
                {
                },
                new ColorReceiptDyeStuffReactiveViewModel()
                {
                    Name     = "air",
                    Quantity = 1
                }
            };
            validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response          = data.Validate(validationContext);

            Assert.NotEmpty(response);

            data.DyeStuffReactives = new List <ColorReceiptDyeStuffReactiveViewModel>()
            {
                new ColorReceiptDyeStuffReactiveViewModel()
                {
                    Name     = "test",
                    Quantity = 1
                },
                new ColorReceiptDyeStuffReactiveViewModel()
                {
                    Name     = "air",
                    Quantity = 1
                }
            };
            validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(data, serviceProvider, null);
            response          = data.Validate(validationContext);

            Assert.NotEmpty(response);

            ColorReceiptItemViewModel vmItem = new ColorReceiptItemViewModel()
            {
                Product = new Lib.ViewModels.Integration.Master.ProductIntegrationViewModel()
                {
                    Id   = 1,
                    Name = "a"
                },
                Quantity = 1
            };

            Assert.NotEqual(0, vmItem.Quantity);
        }