public void InvokeIHubConnectionProvider_StartMethod() { // Arrange var hubConnectionProviderFactory = new Mock <IHubConnectionProviderFactory>(); var hubProxyProviderFactory = new Mock <IHubProxyProviderFactory>(); var hubConnectionProvider = new Mock <IHubConnectionProvider>(); hubConnectionProviderFactory.Setup(f => f.CreateHubConnectionProvider(It.IsAny <string>())).Returns(hubConnectionProvider.Object); // Act var signalRHubConnectionService = new SignalRHubConnectionService(hubConnectionProviderFactory.Object, hubProxyProviderFactory.Object); // Assert hubConnectionProvider.Verify(p => p.Start(), Times.Once); }
public void CreateValidInstance_WhenParametersAreValid() { // Arrange var hubConnectionProviderFactory = new Mock <IHubConnectionProviderFactory>(); var hubProxyProviderFactory = new Mock <IHubProxyProviderFactory>(); var hubConnectionProvider = new Mock <IHubConnectionProvider>(); hubConnectionProviderFactory.Setup(f => f.CreateHubConnectionProvider(It.IsAny <string>())).Returns(hubConnectionProvider.Object); // Act var signalRHubConnectionService = new SignalRHubConnectionService(hubConnectionProviderFactory.Object, hubProxyProviderFactory.Object); // Assert Assert.That(signalRHubConnectionService, Is.Not.Null.And.InstanceOf <ISignalRHubConnectionService>()); }
public void ThrowArgumentException_WhenHubNameParameterIsNull() { // Arrange var hubConnectionProviderFactory = new Mock <IHubConnectionProviderFactory>(); var hubProxyProviderFactory = new Mock <IHubProxyProviderFactory>(); var hubConnectionProvider = new Mock <IHubConnectionProvider>(); hubConnectionProviderFactory.Setup(f => f.CreateHubConnectionProvider(It.IsAny <string>())).Returns(hubConnectionProvider.Object); var signalRHubConnectionService = new SignalRHubConnectionService(hubConnectionProviderFactory.Object, hubProxyProviderFactory.Object); var hubName = string.Empty; // Act & Assert Assert.That( () => signalRHubConnectionService.GetHubProxyProvider(hubName), Throws.InstanceOf <ArgumentException>().With.Message.Contains(nameof(hubName))); }
public void InvokeIHubConnectionProvider_StopMethodOnce_WhenRequestedHubNameDoesNotExistInHubProxyProvidersDictionary() { // Arrange var hubConnectionProviderFactory = new Mock <IHubConnectionProviderFactory>(); var hubProxyProviderFactory = new Mock <IHubProxyProviderFactory>(); var hubConnectionProvider = new Mock <IHubConnectionProvider>(); hubConnectionProviderFactory.Setup(f => f.CreateHubConnectionProvider(It.IsAny <string>())).Returns(hubConnectionProvider.Object); var unexistingIHubProxyProviderHubName = "unexisting hubName"; var signalRHubConnectionService = new SignalRHubConnectionService(hubConnectionProviderFactory.Object, hubProxyProviderFactory.Object); // Act signalRHubConnectionService.GetHubProxyProvider(unexistingIHubProxyProviderHubName); // Assert hubConnectionProvider.Verify(p => p.Stop(), Times.Once); }