Exemple #1
0
        public void NotFoundTwiceForSameHost_CouldNotDownloadExceptionMessage()
        {
            var host          = "flaky404.githubusercontent.com";
            var url           = new Uri("https://" + host + "/u/00000000?v=4");
            var expectMessage = ImageDownloader.CouldNotDownloadExceptionMessage(url);
            var httpClient    = Substitute.For <IHttpClient>();
            var response      = Substitute.For <IResponse>();

            response.StatusCode.Returns(HttpStatusCode.NotFound);
            httpClient.Send(null, default(CancellationToken)).ReturnsForAnyArgs(Task.FromResult(response));
            var target = new ImageDownloader(new Lazy <IHttpClient>(() => httpClient));

            var ex1 = Assert.CatchAsync <HttpRequestException>(async() => await target.DownloadImageBytes(url));
            var ex2 = Assert.CatchAsync <HttpRequestException>(async() => await target.DownloadImageBytes(url));

            Assert.That(ex1?.Message, Is.EqualTo(expectMessage));
            Assert.That(ex2?.Message, Is.EqualTo(expectMessage));
        }