增加record测试

This commit is contained in:
Falcon 2024-07-25 11:46:05 +08:00
parent fa709f283b
commit 6c52267815
4 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
</Project>

31
CSharpTest/UnitTest1.cs Normal file
View File

@ -0,0 +1,31 @@
using System.Text.Json;
namespace CSharpTest
{
public record Person(string name,int age);
public class RecordTests
{
[SetUp]
public void Setup() {
}
[Test]
public void Test1() {
var p1 = new Person("ÕÅÈý",40);
var p2 = p1 with { age = 50 };
Console.WriteLine(p1 == p2);
Console.WriteLine(p1.Equals(p2));
Console.WriteLine(p1.ToString());
Console.WriteLine(JsonSerializer.Serialize(p1));
Console.WriteLine(JsonSerializer.Serialize(p2));
var p3 = new Person("ÕÅÈý",40);
var p4 = new Person("ÕÅÈý",40);
Console.WriteLine(p3 == p4);
Assert.IsTrue(p3 == p4);
}
}
}

1
CSharpTest/Usings.cs Normal file
View File

@ -0,0 +1 @@
global using NUnit.Framework;

View File

@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Falcon.SugarApi.Windows", "
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RabbitMqTest", "RabbitMqTest\RabbitMqTest.csproj", "{7F308FE9-B5C5-45BA-B882-15B4B983C39C}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RabbitMqTest", "RabbitMqTest\RabbitMqTest.csproj", "{7F308FE9-B5C5-45BA-B882-15B4B983C39C}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpTest", "CSharpTest\CSharpTest.csproj", "{FA6A7A47-7EEE-4264-9C89-C2E717B1CB78}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -45,6 +47,10 @@ Global
{7F308FE9-B5C5-45BA-B882-15B4B983C39C}.Debug|Any CPU.Build.0 = Debug|Any CPU {7F308FE9-B5C5-45BA-B882-15B4B983C39C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F308FE9-B5C5-45BA-B882-15B4B983C39C}.Release|Any CPU.ActiveCfg = Release|Any CPU {7F308FE9-B5C5-45BA-B882-15B4B983C39C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F308FE9-B5C5-45BA-B882-15B4B983C39C}.Release|Any CPU.Build.0 = Release|Any CPU {7F308FE9-B5C5-45BA-B882-15B4B983C39C}.Release|Any CPU.Build.0 = Release|Any CPU
{FA6A7A47-7EEE-4264-9C89-C2E717B1CB78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA6A7A47-7EEE-4264-9C89-C2E717B1CB78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA6A7A47-7EEE-4264-9C89-C2E717B1CB78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA6A7A47-7EEE-4264-9C89-C2E717B1CB78}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE