예제 #1
0
        public void Mapping_With_AutoMapper_Profiles()
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <FinishingPrintingCostCalculationMapper>();
                cfg.AddProfile <FinishingPrintingCostCalculationMachineMapper>();
                cfg.AddProfile <FinishingPrintingCostCalculationChemicalMapper>();
            });
            var mapper = configuration.CreateMapper();

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

            Assert.Equal(vm.Id, model.Id);
        }
예제 #2
0
        public async void ValidateVM()
        {
            var vm = new FinishingPrintingCostCalculationViewModel()
            {
                Remark = "1",

                ProductionOrderNo         = "ee",
                IsPosted                  = false,
                ManufacturingServiceCost  = 1,
                HelperMaterial            = 1,
                MiscMaterial              = 1,
                Lubricant                 = 1,
                SparePart                 = 1,
                StructureMaintenance      = 1,
                MachineMaintenance        = 1,
                Embalase                  = 1,
                GeneralAdministrationCost = 1,
                DirectorOfficeCost        = 1,
                BankMiscCost              = 1
            };

            var sp = GetServiceProviderMock(DbContext(GetCurrentMethod()));

            var facade = new FinishingPrintingCostCalculationFacade(sp.Object, DbContext(GetCurrentMethod()));

            sp.Setup(s => s.GetService(typeof(IFinishingPrintingCostCalculationService)))
            .Returns(facade);

            var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(vm, sp.Object, null);
            var response          = vm.Validate(validationContext);

            Assert.NotEmpty(response);
            Assert.NotNull(vm.Remark);
            Assert.NotNull(vm.ProductionOrderNo);
            Assert.False(vm.IsPosted);


            var data = await DataUtil(facade, DbContext(GetCurrentMethod())).GetTestData();

            vm.PreSalesContract = new FinishingPrintingPreSalesContractViewModel()
            {
                Id   = data.PreSalesContractId,
                Unit = new UnitViewModel()
                {
                    Name = data.UnitName
                }
            };
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.PreSalesContract = new FinishingPrintingPreSalesContractViewModel()
            {
                Id   = 0,
                Unit = new UnitViewModel()
                {
                    Name = "Printing"
                }
            };

            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.Instruction = new InstructionViewModel()
            {
                Id = 1
            };
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.UOM = new UomViewModel()
            {
                Id = 1,
            };
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.Sales = new AccountViewModel()
            {
                profile = new ProfileViewModel()
                {
                    firstname = "a",
                    lastname  = "a"
                },
                UserName = "******"
            };
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.Color = "a";
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.Greige = new ProductViewModel()
            {
                Id = 1
            };
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.Date  = DateTimeOffset.UtcNow;
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.Material = new MaterialViewModel()
            {
                Id = 1
            };
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.CurrencyRate = 1;
            response        = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.ProductionUnitValue = 1;
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.ScreenCost = 1;
            response      = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.ScreenDocumentNo = "as";
            response            = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.PreparationFabricWeight = 1;
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.RFDFabricWeight = 1;
            response           = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.ActualPrice = 1;
            response       = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.ConfirmPrice = 1;
            response        = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.FreightCost = 1;
            response       = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.Machines = new List <FinishingPrintingCostCalculationMachineViewModel>()
            {
                new FinishingPrintingCostCalculationMachineViewModel()
            };
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.Machines = new List <FinishingPrintingCostCalculationMachineViewModel>()
            {
                new FinishingPrintingCostCalculationMachineViewModel()
                {
                    Chemicals = new List <FinishingPrintingCostCalculationChemicalViewModel>()
                    {
                        new FinishingPrintingCostCalculationChemicalViewModel()
                    }
                }
            };
            response = vm.Validate(validationContext);
            Assert.NotEmpty(response);

            vm.Machines = new List <FinishingPrintingCostCalculationMachineViewModel>()
            {
                new FinishingPrintingCostCalculationMachineViewModel()
                {
                    Machine = new MachineViewModel()
                    {
                        Id       = 1,
                        Name     = "a",
                        Process  = "a",
                        LPG      = 1,
                        Solar    = 1,
                        Steam    = 1,
                        Water    = 1,
                        Electric = 1,
                    },
                    Step = new StepViewModel()
                    {
                        Id      = 1,
                        Process = "a"
                    },
                    Depretiation      = 1,
                    Index             = 1,
                    CostCalculationId = 1,

                    Chemicals = new List <FinishingPrintingCostCalculationChemicalViewModel>()
                    {
                        new FinishingPrintingCostCalculationChemicalViewModel()
                        {
                            Chemical = new ProductViewModel()
                            {
                                Id    = 1,
                                Price = 1,
                                Name  = "a"
                            },
                            ChemicalQuantity         = 1,
                            CostCalculationId        = 1,
                            CostCalculationMachineId = 1
                        }
                    }
                }
            };

            response = vm.Validate(validationContext);
            Assert.Empty(response);
        }
