mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 19:48:46 +00:00
Add tests for DateTime/Offset
This commit is contained in:
parent
30e925cdb0
commit
e2a496face
69
X10D.Tests/src/Time/DateTimeOffsetTests.cs
Normal file
69
X10D.Tests/src/Time/DateTimeOffsetTests.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Time;
|
||||
|
||||
namespace X10D.Tests.Time;
|
||||
|
||||
[TestClass]
|
||||
public class DateTimeOffsetTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void AgeShouldBeCorrect()
|
||||
{
|
||||
DateTimeOffset birthday = new DateTime(2000, 1, 1);
|
||||
DateTimeOffset today = DateTime.Now.Date;
|
||||
|
||||
Assert.AreEqual(today.Year - birthday.Year, birthday.Age());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FirstShouldBeCorrect()
|
||||
{
|
||||
DateTimeOffset date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(new DateTime(2000, 1, 1), date.First(DayOfWeek.Saturday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 2), date.First(DayOfWeek.Sunday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 3), date.First(DayOfWeek.Monday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 4), date.First(DayOfWeek.Tuesday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 5), date.First(DayOfWeek.Wednesday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 6), date.First(DayOfWeek.Thursday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 7), date.First(DayOfWeek.Friday));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FirstDayOfMonthShouldBeCorrect()
|
||||
{
|
||||
DateTimeOffset today = DateTime.Now.Date;
|
||||
|
||||
Assert.AreEqual(new DateTime(today.Year, today.Month, 1), today.FirstDayOfMonth());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LastShouldBeCorrect()
|
||||
{
|
||||
DateTimeOffset date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(new DateTime(2000, 1, 29), date.Last(DayOfWeek.Saturday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 30), date.Last(DayOfWeek.Sunday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 31), date.Last(DayOfWeek.Monday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 25), date.Last(DayOfWeek.Tuesday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 26), date.Last(DayOfWeek.Wednesday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 27), date.Last(DayOfWeek.Thursday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 28), date.Last(DayOfWeek.Friday));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LastDayOfMonthShouldBeCorrect()
|
||||
{
|
||||
DateTimeOffset date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(new DateTime(date.Year, date.Month, 31), date.LastDayOfMonth());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NextShouldBeCorrect()
|
||||
{
|
||||
DateTimeOffset date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(new DateTime(2000, 1, 8), date.Next(DayOfWeek.Saturday));
|
||||
}
|
||||
}
|
85
X10D.Tests/src/Time/DateTimeTests.cs
Normal file
85
X10D.Tests/src/Time/DateTimeTests.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Time;
|
||||
|
||||
namespace X10D.Tests.Time;
|
||||
|
||||
[TestClass]
|
||||
public class DateTimeTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void AgeShouldBeCorrect()
|
||||
{
|
||||
var birthday = new DateTime(2000, 1, 1);
|
||||
DateTime today = DateTime.Now.Date;
|
||||
|
||||
Assert.AreEqual(today.Year - birthday.Year, birthday.Age());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FirstShouldBeCorrect()
|
||||
{
|
||||
var date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(new DateTime(2000, 1, 1), date.First(DayOfWeek.Saturday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 2), date.First(DayOfWeek.Sunday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 3), date.First(DayOfWeek.Monday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 4), date.First(DayOfWeek.Tuesday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 5), date.First(DayOfWeek.Wednesday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 6), date.First(DayOfWeek.Thursday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 7), date.First(DayOfWeek.Friday));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FirstDayOfMonthShouldBeCorrect()
|
||||
{
|
||||
DateTime today = DateTime.Now.Date;
|
||||
|
||||
Assert.AreEqual(new DateTime(today.Year, today.Month, 1), today.FirstDayOfMonth());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LastShouldBeCorrect()
|
||||
{
|
||||
var date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(new DateTime(2000, 1, 29), date.Last(DayOfWeek.Saturday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 30), date.Last(DayOfWeek.Sunday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 31), date.Last(DayOfWeek.Monday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 25), date.Last(DayOfWeek.Tuesday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 26), date.Last(DayOfWeek.Wednesday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 27), date.Last(DayOfWeek.Thursday));
|
||||
Assert.AreEqual(new DateTime(2000, 1, 28), date.Last(DayOfWeek.Friday));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LastDayOfMonthShouldBeCorrect()
|
||||
{
|
||||
var date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(new DateTime(date.Year, date.Month, 31), date.LastDayOfMonth());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NextShouldBeCorrect()
|
||||
{
|
||||
var date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(new DateTime(2000, 1, 8), date.Next(DayOfWeek.Saturday));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ToUnixTimeMillisecondsShouldBeCorrect()
|
||||
{
|
||||
var date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(946684800000, date.ToUnixTimeMilliseconds());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ToUnixTimeSecondsShouldBeCorrect()
|
||||
{
|
||||
var date = new DateTime(2000, 1, 1);
|
||||
|
||||
Assert.AreEqual(946684800, date.ToUnixTimeSeconds());
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace X10D;
|
||||
namespace X10D.Time;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="DateTime" />.
|
@ -1,4 +1,4 @@
|
||||
namespace X10D;
|
||||
namespace X10D.Time;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="DateTimeOffset" />.
|
Loading…
Reference in New Issue
Block a user