添加VS项目
parent
67e4274992
commit
97d555c778
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.3.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||||
|
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DateTimeStudy\DateTimeStudy.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace DateTimeStudy.XUnitTest
|
||||||
|
{
|
||||||
|
public class DateTimeStudyTest:IDisposable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数:单元测试前的准备
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeStudyTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Test1()
|
||||||
|
{
|
||||||
|
Assert.Equal(1, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateDateTimeDefaultTest()
|
||||||
|
{
|
||||||
|
DateTimeStudy sudy = new DateTimeStudy();
|
||||||
|
//无参时间:0001年1月1日 0时 0分 0秒
|
||||||
|
var time = sudy.CreateDateTime();
|
||||||
|
Assert.True(time.Year==1 && time.Month==1 && time.Day==1 && time.Hour==0 && time.Minute==0 && time.Second==0 && time.Millisecond==0);
|
||||||
|
Assert.True(time.Kind == DateTimeKind.Unspecified);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateDateTime4TicksTest()
|
||||||
|
{
|
||||||
|
DateTimeStudy sudy = new DateTimeStudy();
|
||||||
|
//UTC时间:2018-01-01
|
||||||
|
long ticks = 636503616000000000;
|
||||||
|
var time = sudy.CreateDateTime(ticks);
|
||||||
|
Assert.True(time.Year == 2018 && time.Month == 1 && time.Day == 1 && time.Hour == 0 && time.Minute == 0 && time.Second == 0 && time.Millisecond == 0);
|
||||||
|
Assert.True(new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Local) == time);
|
||||||
|
Assert.True(time.Kind == DateTimeKind.Unspecified);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateDateTimeTest4()
|
||||||
|
{
|
||||||
|
DateTimeStudy sudy = new DateTimeStudy();
|
||||||
|
//UTC时间:2018-01-01
|
||||||
|
long ticks = 636503616000000000;
|
||||||
|
var time = sudy.CreateDateTime(ticks, DateTimeKind.Utc);
|
||||||
|
var time2 = sudy.CreateDateTime(ticks, DateTimeKind.Local);
|
||||||
|
|
||||||
|
//这很奇怪:竟然相等
|
||||||
|
Assert.Equal<DateTime>(time, time2);
|
||||||
|
Assert.True(time.Year == 2018 && time.Month == 1 && time.Day == 1 && time.Hour == 0 && time.Minute == 0 && time.Second == 0 && time.Millisecond == 0);
|
||||||
|
Assert.True(time2.Year == 2018 && time2.Month == 1 && time2.Day == 1 && time2.Hour == 0 && time2.Minute == 0 && time2.Second == 0 && time2.Millisecond == 0);
|
||||||
|
Assert.True(new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Local) == time);
|
||||||
|
Assert.True(new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) == time);
|
||||||
|
Assert.True(new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Local) == time2);
|
||||||
|
Assert.True(new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) == time2);
|
||||||
|
Assert.True(time.Kind == DateTimeKind.Utc);
|
||||||
|
Assert.True(time2.Kind == DateTimeKind.Local);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 相当于析构函数:单元测试收尾清理
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in New Issue