Exemplo n.º 1
0
        public void LessThanAttribute_SetsMaximum()
        {
            Decimal actual   = new LessThanAttribute(12.56).Maximum;
            Decimal expected = 12.56M;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        public void FormatErrorMessage_ForName()
        {
            attribute = new LessThanAttribute(12.56);

            String actual   = attribute.FormatErrorMessage("Sum");
            String expected = Validation.For("LessThan", "Sum", attribute.Maximum);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Utility method which checks how many seconds the method can maximally take. This value
        /// is extracted from the <see cref="LessThanAttribute"/> attribute surrounding the method.
        /// The value is stored in this object's <see cref="Seconds"/> property.
        /// </summary>
        /// <param name="methodInfo">A method attributed with a <see cref="LessThanAttribute"/> attribute.</param>
        private void DetectSecondsFromMethod(MethodInfo methodInfo)
        {
            object[] lessThanAttributes = methodInfo.GetCustomAttributes(typeof(LessThanAttribute), true);

            LessThanAttribute lessThanAttribute = lessThanAttributes.FirstOrDefault(x => x is LessThanAttribute) as LessThanAttribute;

            // ReSharper disable once PossibleNullReferenceException
            Seconds = lessThanAttribute.Seconds;
        }
Exemplo n.º 4
0
        public void When_Object_Is_Null_Then_Valid()
        {
            // Arrange
            var    lessThanAttribute = new LessThanAttribute(1);
            object nullObject        = null;

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

            // Assert
            Assert.IsTrue(isValid);
        }
        public void When_Value_Type_Is_Not_Numeric_Then_Exception_Is_Thrown()
        {
            // Arrange
            var          lessThanAttribute = new LessThanAttribute(10);
            const string typedValue        = "A String";

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

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

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

            // Assert
            isValid.Should().BeTrue();
        }
Exemplo n.º 7
0
        public void When_Value_Is_Less_Than_Required_Value_Then_Valid()
        {
            // Arrange
            var lessThanAttribute = new LessThanAttribute(2);
            var value             = 0;

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

            // Assert
            isValid.Should().BeTrue();
        }
Exemplo n.º 8
0
        public void When_Value_Is_Greater_Than_Required_Then_Invalid()
        {
            // Arrange
            var lessThanAttribute = new LessThanAttribute(2);
            var value             = 4;

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

            // Assert
            isValid.Should().BeFalse();
        }
Exemplo n.º 9
0
        private static string BuildLessThan(string propertyPath, LessThanAttribute lessThanAttribute)
        {
            switch (lessThanAttribute.ReferenceType)
            {
            case ComparisonReferenceType.Static:
                return($"{propertyPath} IS LESS THAN {lessThanAttribute.UpperLimit}");

            case ComparisonReferenceType.OtherProperty:
                return($"{propertyPath} IS LESS THAN {lessThanAttribute.PropertyName}");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 10
0
 public LessThanAttributeTests()
 {
     attribute = new LessThanAttribute(12.56);
 }