Пример #1
0
        private async Task should_return_stream(
            Mock <IWebSocketClient> webSocket,
            SlackConnection slackConnection,
            string slackKey,
            Fixture fixture)
        {
            using (var httpTest = new HttpTest())
            {
                // given
                var downloadUri = new Uri($"https://files.slack.com/{fixture.Create<string>()}");

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

                httpTest
                .RespondWithJson(new { fakeObject = true });

                // when
                var result = await slackConnection.DownloadFile(downloadUri);

                // then
                result.ShouldNotBeNull();
                httpTest
                .ShouldHaveCalled(downloadUri.AbsoluteUri)
                .WithOAuthBearerToken(slackKey);
            }
        }
Пример #2
0
        public async Task should_download_file()
        {
            // given
            var uri = new Uri("https://files.slack.com/files-pri/T3NFBGBAS-FBUSTA0P4/fuuuu.gif");

            // when
            var download = await SlackConnection.DownloadFile(uri);

            // then
            using (download)
            {
                download.ShouldNotBeNull();
                download.Length.ShouldBeGreaterThan(0);

                var image = Image.Load(download);
                image.Width.ShouldBe(43);
                image.Height.ShouldBe(29);
            }
        }
Пример #3
0
        private async Task throws_exception_if_uri_isnt_slack(
            Mock <IWebSocketClient> webSocket,
            SlackConnection slackConnection,
            string slackKey,
            Fixture fixture)
        {
            // given
            var downloadUri = new Uri($"https://something.com/{fixture.Create<string>()}");

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

            // when
            var exception = Should.Throw <ArgumentException>(async() => await slackConnection.DownloadFile(downloadUri));

            // then
            exception.ShouldNotBeNull();
            exception.Message.ShouldContain("Invalid uri");
        }