-
Notifications
You must be signed in to change notification settings - Fork 1
Associated with IHubContext for HubT
Mateusz Soboń edited this page Feb 9, 2020
·
9 revisions
public Mock<IGroupManager> GroupsMock { get; }
public Mock<IHubContext<THub, THubResponses>> IHubContextMock { get; protected set; }
public Mock<IHubClients<THubResponses>> ClientsMock { get; protected set; }
public Mock<THubResponses> ClientsAllMock { get; protected set; }
public Mock<THubResponses> ClientsAllExceptMock { get; protected set; }
public Mock<THubResponses> ClientsClientMock { get; protected set; }
public Mock<THubResponses> ClientsClientsMock { get; protected set; }
public Mock<THubResponses> ClientsGroupMock { get; protected set; }
public Mock<THubResponses> ClientsGroupExceptMock { get; protected set; }
public Mock<THubResponses> ClientsGroupsMock { get; protected set; }
public Mock<THubResponses> ClientsUserMock { get; protected set; }
public Mock<THubResponses> ClientsUsersMock { get; protected set; }
public void VerifySomebodyAddedToGroup(Times times);
public void VerifySomebodyAddedToGroup(Times times, string groupName);
public void VerifySomebodyAddedToGroup(Times times, string groupName, string connectionId);
public void VerifySomebodyRemovedFromGroup(Times times);
public void VerifySomebodyRemovedFromGroup(Times times, string groupName);
public void VerifySomebodyRemovedFromGroup(Times times, string groupName, string connectionId);
public void VerifyUserAddedToGroupByConnId(Times times, string connectionId);
public void VerifyUserRemovedFromGroupByConnId(Times times, string connectionId);- In your test create instance of
UnitTestingSupportForIHubContext<THub, TIHubResponses>. - Inject
UnitTestingSupportForIHubContext.IHubContextMock.Objectwhere you want (for example, service). - Call tested method.
- Verify (examples below).
public void TestedMethodName_TestScenario_ExpectedResult()
{
//Arrange
var iHubContextSupport
= new UnitTestingSupportForIHubContext<ExampleGenericHub, IGenericHubResponses>();
var exampleService
= new ServiceWhichUseIHubContext(iHubContextSupport.IHubContextMock.Object);
//Act
//Assume NotifyAllAboutSomething call inside:
//Clients
// .All
// .NotifyAboutSomethingAwesome("First argument", "SecondArgument");
exampleService.NotifyAllAboutSomething();
//Assert
iHubContextSupport.ClientsAllMock
.Verify(
x => x.NotifyAboutSomethingAwesome("First argument" , "SecondArgument"),
Times.Once()
);
}public void TestedMethodName_TestScenario_ExpectedResult()
{
//Arrange
var iHubContextSupport
= new UnitTestingSupportForIHubContext<ExampleGenericHub, IGenericHubResponses>();
var exampleService
= new ServiceWhichUseIHubContext(unitTestingSupport.IHubContextMock.Object);
//Act
//Assume AddUserToChatRoom call inside:
//_exampleGenericHub
// .Groups
// .AddToGroupAsync("connId", "groupName");
exampleService.AddUserToChatRoom("groupName");
//Assert
iHubContextSupport
.VerifySomebodyAddedToGroup(Times.Once(), "groupName");
}