Skip to content

Commit

Permalink
Added basic unit tests for DateTimeOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
lpreiner committed Jan 7, 2021
1 parent c1cb139 commit 1fd5300
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions CSharpDate.Test/DateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public void CanConstructFromDateTime()
Assert.True(d1.Equals(d2));
}

[Fact]
public void CanConstructFromDateTimeOffset()
{
Date d1 = new Date(new DateTimeOffset(2001, 2, 3, 4, 5, 6, 7, TimeSpan.Zero).AddTicks(8));
Date d2 = new Date(2001, 2, 3);
Assert.Equal(d1, d2);
Assert.True(d1.Equals(d2));
}

[Fact]
public void ToDateRemovesAllTimePortion()
{
Expand All @@ -76,6 +85,17 @@ public void CanGetDateFromDateTime()
Assert.Equal(dt.Day, d.Day);
}

[Fact]
public void CanGetDateFromDateTimeOffset()
{
DateTimeOffset dto = new DateTimeOffset(2013, 4, 5, 6, 7, 8, 9, TimeSpan.Zero);
Date d = dto.ToDate();

Assert.Equal(dto.Year, d.Year);
Assert.Equal(dto.Month, d.Month);
Assert.Equal(dto.Day, d.Day);
}

[Fact]
public void CanAddYears()
{
Expand Down Expand Up @@ -220,6 +240,35 @@ public void CanExplicitCastToDateTime()
Assert.Equal(dt.Day, d.Day);
}

[Fact]
public void CanImplicitCastToDateTimeOffset()
{
Date d = new Date(2013, 4, 5);
DateTimeOffset dt = d;

Assert.Equal(d.Year, dt.Year);
Assert.Equal(d.Month, dt.Month);
Assert.Equal(d.Day, dt.Day);
Assert.Equal(d.DayOfWeek, dt.DayOfWeek);
Assert.Equal(d.DayOfYear, dt.DayOfYear);
Assert.Equal(0, dt.Hour);
Assert.Equal(0, dt.Minute);
Assert.Equal(0, dt.Second);
Assert.Equal(0, dt.Millisecond);
}

[Fact]
public void CanExplicitCastToDateTimeOffset()
{
DateTime dt = new DateTime(2000, 1, 2, 3, 4, 5);
DateTimeOffset dto = new DateTimeOffset(dt, TimeSpan.FromMinutes(1));
Date d = (Date)dto;

Assert.Equal(dto.Year, d.Year);
Assert.Equal(dto.Month, d.Month);
Assert.Equal(dto.Day, d.Day);
}

[Fact]
public void CanToShortString()
{
Expand Down

0 comments on commit 1fd5300

Please sign in to comment.