Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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>());
        }
Exemplo n.º 3
0
        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)));
        }
Exemplo n.º 4
0
        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);
        }