Пример #1
0
        public void Empty()
        {
            Csla.SmartDate d2 = new Csla.SmartDate();
            Csla.SmartDate d3;

            d3 = new Csla.SmartDate(d2.Add(new TimeSpan(30, 0, 0, 0)));
            Assert.AreEqual(d2, d3, "Dates should be equal");
            Assert.AreEqual("", d2.Text, "Text should be empty");

            d3 = new Csla.SmartDate(d2.Subtract(new TimeSpan(30, 0, 0, 0)));
            Assert.AreEqual(d2, d3, "Dates should be equal");
            Assert.AreEqual("", d2.Text, "Text should be empty");

            d3 = new Csla.SmartDate();
            Assert.AreEqual(0, d2.CompareTo(d3), "d2 and d3 should be the same");
            Assert.IsTrue(d2.Equals(d3), "d2 and d3 should be the same");
            Assert.IsTrue(Csla.SmartDate.Equals(d2, d3), "d2 and d3 should be the same");

            d3.Date = DateTime.Now;
            Assert.AreEqual(-1, d2.CompareTo(d3), "d2 and d3 should not be the same");
            Assert.AreEqual(1, d3.CompareTo(d2), "d2 and d3 should not be the same");
            Assert.IsFalse(d2.Equals(d3), "d2 and d3 should not be the same");
            Assert.IsFalse(Csla.SmartDate.Equals(d2, d3), "d2 and d3 should not be the same");
            Assert.IsFalse(d3.Equals(d2), "d2 and d3 should not be the same");
            Assert.IsFalse(Csla.SmartDate.Equals(d3, d2), "d2 and d3 should not be the same");
        }
Пример #2
0
        public void Comparison()
        {
            Csla.SmartDate d2 = new Csla.SmartDate(true);
            Csla.SmartDate d3 = new Csla.SmartDate(false);
            Csla.SmartDate d4 = new Csla.SmartDate(Csla.SmartDate.EmptyValue.MinDate);
            Csla.SmartDate d5 = new Csla.SmartDate(Csla.SmartDate.EmptyValue.MaxDate);

            Assert.IsTrue(d2.Equals(d3), "Empty dates should be equal");
            Assert.IsTrue(Csla.SmartDate.Equals(d2, d3), "Empty dates should be equal (shared)");
            Assert.IsTrue(d2.Equals(d3), "Empty dates should be equal (unary)");
            Assert.IsTrue(d2.Equals(""), "Should be equal to an empty string (d2)");
            Assert.IsTrue(d3.Equals(""), "Should be equal to an empty string (d3)");

            Assert.IsTrue(d2.Date.Equals(DateTime.MinValue), "Should be DateTime.MinValue");
            Assert.IsTrue(d3.Date.Equals(DateTime.MaxValue), "Should be DateTime.MaxValue");

            Assert.IsTrue(d4.Date.Equals(DateTime.MinValue), "Should be DateTime.MinValue (d4)");
            Assert.IsTrue(d5.Date.Equals(DateTime.MaxValue), "Should be DateTime.MaxValue (d5)");

            d2.Date = new DateTime(2005, 1, 1);
            d3      = new Csla.SmartDate(d2.Date, d2.EmptyIsMin);
            Assert.AreEqual(d2, d3, "Assigned dates should be equal");

            d3.Date = new DateTime(2005, 2, 2);
            Assert.AreEqual(1, d3.CompareTo(d2), "Should be greater than");
            Assert.AreEqual(-1, d2.CompareTo(d3), "Should be less than");
            Assert.IsFalse(d2.CompareTo(d3) == 0, "should not be equal");

            d3.Date = new DateTime(2005, 1, 1);
            Assert.IsFalse(1 == d2.CompareTo(d3), "should be equal");
            Assert.IsFalse(-1 == d2.CompareTo(d3), "should be equal");
            Assert.AreEqual(0, d2.CompareTo(d3), "should be equal");

            Assert.IsTrue(d3.Equals("1/1/2005"), "Should be equal to string date");
            Assert.IsTrue(d3.Equals(new DateTime(2005, 1, 1)), "should be equal to DateTime");

            Assert.IsTrue(d3.Equals(d2.Date.ToString()), "Should be equal to any date time string");
            Assert.IsTrue(d3.Equals(d2.Date.ToLongDateString()), "Should be equal to any date time string");
            Assert.IsTrue(d3.Equals(d2.Date.ToShortDateString()), "Should be equal to any date time string");
            Assert.IsFalse(d3.Equals(""), "Should not be equal to a blank string");

            //DateTime can be compared using all sorts of formats but the SmartDate cannot.
            //DateTime dt = DateTime.Now;
            //long ldt = dt.ToBinary();
            //Assert.IsTrue(dt.Equals(ldt), "Should be equal");
            //Should smart date also be converted into these various types?
        }
Пример #3
0
 protected bool EqualNullableSmartDate(System.Nullable <Csla.SmartDate> d1, System.Nullable <Csla.SmartDate> d2)
 {
     if (!d1.HasValue && !d2.HasValue)
     {
         return(true);
     }
     if (!d1.HasValue && d2.HasValue)
     {
         return(false);
     }
     if (!d2.HasValue && d1.HasValue)
     {
         return(false);
     }
     Csla.SmartDate smartDate = d1.Value;
     return(smartDate.Equals(d2.Value));
 }