示例#1
0
        public async Task Publish_invalid_channel()
        {
            // arrange
            _fayeServerProcess.StartThinServer();
            var socket = new WebSocketClient(uri: TEST_SERVER_URL);

            SetupWebSocket(socket);
            InstantiateFayeClient();
            _connection = await _fayeClient.Connect();

            const string invalidChannel   = "/*";
            var          messageToSendObj = new TestMsg {
                Stuff = "the message"
            };
            var messageToSend = JsonConvert.SerializeObject(messageToSendObj);

            // act + assert
            var exception = await _connection.InvokingAsync(c => c.Publish(channel: invalidChannel,
                                                                           message: messageToSend))
                            .ShouldThrow <PublishException>();

            exception.Message
            .Should()
            .Be("405:/*:Invalid channel");
        }
示例#2
0
        public async Task Subscribe_wildcard_channel()
        {
            // arrange
            _fayeServerProcess.StartThinServer();
            var socket = new WebSocketClient(uri: TEST_SERVER_URL);

            SetupWebSocket(socket);
            InstantiateFayeClient();
            _connection = await _fayeClient.Connect();

            const string    wildcardChannel = "/*";
            Action <string> dummyAction     = msg => Console.WriteLine("hi");

            // act + assert
            var exception = await _connection.InvokingAsync(c => c.Subscribe(wildcardChannel,
                                                                             dummyAction))
                            .ShouldThrow <SubscriptionException>();

            var expectedMessage = string.Format(FayeConnection.WILDCARD_CHANNEL_ERROR_FORMAT,
                                                wildcardChannel);

            exception.Message
            .Should()
            .Be(expectedMessage);
        }
示例#3
0
        public async Task Subscribe_reserved_channel_name()
        {
            // arrange
            _fayeServerProcess.StartThinServer();
            var socket = new WebSocketClient(uri: TEST_SERVER_URL);

            SetupWebSocket(socket);
            InstantiateFayeClient();
            _connection = await _fayeClient.Connect();

            const string    reservedChannelName = "/meta/subscribe";
            Action <string> dummyAction         = msg => Console.WriteLine("hi");

            // act + assert
            var exception = await _connection.InvokingAsync(s => s.Subscribe(channel: reservedChannelName,
                                                                             messageReceivedAction: dummyAction))
                            .ShouldThrow <SubscriptionException>();

            exception.Message
            .Should()
            .Be("403:/meta/subscribe:Forbidden channel");
        }
示例#4
0
        public async Task Unsubscribe_not_currently_subscribed()
        {
            // arrange
            _fayeServerProcess.StartThinServer();
            var socket = new WebSocketClient(uri: TEST_SERVER_URL);

            SetupWebSocket(socket);
            InstantiateFayeClient();
            _connection = await _fayeClient.Connect();

            const string channelWeDidntSubscribeTo = "/foobar";

            // act + assert
            var exception = await _connection.InvokingAsync(c => c.Unsubscribe(channelWeDidntSubscribeTo))
                            .ShouldThrow <SubscriptionException>();

            var expectedError = string.Format(FayeConnection.NOT_SUBSCRIBED,
                                              channelWeDidntSubscribeTo);

            exception.Message
            .Should()
            .Be(expectedError);
        }