コード例 #1
0
            public async Task WithMessageThatCantBeDecoded_ShouldDeliverMessageWithResidualEncodingAndEmitTheErrorOnTheChannel()
            {
                var channel = _client.Channels.Get("test");

                SetState(channel, ChannelState.Attached);

                Message receivedMessage = null;

                channel.Subscribe(msg =>
                {
                    receivedMessage = msg;
                });

                ErrorInfo error = null;

                channel.Error += (sender, args) =>
                {
                    error = args.Reason;
                    Done();
                };

                var message = new Message("name", "encrypted with otherChannelOptions")
                {
                    Encoding = "json"
                };
                await _client.FakeMessageReceived(message, channel.Name);

                WaitOne();

                error.Should().NotBeNull();
                receivedMessage.Encoding.Should().Be("json");
            }
コード例 #2
0
        WithExpiredRenewableToken_ShouldAutomaticallyRenewTokenAndNoErrorShouldBeEmitted(Protocol protocol)
        {
            var restClient = await GetRestClient(protocol);

            var invalidToken = await restClient.Auth.RequestTokenAsync();

            //Use an old token which will result in 40143 Unrecognised token
            invalidToken.Token = invalidToken.Token.Split('.')[0] +
                                 ".DOcRVPgv1Wf1-YGgJFjyk2PNOGl_DFL7aCDzEPju8TYHorfxHHVoNoDGz5fKRW0UxePiVjD1EVEW0ZiknIK8u3S5p1FBq5Rtw_I7OX7fW8U4sGxJjAfMS_fTcXFdvouTQ";

            var realtimeClient = await GetRealtimeClient(protocol, (options, _) =>
            {
                options.TokenDetails = invalidToken;
                options.AutoConnect  = false;
            });

            ErrorInfo error = null;

            realtimeClient.Connection.On(ConnectionState.Connected, (args) =>
            {
                error = args.Reason;
                _resetEvent.Set();
            });

            realtimeClient.Connect();

            _resetEvent.WaitOne(10000);

            realtimeClient.RestClient.AblyAuth.CurrentToken.Expires.Should()
            .BeAfter(TestHelpers.Now(), "The token should be valid and expire in the future.");
            error.Should().BeNull("No error should be raised!");
        }
コード例 #3
0
            public async Task ShouldReturnToPreviousStateIfDetachedMessageWasNotReceivedWithinDefaultTimeout()
            {
                SetState(ChannelState.Attached);
                _client.Options.RealtimeRequestTimeout = TimeSpan.FromMilliseconds(100);
                bool      detachSuccess = true;
                ErrorInfo detachError   = null;

                // use a TaskCompletionSource to let us know when the Detach event has been handled
                TaskCompletionSource <bool> tsc = new TaskCompletionSource <bool>(false);

                _channel.Detach((success, error) =>
                {
                    detachSuccess = success;
                    detachError   = error;
                    tsc.SetResult(true);
                });

                // timeout the tsc incase the detached event never happens
                async Task Timeoutfn()
                {
                    await Task.Delay(1000);

                    tsc.TrySetCanceled();
                }

#pragma warning disable 4014
                Timeoutfn();
#pragma warning restore 4014
                await tsc.Task;

                _channel.State.Should().Be(ChannelState.Attached);
                _channel.ErrorReason.Should().NotBeNull();
                detachSuccess.Should().BeFalse();
                detachError.Should().NotBeNull();
            }
コード例 #4
0
            public async Task ShouldEmmitErrorWithTheErrorThatHasOccuredOnTheChannel()
            {
                var       error         = new ErrorInfo();
                ErrorInfo expectedError = null;

                _channel.On((args) =>
                {
                    expectedError = args.Error;
                    Done();
                });

                (_channel as RealtimeChannel).SetChannelState(ChannelState.Attached, error);

                WaitOne();

                expectedError.Should().BeSameAs(error);
                _channel.ErrorReason.Should().BeSameAs(error);
            }
コード例 #5
0
        public async Task WithAConnectionError_ShouldRaiseChangeStateEventWithError()
        {
            var       client      = GetClientWithFakeTransport();
            bool      hasError    = false;
            ErrorInfo actualError = null;

            client.Connection.InternalStateChanged += (sender, args) =>
            {
                hasError    = args.HasError;
                actualError = args.Reason;
            };
            var expectedError = new ErrorInfo();

            await client.ConnectionManager.OnTransportMessageReceived(
                new ProtocolMessage(ProtocolMessage.MessageAction.Error) { Error = expectedError });

            hasError.Should().BeTrue();
            actualError.Should().Be(expectedError);
        }
コード例 #6
0
        public async Task WithInvalidApiKey_ShouldSetToFailedStateAndAddErrorMessageToEmittedState(Protocol protocol)
        {
            var client = await GetRealtimeClient(protocol, (opts, _) =>
            {
                opts.AutoConnect = false;
                opts.Key         = "baba.bobo:bosh";
            });

            ErrorInfo error = null;

            client.Connection.InternalStateChanged += (sender, args) =>
            {
                error = args.Reason;
            };

            client.Connect();

            await WaitForState(client, ConnectionState.Failed);

            error.Should().NotBeNull();
            client.Connection.ErrorReason.Should().BeSameAs(error);
        }
コード例 #7
0
            public async Task OnceAttachedWhenConsequentAttachMessageArriveWithError_ShouldEmitErrorOnChannelButNoStateChange()
            {
                var client  = GetConnectedClient();
                var channel = client.Channels.Get("test");

                SetState(channel, ChannelState.Attached);

                ErrorInfo expectedError = new ErrorInfo();
                ErrorInfo error         = null;

                channel.Error += (sender, args) =>
                {
                    error = args.Reason;
                };
                bool stateChanged = false;

                await Task.Delay(10); //Allow the notification thread to fire

                ChannelState newState = ChannelState.Initialized;

                channel.On((args) =>
                {
                    stateChanged = true;
                    newState     = args.Current;
                });

                await
                client.FakeProtocolMessageReceived(new ProtocolMessage(ProtocolMessage.MessageAction.Attached)
                {
                    Error   = expectedError,
                    Channel = "test"
                });

                await Task.Delay(10); //Allow the notification thread to fire

                error.Should().BeSameAs(expectedError);
                stateChanged.Should().BeFalse("State should not have changed but is now: " + newState);
            }