Esempio n. 1
0
        public async Task Should_Success_Validate_Data()
        {
            GarmentUnitDeliveryOrderViewModel viewModel = new GarmentUnitDeliveryOrderViewModel {
                UnitRequest = new Lib.ViewModels.NewIntegrationViewModel.UnitViewModel
                {
                    Id = "1"
                },
                UnitSender = new Lib.ViewModels.NewIntegrationViewModel.UnitViewModel
                {
                    Id = "1"
                },
                UnitDOType = "TRANSFER"
            };

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

            GarmentUnitDeliveryOrderViewModel viewModelNullItems = new GarmentUnitDeliveryOrderViewModel
            {
                RONo = "RONo"
            };

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

            GarmentUnitDeliveryOrderViewModel viewModelWithItems = new GarmentUnitDeliveryOrderViewModel
            {
                RONo  = "RONo",
                Items = new List <GarmentUnitDeliveryOrderItemViewModel>
                {
                    new GarmentUnitDeliveryOrderItemViewModel
                    {
                        IsSave   = true,
                        Quantity = 0
                    }
                }
            };

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

            GarmentUnitDeliveryOrderViewModel viewModelLL = new GarmentUnitDeliveryOrderViewModel
            {
                UnitRequest = new Lib.ViewModels.NewIntegrationViewModel.UnitViewModel
                {
                    Id = "1"
                },
                UnitSender = new Lib.ViewModels.NewIntegrationViewModel.UnitViewModel
                {
                    Id = "1"
                },
                UnitDOType = "LAIN-LAIN"
            };

            Assert.True(viewModelLL.Validate(null).Count() > 0);
        }
        public async Task Should_Success_Validate_Data()
        {
            GarmentUnitDeliveryOrderViewModel viewModelNullItems = new GarmentUnitDeliveryOrderViewModel
            {
                DONo = "DONo"
            };

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

            GarmentUnitDeliveryOrderViewModel viewModelWithItems = new GarmentUnitDeliveryOrderViewModel
            {
                DONo  = "DONo",
                Items = new List <GarmentUnitDeliveryOrderItemViewModel>
                {
                    new GarmentUnitDeliveryOrderItemViewModel
                    {
                        IsSave   = true,
                        Quantity = 0
                    }
                }
            };

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

            var garmentUnitReceiptNoteFacade = new GarmentUnitReceiptNoteFacade(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            var data = await garmentUnitReceiptNoteDataUtil(garmentUnitReceiptNoteFacade, GetCurrentMethod()).GetTestData();

            var item = data.Items.First();

            var serviceProvider = GetServiceProvider();

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

            GarmentUnitDeliveryOrderViewModel viewModelWithItemsQuantityOver = new GarmentUnitDeliveryOrderViewModel
            {
                DONo  = "DONo",
                Items = new List <GarmentUnitDeliveryOrderItemViewModel>
                {
                    new GarmentUnitDeliveryOrderItemViewModel
                    {
                        URNItemId = item.Id,
                        IsSave    = true,
                        Quantity  = (double)(item.SmallQuantity - item.OrderQuantity + 1)
                    }
                }
            };

            System.ComponentModel.DataAnnotations.ValidationContext validationDuplicateContext = new System.ComponentModel.DataAnnotations.ValidationContext(viewModelWithItemsQuantityOver, serviceProvider.Object, null);
            Assert.True(viewModelWithItemsQuantityOver.Validate(validationDuplicateContext).Count() > 0);
        }
        public async Task Should_Success_Validate_Data()
        {
            GarmentUnitDeliveryOrderViewModel viewModel = new GarmentUnitDeliveryOrderViewModel {
                UnitRequest = new Lib.ViewModels.NewIntegrationViewModel.UnitViewModel
                {
                    Id = "1"
                },
                UnitSender = new Lib.ViewModels.NewIntegrationViewModel.UnitViewModel
                {
                    Id = "1"
                },
                UnitDOType = "TRANSFER"
            };

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

            GarmentUnitDeliveryOrderViewModel viewModelNullItems = new GarmentUnitDeliveryOrderViewModel
            {
                RONo = "RONo"
            };

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

            GarmentUnitDeliveryOrderViewModel viewModelWithItems = new GarmentUnitDeliveryOrderViewModel
            {
                RONo  = "RONo",
                Items = new List <GarmentUnitDeliveryOrderItemViewModel>
                {
                    new GarmentUnitDeliveryOrderItemViewModel
                    {
                        IsSave   = true,
                        Quantity = 0
                    }
                }
            };

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

            var garmentUnitReceiptNoteFacade = new GarmentUnitReceiptNoteFacade(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            var dataUtil = garmentUnitReceiptNoteDataUtil(garmentUnitReceiptNoteFacade, GetCurrentMethod());
            var data     = await dataUtil.GetTestData();

            var item = data.Items.First();

            var serviceProvider = GetServiceProvider();

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

            GarmentUnitDeliveryOrderViewModel viewModelWithItemsQuantityOver = new GarmentUnitDeliveryOrderViewModel
            {
                RONo  = "RONo",
                Items = new List <GarmentUnitDeliveryOrderItemViewModel>
                {
                    new GarmentUnitDeliveryOrderItemViewModel
                    {
                        URNItemId = item.Id,
                        DOItemsId = (int)dataUtil.ReadDOItemsByURNItemId((int)item.Id).Id,
                        IsSave    = true,
                        Quantity  = (double)10000
                    }
                }
            };

            System.ComponentModel.DataAnnotations.ValidationContext validationDuplicateContext = new System.ComponentModel.DataAnnotations.ValidationContext(viewModelWithItemsQuantityOver, serviceProvider.Object, null);
            Assert.True(viewModelWithItemsQuantityOver.Validate(validationDuplicateContext).Count() > 0);

            GarmentUnitDeliveryOrderViewModel viewModel1 = new GarmentUnitDeliveryOrderViewModel
            {
                UnitDOType = "MARKETING",
                UnitDODate = DateTimeOffset.Now.AddDays(3)
            };

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