Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unit Test Project #124

Merged
merged 3 commits into from
Mar 8, 2024
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
8 changes: 6 additions & 2 deletions ProjBobcat/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[*.cs]

dotnet_diagnostic.CS1591.severity = suggestion

dotnet_diagnostic.CA2007.severity = none

dotnet_diagnostic.CA1816.severity = silent

# IDE0040: 添加可访问性修饰符
dotnet_style_require_accessibility_modifiers = never

# this. 和 Me. 首选项
dotnet_style_qualification_for_event = true:silent
dotnet_style_qualification_for_field = true:silent
dotnet_style_qualification_for_method = true:silent
dotnet_style_qualification_for_property = true:silent
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ProjBobcat.JsonConverter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace ProjBobcat.Tests.ClassOrientedTests.JsonConverter;

[TestClass()]
public class DateTimeConverterUsingDateTimeParseTests
{
[TestMethod()]
public void ReadTest()
{
var converter = new DateTimeConverterUsingDateTimeParse();
var dateTime = DateTime.Now;
var jsonData = JsonSerializer.SerializeToUtf8Bytes($"{dateTime}");
Utf8JsonReader reader = new Utf8JsonReader(jsonData);
Assert.IsTrue(reader.Read());
var result = converter.Read(ref reader, typeof(DateTime), JsonSerializerOptions.Default);
Assert.AreEqual(dateTime.Ticks, result.Ticks, TimeSpan.FromSeconds(1).Ticks);
Assert.IsFalse(reader.Read());
}

[TestMethod()]
public void WriteTest()
{
var converter = new DateTimeConverterUsingDateTimeParse();
using var stream = new MemoryStream();
var dateTime = DateTime.Now;
using (var writer = new Utf8JsonWriter(stream))
converter.Write(writer, dateTime, JsonSerializerOptions.Default);

var actual = stream.ToArray();
var expected = JsonSerializer.SerializeToUtf8Bytes($"{dateTime}");
#warning different result in different culture. is this really expected?

Check warning on line 39 in ProjBobcat/ProjBobcat.Tests/ClassOrientedTests/JsonConverter/DateTimeConverterUsingDateTimeParseTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

#warning: 'different result in different culture. is this really expected?'

Check warning on line 39 in ProjBobcat/ProjBobcat.Tests/ClassOrientedTests/JsonConverter/DateTimeConverterUsingDateTimeParseTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

#warning: 'different result in different culture. is this really expected?'

Check warning on line 39 in ProjBobcat/ProjBobcat.Tests/ClassOrientedTests/JsonConverter/DateTimeConverterUsingDateTimeParseTests.cs

View workflow job for this annotation

GitHub Actions / Test build on ubuntu-latest .NET 8.0

#warning: 'different result in different culture. is this really expected?'

Check warning on line 39 in ProjBobcat/ProjBobcat.Tests/ClassOrientedTests/JsonConverter/DateTimeConverterUsingDateTimeParseTests.cs

View workflow job for this annotation

GitHub Actions / Test build on ubuntu-latest .NET 8.0

#warning: 'different result in different culture. is this really expected?'

Check warning on line 39 in ProjBobcat/ProjBobcat.Tests/ClassOrientedTests/JsonConverter/DateTimeConverterUsingDateTimeParseTests.cs

View workflow job for this annotation

GitHub Actions / Test build on windows-latest .NET 8.0

#warning: 'different result in different culture. is this really expected?'

Check warning on line 39 in ProjBobcat/ProjBobcat.Tests/ClassOrientedTests/JsonConverter/DateTimeConverterUsingDateTimeParseTests.cs

View workflow job for this annotation

GitHub Actions / Test build on windows-latest .NET 8.0

#warning: 'different result in different culture. is this really expected?'

Check warning on line 39 in ProjBobcat/ProjBobcat.Tests/ClassOrientedTests/JsonConverter/DateTimeConverterUsingDateTimeParseTests.cs

View workflow job for this annotation

GitHub Actions / Test build on macOS-latest .NET 8.0

#warning: 'different result in different culture. is this really expected?'

Check warning on line 39 in ProjBobcat/ProjBobcat.Tests/ClassOrientedTests/JsonConverter/DateTimeConverterUsingDateTimeParseTests.cs

View workflow job for this annotation

GitHub Actions / Test build on macOS-latest .NET 8.0

#warning: 'different result in different culture. is this really expected?'
CollectionAssert.AreEqual(expected, actual);
}
}
27 changes: 27 additions & 0 deletions ProjBobcat/ProjBobcat.Tests/ProjBobcat.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ProjBobcat\ProjBobcat.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions ProjBobcat/ProjBobcat.sln
yueyinqiu marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjBobcat.Tests", "ProjBobcat.Tests\ProjBobcat.Tests.csproj", "{583559EB-2B84-468A-B4DA-15E116850F3C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -20,6 +22,10 @@ Global
{9777E280-8601-4A6C-BD75-0D29FD4F5D6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9777E280-8601-4A6C-BD75-0D29FD4F5D6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9777E280-8601-4A6C-BD75-0D29FD4F5D6F}.Release|Any CPU.Build.0 = Release|Any CPU
{583559EB-2B84-468A-B4DA-15E116850F3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{583559EB-2B84-468A-B4DA-15E116850F3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{583559EB-2B84-468A-B4DA-15E116850F3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{583559EB-2B84-468A-B4DA-15E116850F3C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading