Esempio n. 1
0
        public async Task SendAsyncThrowsIfSerializingMessageFails()
        {
            var exception     = new InvalidOperationException();
            var hubConnection = CreateHubConnection(new TestConnection(), protocol: MockHubProtocol.Throw(exception));
            await hubConnection.StartAsync().OrTimeout();

            var actualException =
                await Assert.ThrowsAsync <InvalidOperationException>(async() => await hubConnection.SendAsync("test").OrTimeout());

            Assert.Same(exception, actualException);
        }
Esempio n. 2
0
        public async Task InvokeThrowsIfSerializingMessageFails()
        {
            var exception     = new InvalidOperationException();
            var mockProtocol  = MockHubProtocol.Throw(exception);
            var hubConnection = new HubConnection(new TestConnection(), mockProtocol, null);
            await hubConnection.StartAsync();

            var actualException =
                await Assert.ThrowsAsync <InvalidOperationException>(async() => await hubConnection.InvokeAsync <int>("test"));

            Assert.Same(exception, actualException);
        }
Esempio n. 3
0
        public async Task DoesNotThrowWhenClientMethodCalledButNoInvocationHandlerHasBeenSetUp()
        {
            var mockConnection = new Mock <IConnection>();

            mockConnection.SetupGet(p => p.Features).Returns(new FeatureCollection());

            var invocation = new InvocationMessage(Guid.NewGuid().ToString(), nonBlocking: true, target: "NonExistingMethod123", arguments: new object[] { true, "arg2", 123 });

            var mockProtocol = MockHubProtocol.ReturnOnParse(invocation);

            var hubConnection = new HubConnection(mockConnection.Object, mockProtocol, null);
            await hubConnection.StartAsync();

            mockConnection.Raise(c => c.Received += null, new object[] { new byte[] { } });
            Assert.Equal(1, mockProtocol.ParseCalls);
        }
Esempio n. 4
0
    public async Task InvokeThrowsIfSerializingMessageFails()
    {
        bool ExpectedErrors(WriteContext writeContext)
        {
            return(writeContext.LoggerName == typeof(HubConnection).FullName &&
                   writeContext.EventId.Name == "FailedToSendInvocation");
        }

        using (StartVerifiableLog(ExpectedErrors))
        {
            var exception     = new InvalidOperationException();
            var hubConnection = CreateHubConnection(new TestConnection(), protocol: MockHubProtocol.Throw(exception), LoggerFactory);
            await hubConnection.StartAsync().DefaultTimeout();

            var actualException =
                await Assert.ThrowsAsync <InvalidOperationException>(async() => await hubConnection.InvokeAsync <int>("test").DefaultTimeout());

            Assert.Same(exception, actualException);
        }
    }