44 Setup =" RegisterTasksService"
55 Test =" WhenTaskIsAddedInputGetsReset" >
66
7- <ComponentUnderTest >
8- <CascadingValue Name =" Theme" Value =@( " dark-theme" ) >
9- <SimpleTodo ></SimpleTodo >
10- </CascadingValue >
11- </ComponentUnderTest >
12-
13- <Fragment >
14- <form >
15- <input placeholder =" Add todo here . . ." type =" text" value =" " />
16- <button type =" submit" >Add task</button >
17- </form >
18- </Fragment >
19-
20- <Fragment Id =" expected tasks" >
21- <ul class =" dark-theme" id =" tasks" >
22- <li >Existing task</li >
23- <li >FOO BAR BAZ</li >
24- </ul >
25- </Fragment >
26-
27- @code
7+ <ComponentUnderTest >
8+ <CascadingValue Name =" Theme" Value =@( " dark-theme" ) >
9+ <SimpleTodo ></SimpleTodo >
10+ </CascadingValue >
11+ </ComponentUnderTest >
12+
13+ <Fragment >
14+ <form >
15+ <input placeholder =" Add todo here . . ." type =" text" value =" " />
16+ <button type =" submit" >Add task</button >
17+ </form >
18+ </Fragment >
19+
20+ <Fragment Id =" expected tasks" >
21+ <ul class =" dark-theme" id =" tasks" >
22+ <li >Existing task</li >
23+ <li >FOO BAR BAZ</li >
24+ </ul >
25+ </Fragment >
26+
27+ @code
28+ {
29+ void RegisterTasksService (Fixture fixture )
30+ => fixture .Services .AddSingleton (new List <string >{ " Existing task" });
31+
32+ void WhenTaskIsAddedInputGetsReset (Fixture fixture )
2833 {
29- void RegisterTasksService (Fixture fixture )
30- => fixture .Services .AddSingleton (new List <string >{ " Existing task" });
31-
32- void WhenTaskIsAddedInputGetsReset (Fixture fixture )
33- {
34- // Arrange - get the component under test and fragments
35- IRenderedComponent <SimpleTodo > cut = fixture .GetComponentUnderTest <SimpleTodo >();
36- IRenderedFragment expectedFormAfterClick = fixture .GetFragment ();
37- IRenderedFragment expectedTasks = fixture .GetFragment (" expected tasks" );
38-
39- // Act - change the value of the input element and click the submit button
40- cut .Find (" input" ).Change (" FOO BAR BAZ" );
41- cut .Find (" button" ).Click ();
42-
43- // Assert - verify cascading value was received
44- Assert .Equal (" dark-theme" , cut .Instance .ThemeClass );
45-
46- // Assert - verify that tasks had the correct theme applied
47- // and the task added.
48- IElement actualTasks = cut .Find (" #tasks" );
49- actualTasks .MarkupMatches (expectedTasks );
50-
51- // Assert - verify that the input form was reset after task was added
52- IElement actualForm = cut .Find (" form" );
53- actualForm .MarkupMatches (expectedFormAfterClick );
54- }
34+ // Arrange - get the component under test and fragments
35+ IRenderedComponent <SimpleTodo > cut = fixture .GetComponentUnderTest <SimpleTodo >();
36+ IRenderedFragment expectedFormAfterClick = fixture .GetFragment ();
37+ IRenderedFragment expectedTasks = fixture .GetFragment (" expected tasks" );
38+
39+ // Act - change the value of the input element and click the submit button
40+ cut .Find (" input" ).Change (" FOO BAR BAZ" );
41+ cut .Find (" button" ).Click ();
42+
43+ // Assert - verify cascading value was received
44+ Assert .Equal (" dark-theme" , cut .Instance .ThemeClass );
45+
46+ // Assert - verify that tasks had the correct theme applied
47+ // and the task added.
48+ IElement actualTasks = cut .Find (" #tasks" );
49+ actualTasks .MarkupMatches (expectedTasks );
50+
51+ // Assert - verify that the input form was reset after task was added
52+ IElement actualForm = cut .Find (" form" );
53+ actualForm .MarkupMatches (expectedFormAfterClick );
5554 }
55+ }
5656</Fixture >
0 commit comments