Example #1
0
        public void GetDistinctProductWidth_Return_InternalServerError()
        {
            //Setup
            Mock <IServiceProvider> serviceProvider = GetServiceProvider();
            GarmentProductService   service         = new GarmentProductService(serviceProvider.Object);

            serviceProvider.Setup(s => s.GetService(typeof(GarmentProductService))).Returns(service);

            //Act
            IActionResult response = GetController(service).GetDistinctProductWidth();


            //Assert
            int statusCode = this.GetStatusCode(response);

            Assert.Equal((int)HttpStatusCode.InternalServerError, statusCode);
        }
Example #2
0
        public void GetDistinctProductWidth_Return_Ok()
        {
            //Setup
            CoreDbContext           dbContext       = GetDbContext(GetCurrentAsyncMethod());
            Mock <IServiceProvider> serviceProvider = GetServiceProvider();

            GarmentProductService service = new GarmentProductService(serviceProvider.Object);

            serviceProvider.Setup(s => s.GetService(typeof(GarmentProductService))).Returns(service);
            serviceProvider.Setup(s => s.GetService(typeof(CoreDbContext))).Returns(dbContext);

            Lib.Models.GarmentProduct testData = GetTestData(dbContext);

            //Act
            IActionResult response = GetController(service).GetDistinctProductWidth();


            //Assert
            int statusCode = this.GetStatusCode(response);

            Assert.Equal((int)HttpStatusCode.OK, statusCode);
        }
Example #3
0
        protected GarmentProductsController GetController(GarmentProductService service)
        {
            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

            user.Setup(u => u.Claims).Returns(claims);

            GarmentProductsController controller = new GarmentProductsController(service);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user.Object
                }
            };
            controller.ControllerContext.HttpContext.Request.Headers["Authorization"] = "Bearer unittesttoken";
            controller.ControllerContext.HttpContext.Request.Path = new PathString("/v1/unit-test");
            return(controller);
        }
Example #4
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> validationResult = new List <ValidationResult>();

            if (string.IsNullOrWhiteSpace(this.Code))
            {
                validationResult.Add(new ValidationResult("Code is required", new List <string> {
                    "code"
                }));
            }

            if (string.IsNullOrWhiteSpace(this.Name))
            {
                validationResult.Add(new ValidationResult("Name is required", new List <string> {
                    "name"
                }));
            }

            if (string.IsNullOrWhiteSpace(this.UomUnit))
            {
                validationResult.Add(new ValidationResult("Uom is required", new List <string> {
                    "uom"
                }));
            }

            if (string.IsNullOrWhiteSpace(this.Composition) && this.ProductType == "FABRIC")
            {
                validationResult.Add(new ValidationResult("Composition is required", new List <string> {
                    "composition"
                }));
            }

            if (string.IsNullOrWhiteSpace(this.Const) && this.ProductType == "FABRIC")
            {
                validationResult.Add(new ValidationResult("Const is required", new List <string> {
                    "const"
                }));
            }

            if (string.IsNullOrWhiteSpace(this.Yarn) && this.ProductType == "FABRIC")
            {
                validationResult.Add(new ValidationResult("Yarn is required", new List <string> {
                    "yarn"
                }));
            }

            if (string.IsNullOrWhiteSpace(this.Width) && this.ProductType == "FABRIC")
            {
                validationResult.Add(new ValidationResult("Width is required", new List <string> {
                    "width"
                }));
            }

            if (validationResult.Count.Equals(0))
            {
                /* Service Validation */
                GarmentProductService service = (GarmentProductService)validationContext.GetService(typeof(GarmentProductService));

                if (service.DbContext.Set <GarmentProduct>().Count(r => r._IsDeleted.Equals(false) && r.Id != this.Id && r.Code.Equals(this.Code)) > 0)
                {
                    validationResult.Add(new ValidationResult("Code is already exist", new List <string> {
                        "code"
                    }));
                }

                if (service.DbContext.Set <GarmentProduct>().Count(r => r._IsDeleted.Equals(false) && r.Id != this.Id && r.Name.Equals(this.Name) && this.ProductType.Equals("NON FABRIC")) > 0) /* Name Unique */
                {
                    validationResult.Add(new ValidationResult("Name already exists", new List <string> {
                        "name"
                    }));
                }

                if (service.DbContext.Set <GarmentProduct>().Count(r => r._IsDeleted.Equals(false) && r.Id != this.Id && this.ProductType.Equals("FABRIC") && r.Composition.Equals(this.Composition) && r.Const.Equals(this.Const) && r.Yarn.Equals(this.Yarn) && r.Width.Equals(this.Width)) > 0)
                {
                    validationResult.Add(new ValidationResult("Product with same Composition, Const, Yarn, Width already exists", new List <string> {
                        "combinationerror"
                    }));
                }
            }

            return(validationResult);
        }