Skip to content

Commit d8a79e4

Browse files
egilduracellkoSiphonophora
authored
BETA 5 (#41)
* Fixed spelling mistake in comment * Reordered parameters to top of TestRenderer * Add support for asynchronous Razor tests (#27) * Add support for asyncrhonous Razor tests * Rename Fixture.AsyncTest to TestAsync * Update description of Fixture Co-Authored-By: Egil Hansen <[email protected]> * Dotnetconf samples (#33) * Basic example tests * Add missing MarkupMatches overload * Added docs to MockHttp extensions * dotnet conf samples * Added unit tests of CompareTo, Generic and Collection assert extensions. * Added tests for general events and touch events dispatch extensions * Added tests for anglesharp extensions, JsRuntimeInvocation and ComponentParameter * Removed assert helpers that conflict with Shoudly * Tests of JsRuntimeAsserts * Reorganized test library * Suppressing warnings in sample * Changed ITestContext to have a CreateNodes method instead of HtmlParser property * Removed empty test * Added missing code documentation * Moved MockJsRuntime to its own namespace * Pulled sample from main solution into own solution * Update main.yml * Change GetNodes and GetMarkup to Nodes and Markup properties in IRenderedFragment (#34) * Add SetupVoid and SetVoidResult capabilities to JsRuntime mock (#35) * Moved MockJsRuntime to its own namespace * Add SetupVoid() and SetVoidResult() to PlannedInvocation and Mock * Updates to template and sample * Add default JsRuntime (#32) * Add default JsRuntime * Update src/Mocking/JSInterop/DefaultJsRuntime.cs Co-Authored-By: Egil Hansen <[email protected]> * Response to review. Add custom exception and code cleanup * Remove unneded method * Update src/Mocking/JSInterop/MissingMockJsRuntimeException.cs Co-Authored-By: Egil Hansen <[email protected]> * Update src/Mocking/JSInterop/MissingMockJsRuntimeException.cs Co-Authored-By: Egil Hansen <[email protected]> * Update src/Mocking/JSInterop/MissingMockJsRuntimeException.cs Co-Authored-By: Egil Hansen <[email protected]> * Update src/Mocking/JSInterop/MissingMockJsRuntimeException.cs Co-Authored-By: Egil Hansen <[email protected]> * Update src/Mocking/JSInterop/MissingMockJsRuntimeException.cs Co-Authored-By: Egil Hansen <[email protected]> * Update src/Mocking/JSInterop/MissingMockJsRuntimeException.cs Co-Authored-By: Egil Hansen <[email protected]> Co-authored-by: Egil Hansen <[email protected]> * Add .vscode to gitignore * TestServiceProvider now explictly implements IServiceCOlelction (#40) * TestServiceProvider now explictly implements IServiceCOlelction * Tweaks to namespaces * Added async setup method to snapshot test * Added test of SnapshotTests use of setup methods * Update to readme * Removed duplicated MarkupMatches method * Removed PR trigger Co-authored-by: Rastislav Novotný <[email protected]> Co-authored-by: Michael J Conrad <[email protected]>
1 parent 3df4dec commit d8a79e4

File tree

94 files changed

+2067
-519
lines changed

Some content is hidden

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

94 files changed

+2067
-519
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
name: CI
33

4-
on: [push, pull_request]
4+
on: push
55

66
env:
77
VERSION: 1337.0.0
@@ -28,8 +28,10 @@ jobs:
2828
dotnet-version: '3.1.100'
2929
- name: Building and verifying library
3030
run: |
31-
dotnet build -c Release /nowarn:CS1591
31+
dotnet build -c Release
3232
dotnet test -c Release /nowarn:CS1591
33+
dotnet build sample -c Release
34+
dotnet test sample -c Release
3335
- name: Creating library package
3436
run: dotnet pack src/ -c Release -o ${GITHUB_WORKSPACE} -p:version=$VERSION /nowarn:CS1591
3537
- name: Buidling template package

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ bld/
2626

2727
# Visual Studio 2015/2017 cache/options directory
2828
.vs/
29+
.vscode/
2930
# Uncomment if you have tasks that create the project's static files in wwwroot
3031
#wwwroot/
3132

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ This library's goal is to make it easy to write _comprehensive, stable unit test
2222
- [Mocking JsRuntime](https://github.com/egil/razor-components-testing-library/wiki/Mocking-JsRuntime)
2323
- [References](https://github.com/egil/razor-components-testing-library/wiki/References)
2424
- [Contribute](https://github.com/egil/razor-components-testing-library/wiki/Contribute)
25+
26+
## Contributors
27+
28+
Shout outs and a big thank you to the contributors to this library. Here they are, in alphabetically:
29+
30+
- [Michael J Conrad (@Siphonophora)](https://github.com/Siphonophora)
31+
- [Rastislav Novotný (@duracellko)](https://github.com/duracellko)

Razor.Components.Testing.Library.sln

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Egil.RazorComponents.Testin
1919
EndProject
2020
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Egil.RazorComponents.Testing.Library.Tests", "tests\Egil.RazorComponents.Testing.Library.Tests.csproj", "{04E0142A-33CC-4E30-B903-F1370D94AD8C}"
2121
EndProject
22-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{26D90CB9-AF66-4F42-A16E-39D2CF69C8FB}"
23-
EndProject
24-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Egil.RazorComponents.Testing.Library.SampleApp", "sample\src\Egil.RazorComponents.Testing.Library.SampleApp.csproj", "{D1FE0F2A-D856-417E-A1FD-4ECE9C64D3AE}"
25-
EndProject
26-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Egil.RazorComponents.Testing.Library.SampleApp.Tests", "sample\tests\Egil.RazorComponents.Testing.Library.SampleApp.Tests.csproj", "{A7B05744-AA61-4F8E-8173-5DE812A4A745}"
27-
EndProject
28-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Razor.Components.Testing.Library.Template", "template\Razor.Components.Testing.Library.Template.csproj", "{FB46378D-BFB8-4C72-9CA3-0407D4665218}"
22+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Egil.Razor.Components.Testing.Library.Template", "template\Egil.Razor.Components.Testing.Library.Template.csproj", "{FB46378D-BFB8-4C72-9CA3-0407D4665218}"
2923
EndProject
3024
Global
3125
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -41,14 +35,6 @@ Global
4135
{04E0142A-33CC-4E30-B903-F1370D94AD8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
4236
{04E0142A-33CC-4E30-B903-F1370D94AD8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
4337
{04E0142A-33CC-4E30-B903-F1370D94AD8C}.Release|Any CPU.Build.0 = Release|Any CPU
44-
{D1FE0F2A-D856-417E-A1FD-4ECE9C64D3AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45-
{D1FE0F2A-D856-417E-A1FD-4ECE9C64D3AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
46-
{D1FE0F2A-D856-417E-A1FD-4ECE9C64D3AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
47-
{D1FE0F2A-D856-417E-A1FD-4ECE9C64D3AE}.Release|Any CPU.Build.0 = Release|Any CPU
48-
{A7B05744-AA61-4F8E-8173-5DE812A4A745}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49-
{A7B05744-AA61-4F8E-8173-5DE812A4A745}.Debug|Any CPU.Build.0 = Debug|Any CPU
50-
{A7B05744-AA61-4F8E-8173-5DE812A4A745}.Release|Any CPU.ActiveCfg = Release|Any CPU
51-
{A7B05744-AA61-4F8E-8173-5DE812A4A745}.Release|Any CPU.Build.0 = Release|Any CPU
5238
{FB46378D-BFB8-4C72-9CA3-0407D4665218}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5339
{FB46378D-BFB8-4C72-9CA3-0407D4665218}.Debug|Any CPU.Build.0 = Debug|Any CPU
5440
{FB46378D-BFB8-4C72-9CA3-0407D4665218}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -60,8 +46,6 @@ Global
6046
GlobalSection(NestedProjects) = preSolution
6147
{AA96790B-67C9-4141-ACDB-037C8DC092EC} = {E006E9A4-F554-46DF-838F-812956521F64}
6248
{04E0142A-33CC-4E30-B903-F1370D94AD8C} = {C929375E-BD70-4B78-88C1-BDD1623C3365}
63-
{D1FE0F2A-D856-417E-A1FD-4ECE9C64D3AE} = {26D90CB9-AF66-4F42-A16E-39D2CF69C8FB}
64-
{A7B05744-AA61-4F8E-8173-5DE812A4A745} = {26D90CB9-AF66-4F42-A16E-39D2CF69C8FB}
6549
{FB46378D-BFB8-4C72-9CA3-0407D4665218} = {E006E9A4-F554-46DF-838F-812956521F64}
6650
EndGlobalSection
6751
GlobalSection(ExtensibilityGlobals) = postSolution

sample/SampleApp.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29613.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApp", "src\SampleApp.csproj", "{0C4F7AE0-EA8A-4ECC-9003-1CEE4412BBA7}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApp.Tests", "tests\SampleApp.Tests.csproj", "{04F6D258-F69C-4BB5-87C5-3813C3CE33D8}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{0C4F7AE0-EA8A-4ECC-9003-1CEE4412BBA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{0C4F7AE0-EA8A-4ECC-9003-1CEE4412BBA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{0C4F7AE0-EA8A-4ECC-9003-1CEE4412BBA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{0C4F7AE0-EA8A-4ECC-9003-1CEE4412BBA7}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{04F6D258-F69C-4BB5-87C5-3813C3CE33D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{04F6D258-F69C-4BB5-87C5-3813C3CE33D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{04F6D258-F69C-4BB5-87C5-3813C3CE33D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{04F6D258-F69C-4BB5-87C5-3813C3CE33D8}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {FBE5B0F6-5496-4BC5-BB38-CF16799DCF93}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<IsPackable>false</IsPackable>
56
<RootNamespace>Egil.RazorComponents.Testing.SampleApp</RootNamespace>
67
</PropertyGroup>
78

sample/src/Startup.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
using Microsoft.Extensions.Configuration;
1010
using Microsoft.Extensions.DependencyInjection;
1111
using Microsoft.Extensions.Hosting;
12+
using System.Diagnostics.CodeAnalysis;
1213
using Egil.RazorComponents.Testing.SampleApp.Data;
1314

1415
namespace Egil.RazorComponents.Testing.SampleApp
1516
{
17+
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
1618
public class Startup
1719
{
1820
public Startup(IConfiguration configuration)
@@ -22,6 +24,7 @@ public Startup(IConfiguration configuration)
2224

2325
public IConfiguration Configuration { get; }
2426

27+
2528
// This method gets called by the runtime. Use this method to add services to the container.
2629
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
2730
public void ConfigureServices(IServiceCollection services)

sample/tests/Assembly.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[assembly: System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]

sample/tests/GlobalSuppressions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage
2+
// attributes that are applied to this project.
3+
// Project-level suppressions either have no target or are given
4+
// a specific target and scoped to a namespace, type, member, etc.
5+
6+
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "<Pending>", Scope = "member", Target = "~M:Egil.RazorComponents.Testing.SampleApp.Tests.Components.AlertTest2.Test008~System.Threading.Tasks.Task")]

sample/tests/MockForecastService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Egil.RazorComponents.Testing.SampleApp
66
{
7-
internal class MockForecastService : IWeatherForecastService
8-
{
9-
public TaskCompletionSource<WeatherForecast[]> Task { get; } = new TaskCompletionSource<WeatherForecast[]>();
7+
internal class MockForecastService : IWeatherForecastService
8+
{
9+
public TaskCompletionSource<WeatherForecast[]> Task { get; } = new TaskCompletionSource<WeatherForecast[]>();
1010

11-
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate) => Task.Task;
12-
}
11+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate) => Task.Task;
12+
}
1313
}

sample/tests/RazorTestComponents/Components/AlertRazorTest.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
@inherits TestComponentBase
1+
@inherits TestComponentBase
22

33
@code {
4-
MockJsRuntimeInvokeHandler MockJsRuntime { get; set; }
4+
MockJsRuntimeInvokeHandler MockJsRuntime { get; set; } = default!;
55

66
void Setup()
77
{

sample/tests/RazorTestComponents/Components/ThemedButtonTest.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
void Test()
1616
{
1717
var cut = GetComponentUnderTest<ThemedButton>();
18-
var x = cut.GetMarkup();
1918
cut.Find("button").ClassList.ShouldContain("btn");
2019
}
2120
}

sample/tests/RazorTestComponents/Pages/FetchDataTest.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
void Setup()
2525
{
26-
Services.AddService<IWeatherForecastService>(forecastService);
26+
Services.AddSingleton<IWeatherForecastService>(forecastService);
2727
}
2828

2929
void InitialLoadingHtmlRendersCorrectly()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<ItemGroup>
2222
<ProjectReference Include="..\..\src\Egil.RazorComponents.Testing.Library.csproj" />
23-
<ProjectReference Include="..\src\Egil.RazorComponents.Testing.Library.SampleApp.csproj" />
23+
<ProjectReference Include="..\src\SampleApp.csproj" />
2424
</ItemGroup>
2525

2626
</Project>

sample/tests/Tests/Components/AlertTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using System;
1+
using System;
22
using System.Threading.Tasks;
33
using Egil.RazorComponents.Testing.Asserting;
44
using Egil.RazorComponents.Testing.EventDispatchExtensions;
5+
using Egil.RazorComponents.Testing.Mocking.JSInterop;
56
using Egil.RazorComponents.Testing.SampleApp.Components;
67
using Egil.RazorComponents.Testing.SampleApp.Data;
78
using Microsoft.AspNetCore.Authentication;
@@ -208,7 +209,7 @@ public void Test007()
208209
cut.MarkupMatches(string.Empty);
209210
}
210211

211-
[Fact(DisplayName = "Alert can be dismissed via Dismiss() mehod")]
212+
[Fact(DisplayName = "Alert can be dismissed via Dismiss() method")]
212213
public async Task Test008()
213214
{
214215
// Arrange

sample/tests/Tests/Components/FocussingInputTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using Egil.RazorComponents.Testing.Asserting;
7+
using Egil.RazorComponents.Testing.Mocking.JSInterop;
78
using Egil.RazorComponents.Testing.SampleApp.Components;
9+
using Egil.RazorComponents.Testing.Mocking.JSInterop;
810
using Xunit;
911

1012
namespace Egil.RazorComponents.Testing.SampleApp.CodeOnlyTests.Components
@@ -24,6 +26,7 @@ public void Test001()
2426
// Assert
2527
// that there is a single call to document.body.focus.call
2628
var invocation = jsRtMock.VerifyInvoke("document.body.focus.call");
29+
2730
// Assert that the invocation received a single argument
2831
// and that it was a reference to the input element.
2932
var expectedReferencedElement = cut.Find("input");

sample/tests/Tests/Components/TodoListTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Shouldly;
22
using AngleSharp.Dom;
33
using Egil.RazorComponents.Testing.Asserting;
4+
using Egil.RazorComponents.Testing.Mocking.JSInterop;
45
using Egil.RazorComponents.Testing.EventDispatchExtensions;
6+
using Egil.RazorComponents.Testing.Mocking.JSInterop;
57
using Egil.RazorComponents.Testing.SampleApp.Components;
68
using Egil.RazorComponents.Testing.SampleApp.Data;
79
using Microsoft.AspNetCore.Components;
@@ -119,8 +121,8 @@ public void Test005()
119121
cut.Find("input").Change(taskValue);
120122
cut.Find("form").Submit();
121123

122-
createdTask.ShouldNotBeNull();
123-
createdTask?.Text.ShouldBe(taskValue);
124+
createdTask = createdTask.ShouldBeOfType<Todo>();
125+
createdTask.Text.ShouldBe(taskValue);
124126
}
125127

126128
[Fact(DisplayName = "When add task form is submitted with no text OnAddingTodo is not called")]

sample/tests/Tests/Components/WikiSearchTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Egil.RazorComponents.Testing.Asserting;
77
using Egil.RazorComponents.Testing.SampleApp.Components;
8+
using Egil.RazorComponents.Testing.Mocking.JSInterop;
89
using Shouldly;
910
using Xunit;
1011

sample/tests/Tests/Pages/FetchDataTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Xunit;
99
using Egil.RazorComponents.Testing.SampleApp.Pages;
1010
using Shouldly;
11+
using Microsoft.Extensions.DependencyInjection;
1112

1213
namespace Egil.RazorComponents.Testing.SampleApp.CodeOnlyTests
1314
{
@@ -17,7 +18,7 @@ public class FetchDataTest : ComponentTestFixture
1718
public void Test001()
1819
{
1920
// Arrange - add the mock forecast service
20-
Services.AddService<IWeatherForecastService, MockForecastService>();
21+
Services.AddSingleton<IWeatherForecastService, MockForecastService>();
2122

2223
// Act - render the FetchData component
2324
var cut = RenderComponent<FetchData>();
@@ -35,7 +36,7 @@ public void Test002()
3536
// Setup the mock forecast service
3637
var forecasts = new[] { new WeatherForecast { Date = DateTime.Now, Summary = "Testy", TemperatureC = 42 } };
3738
var mockForecastService = new MockForecastService();
38-
Services.AddService<IWeatherForecastService>(mockForecastService);
39+
Services.AddSingleton<IWeatherForecastService>(mockForecastService);
3940

4041
// Arrange - render the FetchData component
4142
var cut = RenderComponent<FetchData>();

sample/tests/Tests/Pages/TodosTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Egil.RazorComponents.Testing.SampleApp.Data;
1111
using Egil.RazorComponents.Testing.EventDispatchExtensions;
1212
using Egil.RazorComponents.Testing.SampleApp.Pages;
13+
using Microsoft.Extensions.DependencyInjection;
1314

1415
namespace Egil.RazorComponents.Testing.SampleApp.CodeOnlyTests.Pages
1516
{
@@ -30,7 +31,7 @@ public void Test001()
3031
var getTask = new TaskCompletionSource<IReadOnlyList<Todo>>();
3132
var todoSrv = new Mock<ITodoService>();
3233
todoSrv.Setup(x => x.GetAll()).Returns(getTask.Task);
33-
Services.AddService(todoSrv.Object);
34+
Services.AddSingleton(todoSrv.Object);
3435

3536
// act
3637
var page = RenderComponent<Todos>();
@@ -51,7 +52,7 @@ public void Test002()
5152
var todos = new[] { new Todo { Id = 1, Text = "First" } };
5253
var todoSrv = new Mock<ITodoService>();
5354
todoSrv.Setup(x => x.GetAll()).Returns(Task.FromResult<IReadOnlyList<Todo>>(todos));
54-
Services.AddService(todoSrv.Object);
55+
Services.AddSingleton(todoSrv.Object);
5556

5657
// act
5758
var page = RenderComponent<Todos>();
@@ -66,7 +67,7 @@ public void Test003()
6667
{
6768
// arrange
6869
var todoSrv = new Mock<ITodoService>();
69-
Services.AddService(todoSrv.Object);
70+
Services.AddSingleton(todoSrv.Object);
7071
var page = RenderComponent<Todos>();
7172

7273
// act

sample/tests/_Imports.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
@using Microsoft.AspNetCore.Components.Web
1+
@using Microsoft.AspNetCore.Components.Web
2+
@using Microsoft.Extensions.DependencyInjection
23

34
@using Egil.RazorComponents.Testing
45
@using Egil.RazorComponents.Testing.EventDispatchExtensions
6+
@using Egil.RazorComponents.Testing.Mocking.JSInterop
57
@using Egil.RazorComponents.Testing.Asserting
68

79
@using Egil.RazorComponents.Testing.SampleApp

src/Assembly.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Egil.RazorComponents.Testing.Library.Tests")]

src/Asserting/GenericAssertExtensions.cs renamed to src/Asserting/CollectionAssertExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
namespace Egil.RazorComponents.Testing.Asserting
99
{
1010
/// <summary>
11-
/// Generic test assertions
11+
/// Collection test assertions
1212
/// </summary>
13-
public static class GenericAssertExtensions
13+
public static class CollectionAssertExtensions
1414
{
1515
/// <summary>
1616
/// Verifies that a collection contains exactly a given number of elements, which

src/Asserting/CompareToDiffingExtensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ public static IReadOnlyList<IDiff> CompareTo(this IRenderedFragment actual, stri
2525
if (actual is null) throw new ArgumentNullException(nameof(actual));
2626
if (expected is null) throw new ArgumentNullException(nameof(expected));
2727

28-
var actualNodes = actual.GetNodes();
29-
var expectedNodes = actual.TestContext.HtmlParser.Parse(expected);
28+
var expectedNodes = actual.TestContext.CreateNodes(expected);
3029

31-
return actualNodes.CompareTo(expectedNodes);
30+
return actual.Nodes.CompareTo(expectedNodes);
3231
}
3332

3433
/// <summary>
@@ -43,7 +42,7 @@ public static IReadOnlyList<IDiff> CompareTo(this IRenderedFragment actual, IRen
4342
if (actual is null) throw new ArgumentNullException(nameof(actual));
4443
if (expected is null) throw new ArgumentNullException(nameof(expected));
4544

46-
return actual.GetNodes().CompareTo(expected.GetNodes());
45+
return actual.Nodes.CompareTo(expected.Nodes);
4746
}
4847

4948
/// <summary>

src/Asserting/DiffAssertExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static IDiff ShouldHaveSingleChange(this IReadOnlyList<IDiff> diffs)
3737
/// The total number of <see cref="IDiff"/> inspectors must exactly match the number of <see cref="IDiff"/>s in the collection</param>
3838
public static void ShouldHaveChanges(this IReadOnlyList<IDiff> diffs, params Action<IDiff>[] diffInspectors)
3939
{
40-
Assert.Collection(diffs, diffInspectors);
40+
CollectionAssertExtensions.ShouldAllBe(diffs, diffInspectors);
4141
}
4242

4343
}

0 commit comments

Comments
 (0)