Exemple #1
0
        private async Task should_not_raise_event_given_missing_data(
            Mock <IWebSocketClient> webSocket,
            SlackConnection slackConnection)
        {
            // given
            var connectionInfo = new ConnectionInformation {
                WebSocket = webSocket.Object
            };
            await slackConnection.Initialise(connectionInfo);

            SlackChannelCreated channelCreated = null;

            slackConnection.OnChannelCreated += channel =>
            {
                channelCreated = channel;
                return(Task.CompletedTask);
            };

            var inboundMessage = new ChannelCreatedMessage {
                Channel = null
            };

            // when
            webSocket.Raise(x => x.OnMessage += null, null, inboundMessage);

            // then
            channelCreated.ShouldBeNull();
            slackConnection.ConnectedHubs.ShouldBeEmpty();
        }
Exemple #2
0
        private void should_return_channel_created_message(MessageInterpreter interpreter)
        {
            // given
            string json = @"
                {
                    'type': 'channel_created',
                    'channel': {
                        'id': 'C024BE91L',
                        'name': 'fun',
                        'created': 1360782804,
                        'creator': 'U024BE7LH'
                    }
                }
            ";

            // when
            var result = interpreter.InterpretMessage(json);

            // then
            var expected = new ChannelCreatedMessage
            {
                MessageType = MessageType.Channel_Created,
                Channel     = new Channel
                {
                    Id      = "C024BE91L",
                    Name    = "fun",
                    Creator = "U024BE7LH"
                },
                RawData = json,
            };

            result.ShouldLookLike(expected);
        }
Exemple #3
0
        private async Task should_raise_event(
            Mock <IWebSocketClient> webSocket,
            SlackConnection slackConnection,
            SlackUser slackUser,
            Fixture fixture)
        {
            // given
            var connectionInfo = new ConnectionInformation
            {
                WebSocket = webSocket.Object,
                Users     = new Dictionary <string, SlackUser>
                {
                    { slackUser.Id, slackUser }
                }
            };
            await slackConnection.Initialise(connectionInfo);

            SlackChannelCreated channelCreated = null;

            slackConnection.OnChannelCreated += channel =>
            {
                channelCreated = channel;
                return(Task.CompletedTask);
            };

            var inboundMessage = new ChannelCreatedMessage
            {
                Channel = new Channel
                {
                    Creator = slackUser.Id,
                    Id      = fixture.Create <string>(),
                    Name    = fixture.Create <string>()
                }
            };

            // when
            webSocket.Raise(x => x.OnMessage += null, null, inboundMessage);

            // then
            channelCreated.Id.ShouldBe(inboundMessage.Channel.Id);
            channelCreated.Name.ShouldBe(inboundMessage.Channel.Name);
            channelCreated.Creator.ShouldBe(slackUser);
            slackConnection.ConnectedHubs.ContainsKey(inboundMessage.Channel.Id).ShouldBeTrue();
        }
        private Task HandleChannelCreated(ChannelCreatedMessage inboundMessage)
        {
            string channelId = inboundMessage?.Channel?.Id;

            if (channelId == null)
            {
                return(Task.CompletedTask);
            }

            var hub = inboundMessage.Channel.ToChatHub();

            this._connectedHubs[channelId] = hub;

            var slackChannelCreated = new SlackChannelCreated
            {
                Id      = channelId,
                Name    = inboundMessage.Channel.Name,
                Creator = this.GetMessageUser(inboundMessage.Channel.Creator)
            };

            return(this.RaiseOnChannelCreated(slackChannelCreated));
        }
Exemple #5
0
 private ActorContinuation OnChannelCreatedMessage(ChannelCreatedMessage channelCreatedMessage)
 {
     ChannelReceivingActor channelReceivingActor = new ChannelReceivingActor(this, this.ActorManager);
     this.channelReceivingActors.Add(channelCreatedMessage.ChannelId, channelReceivingActor);
     this.ActorManager.RunActor(channelReceivingActor);
     return ActorContinuation.BlockOnReceive;
 }