public async Task Should_Success_Validate_Data_Error_Items()
        {
            var dbContext        = DbContext(GetCurrentMethod());
            var iserviceProvider = GetServiceProviderMock(dbContext).Object;
            Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.
            Setup(x => x.GetService(typeof(SalesDbContext)))
            .Returns(dbContext);

            GarmentSewingBlockingPlanFacade facade = new GarmentSewingBlockingPlanFacade(serviceProvider.Object, dbContext);

            var data = await DataUtil(facade, dbContext).GetNewData();

            GarmentSewingBlockingPlanViewModel vm = new GarmentSewingBlockingPlanViewModel
            {
                BookingOrderNo   = data.BookingOrderNo,
                BookingOrderDate = data.BookingOrderDate,
                DeliveryDate     = data.DeliveryDate,
                Items            = new List <GarmentSewingBlockingPlanItemViewModel> {
                    new GarmentSewingBlockingPlanItemViewModel
                    {
                        IsConfirm        = true,
                        DeliveryDate     = DateTimeOffset.UtcNow.Date.AddDays(-2),
                        WeeklyPlanItemId = data.Items.First().WeeklyPlanItemId,
                        whConfirm        = 63,
                        Unit             = new UnitViewModel
                        {
                            Name = "unit",
                            Id   = 1,
                            Code = "unit"
                        }
                    },
                    new GarmentSewingBlockingPlanItemViewModel
                    {
                        IsConfirm        = true,
                        DeliveryDate     = data.DeliveryDate.Date.AddDays(2),
                        WeeklyPlanItemId = data.Items.First().WeeklyPlanItemId,
                        whConfirm        = 63,
                        Unit             = new UnitViewModel
                        {
                            Name = "unit",
                            Id   = 1,
                            Code = "unit"
                        }
                    },
                    new GarmentSewingBlockingPlanItemViewModel
                    {
                        IsConfirm        = true,
                        DeliveryDate     = data.DeliveryDate.Date.AddDays(2),
                        WeeklyPlanItemId = data.Items.First().WeeklyPlanItemId,
                        whConfirm        = 63,
                    }
                }
            };
            ValidationContext validationContext1 = new ValidationContext(vm, serviceProvider.Object, null);
            var validationResultCreate1          = vm.Validate(validationContext1).ToList();

            Assert.True(validationResultCreate1.Count() > 0);
        }
Esempio n. 2
0
        public void Should_Success_Validate_Data()
        {
            var dbContext       = DbContext(GetCurrentMethod());
            var serviceProvider = GetServiceProviderMock(dbContext).Object;

            GarmentSewingBlockingPlanFacade facade = new GarmentSewingBlockingPlanFacade(serviceProvider, dbContext);

            var data = DataUtil(facade, dbContext).GetNewData();
            GarmentSewingBlockingPlanViewModel nullViewModel = new GarmentSewingBlockingPlanViewModel();

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

            GarmentSewingBlockingPlanViewModel vm = new GarmentSewingBlockingPlanViewModel {
                BookingOrderNo   = data.BookingOrderNo,
                BookingOrderDate = data.BookingOrderDate,
                DeliveryDate     = data.DeliveryDate,
                Items            = new List <GarmentSewingBlockingPlanItemViewModel> {
                    new GarmentSewingBlockingPlanItemViewModel
                    {
                        DeliveryDate = DateTimeOffset.UtcNow.Date.AddDays(-2)
                    },
                    new GarmentSewingBlockingPlanItemViewModel
                    {
                        DeliveryDate = data.DeliveryDate.Date.AddDays(2)
                    }
                }
            };

            Assert.True(vm.Validate(null).Count() > 0);
        }
Esempio n. 3
0
        public void Mapping_With_AutoMapper_Profiles()
        {
            var configuration = new AutoMapper.MapperConfiguration(cfg =>
            {
                cfg.AddProfile <GarmentSewingBlockingPlanMapper>();
            });
            var mapper = configuration.CreateMapper();

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

            Assert.Equal(vm.Id, model.Id);
        }
        public async Task Should_Success_Validate_Data_Null()
        {
            var dbContext        = DbContext(GetCurrentMethod());
            var iserviceProvider = GetServiceProviderMock(dbContext).Object;
            Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.
            Setup(x => x.GetService(typeof(SalesDbContext)))
            .Returns(dbContext);

            GarmentSewingBlockingPlanFacade facade = new GarmentSewingBlockingPlanFacade(serviceProvider.Object, dbContext);

            var data = await DataUtil(facade, dbContext).GetNewData();

            GarmentSewingBlockingPlanViewModel nullViewModel = new GarmentSewingBlockingPlanViewModel();
            //Assert.True(nullViewModel.Validate(null).Count() > 0);

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

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

            Assert.True(validationResultCreate.Count() > 0);
        }