using System; using NUnit.Framework; namespace ChadSoft.Validation { [TestFixture] public class RangeValidatorTests { [Test] public void Returns_false_for_value_over_max_range() { Assert.IsFalse(new RangeValidatorAttribute(0, 2).IsValid(3)); } [Test] public void Returns_false_for_value_under_min_range() { Assert.IsFalse(new RangeValidatorAttribute(0, 2).IsValid(-1)); } [Test] public void Returns_true_for_int_in_range() { Assert.IsTrue(new RangeValidatorAttribute(0, 2).IsValid(1)); } [Test] public void Returns_true_for_value_as_max_value() { Assert.IsTrue(new RangeValidatorAttribute(0, 2).IsValid(2)); } [Test] public void Returns_true_for_doubles_in_range() { Assert.IsTrue(new RangeValidatorAttribute(0.0, 2.1).IsValid(1.9)); } [Test] public void Returns_true_for_DateTimes_in_range() { Assert.IsTrue(new RangeValidatorAttribute(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1)) .IsValid(DateTime.Now)); } [Test] [ExpectedException(typeof(ArgumentNullException))] public void Null_ranges_throw_exception() { new RangeValidatorAttribute(null, null); } [Test] [ExpectedException(typeof(ArgumentNullException))] public void Null_min_range_throw_exception() { new RangeValidatorAttribute(null, 1); } [Test] [ExpectedException(typeof(ArgumentNullException))] public void Null_max_range_throw_exception() { new RangeValidatorAttribute(2, null); } [Test] [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Min and Max values must be the same type.")] public void Min_and_max_of_different_types_throws_exception() { new RangeValidatorAttribute(2, DateTime.Now); } } }