Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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()
                          .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);
        }
Exemplo n.º 4
0
        public async Task Can_Get_Stop_Points_If_Response_Cannot_Be_Cached()
        {
            // Arrange
            var builder = CreateBuilder()
                          .Requests()
                          .ForPath("Line/victoria/StopPoints")
                          .Responds()
                          .WithJsonContent(new[] { new { id = "940GZZLUGPK", commonName = "Green Park Underground Station", lat = 51.506947, lon = -0.142787 } });

            _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 <StopPoint> actual1 = await target.GetStopPointsByLineAsync("victoria");

            ICollection <StopPoint> actual2 = await target.GetStopPointsByLineAsync("victoria");

            // Assert
            Assert.NotNull(actual1);
            Assert.Equal(1, actual1.Count);

            var item = actual1.First();

            Assert.Equal("940GZZLUGPK", item.Id);
            Assert.Equal("Green Park Underground Station", item.Name);
            Assert.Equal(51.506947, item.Latitude);
            Assert.Equal(-0.142787, item.Longitude);

            Assert.NotSame(actual1, actual2);
        }
        public async Task Can_Get_Stop_Points_If_Response_Can_Be_Cached()
        {
            // Arrange
            var builder = CreateBuilder()
                          .Requests()
                          .ForPath("Line/victoria/StopPoints")
                          .Responds()
                          .WithResponseHeader("Cache-Control", "max-age=3600")
                          .WithJsonContent(new[] { new { id = "940GZZLUOXC", commonName = "Oxford Circus Underground Station", lat = 51.515224, lon = -0.141903 } });

            _interceptor.Register(builder);

            ICollection <StopPoint> actual1;
            ICollection <StopPoint> actual2;

            using (var httpClient = _interceptor.CreateHttpClient())
            {
                httpClient.BaseAddress = _options.BaseUri;

                var client = Refit.RestService.For <ITflClient>(httpClient);
                var target = new TflService(client, _cache, _options);

                // Act
                actual1 = await target.GetStopPointsByLineAsync("victoria");

                actual2 = await target.GetStopPointsByLineAsync("victoria");
            }

            // Assert
            Assert.NotNull(actual1);
            Assert.Equal(1, actual1.Count);

            var item = actual1.First();

            Assert.Equal("940GZZLUOXC", item.Id);
            Assert.Equal("Oxford Circus Underground Station", item.Name);
            Assert.Equal(51.515224, item.Latitude);
            Assert.Equal(-0.141903, item.Longitude);

            Assert.Same(actual1, actual2);
        }