Skip to content

Commit 893fdad

Browse files
committed
Added test of SnapshotTests use of setup methods
1 parent ea034d1 commit 893fdad

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/TestServiceProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public ServiceDescriptor this[int index]
4444
}
4545
}
4646

47+
/// <summary>
48+
/// Creates an instance of the <see cref="TestServiceProvider"/> and sets its service collection to the
49+
/// provided <paramref name="initialServiceCollection"/>, if any.
50+
/// </summary>
51+
/// <param name="initialServiceCollection"></param>
4752
public TestServiceProvider(IServiceCollection? initialServiceCollection = null) : this(initialServiceCollection ?? new ServiceCollection(), false)
4853
{
4954
}
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
@inherits TestComponentBase
22
@using Shouldly
33

4-
<SnapshotTest Setup="() => Services">
4+
@code {
5+
class Dep1 : ITestDep { public string Name { get; } = "FOO"; }
6+
class Dep2 : IAsyncTestDep { public Task<string> GetData() => Task.FromResult("BAR"); }
7+
}
8+
9+
<SnapshotTest Setup="() => Services.AddSingleton<ITestDep, Dep1>()"
10+
SetupAsync="() => { Services.AddSingleton<IAsyncTestDep, Dep2>(); return Task.CompletedTask; }">
511
<TestInput>
612
<SimpleWithDeps></SimpleWithDeps>
713
<SimpleWithAyncDeps></SimpleWithAyncDeps>
814
</TestInput>
915
<ExpectedOutput>
10-
@inject ITestDep testDep
11-
<p>@testDep.Name</p>
16+
<p>FOO</p>
17+
<p>BAR</p>
1218
</ExpectedOutput>
1319
</SnapshotTest>

0 commit comments

Comments
 (0)