public void TestSimpleFormatOfDateTimeExplicitBoth() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008 04:13 AM")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Both.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 4, 13, 0))); }
public void TestSimpleFormatOfDateTimeOnlyDate() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008")); date.Exact = new MockAttribute(new Constant("true")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 0, 0, 0))); }
public void TestEmpty() { var date = new ParseDate(); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); }
public void CheckRequired() { var tag = new ParseDate(); RequiredAttribute.Check(tag); //no exceptions }
public void TestSimpleParse_NonExact() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008 12:00:00")); date.Exact = new MockAttribute(new Constant("false")); date.Var = new MockAttribute(new Constant("result")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 12, 0, 0))); }
public void TestSimpleParse_ExplicitExact_WrongFormat() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008 12:00:00")); date.Exact = new MockAttribute(new Constant("true")); try { date.Evaluate(_model); Assert.Fail("Should fail"); } catch (TagException Te) { Assert.That(Te.Message, Is.EqualTo(TagException.ParseException("1/6/2008 12:00:00", "Date").Message)); } }
public void TestSimpleFormatOfWithCustomPatternWithTimeZone() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("04:05 +02:00")); date.Pattern = new MockAttribute(new Constant("HH:mm zzz")); date.Var = new MockAttribute(new Constant("result")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 3, 5, 0); if (dt.IsDaylightSavingTime()) { dt = dt.AddHours(1); } Assert.That(((DateTime) _model.Page["result"]), Is.EqualTo(dt)); }
public void TestSimpleFormatOfDifferentDateStyle_Long() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("Saturday, February 03, 2001")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); date.DateStyle = new MockAttribute(new Constant(DateStyle.Long.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2001, 2, 3, 0, 0, 0))); }
public void TestSimpleFormatOfWithBothLongFormat() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("Saturday, February 03, 2001 4:05:06 AM")); date.TimeStyle = new MockAttribute(new Constant(TimeStyle.Long.ToString())); date.DateStyle = new MockAttribute(new Constant(DateStyle.Long.ToString())); date.Var = new MockAttribute(new Constant("result")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2001, 2, 3, 4, 5, 6))); }
public void TestSimpleFormatOfEmptyString() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); }
public void TestSimpleFormatOfDifferentTimeStyle_ShortDifferentCulture() { _model.Page[FormatConstants.LOCALE] = new CultureInfo("nl-NL"); var date = new ParseDate(); date.Value = new MockAttribute(new Constant("16:12")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Time.ToString())); date.TimeStyle = new MockAttribute(new Constant(TimeStyle.Default.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 16, 12, 0))); }
public void TestSimpleFormatOfDifferentTimeStyle_Long() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("4:05:06 AM")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Time.ToString())); date.TimeStyle = new MockAttribute(new Constant(TimeStyle.Long.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 5, 6))); }
public void TestSimpleFormatOfDifferentDateStyle_Wrong() { var date = new ParseDate(); _model.Model["DateValue"] = new DateTime(2001, 2, 3, 4, 5, 6); date.Value = new MockAttribute(new Property("DateValue")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); date.DateStyle = new MockAttribute(new Constant("Wrong")); try { date.Evaluate(_model); Assert.Fail("Expected failure"); } catch (ArgumentException Ae) { Assert.That(Ae.Message.Contains("Wrong")); } }
public void TestSimpleFormatOfDifferentDateStyle_ShortDifferentCulture() { _model.Page[FormatConstants.LOCALE] = new CultureInfo("nl-NL"); var date = new ParseDate(); date.Value = new MockAttribute(new Constant("6-1-2008")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); date.DateStyle = new MockAttribute(new Constant(DateStyle.Default.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 0, 0, 0))); }
public void TestSimpleFormatOfWithCustomPattern() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("03 Feb 2001T04:05")); date.Var = new MockAttribute(new Constant("result")); date.Pattern = new MockAttribute(new Constant("dd MMM yyyy'T'HH:mm")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2001, 2, 3, 4, 5, 0))); }
public void TestSimpleFormatOfDateTimeOnlyTime() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("4:12 AM")); date.Exact = new MockAttribute(new Constant("true")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Time.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 12, 0))); }
public void TestSimpleFormatOfDifferentDateStyle_ExplicitDefault() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); date.DateStyle = new MockAttribute(new Constant(DateStyle.Default.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 0, 0, 0))); }