Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        private async Task RaiseOnChannelCreated(SlackChannelCreated chatHub)
        {
            var e = this.OnChannelCreated;

            if (e != null)
            {
                try
                {
                    await e(chatHub);
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 4
0
        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));
        }