public void Validate_Success()
        {
            Mock <IServiceProvider>   serviceProvider = new Mock <IServiceProvider>();
            ColorReceiptItemViewModel viewModel       = new ColorReceiptItemViewModel();

            ValidateService service = new ValidateService(serviceProvider.Object);

            service.Validate(viewModel);
        }
Esempio n. 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);
        }