Exemple #1
0
        public async Task Call_Http()
        {
            var make = "yo";
            var sut  = new VehicleSummaryService();

            var modelResponse = new string[]
            {
                "First",
                "Second"
            };

            VehicleSummaryResponse response;

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(modelResponse);

                response = await sut.GetSummaryByMake(make);


                //httpTest.ShouldHaveCalled()
            }

            response.Make.Should().Be(make);

            response.Models.Count.Should().Be(modelResponse.Length);



//            var a = JsonConvert.SerializeObject(response);
//            _testOutputHelper.WriteLine(a);
        }
Exemple #2
0
        public async Task Return_vehicle_summary_response_for_make()
        {
            // Arrange
            var make          = "yo";
            var modelResponse = new string[]
            {
                "FirstModel",
                "SecondModel"
            };
            var firstModelYearsReponse = new int[]
            {
                1990,
                1995
            };
            var secondModelYearsReponse = new int[]
            {
                2000,
                2001,
                2002
            };
            var sut = new VehicleSummaryService(_testConfiguration, _fakeLogger);

            // Act
            VehicleSummaryResponse response;

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(modelResponse)
                .RespondWithJson(firstModelYearsReponse)
                .RespondWithJson(secondModelYearsReponse);

                response = await sut.GetSummaryByMake(make);

                // Assert
                httpTest.ShouldHaveCalled("http://fake-models-by-make-url/yo")
                .WithQueryParamValue("api-version", "fake-version")
                .WithHeader("Ocp-Apim-Subscription-Key", "fake-key");

                httpTest.ShouldHaveCalled("http://fake-years-of-models-by-make-url/yo/FirstModel")
                .WithQueryParamValue("api-version", "fake-version")
                .WithHeader("Ocp-Apim-Subscription-Key", "fake-key");

                httpTest.ShouldHaveCalled("http://fake-years-of-models-by-make-url/yo/SecondModel")
                .WithQueryParamValue("api-version", "fake-version")
                .WithHeader("Ocp-Apim-Subscription-Key", "fake-key");
            }

            response.Make.Should().Be(make);
            response.Models.Count.Should().Be(modelResponse.Length);
            response.Models[0].Name.Should().Be("FirstModel");
            response.Models[0].YearsAvailable.Should().Be(firstModelYearsReponse.Length);
            response.Models[1].Name.Should().Be("SecondModel");
            response.Models[1].YearsAvailable.Should().Be(secondModelYearsReponse.Length);
        }
Exemple #3
0
        public async Task Throws_vehicle_make_not_found_exception_when_api_returns_404()
        {
            // Arrange
            var make = "yo";
            var sut  = new VehicleSummaryService(_testConfiguration, _fakeLogger);

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith("Not found", 404);

                // Act
                // Assert
                await Assert.ThrowsAsync <VehicleMakeNotFoundException>(async() => await sut.GetSummaryByMake(make));

                httpTest.ShouldHaveCalled("http://fake-models-by-make-url/yo")
                .WithQueryParamValue("api-version", "fake-version")
                .WithHeader("Ocp-Apim-Subscription-Key", "fake-key");

                httpTest.ShouldNotHaveCalled("http://fake-years-of-models-by-make-url/*");
            }
        }