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+ }
0 commit comments