Esempio n. 1
0
        public void When_Value_Type_Is_Not_Numeric_Then_Exception_Is_Thrown()
        {
            // Arrange
            var          lessThanAttribute = new LessThanOrEqualToAttribute(10);
            const string typedValue        = "A String";

            // Act
            var exception = Assert.Throws <FormatException>(() => lessThanAttribute.IsValid(typedValue));

            // Assert
            exception.Should().NotBeNull();
        }
        public void When_Value_Type_Is_Numeric_And_Less_Than_Required_Then_Valid(Type type, object value)
        {
            // Arrange
            var lessThanAttribute = new LessThanOrEqualToAttribute(10);
            var typedValue        = Convert.ChangeType(value, type);

            // Act
            var isValid = lessThanAttribute.IsValid(typedValue);

            // Assert
            isValid.Should().BeTrue();
        }
        public void When_Value_Is_Greater_Than_Required_Then_Invalid()
        {
            // Arrange
            var lessThanAttribute = new LessThanOrEqualToAttribute(2);
            var value             = 4;

            // Act
            var isValid = lessThanAttribute.IsValid(value);

            // Assert
            isValid.Should().BeFalse();
        }
        public void When_Value_Is_Less_Than_Required_Value_Then_Valid()
        {
            // Arrange
            var lessThanAttribute = new LessThanOrEqualToAttribute(2);
            var value             = 0;

            // Act
            var isValid = lessThanAttribute.IsValid(value);

            // Assert
            isValid.Should().BeTrue();
        }
        public void When_Object_Is_Null_Then_Valid()
        {
            // Arrange
            var    lessThanAttribute = new LessThanOrEqualToAttribute(1);
            object nullObject        = null;

            // Act
            var isValid = lessThanAttribute.IsValid(nullObject);

            // Assert
            Assert.IsTrue(isValid);
        }