コード例 #1
0
        public void 開始時刻のPropertyが存在しない場合ArgumentException表示()
        {
            // Arrange
            var endDateTime = new DateTime(2020, 1, 2, 0, 0, 0);
            var model       = new DateTimeAfterAttributeTestModel();
            var context     = new ValidationContext(model, null, null);
            var attribute   = new DateTimeAfterAttribute("test");

            // Assert
            var result = Assert.Throws <ArgumentException>(() =>
            {
                attribute.GetValidationResult(endDateTime, context);
            });
        }
コード例 #2
0
        public void 開始時刻と終了時刻の値が同じ場合無効()
        {
            // Arrange
            var beginPropertyName = "BeginDateTime";
            var sameDateTime      = new DateTime(2020, 1, 1, 0, 0, 0);
            var testModel         = new DateTimeAfterAttributeTestModel()
            {
                BeginDateTime = sameDateTime
            };
            var context   = new ValidationContext(testModel, null, null);
            var attribute = new DateTimeAfterAttribute(beginPropertyName, "エラーテキスト");

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

            // Assert
            Assert.Equal("エラーテキスト", result.ErrorMessage);
        }
コード例 #3
0
        public void AllowEquivalentがtrueの時開始時刻と終了時刻の値が同じ場合検証有効()
        {
            // Arrange
            var beginPropertyName = "BeginDateTime";
            var sameDateTime      = new DateTime(2020, 1, 1, 0, 0, 0);
            var testModel         = new DateTimeAfterAttributeTestModel()
            {
                BeginDateTime = sameDateTime
            };
            var context   = new ValidationContext(testModel, null, null);
            var attribute = new DateTimeAfterAttribute(beginPropertyName, true, "エラーテキスト");

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

            // Assert
            Assert.Equal(ValidationResult.Success, result);
        }
コード例 #4
0
        public void 開始時刻の値が終了時刻の値より古い場合検証有効()
        {
            // Arrange
            var beginPropertyName = "BeginDateTime";
            var endDateTime       = new DateTime(2020, 1, 2, 0, 0, 0);
            var model             = new DateTimeAfterAttributeTestModel()
            {
                BeginDateTime = new DateTime(2020, 1, 1, 0, 0, 0)
            };
            var context   = new ValidationContext(model, null, null);
            var attribute = new DateTimeAfterAttribute(beginPropertyName);

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

            // Assert
            Assert.Equal(ValidationResult.Success, result);
        }