public async Task LocationController_GetWithValidWoeId_ReturnsValidLocationAsync(ILogger <LocationController> logger,
                                                                                         ApiOptions apiOptions,
                                                                                         IApiProxy apiProxy)
        {
            var expectedCount = 1;

            _apiProxy = apiProxy;

            // Arrange
            _apiProxy = Substitute.For <IApiProxy>();
            _locationResponseBuilder = new TestLocationResponseBuilder();

            _locationController = new LocationController(logger, apiOptions, _apiProxy);
            _apiProxy.SubmitLocationRequest(Arg.Any <ILocationRequest>())
            .Returns(_locationResponseBuilder.Default().WithBelfast().Build());

            // Act
            var locationResponse = await _locationController.Post(new LocationRequest()).ConfigureAwait(false);


            // Assert
            using (new AssertionScope())
            {
                locationResponse.Should().BeOkObjectResult().ValueAs <ILocationResponse>().Locations
                .Should()
                .HaveCount(expectedCount);
            }
        }
Exemplo n.º 2
0
        public void Background()
        {
            _mockHttpMessageHandler = new MockHttpMessageHandler();
            var locationBuilder = new TestLocationResponseBuilder();
            var weatherBuilder  = new TestWeatherResponseBuilder();

            _mockHttpMessageHandler.When(STR_Search)
            .WithQueryString("query", "Belfast")
            .Respond(() => locationBuilder.Default().WithBelfast().BuildHttpResponse());

            _mockHttpMessageHandler.When(STR_Search)
            .WithQueryString("query", "Birmingham")
            .Respond(() => locationBuilder.Default().WithBirmingham().BuildHttpResponse());

            _mockHttpMessageHandler.When(STR_44544)
            .Respond(() => weatherBuilder.Default().WithBelfast().BuildHttpResponse());

            _mockHttpMessageHandler.When(STR_12723)
            .Respond(() => weatherBuilder.Default().WithBirmingham().BuildHttpResponse());

            _mockHttpMessageHandler.Fallback
            .Respond(
                req => new HttpResponseMessage(HttpStatusCode.NotFound)
            {
                ReasonPhrase =
                    $"No matching mock handler found for \"{req.Method.ToString().ToUpperInvariant()} {req.RequestUri.AbsoluteUri}\""
            });

            var settings = new RefitSettings {
                HttpMessageHandlerFactory = () => _mockHttpMessageHandler
            };

            _metaWeatherService = RestService.For <IMetaWeatherService>("https://www.metaweather.com", settings);
        }
Exemplo n.º 3
0
        public void Background()
        {
            _mockHttpMessageHandler = new MockHttpMessageHandler();
            var builder = new TestLocationResponseBuilder();

            _mockHttpMessageHandler.When("https://www.metaweather.com/api/location/search")
            .WithQueryString("query", "Belfast")
            .Respond(() => builder.Default().WithBelfast().BuildHttpResponse());

            _mockHttpMessageHandler.When("https://www.metaweather.com/api/location/search")
            .WithQueryString("query", "Birmingham")
            .Respond(() => builder.Default().WithBirmingham().BuildHttpResponse());

            var settings = new RefitSettings {
                HttpMessageHandlerFactory = () => _mockHttpMessageHandler
            };

            _metaWeatherService = RestService.For <IMetaWeatherService>("https://www.metaweather.com", settings);
        }