Пример #1
0
 public static void VerifyGreaterThan <T>(this IComparable <T> item, T value, string parameterName)
 {
     if (item.IsLessThanOrEqualTo(value))
     {
         throw new ArgumentOutOfRangeException(parameterName);
     }
 }
Пример #2
0
        public static void IsLessThanOrEqualTo()
        {
            IComparable <string> instance = null;
            string value  = null;
            var    result = false;

            When("an extension is called", () =>
            {
                Act(() =>
                {
                    result = instance.IsLessThanOrEqualTo(value);
                });

                And("an instance is null", () =>
                {
                    instance = null;

                    Should("return false", () =>
                    {
                        Assert.That(result, Is.False);
                    });
                });

                And("an instance is not null", () =>
                {
                    value = "121";

                    And("the instance is less than the value", () =>
                    {
                        instance = "111";

                        Should("return true", () =>
                        {
                            Assert.That(result, Is.True);
                        });
                    });

                    And("the instance is greater than the value", () =>
                    {
                        instance = "131";

                        Should("return false", () =>
                        {
                            Assert.That(result, Is.False);
                        });
                    });

                    And("the instance is equal to the value", () =>
                    {
                        instance = "121";

                        Should("return true", () =>
                        {
                            Assert.That(result, Is.True);
                        });
                    });
                });
            });
        }
Пример #3
0
        public void When_IsLessThanOrEqualTo_is_called_with_a_same_value()
        {
            // Arrange.
            IComparable <int> value = 10;

            // Act.
            bool result = value.IsLessThanOrEqualTo(10);

            // Assert.
            result.Should().Be(true);
        }
Пример #4
0
 public static bool IsBetween <T>(this IComparable <T> item, T minimum, T maximum, bool inclusive)
 {
     if (inclusive)
     {
         return(item.IsGreaterThanOrEqualTo(minimum) || item.IsLessThanOrEqualTo(maximum));
     }
     else
     {
         return(item.IsGreaterThan(minimum) || item.IsLessThan(maximum));
     }
 }
Пример #5
0
 /// <summary>
 ///     Returns whether the specified <see cref="IComparable"/> is between two ranges (inclusive)
 /// </summary>
 public static bool IsBetweenInclusive(this IComparable comparable, IComparable lower, IComparable upper)
 => comparable.IsGreaterThanOrEqualTo(lower) && comparable.IsLessThanOrEqualTo(upper);