Skip to content

Commit 315b1da

Browse files
committed
refactor: upgrade template to net 6
1 parent 21ed961 commit 315b1da

4 files changed

Lines changed: 81 additions & 45 deletions

File tree

src/bunit.template/bunit.template.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@
3333
<EmbeddedResource Remove="template\obj\**" />
3434
<None Remove="template\obj\**" />
3535
</ItemGroup>
36+
37+
<ItemGroup>
38+
<None Remove="template\CounterRazorTests.razor" />
39+
</ItemGroup>
3640

3741
</Project>
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Razor">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

3-
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
5-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
68

7-
<ItemGroup>
9+
<ItemGroup>
10+
<Using Include="Bunit" />
11+
<Using Include="Bunit.TestDoubles" />
12+
<Using Include="Xunit" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
816
<PackageReference Include="bunit" Version="#{NBGV_NuGetPackageVersion}#" />
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
10-
<PackageReference Include="xunit" Version="2.4.1" />
11-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
12-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13-
<PrivateAssets>all</PrivateAssets>
14-
</PackageReference>
15-
<PackageReference Include="coverlet.collector" Version="3.0.3">
16-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17-
<PrivateAssets>all</PrivateAssets>
18-
</PackageReference>
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
18+
<PackageReference Include="xunit" Version="2.4.1" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
<PrivateAssets>all</PrivateAssets>
22+
</PackageReference>
23+
<PackageReference Include="coverlet.collector" Version="3.1.0">
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25+
<PrivateAssets>all</PrivateAssets>
26+
</PackageReference>
1927
</ItemGroup>
2028

2129
</Project>
Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
1-
using System;
2-
using Bunit;
3-
using Bunit.TestDoubles;
4-
using Xunit;
1+
namespace Company.BlazorTests1;
52

6-
namespace Company.BlazorTests1
3+
/// <summary>
4+
/// These tests are written entirely in C#.
5+
/// Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating-basic-tests-in-cs-files
6+
/// </summary>
7+
public class CounterCSharpTests : TestContext
78
{
8-
/// <summary>
9-
/// These tests are written entirely in C#.
10-
/// Learn more at https://bunit.egilhansen.com/docs/getting-started/
11-
/// </summary>
12-
public class CounterCSharpTests : TestContext
13-
{
14-
[Fact]
15-
public void CounterStartsAtZero()
16-
{
17-
// Arrange
18-
var cut = RenderComponent<Counter>();
9+
[Fact]
10+
public void CounterStartsAtZero()
11+
{
12+
// Arrange
13+
var cut = RenderComponent<Counter>();
1914

20-
// Assert that content of the paragraph shows counter at zero
21-
cut.Find("p").MarkupMatches("<p>Current count: 0</p>");
22-
}
15+
// Assert that content of the paragraph shows counter at zero
16+
cut.Find("p").MarkupMatches("<p>Current count: 0</p>");
17+
}
2318

24-
[Fact]
25-
public void ClickingButtonIncrementsCounter()
26-
{
27-
// Arrange
28-
var cut = RenderComponent<Counter>();
19+
[Fact]
20+
public void ClickingButtonIncrementsCounter()
21+
{
22+
// Arrange
23+
var cut = RenderComponent<Counter>();
2924

30-
// Act - click button to increment counter
31-
cut.Find("button").Click();
25+
// Act - click button to increment counter
26+
cut.Find("button").Click();
3227

33-
// Assert that the counter was incremented
34-
cut.Find("p").MarkupMatches("<p>Current count: 1</p>");
35-
}
36-
}
28+
// Assert that the counter was incremented
29+
cut.Find("p").MarkupMatches("<p>Current count: 1</p>");
30+
}
3731
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@inherits TestContext
2+
3+
These tests are written entirely in razor and C# syntax.
4+
5+
Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating-basic-tests-in-razor-files
6+
7+
@code {
8+
[Fact]
9+
public void CounterStartsAtZero()
10+
{
11+
// Arrange
12+
var cut = Render(@<Counter />);
13+
14+
// Assert that content of the paragraph shows counter at zero
15+
cut.Find("p").MarkupMatches(@<p>Current count: 0</p>);
16+
}
17+
18+
[Fact]
19+
public void ClickingButtonIncrementsCounter()
20+
{
21+
// Arrange
22+
var cut = Render(@<Counter />);
23+
24+
// Act - click button to increment counter
25+
cut.Find("button").Click();
26+
27+
// Assert that the counter was incremented
28+
cut.Find("p").MarkupMatches(@<p>Current count: 1</p>);
29+
}
30+
}

0 commit comments

Comments
 (0)