-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathStubTest.cs
More file actions
47 lines (38 loc) · 1.33 KB
/
StubTest.cs
File metadata and controls
47 lines (38 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Microsoft.AspNetCore.Components.Authorization;
namespace Bunit.TestDoubles.Components;
public class StubTest : BunitContext
{
[Fact(DisplayName = "Stub<TComponent> renders nothing without a replacement template")]
public void Test001()
{
var cut = Render<Stub<Simple1>>();
cut.Nodes.Length.ShouldBe(0);
}
[Theory(DisplayName = "Stub<TComponent> captures parameters passed to TComponent")]
[AutoData]
public void Test002(string header, string attrValue)
{
var cut = Render<Stub<Simple1>>(ps => ps
.AddUnmatched(nameof(Simple1.Header), header)
.AddUnmatched(nameof(Simple1.AttrValue), attrValue));
cut.Instance
.Parameters
.ShouldSatisfyAllConditions(
ps => ps.ShouldContain(x => x.Key == nameof(Simple1.Header) && header.Equals(x.Value)),
ps => ps.ShouldContain(x => x.Key == nameof(Simple1.AttrValue) && attrValue.Equals(x.Value)),
ps => ps.Count.ShouldBe(2));
}
[Fact(DisplayName = "Stubbing everything except cut keeps cascading AuthenticationState")]
public void Test003()
{
AddAuthorization();
ComponentFactories.AddStub(c => c != typeof(AuthTestComponent));
var cut = Render<AuthTestComponent>();
cut.Instance.Auth.ShouldNotBeNull();
}
private sealed class AuthTestComponent : ComponentBase
{
[CascadingParameter]
public Task<AuthenticationState> Auth { get; set; } = null!;
}
}