Пример #1
0
        public void 年月日が正しくない場合検証無効(int year, int month, int day)
        {
            var model = new DateConsistencyAttributeTestModel()
            {
                Year  = year,
                Month = month,
                Day   = day
            };
            var context   = new ValidationContext(model, null, null);
            var attribute = new DateConsistencyAttribute("Year", "Month", "エラーテキスト");

            // Act
            var result = attribute.GetValidationResult(day, context);

            // Assert
            Assert.Equal("エラーテキスト", result.ErrorMessage);
        }
Пример #2
0
        public void 年月日が正しい場合検証成功(int year, int month, int day)
        {
            var model = new DateConsistencyAttributeTestModel()
            {
                Year  = year,
                Month = month,
                Day   = day
            };
            var context   = new ValidationContext(model, null, null);
            var attribute = new DateConsistencyAttribute("Year", "Month");

            // Act
            var result = attribute.GetValidationResult(day, context);

            // Assert
            Assert.Equal(ValidationResult.Success, result);
        }
Пример #3
0
        public void 検証対象の日がNullだった場合検証しない()
        {
            // Arrange
            var day   = 1;
            var model = new DateConsistencyAttributeTestNullModel()
            {
                Year  = 2020,
                Month = 4
            };
            var context   = new ValidationContext(model, null, null);
            var attribute = new DateConsistencyAttribute("Year", "Month");

            // Act
            var result = attribute.GetValidationResult(null, context);

            // Assert
            Assert.Equal(ValidationResult.Success, result);
        }
Пример #4
0
        public void 指定した月のプロパティが存在しない場合例外()
        {
            // Arrange
            var day   = 1;
            var model = new DateConsistencyAttributeTestModel()
            {
                Year  = 2020,
                Month = 4
            };
            var context   = new ValidationContext(model, null, null);
            var attribute = new DateConsistencyAttribute("Year", "DifferentMonth");

            // Assert
            var result = Assert.Throws <InvalidOperationException>(() =>
            {
                attribute.GetValidationResult(day, context);
            });

            Assert.Equal("指定したプロパティ名が見つかりません。Name:DifferentMonth", result.Message);
        }