Ejemplo n.º 1
0
        public async Task All_GivenUnsuccessfulResponse_ThrowsException()
        {
            const string subscriptionKey = "subscriptionKey";
            var          requestReceived = new ManualResetEvent(false);

            using (var server = TestServerBuilder.New()
                                .WithResponseFromJsonResource(departureResource, HttpStatusCode.OK)
                                .WithMiddleware(RequestListener)
                                .Build())
            {
                var tranInformation = NsSharpFactory.Create(subscriptionKey, server.CreateClient(), A.JsonConverter)
                                      .NsTravelInformation();

                await tranInformation.Departures.All(DepartureRequest.Create(A.StationCode));

                requestReceived.WaitOne(1500, false)
                .Should().BeTrue();
            }

            Task RequestListener(HttpContext context, Func <Task> next)
            {
                context.Request.Headers.Values.Should().Contain(subscriptionKey);
                context.Request.GetDisplayUrl().Should().Contain(Constants.NsPublicTravelInformationApiAddress);

                requestReceived.Set();
                return(next());
            }
        }
Ejemplo n.º 2
0
Archivo: A.cs Proyecto: droosma/NSSharp
 public static NsTravelInformation NsTravelInformation(this TestServer server)
 => NsSharpFactory.Create("subscriptionKey", server.CreateClient(), JsonConverter).NsTravelInformation();