using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DateTimeExtensions;
namespace TestExtensions
{
[TestFixture]
public class Date
{
[Test]
public void TEST_MIDNIGHT_NOON()
{
DateTime dateTime1 = new DateTime(2009, 11, 2,5,5,5);
DateTime result1 = new DateTime(2009, 11, 2,12,0,0);
DateTime dateTime2 = new DateTime(2009, 11, 1,4,3,10);
DateTime result2 = new DateTime(2009, 11, 1,0,0,0);
Assert.AreEqual(result1, dateTime1.Noon());
Assert.AreEqual(result2, dateTime2.MidNight());
}
[Test]
public void TEST_TIMESPAN_TO_WORDS()
{
TimeSpan timeSpan1 = new TimeSpan(5, 11, 2, 5);
string result1 = "5 days, 11 hours, 2 minutes and 5 seconds";
TimeSpan timeSpan2 = new TimeSpan(7, 1, 0, 0);
string result2 = "1 week and 1 hour";
TimeSpan timeSpan3 = new TimeSpan(365, 24, 0, 0);
string result3 = "1 year and 1 day";
TimeSpan timeSpan4 = new TimeSpan(14, 24, 0, 0);
string result4 = "2 weeks and 1 day";
Assert.AreEqual(result1, timeSpan1.ToWords());
Assert.AreEqual(result2, timeSpan2.ToWords());
Assert.AreEqual(result3, timeSpan3.ToWords());
Assert.AreEqual(result4, timeSpan4.ToWords());
}
[Test]
public void TEST_DATE_WITHIN_RANGE()
{
DateTime dateTime1 = new DateTime(2009, 1, 1);
DateTime floor1 = new DateTime(2008, 12, 31);
DateTime ceiling1 = new DateTime(2009, 1, 2);
DateTime dateTime2 = new DateTime(2009, 1, 1);
DateTime floor2 = new DateTime(2008, 1, 12);
DateTime ceiling2 = new DateTime(2008, 12, 31);
DateTime dateTime3 = new DateTime(2009, 1, 1);
DateTime floor3 = new DateTime(2009, 1, 1);
DateTime ceiling3 = new DateTime(2009, 1, 2);
Assert.AreEqual(true,dateTime1.IsWithinRange(floor1,ceiling1,true));
Assert.AreEqual(false,dateTime1.IsWithinRange(floor2,ceiling2,true));
Assert.AreEqual(true,dateTime1.IsWithinRange(floor3,ceiling3,true));
Assert.AreEqual(false,dateTime1.IsWithinRange(floor3,ceiling3,false));
}
[Test]
public void TEST_TIME_SPAN()
{
DateTime futureDate = DateTime.Now.Add(new TimeSpan(2,3,4));
DateTime pastDate = DateTime.Now.Subtract(new TimeSpan(2, 3, 4));
TimeSpan result1 = new TimeSpan(2, 3, 4);
Assert.AreEqual(result1, futureDate.GetTimeSpan());
Assert.AreEqual(result1, pastDate.GetTimeSpan());
}
}
}