Skip to content

Commit 920190b

Browse files
linkdotnetegil
andauthored
docs: Use TestContext as base class for Passing parameters to components (#1034)
* refactor: Use TestContext as base class * fixes to docs * Indent size 2 * fix getting started and index --------- Co-authored-by: Egil Hansen <egil@assimilated.dk>
1 parent d48e449 commit 920190b

File tree

98 files changed

+1480
-1733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1480
-1733
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ root = true
33
[*]
44
indent_style = tab
55
indent_size = tab
6-
tab_size = 4
6+
tab_width = 4
77
charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true

docs/.editorconfig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ root = true
22

33
[*]
44
indent_style = space
5-
tab_size = 2
5+
indent_size = 2
66
charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = false
@@ -11,8 +11,6 @@ insert_final_newline = false
1111
trim_trailing_whitespace = false
1212

1313
[*.{cs,razor}]
14-
tab_size = 2
15-
indent_style = space
1614
dotnet_diagnostic.BL0001.severity = none
1715
dotnet_diagnostic.BL0002.severity = none
1816
dotnet_diagnostic.BL0003.severity = none
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
namespace Bunit.Docs.Samples;
2+
13
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using Bunit;
25

3-
namespace Bunit.Docs.Samples
6+
public abstract class BunitTestContext : TestContextWrapper
47
{
5-
public abstract class BunitTestContext : TestContextWrapper
6-
{
7-
[TestInitialize]
8-
public void Setup() => TestContext = new Bunit.TestContext();
8+
[TestInitialize]
9+
public void Setup() => TestContext = new Bunit.TestContext();
910

10-
[TestCleanup]
11-
public void TearDown() => TestContext?.Dispose();
12-
}
11+
[TestCleanup]
12+
public void TearDown() => TestContext?.Dispose();
1313
}

docs/samples/tests/mstest/HelloWorldImplicitContextTest.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/samples/tests/mstest/HelloWorldRazorTest.razor

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
@attribute [TestClass]
2-
@code
2+
@inherits BunitTestContext
3+
@code
34
{
45
[TestMethod]
56
public void HelloWorldComponentRendersCorrectly()
67
{
7-
// Arrange
8-
using var ctx = new Bunit.TestContext();
9-
108
// Act
11-
var cut = ctx.Render(@<HelloWorld/>);
9+
var cut = Render(@<HelloWorld/>);
1210

1311
// Assert
1412
cut.MarkupMatches(@<h1>Hello world from Blazor</h1>);
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
using Bunit;
1+
namespace Bunit.Docs.Samples;
2+
23
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using Bunit;
35

4-
namespace Bunit.Docs.Samples
6+
[TestClass]
7+
public class HelloWorldTest : BunitTestContext
58
{
6-
[TestClass]
7-
public class HelloWorldTest
9+
[TestMethod]
10+
public void HelloWorldComponentRendersCorrectly()
811
{
9-
[TestMethod]
10-
public void HelloWorldComponentRendersCorrectly()
11-
{
12-
// Arrange
13-
using var ctx = new Bunit.TestContext();
14-
15-
// Act
16-
var cut = ctx.RenderComponent<HelloWorld>();
12+
// Act
13+
var cut = RenderComponent<HelloWorld>();
1714

18-
// Assert
19-
cut.MarkupMatches("<h1>Hello world from Blazor</h1>");
20-
}
15+
// Assert
16+
cut.MarkupMatches("<h1>Hello world from Blazor</h1>");
2117
}
2218
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
namespace Bunit.Docs.Samples;
2+
13
using Bunit;
24
using NUnit.Framework;
35

4-
namespace Bunit.Docs.Samples
6+
public abstract class BunitTestContext : TestContextWrapper
57
{
6-
public abstract class BunitTestContext : TestContextWrapper
7-
{
8-
[SetUp]
9-
public void Setup() => TestContext = new Bunit.TestContext();
8+
[SetUp]
9+
public void Setup() => TestContext = new Bunit.TestContext();
1010

11-
[TearDown]
12-
public void TearDown() => TestContext?.Dispose();
13-
}
11+
[TearDown]
12+
public void TearDown() => TestContext?.Dispose();
1413
}

docs/samples/tests/nunit/HelloWorldImplicitContextRazorTest.razor

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/samples/tests/nunit/HelloWorldImplicitContextTest.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/samples/tests/nunit/HelloWorldRazorTest.razor

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
@inherits BunitTestContext
12
@code
23
{
34
[Test]
45
public void HelloWorldComponentRendersCorrectly()
56
{
6-
// Arrange
7-
using var ctx = new Bunit.TestContext();
8-
97
// Act
10-
var cut = ctx.Render(@<HelloWorld />);
8+
var cut = Render(@<HelloWorld />);
119

1210
// Assert
1311
cut.MarkupMatches(@<h1>Hello world from Blazor</h1>);

0 commit comments

Comments
 (0)