-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathSenderProperty.razor
More file actions
56 lines (46 loc) · 1.54 KB
/
SenderProperty.razor
File metadata and controls
56 lines (46 loc) · 1.54 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
48
49
50
51
52
53
54
55
56
@using Moq
@using Microsoft.AspNetCore.Http
@using Microsoft.AspNetCore.Routing
@inherits BunitContext
@code {
private object capturedSender = null;
private string commandName = string.Empty;
private object commandArg = null;
void OnCommand(CommandEventArgs args)
{
capturedSender = args.Sender;
commandName = args.CommandName;
commandArg = args.CommandArgument;
}
[Fact]
public void Button_Command_PopulatesSenderProperty()
{
// Arrange
Services.AddSingleton<LinkGenerator>(new Mock<LinkGenerator>().Object);
Services.AddSingleton<IHttpContextAccessor>(new Mock<IHttpContextAccessor>().Object);
capturedSender = null;
var cut = Render(@<Button CommandName="TestCommand" CommandArgument="@("TestArg")" OnCommand="OnCommand">Test Button</Button>);
// Act
cut.Find("button").Click();
// Assert
capturedSender.ShouldNotBeNull();
capturedSender.ShouldBeOfType<Button>();
commandName.ShouldBe("TestCommand");
commandArg.ShouldBe("TestArg");
}
[Fact]
public void Button_Command_SenderIsTheButtonInstance()
{
// Arrange
Services.AddSingleton<LinkGenerator>(new Mock<LinkGenerator>().Object);
Services.AddSingleton<IHttpContextAccessor>(new Mock<IHttpContextAccessor>().Object);
Button buttonRef = null;
capturedSender = null;
var cut = Render(@<Button @ref="buttonRef" CommandName="TestCmd" CommandArgument="@("Arg")" OnCommand="OnCommand" Text="Click" />);
var buttonInstance = cut.FindComponent<Button>().Instance;
// Act
cut.Find("button").Click();
// Assert
capturedSender.ShouldBe(buttonInstance);
}
}