IsValid() public method

public IsValid ( object value ) : bool
value object
return bool
Example #1
0
        public void ValidateDate(int days, Temporality temporality, bool expected)
        {
            var attribute = new DateAttribute(temporality);
            var actual    = attribute.IsValid(DateTime.Now.AddDays(days));

            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void Test_DateAttribute([ValueSource(nameof(Comparisons))] ValidationComparison comparison, [ValueSource(nameof(Dates))] DateTime date)
        {
            var attribute = new DateAttribute(comparison);

            var result = attribute.IsValid(date);

            Assert.IsTrue(result);
        }
Example #3
0
        public void IsValidTests()
        {
            var attribute = new DateAttribute();

            Assert.IsTrue(attribute.IsValid(null)); // Don't check for required
            Assert.IsTrue(attribute.IsValid(DateTime.Now));
            Assert.IsTrue(attribute.IsValid(DateTime.Now.ToShortDateString()));
            Assert.IsTrue(attribute.IsValid("12/31/2010"));
            Assert.IsFalse(attribute.IsValid(12));
            Assert.IsFalse(attribute.IsValid("12.90"));
            Assert.IsFalse(attribute.IsValid("February 24th"));
            Assert.IsFalse(attribute.IsValid("yesterday"));
            Assert.IsFalse(attribute.IsValid("80/80/2011"));
        }
Example #4
0
        public void IsValidTests()
        {
            var attribute = new DateAttribute();

            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-us");

            Assert.IsTrue(attribute.IsValid(null)); // Don't check for required
            Assert.IsTrue(attribute.IsValid(DateTime.Now));
            Assert.IsTrue(attribute.IsValid(DateTime.Now.ToShortDateString()));
            Assert.IsTrue(attribute.IsValid("12/31/2010"));
            Assert.IsFalse(attribute.IsValid(12));
            Assert.IsFalse(attribute.IsValid("12.90"));
            Assert.IsFalse(attribute.IsValid("February 24th"));
            Assert.IsFalse(attribute.IsValid("yesterday"));
            Assert.IsFalse(attribute.IsValid("80/80/2011"));
        }
Example #5
0
        public void testAddBooking()
        {
            var range          = new System.ComponentModel.DataAnnotations.RangeAttribute(0, 100);
            var dateValidation = new DateAttribute();

            // Alle Attribute richtig
            Booking b1 = new Booking {
                currentCharge    = 30,
                requiredDistance = 150,
                connectorType    = ConnectorType.CCSCombo2Plug,
                start            = new DateTime(2020, 7, 8, 8, 0, 0),
                end = new DateTime(2020, 7, 8, 10, 0, 0)
            };

            Assert.IsTrue(range.IsValid(b1.currentCharge));
            Assert.IsTrue(b1.requiredDistance > 0 && b1.requiredDistance <= 1000);
            Assert.IsTrue(dateValidation.IsValid(b1.start));
            Assert.IsTrue(dateValidation.IsValid(b1.end));
            Assert.IsTrue(b1.end > b1.start);

            // currentCharge ungültig
            Booking b2 = new Booking
            {
                currentCharge    = -30,
                requiredDistance = 150,
                connectorType    = ConnectorType.CCSCombo2Plug,
                start            = new DateTime(2020, 7, 8, 8, 0, 0),
                end = new DateTime(2020, 7, 8, 10, 0, 0)
            };

            Assert.IsFalse(range.IsValid(b2.currentCharge));
            Assert.IsTrue(b2.requiredDistance > 0 && b2.requiredDistance <= 1000);
            Assert.IsTrue(dateValidation.IsValid(b2.start));
            Assert.IsTrue(dateValidation.IsValid(b2.end));
            Assert.IsTrue(b2.end > b2.start);

            // requiredDistance ungültig
            Booking b3 = new Booking
            {
                currentCharge    = 30,
                requiredDistance = -150,
                connectorType    = ConnectorType.CCSCombo2Plug,
                start            = new DateTime(2020, 7, 8, 8, 0, 0),
                end = new DateTime(2020, 7, 8, 10, 0, 0)
            };

            Assert.IsTrue(range.IsValid(b3.currentCharge));
            Assert.IsFalse(b3.requiredDistance > 0 && b3.requiredDistance <= 1000);
            Assert.IsTrue(dateValidation.IsValid(b3.start));
            Assert.IsTrue(dateValidation.IsValid(b3.end));
            Assert.IsTrue(b3.end > b3.start);

            // start ungültig
            Booking b4 = new Booking
            {
                currentCharge    = 30,
                requiredDistance = 150,
                connectorType    = ConnectorType.CCSCombo2Plug,
                start            = new DateTime(2020, 5, 5, 8, 0, 0),
                end = new DateTime(2020, 7, 8, 10, 0, 0)
            };

            Assert.IsTrue(range.IsValid(b4.currentCharge));
            Assert.IsTrue(b4.requiredDistance > 0 && b4.requiredDistance <= 1000);
            Assert.IsFalse(dateValidation.IsValid(b4.start));
            Assert.IsTrue(dateValidation.IsValid(b4.end));
            Assert.IsTrue(b4.end > b4.start);

            // end ungültig
            Booking b5 = new Booking
            {
                currentCharge    = 30,
                requiredDistance = 150,
                connectorType    = ConnectorType.CCSCombo2Plug,
                start            = new DateTime(2020, 7, 8, 8, 0, 0),
                end = new DateTime(2020, 7, 7, 10, 0, 0)
            };

            Assert.IsTrue(range.IsValid(b5.currentCharge));
            Assert.IsTrue(b5.requiredDistance > 0 && b3.requiredDistance <= 1000);
            Assert.IsTrue(dateValidation.IsValid(b5.start));
            Assert.IsTrue(dateValidation.IsValid(b5.end));
            Assert.IsFalse(b5.end > b5.start);
        }