public void Test_IResolvableToValueDateTime() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- DateTimeToday dateTimeToday = new DateTimeToday(); //---------------Test Result ----------------------- TestUtil.AssertIsInstanceOf<IResolvableToValue<DateTime>>(dateTimeToday); }
public void Test_IResolvableToValueDateTime() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- DateTimeToday dateTimeToday = new DateTimeToday(); //---------------Test Result ----------------------- TestUtil.AssertIsInstanceOf <IResolvableToValue <DateTime> >(dateTimeToday); }
public void Test_ResolveToValue_WhenHasOffset1_ShouldResolveToTomorrow() { //---------------Set up test pack------------------- DateTimeToday dateTimeToday = new DateTimeToday {OffSet = 1}; //---------------Assert Precondition---------------- Assert.AreEqual(1, dateTimeToday.OffSet); //---------------Execute Test ---------------------- DateTime resolveToValue = dateTimeToday.ResolveToValue(); //---------------Test Result ----------------------- Assert.AreEqual(DateTime.Today.AddDays(dateTimeToday.OffSet), resolveToValue); }
public void Test_Comparable_Equals_WithDateTimeTodayType() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); IComparable comparable = dateTimeToday; //-------------Execute test --------------------- int i = comparable.CompareTo(new DateTimeToday()); //-------------Test Result ---------------------- Assert.AreEqual(0, i); }
public void Test_Equals_WithNull_ShouldReturnFalse() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); const DateTimeToday dateTimeToday2 = null; //-------------Execute test --------------------- bool result = dateTimeToday.Equals(dateTimeToday2); //-------------Test Result ---------------------- Assert.IsFalse(result); }
public void Test_Equals_WithDateTimeValue_ShouldReturnFalse() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); DateTime dateTime2 = DateTime.Now; //-------------Execute test --------------------- bool result = dateTimeToday.Equals(dateTime2); //-------------Test Result ---------------------- Assert.IsFalse(result); }
public void Test_Equals_WithDateTimeTodayType_ShouldReturnTrue() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); DateTimeToday dateTimeToday2 = new DateTimeToday(); //-------------Execute test --------------------- bool result = dateTimeToday.Equals(dateTimeToday2); //-------------Test Result ---------------------- Assert.IsTrue(result); }
public void Test_SetOffSet_ShouldSetOffSet() { //---------------Set up test pack------------------- DateTimeToday dateTimeToday = new DateTimeToday(); //---------------Assert Precondition---------------- Assert.AreEqual(0, dateTimeToday.OffSet); //---------------Execute Test ---------------------- dateTimeToday.OffSet = 1; //---------------Test Result ----------------------- Assert.AreEqual(1, dateTimeToday.OffSet); }
public void Test_ConvertTo_WithDateTime_ShouldReturnTodayValue() { //---------------Set up test pack------------------- DateTimeTodayConverter dateTimeTodayConverter = new DateTimeTodayConverter(); DateTimeToday dateTimeToday = new DateTimeToday(); DateTime snapshot = DateTime.Today; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object result = dateTimeTodayConverter.ConvertTo(dateTimeToday, typeof(DateTime)); //---------------Test Result ----------------------- DateTime dateTime = TestUtil.AssertIsInstanceOf<DateTime>(result); Assert.AreEqual(snapshot, dateTime); }
public void Test_IResolvableToValue_ResolveToValue() { //---------------Set up test pack------------------- DateTimeToday dateTimeToday = new DateTimeToday(); IResolvableToValue<DateTime> resolvableToValue = dateTimeToday; DateTime today = DateTime.Today; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object resolvedValue = resolvableToValue.ResolveToValue(); //---------------Test Result ----------------------- DateTime dateTime = TestUtil.AssertIsInstanceOf<DateTime>(resolvedValue); Assert.AreEqual(today, dateTime); }
public void Test_ConvertTo_WhenDateTimeTodayWithOfSet_ShouldRetOffSetValue() { //---------------Set up test pack------------------- DateTimeTodayConverter dateTimeTodayConverter = new DateTimeTodayConverter(); DateTimeToday dateTimeToday = new DateTimeToday{OffSet = -5}; DateTime expectedResult = DateTime.Today.AddDays(dateTimeToday.OffSet); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object result = dateTimeTodayConverter.ConvertTo(dateTimeToday, typeof(DateTime)); //---------------Test Result ----------------------- Assert.AreEqual(expectedResult, result); }
public void Test_Comparable_OfDateTime_LessThan() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); IComparable <DateTime> comparable = dateTimeToday; //-------------Test Pre-conditions -------------- //-------------Execute test --------------------- int i = comparable.CompareTo(DateTimeToday.Value.AddDays(1)); //-------------Test Result ---------------------- Assert.AreEqual(-1, i); }
public void Test_DataMapper_ParsePropValue_FromDateTimeTodayObject() { //---------------Set up test pack------------------- DateTimeToday dateTimeToday = new DateTimeToday(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object parsedValue; bool parseSucceed = _dataMapper.TryParsePropValue(dateTimeToday, out parsedValue); //---------------Test Result ----------------------- Assert.IsTrue(parseSucceed); Assert.AreEqual(dateTimeToday, parsedValue); }
public void Test_SetOffSet_ShouldSetOffSet() { //---------------Set up test pack------------------- DateTimeToday dateTimeToday = new DateTimeToday(); //---------------Assert Precondition---------------- Assert.AreEqual(0, dateTimeToday.OffSet); //---------------Execute Test ---------------------- dateTimeToday.OffSet = 1; //---------------Test Result ----------------------- Assert.AreEqual(1, dateTimeToday.OffSet); }
public void Test_DefaultTypeConverter_WithDateTime_ShouldReturnTodayValue() { //---------------Set up test pack------------------- TypeConverter typeConverter = TypeDescriptor.GetConverter(typeof(DateTimeToday)); DateTimeToday dateTimeToday = new DateTimeToday(); DateTime snapshot = DateTime.Today; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object result = typeConverter.ConvertTo(dateTimeToday, typeof(DateTime)); //---------------Test Result ----------------------- DateTime dateTime = TestUtil.AssertIsInstanceOf <DateTime>(result); Assert.AreEqual(snapshot, dateTime); }
public void Test_IResolvableToValue_ResolveToValue() { //---------------Set up test pack------------------- DateTimeToday dateTimeToday = new DateTimeToday(); IResolvableToValue <DateTime> resolvableToValue = dateTimeToday; DateTime today = DateTime.Today; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object resolvedValue = resolvableToValue.ResolveToValue(); //---------------Test Result ----------------------- DateTime dateTime = TestUtil.AssertIsInstanceOf <DateTime>(resolvedValue); Assert.AreEqual(today, dateTime); }
public void Test_Comparable_GreaterThan() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); IComparable comparable = dateTimeToday; DateTime dateTime = DateTimeToday.Value.AddDays(-1); //-------------Test Pre-conditions -------------- //-------------Execute test --------------------- int i = comparable.CompareTo(dateTime); //-------------Test Result ---------------------- Assert.AreEqual(1, i); }
public void Test_ToString() { //---------------Set up test pack------------------- DateTimeToday dteNow = new DateTimeToday(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- string toString = dteNow.ToString(); //---------------Test Result ----------------------- DateTime dteParsedDateTime; Assert.IsTrue(DateTime.TryParse(toString, out dteParsedDateTime)); // Assert.IsTrue(dteNow == dteParsedDateTime); Assert.AreEqual(toString, dteParsedDateTime.ToString()); }
public void TestPrepareCriteria_ConvertsValue_StringTodayToDateTimeToday() { //---------------Set up test pack------------------- IClassDef myBoClassDef = MyBO.LoadClassDefWithDateTime(); const string dateTimeString = "Today"; DateTimeToday dateTimeToday = new DateTimeToday(); Criteria criteria = new Criteria("TestDateTime", Criteria.ComparisonOp.Equals, dateTimeString); //---------------Execute Test ---------------------- QueryBuilder.PrepareCriteria(myBoClassDef, criteria); //---------------Test Result ----------------------- Assert.IsInstanceOf(typeof(DateTimeToday), criteria.FieldValue); Assert.AreEqual(dateTimeToday, criteria.FieldValue); }
public void Test_ResolveToValue_WhenHasOffset1_ShouldResolveToTomorrow() { //---------------Set up test pack------------------- DateTimeToday dateTimeToday = new DateTimeToday { OffSet = 1 }; //---------------Assert Precondition---------------- Assert.AreEqual(1, dateTimeToday.OffSet); //---------------Execute Test ---------------------- DateTime resolveToValue = dateTimeToday.ResolveToValue(); //---------------Test Result ----------------------- Assert.AreEqual(DateTime.Today.AddDays(dateTimeToday.OffSet), resolveToValue); }
public void Test_ConvertTo_WhenDateTimeTodayWithOfSet_ShouldRetOffSetValue() { //---------------Set up test pack------------------- DateTimeTodayConverter dateTimeTodayConverter = new DateTimeTodayConverter(); DateTimeToday dateTimeToday = new DateTimeToday { OffSet = -5 }; DateTime expectedResult = DateTime.Today.AddDays(dateTimeToday.OffSet); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object result = dateTimeTodayConverter.ConvertTo(dateTimeToday, typeof(DateTime)); //---------------Test Result ----------------------- Assert.AreEqual(expectedResult, result); }
public static int Main(string[] args) { DateTimeToday today = new DateTimeToday(); TestLibrary.TestFramework.BeginTestCase("Testing System.DateTime.Today property..."); if (today.RunTests()) { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("PASS"); return 100; } else { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("FAIL"); return 0; } }
public static int Main(string[] args) { DateTimeToday today = new DateTimeToday(); TestLibrary.TestFramework.BeginTestCase("Testing System.DateTime.Today property..."); if (today.RunTests()) { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("PASS"); return(100); } else { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("FAIL"); return(0); } }
public void TestConvertValueToPropertyType_TodayStringToDateTimeToday_VariedCase() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("a", typeof (DateTime), PropReadWriteRule.ReadWrite, null); const string dateTimeString = "ToDaY"; DateTimeToday dateTimeToday = new DateTimeToday(); //---------------Execute Test ---------------------- object convertedDateTimeValue; bool parsed = propDef.TryParsePropValue(dateTimeString, out convertedDateTimeValue); //---------------Test Result ----------------------- Assert.IsTrue(parsed); Assert.IsInstanceOf(typeof(DateTimeToday), convertedDateTimeValue); Assert.AreEqual(dateTimeToday, convertedDateTimeValue); }
public void Test_Comparable_Equals_WithDateTimeTodayType() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); IComparable comparable = dateTimeToday; //-------------Execute test --------------------- int i = comparable.CompareTo(new DateTimeToday()); //-------------Test Result ---------------------- Assert.AreEqual(0, i); }
public void TestIsMatch_DateTimeToday_GreaterThan_NoMatch() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); ContactPersonTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO(); cp.Surname = Guid.NewGuid().ToString("N"); DateTimeToday dateTimeToday = new DateTimeToday(); cp.DateOfBirth = DateTime.Today.AddDays(-1); //---------------Assert PreConditions--------------- //---------------Execute Test ---------------------- Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.GreaterThan, dateTimeToday); bool isMatch = criteria.IsMatch(cp); //---------------Test Result ----------------------- Assert.IsFalse(isMatch, "The object should not be a match since it does not match the criteria given."); //---------------Tear Down ------------------------- }
public void Test_Comparable_GreaterThan() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); IComparable comparable = dateTimeToday; DateTime dateTime = DateTimeToday.Value.AddDays(-1); //-------------Test Pre-conditions -------------- //-------------Execute test --------------------- int i = comparable.CompareTo(dateTime); //-------------Test Result ---------------------- Assert.AreEqual(1, i); }
public void Test_Comparable_OfDateTime_LessThan() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); IComparable<DateTime> comparable = dateTimeToday; //-------------Test Pre-conditions -------------- //-------------Execute test --------------------- int i = comparable.CompareTo(DateTimeToday.Value.AddDays(1)); //-------------Test Result ---------------------- Assert.AreEqual(-1, i); }
public void Test_Equals_WithNull_ShouldReturnFalse() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); const DateTimeToday dateTimeToday2 = null; //-------------Execute test --------------------- bool result = dateTimeToday.Equals(dateTimeToday2); //-------------Test Result ---------------------- Assert.IsFalse(result); }
public void Test_Equals_WithDateTimeValue_ShouldReturnFalse() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); DateTime dateTime2 = DateTime.Now; //-------------Execute test --------------------- bool result = dateTimeToday.Equals(dateTime2); //-------------Test Result ---------------------- Assert.IsFalse(result); }
public void Test_Equals_WithDateTimeTodayType_ShouldReturnTrue() { //-------------Setup Test Pack ------------------ DateTimeToday dateTimeToday = new DateTimeToday(); DateTimeToday dateTimeToday2 = new DateTimeToday(); //-------------Execute test --------------------- bool result = dateTimeToday.Equals(dateTimeToday2); //-------------Test Result ---------------------- Assert.IsTrue(result); }
public void Test_ToString() { //---------------Set up test pack------------------- DateTimeToday dteNow = new DateTimeToday(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- string toString = dteNow.ToString(); //---------------Test Result ----------------------- DateTime dteParsedDateTime; Assert.IsTrue(DateTime.TryParse(toString, out dteParsedDateTime)); // Assert.IsTrue(dteNow == dteParsedDateTime); Assert.AreEqual(toString, dteParsedDateTime.ToString()); }
public void Test_DataMapper_ParsePropValue_FromDateTimeTodayObject() { //---------------Set up test pack------------------- DateTimeToday dateTimeToday = new DateTimeToday(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object parsedValue; bool parseSucceed = _dataMapper.TryParsePropValue(dateTimeToday, out parsedValue); //---------------Test Result ----------------------- Assert.IsTrue(parseSucceed); Assert.AreEqual(dateTimeToday, parsedValue); }
public void TestConvertValueToPropertyType_DateTimeAcceptsDateTimeToday() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("a", typeof (DateTime), PropReadWriteRule.ReadWrite, null); DateTimeToday dateTimeToday = new DateTimeToday(); //---------------Execute Test ---------------------- object convertedDateTimeValue; bool parsed = propDef.TryParsePropValue(dateTimeToday, out convertedDateTimeValue); //---------------Test Result ----------------------- Assert.IsTrue(parsed); Assert.IsInstanceOf(typeof (DateTimeToday), convertedDateTimeValue); Assert.AreSame(dateTimeToday, convertedDateTimeValue); }
///<summary> /// Tries to parse a value as an object to a valid DateTimeValue or a resolvable DateTimeValue. /// The valid value may not be a date but could instead return a <see cref="DateTimeToday"/> or <see cref="DateTimeNow"/> etc /// These objects are convertable to DateTime via the <see cref="DateTimeToday.ResolveToValue"/> ///</summary> ///<param name="valueToParse"></param> ///<param name="returnValue"></param> ///<returns>If the value cannot be parsed to a valid date time then returns false else true</returns> public static bool TryParseValue(object valueToParse, out object returnValue) { returnValue = null; if (valueToParse != null && valueToParse is string && ((string)valueToParse).Length == 0) return true; if(valueToParse == null || valueToParse == DBNull.Value) return true; if (!(valueToParse is DateTime)) { if (valueToParse is DateTimeToday || valueToParse is DateTimeNow) { returnValue = valueToParse; return true; } if (valueToParse is String) { string stringValueToConvert = (string)valueToParse; var stringValueToConvertUpperCase = stringValueToConvert.ToUpper(); if (stringValueToConvertUpperCase == "TODAY") { returnValue = new DateTimeToday(); return true; } if (stringValueToConvertUpperCase == "YESTERDAY") { returnValue = new DateTimeToday(); ((DateTimeToday) returnValue).OffSet = -1; return true; } if (stringValueToConvertUpperCase == "TOMORROW") { returnValue = new DateTimeToday(); ((DateTimeToday) returnValue).OffSet = 1; return true; } if (stringValueToConvertUpperCase == "NOW") { returnValue = new DateTimeNow(); return true; } DateTime dtOut; if (DateTime.TryParseExact(stringValueToConvert, StandardDateTimeFormat, _dateTimeFormatProvider, DateTimeStyles.AllowWhiteSpaces, out dtOut)) { returnValue = dtOut; return true; } } DateTime dateTimeOut; string valueToParseAsString = valueToParse.ToString(); if (DateTime.TryParse(valueToParseAsString, out dateTimeOut)) { returnValue = dateTimeOut; return true; } if (DateTime.TryParse(valueToParseAsString, new DateTimeFormatInfo { FullDateTimePattern = "dd/MM/yyyy HH:mm:ss:fff" }, DateTimeStyles.AllowWhiteSpaces, out dateTimeOut)) { returnValue = dateTimeOut; return true; } if (DateTime.TryParse(valueToParseAsString, new DateTimeFormatInfo { FullDateTimePattern = "MM/dd/yyyy HH:mm:ss:fff" }, DateTimeStyles.AllowWhiteSpaces, out dateTimeOut)) { returnValue = dateTimeOut; return true; } return false; } returnValue = valueToParse; return true; }
public void Test_Value_WhenDateTimeToday_ShouldReturnResolvedValue() { //---------------Set up test pack------------------- PropDef propDef = CreateTestPropDateTimePropDef(); IBOProp boProp = propDef.CreateBOProp(true); DateTimeToday dateTimeToday = new DateTimeToday(); boProp.Value = dateTimeToday; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object value = boProp.Value; //---------------Test Result ----------------------- Assert.IsNotNull(value); Assert.AreNotSame(dateTimeToday, value); }
///<summary> /// Tries to parse a value as an object to a valid DateTimeValue or a resolvable DateTimeValue. /// The valid value may not be a date but could instead return a <see cref="DateTimeToday"/> or <see cref="DateTimeNow"/> etc /// These objects are convertable to DateTime via the <see cref="DateTimeToday.ResolveToValue"/> ///</summary> ///<param name="valueToParse"></param> ///<param name="returnValue"></param> ///<returns>If the value cannot be parsed to a valid date time then returns false else true</returns> public static bool TryParseValue(object valueToParse, out object returnValue) { returnValue = null; if (valueToParse != null && valueToParse is string && ((string)valueToParse).Length == 0) { return(true); } if (valueToParse == null || valueToParse == DBNull.Value) { return(true); } if (!(valueToParse is DateTime)) { if (valueToParse is DateTimeToday || valueToParse is DateTimeNow || valueToParse is DateTimeUtcNow) { returnValue = valueToParse; return(true); } if (valueToParse is String) { string stringValueToConvert = (string)valueToParse; var stringValueToConvertUpperCase = stringValueToConvert.ToUpper(); if (stringValueToConvertUpperCase == "TODAY") { returnValue = new DateTimeToday(); return(true); } if (stringValueToConvertUpperCase == "YESTERDAY") { returnValue = new DateTimeToday(); ((DateTimeToday)returnValue).OffSet = -1; return(true); } if (stringValueToConvertUpperCase == "TOMORROW") { returnValue = new DateTimeToday(); ((DateTimeToday)returnValue).OffSet = 1; return(true); } if (stringValueToConvertUpperCase == "NOW") { returnValue = new DateTimeNow(); return(true); } if (stringValueToConvertUpperCase == "UTCNOW") { returnValue = new DateTimeUtcNow(); return(true); } DateTime dtOut; if (DateTime.TryParseExact(stringValueToConvert, StandardDateTimeFormat, _dateTimeFormatProvider, DateTimeStyles.AllowWhiteSpaces, out dtOut)) { returnValue = dtOut; return(true); } } DateTime dateTimeOut; string valueToParseAsString = valueToParse.ToString(); if (DateTime.TryParse(valueToParseAsString, out dateTimeOut)) { returnValue = dateTimeOut; return(true); } if (DateTime.TryParse(valueToParseAsString, new DateTimeFormatInfo { FullDateTimePattern = "dd/MM/yyyy HH:mm:ss:fff" }, DateTimeStyles.AllowWhiteSpaces, out dateTimeOut)) { returnValue = dateTimeOut; return(true); } if (DateTime.TryParse(valueToParseAsString, new DateTimeFormatInfo { FullDateTimePattern = "MM/dd/yyyy HH:mm:ss:fff" }, DateTimeStyles.AllowWhiteSpaces, out dateTimeOut)) { returnValue = dateTimeOut; return(true); } return(false); } returnValue = valueToParse; return(true); }