Skip to content

Commit 89fcf9a

Browse files
committed
添加单元测试
1 parent 2d6ca10 commit 89fcf9a

4 files changed

Lines changed: 46 additions & 2 deletions

File tree

tests/dotnetCampus.LatestCSharpFeatures.Tests/IsExternalInitTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace dotnetCampus.LatestCSharpFeatures.Tests;
24

35
[TestClass]
@@ -8,5 +10,5 @@ public void CanBeCompiled()
810
{
911
}
1012

11-
//public record Foo(string Bar);
13+
public record Foo(string Bar);
1214
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace dotnetCampus.LatestCSharpFeatures.Tests;
4+
5+
[TestClass]
6+
public class NullableTest
7+
{
8+
[TestMethod]
9+
public void CanBeCompiled()
10+
{
11+
MemberNotNull();
12+
TryDo("");
13+
}
14+
15+
public string? Foo { get; set; }
16+
17+
private bool TryDo([NotNullWhen(true)] string? text)
18+
{
19+
return false;
20+
}
21+
22+
[MemberNotNull(nameof(Foo))]
23+
private void MemberNotNull()
24+
{
25+
Foo = "";
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace dotnetCampus.LatestCSharpFeatures.Tests;
2+
3+
[TestClass]
4+
public class RequiredTest
5+
{
6+
[TestMethod]
7+
public void CanBeCompiled()
8+
{
9+
}
10+
11+
public record Foo(string Bar)
12+
{
13+
public required string R { get; init; }
14+
}
15+
}

tests/dotnetCampus.LatestCSharpFeatures.Tests/dotnetCampus.LatestCSharpFeatures.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFrameworks>net7.0;net6.0;net5.0;netcoreapp3.1;netcoreapp3.0;netstandard2.0;net48</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<IsPackable>false</IsPackable>

0 commit comments

Comments
 (0)