public async Task Can_Get_Line_Information_If_Response_Can_Be_Cached() { // Arrange var builder = CreateBuilder() .Requests() .ForPath("Line/Mode/dlr%2Coverground%2Ctflrail%2Ctube") .Responds() .WithResponseHeader("Cache-Control", "max-age=3600") .WithJsonContent(new[] { new { id = "waterloo-city", name = "Waterloo & City" } }); _interceptor.Register(builder); using var httpClient = _interceptor.CreateHttpClient(); httpClient.BaseAddress = _options.BaseUri; var client = Refit.RestService.For <ITflClient>(httpClient); var target = new TflService(client, _cache, _options); // Act ICollection <LineInfo> actual1 = await target.GetLinesAsync(); ICollection <LineInfo> actual2 = await target.GetLinesAsync(); // Assert Assert.NotNull(actual1); Assert.Equal(1, actual1.Count); var item = actual1.First(); Assert.Equal("waterloo-city", item.Id); Assert.Equal("Waterloo & City", item.Name); Assert.Same(actual1, actual2); }
public async Task Can_Get_Line_Information_If_Response_Cannot_Be_Cached() { // Arrange var builder = CreateBuilder() .Requests() .ForPath("Line/Mode/dlr%2Coverground%2Ctflrail%2Ctube") .Responds() .WithJsonContent(new[] { new { id = "district", name = "District" } }); _interceptor.Register(builder); using var httpClient = _interceptor.CreateHttpClient(); httpClient.BaseAddress = _options.BaseUri; ITflClient client = CreateClient(httpClient); var target = new TflService(client, _cache, _options); // Act ICollection <LineInfo> actual1 = await target.GetLinesAsync(); ICollection <LineInfo> actual2 = await target.GetLinesAsync(); // Assert Assert.NotNull(actual1); Assert.Equal(1, actual1.Count); var item = actual1.First(); Assert.Equal("district", item.Id); Assert.Equal("District", item.Name); Assert.NotSame(actual1, actual2); }
public async Task Can_Get_Line_Information_If_Response_Cannot_Be_Cached() { // Arrange var builder = CreateBuilder() .ForPath("Line/Mode/dlr,overground,tflrail,tube") .WithJsonContent(new[] { new { id = "district", name = "District" } }); _interceptor.Register(builder); ICollection <LineInfo> actual1; ICollection <LineInfo> actual2; using (var httpClient = _interceptor.CreateHttpClient()) { using (var target = new TflService(httpClient, _cache, _options)) { // Act actual1 = await target.GetLinesAsync(); actual2 = await target.GetLinesAsync(); } } // Assert Assert.NotNull(actual1); Assert.Equal(1, actual1.Count); var item = actual1.First(); Assert.Equal("district", item.Id); Assert.Equal("District", item.Name); Assert.NotSame(actual1, actual2); }