| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using Diligent.WebAPI.Host.Hubs;
- using Microsoft.AspNetCore.SignalR;
- using Moq;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace Tests
- {
- [TestFixture]
- public class ConnectionHubTests
- {
- private Mock<IHubCallerClients> _mockClients;
- private Mock<IClientProxy> _mockClientProxy;
- private ConnectionHub _connectionHub;
-
- [SetUp]
- public void SetUp()
- {
- _mockClients = new Mock<IHubCallerClients>();
- _mockClientProxy = new Mock<IClientProxy>();
- _connectionHub = new ConnectionHub()
- {
- Clients = _mockClients.Object
- };
- }
-
- [Test]
- public async Task SignalR_OnConnect_ShouldReturnMessage()
- {
- // Arrange
- _mockClients.Setup(clients => clients.Others).Returns(_mockClientProxy.Object);
-
- // Act
- await _connectionHub.Unsubscribe(new SenderObj { ConnId = "aaa", Id = "1" });
-
- // Assert
- _mockClients.Verify(clients => clients.Others, Times.Once);
- _mockClientProxy.Verify(clientProxy =>
- clientProxy.SendCoreAsync("Notify", It.Is<object[]>(o => o != null && o.Length == 1 && ((StatusMessage)o[0]).Id == "1" && ((StatusMessage)o[0]).M == "unsubscription"),
- default(CancellationToken)),
- Times.Once);
- }
- }
- }
|