예제 #3
0
        public void ValidateVM()
        {
            var vm = new FinishingPrintingCostCalculationViewModel()
            {
                Remark = "1",

                ProductionOrderNo         = "ee",
                IsPosted                  = false,
                ManufacturingServiceCost  = 1,
                HelperMaterial            = 1,
                MiscMaterial              = 1,
                Lubricant                 = 1,
                SparePart                 = 1,
                StructureMaintenance      = 1,
                MachineMaintenance        = 1,
                Embalase                  = 1,
                GeneralAdministrationCost = 1,
                DirectorOfficeCost        = 1,
                BankMiscCost              = 1
            };
            var response = vm.Validate(null);

            Assert.NotEmpty(response);
            Assert.NotNull(vm.Remark);
            Assert.NotNull(vm.ProductionOrderNo);
            Assert.False(vm.IsPosted);

            vm.PreSalesContract = new FinishingPrintingPreSalesContractViewModel()
            {
                Id   = 1,
                Unit = new UnitViewModel()
                {
                    Name = "Printing"
                }
            };
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.Instruction = new InstructionViewModel()
            {
                Id = 1
            };
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.UOM = new UomViewModel()
            {
                Id = 1,
            };
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.Sales = new AccountViewModel()
            {
                profile = new ProfileViewModel()
                {
                    firstname = "a",
                    lastname  = "a"
                },
                UserName = "******"
            };
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.Color = "a";
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.Greige = new ProductViewModel()
            {
                Id = 1
            };
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.Date  = DateTimeOffset.UtcNow;
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.Material = new MaterialViewModel()
            {
                Id = 1
            };
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.CurrencyRate = 1;
            response        = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.ProductionUnitValue = 1;
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.ScreenCost = 1;
            response      = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.ScreenDocumentNo = "as";
            response            = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.PreparationFabricWeight = 1;
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.RFDFabricWeight = 1;
            response           = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.ActualPrice = 1;
            response       = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.ConfirmPrice = 1;
            response        = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.FreightCost = 1;
            response       = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.Machines = new List <FinishingPrintingCostCalculationMachineViewModel>()
            {
                new FinishingPrintingCostCalculationMachineViewModel()
            };
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.Machines = new List <FinishingPrintingCostCalculationMachineViewModel>()
            {
                new FinishingPrintingCostCalculationMachineViewModel()
                {
                    Chemicals = new List <FinishingPrintingCostCalculationChemicalViewModel>()
                    {
                        new FinishingPrintingCostCalculationChemicalViewModel()
                    }
                }
            };
            response = vm.Validate(null);
            Assert.NotEmpty(response);

            vm.Machines = new List <FinishingPrintingCostCalculationMachineViewModel>()
            {
                new FinishingPrintingCostCalculationMachineViewModel()
                {
                    Machine = new MachineViewModel()
                    {
                        Id       = 1,
                        Name     = "a",
                        Process  = "a",
                        LPG      = 1,
                        Solar    = 1,
                        Steam    = 1,
                        Water    = 1,
                        Electric = 1,
                    },
                    Step = new StepViewModel()
                    {
                        Id      = 1,
                        Process = "a"
                    },
                    Depretiation      = 1,
                    Index             = 1,
                    CostCalculationId = 1,

                    Chemicals = new List <FinishingPrintingCostCalculationChemicalViewModel>()
                    {
                        new FinishingPrintingCostCalculationChemicalViewModel()
                        {
                            Chemical = new ProductViewModel()
                            {
                                Id    = 1,
                                Price = 1,
                                Name  = "a"
                            },
                            ChemicalQuantity         = 1,
                            CostCalculationId        = 1,
                            CostCalculationMachineId = 1
                        }
                    }
                }
            };

            response = vm.Validate(null);
            Assert.Empty(response);
        }