コード例 #1
0
        public void Validate_NoDatesProvidedValueIsValid_Ok(string dateString)
        {
            // Arrange
            MinDate = null;
            MaxDate = null;

            var validator = new DtoValidator();

            DateTime date;

            if (dateString == "DateTime.MinValue")
            {
                date = DateTime.MinValue;
            }
            else if (dateString == "DateTime.MaxValue")
            {
                date = DateTime.MaxValue.Date;
            }
            else
            {
                date = DateTime.Parse(dateString);
            }

            var dto = new Dto
            {
                TheDate = date,
            };

            // Act
            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.True);
        }
コード例 #2
0
        public void Validate_CurrencyCodeIsValid_Ok(string code)
        {
            // Arrange
            var validator = new DtoValidator();
            var dto       = new Dto
            {
                CurrencyCode = code,
            };

            // Act
            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.True);
        }
コード例 #3
0
        public void Validate_ValidUsername_Ok(string username)
        {
            // Arrange
            var validator = new DtoValidator();

            // Act
            var dto = new Dto
            {
                MyUsername = username,
            };

            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.True);
        }
コード例 #4
0
        public void Validate_ValidWebCode_Ok(string webCode)
        {
            // Arrange
            var validator = new DtoValidator();

            // Act
            var dto = new Dto
            {
                TheWebCode = webCode,
            };

            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.True);
        }
コード例 #5
0
        public void Validate_CodeIsValid_Ok(string code)
        {
            // Arrange
            MinLength = 2;
            MaxLength = 30;

            var validator = new DtoValidator();
            var dto       = new Dto
            {
                TheCode = code,
            };

            // Act
            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.True);
        }
コード例 #6
0
        public void Validate_MaxDateProvidedValueIsValid_Ok(string dateString)
        {
            // Arrange
            MinDate = null;
            MaxDate = "2010-06-06".ToExactDate();

            var validator = new DtoValidator();

            // Act
            var dto = new Dto
            {
                TheDate = dateString.ToExactDate(),
            };

            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.True);
        }
コード例 #7
0
        public void Validate_CurrencyCodeIsInvalid_Error(string code)
        {
            // Arrange
            var validator = new DtoValidator();
            var dto       = new Dto
            {
                CurrencyCode = code,
            };

            // Act
            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.False);
            var error = result.Errors.Single();

            Assert.That(error.ErrorCode, Is.EqualTo("CurrencyCodeValidator"));
            Assert.That(error.ErrorMessage, Is.EqualTo("'Currency Code' must be a valid currency code."));
        }
コード例 #8
0
        public void Validate_InvalidCode_Error(string code)
        {
            // Arrange
            var validator = new DtoValidator();

            // Act
            var dto = new Dto
            {
                TheCode = code,
            };

            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.False);
            var error = result.Errors.Single();

            Assert.That(error.ErrorCode, Is.EqualTo("LowercaseCodeValidator"));
            Assert.That(error.ErrorMessage, Is.EqualTo("'The Code' must be a valid lowercase code."));
        }
コード例 #9
0
        public void Validate_InvalidUsername_Error(string username)
        {
            // Arrange
            var validator = new DtoValidator();

            // Act
            var dto = new Dto
            {
                MyUsername = username,
            };

            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.False);
            var error = result.Errors.Single();

            Assert.That(error.ErrorCode, Is.EqualTo("UsernameValidator"));
            Assert.That(error.ErrorMessage, Is.EqualTo("'My Username' must be a valid username."));
        }
コード例 #10
0
        public void Validate_CodeIsInvalidValid_Error(string code)
        {
            // Arrange
            MinLength = 2;
            MaxLength = 30;

            var validator = new DtoValidator();
            var dto       = new Dto
            {
                TheCode = code,
            };

            // Act
            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.False);
            var error = result.Errors.Single();

            Assert.That(error.ErrorCode, Is.EqualTo("CodeValidator"));
            Assert.That(error.ErrorMessage, Is.EqualTo("'The Code' must be a valid code with length 2..30."));
        }
コード例 #11
0
        public void Validate_MinDateProvidedValueIsInvalid_Error(string dateString)
        {
            // Arrange
            MinDate = "2010-06-06".ToExactDate();
            MaxDate = null;

            var validator = new DtoValidator();

            // Act
            var dto = new Dto
            {
                TheDate = DateTime.Parse(dateString),
            };

            var result = validator.Validate(dto);

            // Assert
            Assert.That(result.IsValid, Is.False);
            var error = result.Errors.Single();

            Assert.That(error.ErrorCode, Is.EqualTo("ExactDateValidator"));
            Assert.That(error.ErrorMessage, Is.EqualTo("'The Date' must be an exact date not less than 2010-06-06."));
        }