Пример #1
0
        public void CleanTest()
        {
            FloatField target = new FloatField();

            // Default test
            Assert.AreEqual((float?)12.2, (float?)target.Clean("12.2"));

            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean(null);
            }).WithMessage("This field is required.");
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("abc");
            }).WithMessage("Enter a number.");

            target.MinValue = (float?)5;
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("4.65");
            }).WithMessage("Ensure this value is greater than or equal to 5.");
            Assert.AreEqual((float?)5.5, (float?)target.Clean("5.5"));

            target.MaxValue = (float?)10.3;
            AssertExtras.Raises <ValidationException>(delegate {
                target.Clean("15");
            }).WithMessage("Ensure this value is less than or equal to 10.3.");
            Assert.AreEqual((float?)10.2, (float?)target.Clean("10.2"));

            target.Required = false;
            Assert.IsNull(target.Clean(null));
        }