Exemple #1
0
        public void When_Object_Is_Null_Then_Valid()
        {
            // Arrange
            var    greaterThanAttribute = new GreaterThanOrEqualToAttribute(1);
            object nullObject           = null;

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

            // Assert
            Assert.IsTrue(isValid);
        }
Exemple #2
0
        public void When_Value_Type_Is_Not_Numeric_Then_Exception_Is_Thrown()
        {
            // Arrange
            var          greaterThanAttribute = new GreaterThanOrEqualToAttribute(10);
            const string typedValue           = "A String";

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

            // Assert
            exception.Should().NotBeNull();
        }
        public void When_Value_Is_Less_Than_Required_Then_Invalid()
        {
            // Arrange
            var greaterThanAttribute = new GreaterThanOrEqualToAttribute(2);
            var value = 0;

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

            // Assert
            isValid.Should().BeFalse();
        }
        public void When_Value_Type_Is_Numeric_And_Greater_Than_Required_Then_Valid(Type type, object value)
        {
            // Arrange
            var greaterThanAttribute = new GreaterThanOrEqualToAttribute(2);
            var typedValue           = Convert.ChangeType(value, type);

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

            // Assert
            isValid.Should().BeTrue();
        }
        public void When_Value_Is_Equal_To_Required_Then_Valid()
        {
            // Arrange
            var greaterThanAttribute = new GreaterThanOrEqualToAttribute(2);
            var value = 2;

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

            // Assert
            isValid.Should().BeTrue();
        }