16using System.Threading;
20using TestClass = NUnit.Framework.TestFixtureAttribute;
21using TestInitialize = NUnit.Framework.SetUpAttribute;
22using TestCleanup = NUnit.Framework.TearDownAttribute;
23using TestMethod = NUnit.Framework.TestAttribute;
24using TestSetup = NUnit.Framework.SetUpAttribute;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
38 private static TestDIContext _testDIContext;
39 System.Globalization.CultureInfo CurrentCulture {
get;
set; }
40 System.Globalization.CultureInfo CurrentUICulture {
get;
set; }
45 _testDIContext = TestDIContextFactory.CreateDefaultContext();
53 CurrentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
54 CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
57 System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(
"en-US");
58 System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(
"en-US");
65 System.Threading.Thread.CurrentThread.CurrentCulture = CurrentCulture;
66 System.Threading.Thread.CurrentThread.CurrentUICulture = CurrentUICulture;
69 #region Test Constructors
75 Assert.AreEqual(now, d.Date);
78 Assert.IsTrue(d.EmptyIsMin);
80 Assert.IsFalse(d.EmptyIsMin);
83 Assert.AreEqual(
"1/1/2005", d.ToString());
85 Assert.AreEqual(
"1/1/2005", d.ToString());
87 Assert.AreEqual(
"1/1/2005", d.ToString());
89 Assert.AreEqual(
"1/1/2005", d.ToString());
91 Assert.AreEqual(
"", d.ToString());
92 Assert.IsTrue(d.IsEmpty);
95 Assert.AreEqual(
"1/1/2005", d.ToString());
96 Assert.IsTrue(d.EmptyIsMin);
98 Assert.AreEqual(
"1/1/2005", d.ToString());
99 Assert.IsFalse(d.EmptyIsMin);
101 Assert.AreEqual(
DateTime.MinValue, d.Date);
102 Assert.AreEqual(
"", d.ToString());
104 Assert.AreEqual(
DateTime.MaxValue, d.Date);
105 Assert.AreEqual(
"", d.ToString());
111 catch (Exception ex) { Assert.IsTrue(ex is ArgumentException); }
116 catch (Exception ex) { Assert.IsTrue(ex is ArgumentException); }
119 Assert.AreEqual(now, d.Date);
120 Assert.IsTrue(d.EmptyIsMin);
122 Assert.AreEqual(now, d.Date);
123 Assert.IsFalse(d.EmptyIsMin);
126 Assert.AreEqual(
DateTime.MinValue, d.Date);
128 Assert.AreEqual(
DateTime.MaxValue, d.Date);
130 Assert.AreEqual(
DateTime.MinValue, d.Date);
132 Assert.AreEqual(
DateTime.MaxValue, d.Date);
141 Assert.AreEqual(
"1/1/2005", d.ToShortDateString());
143 Assert.AreEqual(
"1/1/2005", d.ToShortDateString());
145 Assert.AreEqual(
DateTime.Now.ToShortDateString(), d.ToShortDateString());
147 Assert.AreEqual(
DateTime.Now.AddDays(-1.0).ToShortDateString(), d.ToShortDateString());
149 Assert.AreEqual(
DateTime.Now.AddDays(1.0).ToShortDateString(), d.ToShortDateString());
156 Assert.IsTrue(ex is System.ArgumentException);
160 Assert.AreEqual(
DateTime.MinValue, d);
162 Assert.AreEqual(
DateTime.MinValue, d);
165 Assert.AreEqual(
DateTime.MinValue, d);
167 Assert.AreEqual(
DateTime.MaxValue, d);
174 Assert.IsTrue(ex is ArgumentException);
182 Assert.IsTrue(ex is ArgumentException);
185 Assert.AreEqual(
DateTime.MinValue, d);
187 Assert.AreEqual(
DateTime.MaxValue, d);
191 Assert.AreEqual(
"02/01/2005", date,
"dd/MM/yyyy test");
193 Assert.AreEqual(
"01/02/05", date,
"MM/dd/yy test");
195 Assert.AreEqual(
"1/2/2005 12:00:00 AM", date);
197 Assert.AreEqual(
"1/2/2005", date);
199 Assert.AreEqual(
"1/2/2005", date);
202 Assert.AreEqual(
"", date,
"MinValue w/ emptyIsMin=true");
204 Assert.AreEqual(
DateTime.MinValue.ToString(
"dd/MM/yyyy"), date,
"MinValue w/ emptyIsMin=false");
206 Assert.AreEqual(
DateTime.MaxValue.ToString(
"dd/MM/yyyy"), date,
"MaxValue w/ emptyIsMin=true");
208 Assert.AreEqual(
"", date,
"MaxValue w/ emptyIsMin=false");
222 Assert.AreEqual(d2.Date.AddDays(30), d3.Date,
"Dates should be equal");
224 Assert.AreEqual(d3, d2 +
new TimeSpan(30, 0, 0, 0, 0),
"Dates should be equal");
237 Assert.AreEqual(d2.Date.AddDays(-30), d3.Date,
"Dates should be equal");
239 Assert.AreEqual(30, ((
TimeSpan)(d2 - d3)).Days,
"Should be 30 days different");
240 Assert.AreEqual(d3, d2 -
new TimeSpan(30, 0, 0, 0, 0),
"Should be equal");
254 Assert.IsTrue(d2.Equals(d3),
"Empty dates should be equal");
256 Assert.IsTrue(d2.Equals(d3),
"Empty dates should be equal (unary)");
257 Assert.IsTrue(d2.Equals(
""),
"Should be equal to an empty string (d2)");
258 Assert.IsTrue(d3.Equals(
""),
"Should be equal to an empty string (d3)");
260 Assert.IsTrue(d2.Date.Equals(
DateTime.MinValue),
"Should be DateTime.MinValue");
261 Assert.IsTrue(d3.Date.Equals(
DateTime.MaxValue),
"Should be DateTime.MaxValue");
263 Assert.IsTrue(d4.Date.Equals(
DateTime.MinValue),
"Should be DateTime.MinValue (d4)");
264 Assert.IsTrue(d5.Date.Equals(
DateTime.MaxValue),
"Should be DateTime.MaxValue (d5)");
268 Assert.AreEqual(d2, d3,
"Assigned dates should be equal");
271 Assert.AreEqual(1, d3.CompareTo(d2),
"Should be greater than");
272 Assert.AreEqual(-1, d2.CompareTo(d3),
"Should be less than");
273 Assert.IsFalse(d2.CompareTo(d3) == 0,
"should not be equal");
276 Assert.IsFalse(1 == d2.CompareTo(d3),
"should be equal");
277 Assert.IsFalse(-1 == d2.CompareTo(d3),
"should be equal");
278 Assert.AreEqual(0, d2.CompareTo(d3),
"should be equal");
280 Assert.IsTrue(d3.Equals(
"1/1/2005"),
"Should be equal to string date");
281 Assert.IsTrue(d3.Equals(
new DateTime(2005, 1, 1)),
"should be equal to DateTime");
283 Assert.IsTrue(d3.Equals(d2.Date.ToString()),
"Should be equal to any date time string");
284 Assert.IsTrue(d3.Equals(d2.Date.ToLongDateString()),
"Should be equal to any date time string");
285 Assert.IsTrue(d3.Equals(d2.Date.ToShortDateString()),
"Should be equal to any date time string");
286 Assert.IsFalse(d3.Equals(
""),
"Should not be equal to a blank string");
304 Assert.AreEqual(d2, d3,
"Dates should be equal");
305 Assert.AreEqual(
"", d2.Text,
"Text should be empty");
308 Assert.AreEqual(d2, d3,
"Dates should be equal");
309 Assert.AreEqual(
"", d2.Text,
"Text should be empty");
312 Assert.AreEqual(0, d2.CompareTo(d3),
"d2 and d3 should be the same");
313 Assert.IsTrue(d2.Equals(d3),
"d2 and d3 should be the same");
317 Assert.AreEqual(-1, d2.CompareTo(d3),
"d2 and d3 should not be the same");
318 Assert.AreEqual(1, d3.CompareTo(d2),
"d2 and d3 should not be the same");
319 Assert.IsFalse(d2.Equals(d3),
"d2 and d3 should not be the same");
321 Assert.IsFalse(d3.Equals(d2),
"d2 and d3 should not be the same");
336 Assert.AreEqual(expected, actual);
341 #region Comparison Operators
350 Assert.IsTrue(d1 < d2,
"d1 should be less than d2");
353 Assert.IsFalse(d1 < d2,
"d1 should be equal to d2");
356 Assert.IsFalse(d1 < d2,
"d1 should be greater than d2");
360 Assert.IsTrue(d1 > d2,
"d1 should be greater than d2");
363 Assert.IsFalse(d1 > d2,
"d1 should be equal to d2");
366 Assert.IsFalse(d1 > d2,
"d1 should be less than d2");
370 Assert.IsTrue(d1 == d2,
"d1 should be equal to d2");
373 Assert.IsFalse(d1 == d2,
"d1 should not be equal to d2");
379 Assert.IsTrue(d1 <= d2,
"d1 should be less than or equal to d2");
381 Assert.IsTrue(d1 <= d2,
"d1 should be less than or equal to d2");
383 Assert.IsFalse(d1 <= d2,
"d1 should be greater than to d2");
387 Assert.IsTrue(d1 >= d2,
"d1 should be greater than or equal to d2");
389 Assert.IsTrue(d1 >= d2,
"d1 should be greater than or equal to d2");
391 Assert.IsFalse(d1 >= d2,
"d1 should be less than to d2");
395 Assert.IsTrue(d1 != d2,
"d1 should not be equal to d2");
397 Assert.IsFalse(d1 != d2,
"d1 should be equal to d2");
399 Assert.IsTrue(d1 != d2,
"d1 should be greater than d2");
407 Assert.AreEqual(
true,
false,
"TryParse should have failed");
409 Assert.AreEqual(
DateTime.Now.Date, sd.Date.Date,
"Date should have been now");
411 Assert.AreEqual(
true,
false,
"TryParse should have succeeded");
416 #region Serialization
422 MemoryStream memoryStream;
424 ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
427 memoryStream =
new MemoryStream();
429 mobileFormatter.
Serialize(memoryStream, d2);
430 memoryStream.Seek(0, SeekOrigin.Begin);
432 Assert.AreEqual(d2, clone,
"Dates should have ben the same");
435 memoryStream =
new MemoryStream();
437 mobileFormatter.
Serialize(memoryStream, d2);
438 memoryStream.Seek(0, SeekOrigin.Begin);
440 Assert.AreEqual(d2, clone,
"Dates should have ben the same");
444 memoryStream =
new MemoryStream();
446 mobileFormatter.
Serialize(memoryStream, d2);
447 memoryStream.Seek(0, SeekOrigin.Begin);
449 Assert.AreEqual(d2, clone,
"Dates should have ben the same");
473 Assert.AreEqual(
"", obj.TextDate,
"Should be empty");
476 obj.TextDate =
string.Format(
"{0:g}", now);
477 Assert.AreEqual(
string.Format(
"{0:g}", now), obj.TextDate,
"Should be today");
486 if (s ==
"test")
return DateTime.Now;
492 Assert.AreEqual(
DateTime.Now.Date, date.Date.Date);
496 Assert.AreEqual(
DateTime.Now.Date, date.Date.Date);
520 return dataPortal.
Create();
524 private void Create()
Provides consistent context information between the client and server DataPortal objects.
This is the base class from which most business objects will be derived.
Maintains metadata about a property.
static SDtest NewSDTest(IDataPortal< SDtest > dataPortal)
static PropertyInfo< Csla.SmartDate > MyDateProperty
static PropertyInfo< Csla.SmartDate > TextDateProperty
void TestSmartDateConstructors()
void ComparisonOperators()
static void ClassInitialize(TestContext context)
void CustomParserReturnsDateTime()
Static dictionary-like class that offers similar functionality to GlobalContext This is used in tests...
static void Reinitialise()
Reinitialise the dictionary, clearing any existing results, ready for the next test
Interface defining the members of the data portal type.
object Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
@ TimeSpan
TimeSpan - time span
@ Serializable
Prevents updating or inserting until the transaction is complete.
Provides a date data type that understands the concept of an empty date value.
EmptyValue
Indicates the empty value of a SmartDate.
DateTime? Date
Gets or sets the date value.
static DateTime StringToDate(string value)
Converts a text date representation into a Date value.
override string ToString()
Returns a text representation of the date value.
static bool TryParse(string value, ref SmartDate result)
Converts a string value into a SmartDate.
static string DateToString(DateTime value, string formatString)
Converts a date value into a text representation.
string FormatString
Gets or sets the format string used to format a date value when it is returned as text.
override bool Equals(object obj)
Compares this object to another SmartDate for equality.
static Func< string, DateTime?> CustomParser
Gets or sets the custom parser.