Skip to content

Commit 7d6261f

Browse files
committed
Updates to template
1 parent d332025 commit 7d6261f

File tree

4 files changed

+27
-45
lines changed

4 files changed

+27
-45
lines changed

src/bunit.template/template/Company.BlazorTests1.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
<RazorLangVersion>3.0</RazorLangVersion>
4+
<TargetFramework>net5.0</TargetFramework>
65
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">RazorTestingClasslib</RootNamespace>
76
</PropertyGroup>
87

98
<ItemGroup>
109
<PackageReference Include="bunit.core" Version="#{VERSION}#" />
1110
<PackageReference Include="bunit.web" Version="#{VERSION}#" />
1211
<PackageReference Include="bunit.xunit" Version="#{VERSION}#" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
1413
<PackageReference Include="xunit" Version="2.4.1" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
<PrivateAssets>all</PrivateAssets>
17+
</PackageReference>
18+
<PackageReference Include="coverlet.collector" Version="1.3.0">
1719
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
<PrivateAssets>all</PrivateAssets>
1821
</PackageReference>
1922
</ItemGroup>
2023

src/bunit.template/template/CounterCSharpTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
using Xunit;
33
using Bunit;
44
using Bunit.TestDoubles;
5-
using static Bunit.ComponentParameterFactory;
65

76
namespace Company.BlazorTests1
87
{
98
/// <summary>
109
/// These tests are written entirely in C#.
11-
/// Learn more at https://bunit.egilhansen.com/docs/
10+
/// Learn more at https://bunit.egilhansen.com/docs/getting-started/
1211
/// </summary>
1312
public class CounterCSharpTests : TestContext
1413
{
Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,33 @@
1-
@inherits TestComponentBase
1+
@inherits TestContext
22
@*
33
This is a special Blazor component, which contains razor tests.
4-
54
These tests are written in a mix of C# and Razor syntax.
6-
7-
The first test is a snapshot test, that will automatically perform a semantic
8-
comparison of the rendered output of TestInput with that of ExpectedOutput.
9-
10-
The second is a Fixture test, where you can declare the component under test
11-
and additional fragments that can be used in the "act" and "assertion" phases
12-
of the test, which runs in the related test method(s).
13-
14-
Learn more at https://bunit.egilhansen.com/docs/
5+
Learn more at https://bunit.egilhansen.com/docs/getting-started/
156
*@
16-
17-
<SnapshotTest Description="Counter starts at zero">
18-
<TestInput>
19-
<Counter />
20-
</TestInput>
21-
<ExpectedOutput>
22-
<h1>Counter</h1>
23-
<p>Current count: 0</p>
24-
<button class="btn btn-primary">Click me</button>
25-
</ExpectedOutput>
26-
</SnapshotTest>
27-
28-
<Fixture Description="Clicking button increments counter" Test="Test">
29-
<ComponentUnderTest>
30-
<Counter></Counter>
31-
</ComponentUnderTest>
32-
<Fragment>
33-
<p>Current count: 1</p>
34-
</Fragment>
35-
</Fixture>
36-
377
@code
388
{
39-
public void Test(Fixture fixture)
9+
[Fact]
10+
public void CounterStartsAtZero()
11+
{
12+
// Arrange
13+
var cut = Render(@<Counter />);
14+
15+
// Assert that content of the paragraph shows counter at zero
16+
cut.MarkupMatches(@<h1>Counter</h1>
17+
<p>Current count: 0</p>
18+
<button class="btn btn-primary">Click me</button>);
19+
}
20+
21+
[Fact]
22+
public void ClickingButtonIncrementsCounter()
4023
{
4124
// Arrange
42-
var cut = fixture.GetComponentUnderTest<Counter>();
25+
var cut = Render(@<Counter />);
4326

4427
// Act - click button to increment counter
4528
cut.Find("button").Click();
4629

4730
// Assert that the counter was incremented
48-
var expected = fixture.GetFragment();
49-
cut.Find("p").MarkupMatches(expected);
31+
cut.Find("p").MarkupMatches(@<p>Current count: 1</p>);
5032
}
51-
}
33+
}

src/bunit.template/template/_Imports.razor

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@using Microsoft.AspNetCore.Components.Forms
2-
@using Microsoft.AspNetCore.Components.Routing
31
@using Microsoft.AspNetCore.Components.Web
42
@using Microsoft.JSInterop
53
@using Microsoft.Extensions.DependencyInjection

0 commit comments

Comments
 (0)