public void GetCdnAssetFileAndVersionReturnsPathWithCurrentDateWhenNoValidResponseFromCDN() { var httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.BadGateway, Content = new MultipartContent(), }; var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>(); A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse); var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender); var httpClient = new HttpClient(fakeHttpMessageHandler); var assetLocationAndVersionService = new AssetLocationAndVersionService(httpClient, asyncHelper, webHostEnvironment, logger, fileInfoHelper); var result = assetLocationAndVersionService.GetCdnAssetFileAndVersion(TestCDNLocation); var expectedFormattedDate = DateTime.Now.ToString("yyyyMMddHH", CultureInfo.InvariantCulture); var expectedResult = $"{TestCDNLocation}?{expectedFormattedDate}"; Assert.Equal(expectedResult, result); httpResponse.Dispose(); fakeHttpMessageHandler.Dispose(); httpClient.Dispose(); }
public void GetCdnAssetFileAndVersionReturnsPathWithHashCodeWhenValidResponseFromCDN() { const string testHeader = "test"; var httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new MultipartContent(), }; httpResponse.Content.Headers.Add("content-md5", testHeader); var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>(); A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse); var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender); var httpClient = new HttpClient(fakeHttpMessageHandler); var assetLocationAndVersionService = new AssetLocationAndVersionService(httpClient, asyncHelper, webHostEnvironment, logger, fileInfoHelper); var result = assetLocationAndVersionService.GetCdnAssetFileAndVersion(TestCDNLocation); var expectedResult = $"{TestCDNLocation}?{testHeader}"; Assert.Equal(expectedResult, result); httpResponse.Dispose(); fakeHttpMessageHandler.Dispose(); httpClient.Dispose(); }
public void GetCdnAssetFileAndVersionLogsErrorWhenExceptionThrown() { var assetLocationAndVersionService = new AssetLocationAndVersionService(defaultHttpClient, asyncHelper, webHostEnvironment, logger, fileInfoHelper); var result = assetLocationAndVersionService.GetCdnAssetFileAndVersion(TestCDNLocation); result.Should().Be($"{TestCDNLocation}?{DateTime.Now.ToString("yyyyMMddHH", CultureInfo.InvariantCulture)}"); }