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

            // when
            var exception = await Assert.ThrowsAsync <ArgumentNullException>(() => slackConnection.JoinDirectMessageChannel(string.Empty));

            // then
            exception.Message.ShouldBe("Value cannot be null.\r\nParameter name: user");
        }
Esempio n. 2
0
        private async Task should_return_expected_slack_hub(
            [Frozen] Mock <IConnectionFactory> connectionFactory,
            Mock <IChannelClient> channelClient,
            Mock <IWebSocketClient> webSocket,
            SlackConnection slackConnection)
        {
            // given
            const string slackKey = "key-yay";
            const string userId   = "some-id";

            var connectionInfo = new ConnectionInformation {
                WebSocket = webSocket.Object, SlackKey = slackKey
            };
            await slackConnection.Initialise(connectionInfo);

            connectionFactory
            .Setup(x => x.CreateChannelClient())
            .Returns(channelClient.Object);

            var returnChannel = new Channel {
                Id = "super-id", Name = "dm-channel"
            };

            channelClient
            .Setup(x => x.JoinDirectMessageChannel(slackKey, userId))
            .ReturnsAsync(returnChannel);

            // when
            var result = await slackConnection.JoinDirectMessageChannel(userId);

            // then
            result.ShouldLookLike(new SlackChatHub
            {
                Id   = returnChannel.Id,
                Name = returnChannel.Name,
                Type = SlackChatHubType.DM
            });
        }
Esempio n. 3
0
        public async Task should_join_channel()
        {
            // given
            if (string.IsNullOrEmpty(Config.Slack.TestUserName))
            {
                throw new InvalidConfiguration("TestUserName is missing from config");
            }

            var users = await SlackConnection.GetUsers();

            string userId = users.First(x => x.Name.Equals(Config.Slack.TestUserName, StringComparison.InvariantCultureIgnoreCase)).Id;

            // when
            SlackChatHub result = await SlackConnection.JoinDirectMessageChannel(userId);

            // then
            result.ShouldNotBeNull();

            var dmChannel = SlackConnection.ConnectedDM($"@{Config.Slack.TestUserName}");

            dmChannel.ShouldNotBeNull();
            await SlackConnection.Say(new BotMessage { ChatHub = dmChannel, Text = "Wuzzup - testing in da haus" });
        }