public async Task ListAppsWithGuid_ThrowsException_WhenStatusCodeIsNotASuccess() { string expectedPath = CfApiClient.ListAppsPath; MockedRequest appsRequest = _mockHttp.Expect(_fakeCfApiAddress + expectedPath) .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}") .Respond(HttpStatusCode.Unauthorized); _sut = new CfApiClient(_mockUaaClient.Object, _mockHttp.ToHttpClient()); Exception thrownException = null; try { var result = await _sut.ListAppsForSpace(_fakeCfApiAddress, _fakeAccessToken, "spaceGuid"); } catch (Exception ex) { thrownException = ex; } Assert.IsNotNull(thrownException); Assert.IsTrue(thrownException.Message.Contains(CfApiClient.ListAppsPath)); Assert.AreEqual(1, _mockHttp.GetMatchCount(appsRequest)); }
public async Task ListAppsWithGuid_ReturnsListOfAllVisibleApps_WhenResponseContainsMultiplePages() { string expectedPath = CfApiClient.ListAppsPath; string page2Identifier = "?page=2&per_page=50"; string page3Identifier = "?page=3&per_page=50"; MockedRequest appsRequest = _mockHttp.Expect(_fakeCfApiAddress + expectedPath) .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}") .Respond("application/json", _fakeAppsJsonResponsePage1); MockedRequest appsPage2Request = _mockHttp.Expect(_fakeCfApiAddress + expectedPath + page2Identifier) .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}") .Respond("application/json", _fakeAppsJsonResponsePage2); MockedRequest appsPage3Request = _mockHttp.Expect(_fakeCfApiAddress + expectedPath + page3Identifier) .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}") .Respond("application/json", _fakeAppsJsonResponsePage3); _sut = new CfApiClient(_mockUaaClient.Object, _mockHttp.ToHttpClient()); var result = await _sut.ListAppsForSpace(_fakeCfApiAddress, _fakeAccessToken, "fake guid"); Assert.IsNotNull(result); Assert.AreEqual(125, result.Count); Assert.AreEqual(1, _mockHttp.GetMatchCount(appsRequest)); Assert.AreEqual(1, _mockHttp.GetMatchCount(appsPage2Request)); Assert.AreEqual(1, _mockHttp.GetMatchCount(appsPage3Request)); }
public async Task ListAppsWithGuid_ReturnsNull_WhenStatusCodeIsNotASuccess() { string expectedPath = CfApiClient.listAppsPath; MockedRequest appsRequest = _mockHttp.Expect(_fakeCfApiAddress + expectedPath) .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}") .Respond(HttpStatusCode.Unauthorized); _sut = new CfApiClient(_mockUaaClient.Object, _mockHttp.ToHttpClient()); var result = await _sut.ListAppsForSpace(_fakeCfApiAddress, _fakeAccessToken, "spaceGuid"); Assert.IsNull(result); Assert.AreEqual(1, _mockHttp.GetMatchCount(appsRequest)); }