Represents the result of a hub invocation.
Exemplo n.º 1
0
        public void InvokeWithStateCopiesStateToHubProxy()
        {
            var hubResult = new HubResult
            {
                State = new Dictionary<string, JToken>
                {
                    { "state", JToken.FromObject(1) }
                }
            };

            var connection = new Mock<IHubConnection>();
            connection.Setup(m => m.RegisterCallback(It.IsAny<Action<HubResult>>()))
                      .Callback<Action<HubResult>>(callback =>
                      {
                          callback(hubResult);
                      });

            connection.Setup(m => m.Send(It.IsAny<string>()))
                      .Returns(TaskAsyncHelper.Empty);

            connection.SetupGet(x => x.JsonSerializer).Returns(new JsonSerializer());

            var hubProxy = new HubProxy(connection.Object, "foo");

            hubProxy.Invoke("Anything").Wait();

            Assert.Equal(1, hubProxy["state"]);
        }
Exemplo n.º 2
0
        public void InvokeReturnsHubsResult()
        {
            var hubResult = new HubResult
            {
                Result = "Something"
            };

            var connection = new Mock<IHubConnection>();
            connection.Setup(m => m.RegisterCallback(It.IsAny<Action<HubResult>>()))
                      .Callback<Action<HubResult>>(callback =>
                      {
                          callback(hubResult);
                      });

            connection.Setup(m => m.Send(It.IsAny<string>()))
                      .Returns(TaskAsyncHelper.Empty);

            connection.SetupGet(x => x.JsonSerializer).Returns(new JsonSerializer());

            var hubProxy = new HubProxy(connection.Object, "foo");

            var result = hubProxy.Invoke<object>("Anything").Result;

            Assert.Equal(result, "Something");
        }
Exemplo n.º 3
0
        public void InvokeWithErrorInHubResultReturnsFaultedTask()
        {
            var result = new HubResult<object>
            {
                Error = "This in an error"
            };

            var connection = new Mock<SignalR.Client.IConnection>();
            connection.Setup(m => m.Send<HubResult<object>>(It.IsAny<string>()))
                      .Returns(TaskAsyncHelper.FromResult(result));

            var hubProxy = new HubProxy(connection.Object, "foo");

            AssertAggregateException(() => hubProxy.Invoke("Invoke").Wait(),
                                     "This in an error");
        }
Exemplo n.º 4
0
        private void ClearInvocationCallbacks(string error)
        {
            var result = new HubResult();

            result.Error = error;

            lock (_callbacks)
            {
                foreach (var callback in _callbacks.Values)
                {
                    callback(result);
                }

                _callbacks.Clear();
            }
        }
Exemplo n.º 5
0
        public void InvokeReturnsHubsResult()
        {
            var hubResult = new HubResult<object>
            {
                Result = "Something"
            };

            var connection = new Mock<SignalR.Client.IConnection>();
            connection.Setup(m => m.Send<HubResult<object>>(It.IsAny<string>()))
                      .Returns(TaskAsyncHelper.FromResult(hubResult));

            var hubProxy = new HubProxy(connection.Object, "foo");

            var result = hubProxy.Invoke<object>("Anything").Result;

            Assert.Equal(result, "Something");
        }
Exemplo n.º 6
0
        public static HubResult FromJson(JSONNode json)
        {
            if (json == null)
            {
                return(null);
            }

            var Result = new HubResult();

            Result.Id             = json["I"].AsString;
            Result.ProgressUpdate = HubProgressUpdate.FromJson(json["P"]);
            Result.Result         = json["R"];
            Result.IsHubException = json["H"].AsBool.GetValueOrDefault();
            Result.Error          = json["E"].AsString;
            Result.ErrorData      = json["D"];
            Result.State          = json["S"].AsObject;

            return(Result);
        }
Exemplo n.º 7
0
        public void InvokeWithErrorInHubResultReturnsFaultedTask()
        {
            var hubResult = new HubResult
            {
                Error = "This in an error"
            };

            var connection = new Mock<SignalR.Client.Hubs.IHubConnection>();
            connection.Setup(m => m.RegisterCallback(It.IsAny<Action<HubResult>>()))
                      .Callback<Action<HubResult>>(callback =>
                      {
                          callback(hubResult);
                      });

            connection.Setup(m => m.Send(It.IsAny<string>()))
                      .Returns(TaskAsyncHelper.Empty);

            var hubProxy = new HubProxy(connection.Object, "foo");

            TestUtilities.AssertAggregateException(() => hubProxy.Invoke("Invoke").Wait(),
                                     "This in an error");
        }
        private void ClearInvocationCallbacks(string error)
        {
            var result = new HubResult();
            result.Error = error;

            lock (_callbacks)
            {
                foreach (var callback in _callbacks.Values)
                {
                    callback(result);
                }

                _callbacks.Clear();
            }
        }
Exemplo n.º 9
0
        public void InvokeWithStateCopiesStateToHubProxy()
        {
            var result = new HubResult<object>
            {
                State = new Dictionary<string, JToken>
                {
                    { "state", JToken.FromObject(1) }
                }
            };

            var connection = new Mock<SignalR.Client.IConnection>();
            connection.Setup(m => m.Send<HubResult<object>>(It.IsAny<string>()))
                      .Returns(TaskAsyncHelper.FromResult(result));

            var hubProxy = new HubProxy(connection.Object, "foo");

            hubProxy.Invoke("Anything").Wait();

            Assert.Equal(1, hubProxy["state"]);
        }