Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="4.3.3" />
<PackageReference Include="MSTest.TestFramework" Version="4.3.3" />
<PackageReference Include="coverlet.collector" Version="10.0.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public void LocalDate_WhenTestKind_ReturnsLocal()
{
var now = DateTime.Now;
Assert.AreEqual(now.Kind, DateTimeKind.Local);

Check warning on line 31 in dotnet-datetime/DateTimeNowVsDateTimeUtcNow/DateTimeNow.Tests/DateTimeTests.cs

View workflow job for this annotation

GitHub Actions / Build & test (dotnet-datetime/DateTimeNowVsDateTimeUtcNow)

Assertion arguments should be passed in the correct order. 'actual' and 'expected'/'notExpected' arguments have been swapped. (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0017)

Check warning on line 31 in dotnet-datetime/DateTimeNowVsDateTimeUtcNow/DateTimeNow.Tests/DateTimeTests.cs

View workflow job for this annotation

GitHub Actions / Build & test (dotnet-datetime/DateTimeNowVsDateTimeUtcNow)

Assertion arguments should be passed in the correct order. 'actual' and 'expected'/'notExpected' arguments have been swapped. (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0017)

}

Expand All @@ -36,7 +36,7 @@
public void UTCDate_WhenTestKind_ReturnsUTC()
{
var utcNow = DateTime.UtcNow;
Assert.AreEqual(utcNow.Kind, DateTimeKind.Utc);

Check warning on line 39 in dotnet-datetime/DateTimeNowVsDateTimeUtcNow/DateTimeNow.Tests/DateTimeTests.cs

View workflow job for this annotation

GitHub Actions / Build & test (dotnet-datetime/DateTimeNowVsDateTimeUtcNow)

Assertion arguments should be passed in the correct order. 'actual' and 'expected'/'notExpected' arguments have been swapped. (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0017)

Check warning on line 39 in dotnet-datetime/DateTimeNowVsDateTimeUtcNow/DateTimeNow.Tests/DateTimeTests.cs

View workflow job for this annotation

GitHub Actions / Build & test (dotnet-datetime/DateTimeNowVsDateTimeUtcNow)

Assertion arguments should be passed in the correct order. 'actual' and 'expected'/'notExpected' arguments have been swapped. (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0017)
}

[TestMethod]
Expand All @@ -56,5 +56,27 @@

Assert.IsTrue(now.Kind == DateTimeKind.Local && utc.Kind == DateTimeKind.Utc);
}

[TestMethod]
public void UnspecifiedDate_WhenConvertedToLocalTime_IsTreatedAsUtc()
{
var value = new DateTime(2022, 1, 9, 14, 34, 42);

var unspecified = DateTime.SpecifyKind(value, DateTimeKind.Unspecified);
var asUtc = DateTime.SpecifyKind(value, DateTimeKind.Utc);

Assert.AreEqual(asUtc.ToLocalTime(), unspecified.ToLocalTime());
}

[TestMethod]
public void UnspecifiedDate_WhenConvertedToUniversalTime_IsTreatedAsLocal()
{
var value = new DateTime(2022, 1, 9, 14, 34, 42);

var unspecified = DateTime.SpecifyKind(value, DateTimeKind.Unspecified);
var asLocal = DateTime.SpecifyKind(value, DateTimeKind.Local);

Assert.AreEqual(asLocal.ToUniversalTime(), unspecified.ToUniversalTime());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Loading