public void ServerProxy_ExecuteCommand_WhenNullPayload_ExceptionThrown()
        {
            //------------Setup for test--------------------------
            var serverProxy = new TestServerProxyWithChunking();

            //------------Execute Test---------------------------
            serverProxy.ExecuteCommand(null, Guid.NewGuid());
            //------------Assert Results-------------------------
        }
        public void ServerProxy_Constructor_DefaultConstruction_ShouldHaveEsbProxyWithSendMemoSubscription()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
            var serverProxy = new TestServerProxyWithChunking();
            //------------Assert Results-------------------------
            var subscription = serverProxy.EsbProxy.Subscribe("SendMemo");

            Assert.IsNotNull(subscription);
        }
        public void ServerProxy_Constructor_DefaultConstruction_ShouldHaveEsbProxy()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
            var serverProxy = new TestServerProxyWithChunking();

            //------------Assert Results-------------------------
            Assert.IsNotNull(serverProxy);
            Assert.IsNotNull(serverProxy.HubConnection);
            Assert.IsNotNull(serverProxy.EsbProxy);
        }
        public void ServerProxy_Constructor_ParameterUserNamePasswordWebserverURI_ShouldHaveEsbProxy()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
            var serverProxy = new TestServerProxyWithChunking("http://localhost:8080", "some user", "some password");

            //------------Assert Results-------------------------
            Assert.IsNotNull(serverProxy);
            Assert.IsNotNull(serverProxy.HubConnection);
            Assert.IsNotNull(serverProxy.EsbProxy);
            Assert.AreEqual("some user", serverProxy.UserName);
            Assert.AreEqual("some password", serverProxy.Password);
            Assert.AreEqual(AuthenticationType.User, serverProxy.AuthenticationType);
        }
        public void ServerProxy_AddDebugWriter_WithArgs_ShouldInvokeCorrectly()
        {
            //------------Setup for test--------------------------
            var mockHubProxy = new Mock <IHubProxyWrapper>();

            mockHubProxy.Setup(proxy => proxy.Invoke("AddDebugWriter", It.IsAny <Guid>())).Returns(new Task(() => { }));
            var serverProxy = new TestServerProxyWithChunking();

            serverProxy.SetEsbProxy(mockHubProxy.Object);
            //------------Execute Test---------------------------
            serverProxy.AddDebugWriter(Guid.NewGuid());
            //------------Assert Results-------------------------
            mockHubProxy.VerifyAll();
        }
        public void ServerProxy_StateChange_FromConnectedToReconnecting_IsAuthorizedFalse()
        {
            //------------Setup for test--------------------------
            bool _permissionsChangedFired = false;

            var serverProxy = new TestServerProxyWithChunking();

            serverProxy.PermissionsChanged += (sender, args) =>
            {
                _permissionsChangedFired = true;
            };
            bool authorisedBeforeStateChange = serverProxy.IsAuthorized;

            //------------Execute Test---------------------------
            serverProxy.CallHubConnectionChanged(new StateChangeWrapped(ConnectionStateWrapped.Connected, ConnectionStateWrapped.Reconnecting));
            //------------Assert Results-------------------------
            Assert.IsTrue(authorisedBeforeStateChange);
            Assert.IsFalse(serverProxy.IsAuthorized);
            Assert.IsTrue(_permissionsChangedFired);
        }
        public void ServerProxy_ExecuteCommand_WithArgs_ShouldInvokeCorrectly()
        {
            //------------Setup for test--------------------------
            const string ServerMsg      = "server result";
            var          mockHubProxy   = new Mock <IHubProxyWrapper>();
            var          expectedResult = new Receipt {
                PartID = 0, ResultParts = 1
            };

            mockHubProxy.Setup(proxy => proxy.Invoke <Receipt>("ExecuteCommand", It.IsAny <Envelope>(), It.IsAny <bool>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(new Task <Receipt>(() => expectedResult));
            mockHubProxy.Setup(proxy => proxy.Invoke <string>("FetchExecutePayloadFragment", It.IsAny <FutureReceipt>())).Returns(new Task <string>(() => ServerMsg));
            var serverProxy = new TestServerProxyWithChunking();

            serverProxy.SetEsbProxy(mockHubProxy.Object);
            //------------Execute Test---------------------------
            var resultOfExecution = serverProxy.ExecuteCommand(new StringBuilder("some payload"), Guid.NewGuid());

            //------------Assert Results-------------------------
            mockHubProxy.VerifyAll();
            Assert.AreEqual(ServerMsg, resultOfExecution.ToString());
        }