Example #1
0
        public async Task RetrieveRoadStatusAsync_WhenInvalidRoadGiven_InvalidRoadErrorReturnedInConsole()
        {
            //Arrange
            var mockApiService = new Mock <IApiService>();

            mockApiService.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >())).ReturnsAsync(new HttpResponseMessage
            {
                Content    = new StringContent(_singleRoadApiResponse),
                StatusCode = HttpStatusCode.NotFound
            });

            var roadStatusService = new RoadStatusService(mockApiService.Object, _applicationConfig);

            var expectedOutput = "Error: 'A23456' is not a valid road or list of roads. Please check the full list of supported road identifiers and try again.\r\n";
            var consoleOutput  = new StringWriter();

            Console.SetOut(consoleOutput);

            //Act
            await roadStatusService.RetreiveRoadStatus("A23456");

            //Assert
            Assert.That(consoleOutput.ToString(), Is.EqualTo(expectedOutput));
            mockApiService.Verify(x => x.GetAsync("https://mockTflApiUrl/A23456", _queryParams), Times.Once);
        }
Example #2
0
        public async Task RetrieveRoadStatusAsync_WhenMultipleRoadsGiven_MultipleRoadsReturnedInConsole()
        {
            //Arrange
            var mockApiService = new Mock <IApiService>();

            mockApiService.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >())).ReturnsAsync(new HttpResponseMessage
            {
                Content    = new StringContent(_multipleRoadApiResponse),
                StatusCode = HttpStatusCode.OK
            });

            var roadStatusService = new RoadStatusService(mockApiService.Object, _applicationConfig);

            var expectedOutput = "The status of the A2 is as follows:\n\tRoad Status is: Serious\n\tRoad Status Description is: Serious Delays.\r\nThe status of the A20 is as follows:\n\tRoad Status is: Serious\n\tRoad Status Description is: Serious Delays.\r\n";
            var consoleOutput  = new StringWriter();

            Console.SetOut(consoleOutput);

            //Act
            await roadStatusService.RetreiveRoadStatus("A2,A20");

            //Assert
            Assert.That(consoleOutput.ToString(), Is.EqualTo(expectedOutput));
            mockApiService.Verify(x => x.GetAsync("https://mockTflApiUrl/A2,A20", _queryParams), Times.Once);
        }