Beispiel #1
0
        public async Task TestWithInValidRoadIdReturnNonZeroExitCode(string baseUrl, string roadId)
        {
            // Arrange
            httpClient.BaseAddress = new Uri(baseUrl);

            roadStatusService = new RoadStatusService(loggerMock.Object, httpClient, optionMock.Object);

            // Act
            var result = await roadStatusService.GetRoadStatusDetail(roadId);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNull(result.RoadStatus);
            Assert.AreEqual(1, result.StatusCode);
        }
Beispiel #2
0
        public async Task TestWithValidUrlReturnCorrectResult(string baseUrl)
        {
            // Arrange
            httpClient.BaseAddress = new Uri(baseUrl);

            roadStatusService = new RoadStatusService(loggerMock.Object, httpClient, optionMock.Object);

            // Act
            var result = await roadStatusService.GetRoadStatusDetail("a2");

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.StatusCode);
            Assert.AreEqual(1, result.RoadStatus.Count());
        }
Beispiel #3
0
        public async Task TestWithInValidUrlRaiseException(string baseUrl)
        {
            // Arrange
            httpClient.BaseAddress = new Uri(baseUrl);

            roadStatusService = new RoadStatusService(loggerMock.Object, httpClient, optionMock.Object);

            // Act
            HttpRequestException ex = await Task.Run(() => Assert.ThrowsAsync <HttpRequestException>(async() => await roadStatusService.GetRoadStatusDetail("a2")));

            // Assert
            Assert.AreEqual("Error: Expected Error occured.", ex.Message);
            Assert.IsTrue(ex.InnerException.Message.Contains("No such host is known"));
        }
Beispiel #4
0
        public async Task TestWithInValidAppKeyAndIdRaiseException(string baseUrl,
                                                                   string roadId,
                                                                   string appkey,
                                                                   string appId)
        {
            // Arrange
            httpClient.BaseAddress = new Uri(baseUrl);

            roadStatusService = new RoadStatusService(loggerMock.Object, httpClient, optionMock.Object);

            optionMock.Setup(x => x.Value).Returns(new RemoteServiceSettings
            {
                ApiId   = appId,
                ApiKey  = appkey,
                BaseUrl = baseUrl
            });

            // Act
            HttpRequestException ex = await Task.Run(() => Assert.ThrowsAsync <HttpRequestException>(async() => await roadStatusService.GetRoadStatusDetail("a2")));

            // Assert
            Assert.AreEqual("Error: Expected Error occured.", ex.Message);
            Assert.IsTrue(ex.InnerException.Message.Contains("Unexpected character encountered"));
        }