Beispiel #1
0
        public void Should_Success_Validate_Data()
        {
            GarmentPurchaseRequestViewModel nullViewModel = new GarmentPurchaseRequestViewModel();

            Assert.True(nullViewModel.Validate(null).Count() > 0);

            GarmentPurchaseRequestViewModel viewModel = new GarmentPurchaseRequestViewModel
            {
                Buyer = new BuyerViewModel(),
                Unit  = new UnitViewModel(),
                Items = new List <GarmentPurchaseRequestItemViewModel>
                {
                    new GarmentPurchaseRequestItemViewModel(),
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Product     = new ProductViewModel(),
                        Uom         = new UomViewModel(),
                        Category    = new CategoryViewModel(),
                        BudgetPrice = -1
                    }
                }
            };

            Assert.True(viewModel.Validate(null).Count() > 0);
        }
Beispiel #2
0
        public void Should_Success_Validate_Data()
        {
            GarmentPurchaseRequestViewModel nullViewModel = new GarmentPurchaseRequestViewModel();

            Assert.True(nullViewModel.Validate(null).Count() > 0);

            GarmentPurchaseRequestViewModel viewModel = new GarmentPurchaseRequestViewModel
            {
                Buyer = new BuyerViewModel(),
                Unit  = new UnitViewModel(),
                Items = new List <GarmentPurchaseRequestItemViewModel>
                {
                    new GarmentPurchaseRequestItemViewModel(),
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Product     = new ProductViewModel(),
                        Uom         = new UomViewModel(),
                        Category    = new CategoryViewModel(),
                        BudgetPrice = -1
                    }
                },
                IsValidatedMD1          = false,
                ValidatedMD1By          = null,
                ValidatedMD1Date        = DateTimeOffset.MinValue,
                IsValidatedMD2          = false,
                ValidatedMD2By          = null,
                ValidatedMD2Date        = DateTimeOffset.MinValue,
                IsValidatedPurchasing   = false,
                ValidatedPurchasingBy   = null,
                ValidatedPurchasingDate = DateTimeOffset.MinValue,
            };

            Assert.True(viewModel.Validate(null).Count() > 0);
        }
Beispiel #3
0
        public async Task Should_Success_Validate_Data_Duplicate()
        {
            GarmentPurchaseRequestFacade facade = new GarmentPurchaseRequestFacade(ServiceProvider, _dbContext(GetCurrentMethod()));
            var model = await dataUtil(facade, GetCurrentMethod()).GetTestData();

            GarmentPurchaseRequestViewModel viewModel = new GarmentPurchaseRequestViewModel();

            viewModel.RONo = model.RONo;

            Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.
            Setup(x => x.GetService(typeof(PurchasingDbContext)))
            .Returns(_dbContext(GetCurrentMethod()));

            ValidationContext validationContext = new ValidationContext(viewModel, serviceProvider.Object, null);

            var validationResultCreate = viewModel.Validate(validationContext).ToList();

            var errorDuplicateRONo = validationResultCreate.SingleOrDefault(r => r.ErrorMessage.Equals("RONo sudah ada"));

            Assert.NotNull(errorDuplicateRONo);

            viewModel.Id    = model.Id;
            viewModel.Items = new List <GarmentPurchaseRequestItemViewModel>();
            viewModel.Items.AddRange(model.Items.Select(i => new GarmentPurchaseRequestItemViewModel
            {
                PO_SerialNumber = i.PO_SerialNumber
            }));

            var validationResultUpdate = viewModel.Validate(validationContext).ToList();
            var errorItems             = validationResultUpdate.SingleOrDefault(r => r.MemberNames.Contains("Items"));
            List <Dictionary <string, object> > errorItemsMessage = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(errorItems.ErrorMessage);
            var errorDuplicatePO_SerialNumber = errorItemsMessage.FirstOrDefault(m => m.ContainsValue("PO SerialNumber sudah ada"));

            Assert.NotNull(errorDuplicatePO_SerialNumber);
        }
Beispiel #4
0
        public void Should_Success_Validate_Data_Master()
        {
            GarmentPurchaseRequestViewModel viewModel = new GarmentPurchaseRequestViewModel
            {
                PRType = "MASTER",
                Buyer  = new BuyerViewModel(),
                Unit   = new UnitViewModel(),
                Items  = new List <GarmentPurchaseRequestItemViewModel>
                {
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        PriceUom = new UomViewModel()
                    },
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        Composition = new GarmentProductViewModel {
                            Composition = "Composition"
                        },
                    },
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        Composition = new GarmentProductViewModel {
                            Composition = "Composition"
                        },
                        Const = new GarmentProductViewModel {
                            Const = "Const"
                        }
                    },
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        Composition = new GarmentProductViewModel {
                            Composition = "Composition"
                        },
                        Const = new GarmentProductViewModel {
                            Const = "Const"
                        },
                        Yarn = new GarmentProductViewModel {
                            Yarn = "Yarn"
                        },
                    },
                    new GarmentPurchaseRequestItemViewModel
                    {
                        Category = new CategoryViewModel {
                            Name = "FABRIC"
                        },
                        Composition = new GarmentProductViewModel {
                            Composition = "Composition"
                        },
                        Const = new GarmentProductViewModel {
                            Const = "Const"
                        },
                        Yarn = new GarmentProductViewModel {
                            Yarn = "Yarn"
                        },
                        Width = new GarmentProductViewModel {
                            Width = "Width"
                        },
                    },
                }
            };

            Assert.True(viewModel.Validate(null).Count() > 0);
        }