Exemplo n.º 1
0
        public void And_Name_Is_Not_Valid(string name)
        {
            // Arrange
            var productOption = new ProductOptionDto {
                Description = "description", Name = name, ProductId = RandomBuilder.NextGuid()
            };

            // Act
            var result = _validator.TestValidate(productOption);

            // Assert
            result.ShouldHaveValidationErrorFor(x => x.Name);
            Assert.True(!result.IsValid);
            Assert.True(result.Errors.Count == 1);
            Assert.Contains(result.Errors, x => x.PropertyName == "Name" && x.ErrorMessage == ValidationErrors.NameRequiredError);
        }
Exemplo n.º 2
0
        public void And_Name_Overflows_Max_Length()
        {
            // Arrange
            string invalidName   = RandomBuilder.NextString(ValidationLimits.NameMaxLength + 1);
            var    productOption = new ProductOptionDto {
                Description = "description", Name = invalidName, ProductId = RandomBuilder.NextGuid()
            };

            // Act
            var result = _validator.TestValidate(productOption);

            // Assert
            result.ShouldHaveValidationErrorFor(x => x.Name);
            Assert.True(!result.IsValid);
            Assert.True(result.Errors.Count == 1);
            Assert.Contains(result.Errors, x => x.PropertyName == "Name" && x.ErrorMessage == ValidationErrors.NameMaxLengthError);
        }