Exemplo n.º 1
0
        public async Task GetVehicleDataByVINAsync_ValidResponse_ReturnsDataWithExpectedModelYear()
        {
            // Arrange

            const string testVIN = "VIN";

            const int expectedModelYear = 2016;

            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("")
            };

            var resultData = new VehicleAPIData
            {
                Results = new List <VehicleAPIDataResult>
                {
                    new VehicleAPIDataResult {
                        Variable = VehicleLookupData.VariableNames.Make, Value = "IGNORED"
                    },
                    new VehicleAPIDataResult {
                        Variable = VehicleLookupData.VariableNames.Model, Value = "IGNORED"
                    },
                    new VehicleAPIDataResult {
                        Variable = VehicleLookupData.VariableNames.ModelYear, Value = expectedModelYear.ToString()
                    }
                }
            };

            var fakeVPICHttpClient = A.Fake <IVPICHttpClient>();

            A.CallTo(() => fakeVPICHttpClient.DecodeVINAsync(testVIN)).Returns(okResponse);

            var fakeVehicleDataResponseParser = A.Fake <IVehicleDataLookupResponseParser>();

            A.CallTo(() => fakeVehicleDataResponseParser.ParseResponse(A <string> .Ignored)).Returns(resultData);

            var sut = new VehicleDataLookup(fakeVPICHttpClient, fakeVehicleDataResponseParser);

            // Act

            var data = await sut.GetVehicleDataByVINAsync(testVIN);

            // Assert

            A.CallTo(() => fakeVPICHttpClient.DecodeVINAsync(testVIN)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeVehicleDataResponseParser.ParseResponse(A <string> .Ignored)).MustHaveHappenedOnceExactly();

            Assert.Equal(expectedModelYear, data.ModelYear);
        }
Exemplo n.º 2
0
        public async Task GetVehicleDataByVINAsync_BadRequestResponse_ThrowsHttpRequestException()
        {
            // Arrange

            const string testVIN = "VIN";

            var badRequestResponse = new HttpResponseMessage(HttpStatusCode.BadRequest);

            var fakeVPICHttpClient = A.Fake <IVPICHttpClient>();

            A.CallTo(() => fakeVPICHttpClient.DecodeVINAsync(testVIN)).Returns(badRequestResponse);

            var fakeVehicleDataResponseParser = A.Fake <IVehicleDataLookupResponseParser>();

            var sut = new VehicleDataLookup(fakeVPICHttpClient, fakeVehicleDataResponseParser);

            // Act/Assert

            await Assert.ThrowsAsync <HttpRequestException>(async() => await sut.GetVehicleDataByVINAsync(testVIN));
        }