Пример #1
0
 public static void VerifyBetween <T>(this IComparable <T> item, T minimum, T maximum, string parameterName, bool inclusive)
 {
     if (!item.IsBetween(minimum, maximum, inclusive))
     {
         throw new ArgumentOutOfRangeException(parameterName);
     }
 }
Пример #2
0
 /// <summary>
 /// Checks whether the value is between a minimum and maximum value.
 /// </summary>
 /// <param name="value">The value to test.</param>
 /// <param name="min">The minimum value to test.</param>
 /// <param name="max">The maximum value to test.</param>
 /// <param name="paramName">The name of the parameter that caused the exception.</param>
 /// <param name="message">A message that describes the error.</param>
 /// <exception cref="ArgumentOutOfRangeException"><em>value</em> is out of
 /// range.</exception>
 public static void IsBetween(IComparable value, IComparable min, IComparable max, string paramName, string message)
 {
     if (!value.IsBetween(min, max))
     {
         throw new ArgumentOutOfRangeException(paramName, message);
     }
 }
Пример #3
0
 /// <summary>
 /// Checks whether the value is between a minimum and maximum value.
 /// </summary>
 /// <param name="value">The value to test.</param>
 /// <param name="min">The minimum value to test.</param>
 /// <param name="max">The maximum value to test.</param>
 /// <exception cref="ArgumentOutOfRangeException"><em>value</em> is out of
 /// range.</exception>
 public static void IsBetween(IComparable value, IComparable min, IComparable max)
 {
     if (!value.IsBetween(min, max))
     {
         throw new ArgumentOutOfRangeException();
     }
 }
Пример #4
0
        public void When_IsBetween_is_called_with_max_value()
        {
            // Arrange.
            IComparable <int> value = 10;

            // Act.
            bool result = value.IsBetween(0, 10);

            // Assert.
            result.Should().Be(false);
        }
Пример #5
0
        public void When_IsBetween_is_called_with_in_between_value()
        {
            // Arrange.
            IComparable <int> value = 10;

            // Act.
            bool result = value.IsBetween(5, 20);

            // Assert.
            result.Should().Be(true);
        }
Пример #6
0
 public static bool IsBetween <T>(this IComparable <T> item, T minimum, T maximum)
 {
     return(item.IsBetween(minimum, maximum, false));
 }
 public void IsBetween_Throws_ArgumentNullException(IComparable value, IComparable min, IComparable max, string expectedParameter)
 {
     AssertThrowsException<ArgumentNullException>(() => value.IsBetween(min, max), expectedParameter);
 }
Пример #8
0
        public static void IsBetween()
        {
            IComparable <string> instance = null;
            string min    = null;
            string max    = null;
            var    result = false;

            When("an extension is called", () =>
            {
                Act(() =>
                {
                    result = instance.IsBetween(min, max);
                });

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

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

                And("an instance is not null", () =>
                {
                    min = "111";
                    max = "222";

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

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

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

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

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

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

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

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

                    And("the instance is between the minimum and maximum value", () =>
                    {
                        instance = "121";

                        Should("return true", () =>
                        {
                            Assert.That(result, Is.True);
                        });
                    });
                });
            });
        }
Пример #9
0
 public void IsBetween_Throws_ArgumentNullException(IComparable value, IComparable min, IComparable max, string expectedParameter)
 {
     AssertThrowsException <ArgumentNullException>(() => value.IsBetween(min, max), expectedParameter);
 }