public async Task ListSpacesWithGuid_ThrowsException_WhenStatusCodeIsNotASuccess() { string expectedPath = CfApiClient.ListSpacesPath; MockedRequest spacesRequest = _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.ListSpacesForOrg(_fakeCfApiAddress, _fakeAccessToken, "orgGuid"); } catch (Exception ex) { thrownException = ex; } Assert.IsNotNull(thrownException); Assert.IsTrue(thrownException.Message.Contains(CfApiClient.ListSpacesPath)); Assert.AreEqual(1, _mockHttp.GetMatchCount(spacesRequest)); }
public async Task ListSpacesWithGuid_ReturnsListOfAllVisibleSpaces_WhenResponseContainsMultiplePages() { string expectedPath = CfApiClient.ListSpacesPath; string page2Identifier = "?page=2&per_page=3"; string page3Identifier = "?page=3&per_page=3"; MockedRequest spacesRequest = _mockHttp.Expect(_fakeCfApiAddress + expectedPath) .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}") .Respond("application/json", _fakeSpacesJsonResponsePage1); MockedRequest spacesPage2Request = _mockHttp.Expect(_fakeCfApiAddress + expectedPath + page2Identifier) .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}") .Respond("application/json", _fakeSpacesJsonResponsePage2); MockedRequest spacesPage3Request = _mockHttp.Expect(_fakeCfApiAddress + expectedPath + page3Identifier) .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}") .Respond("application/json", _fakeSpacesJsonResponsePage3); _sut = new CfApiClient(_mockUaaClient.Object, _mockHttp.ToHttpClient()); var result = await _sut.ListSpacesForOrg(_fakeCfApiAddress, _fakeAccessToken, "fake guid"); Assert.IsNotNull(result); Assert.AreEqual(7, result.Count); Assert.AreEqual(1, _mockHttp.GetMatchCount(spacesRequest)); Assert.AreEqual(1, _mockHttp.GetMatchCount(spacesPage2Request)); Assert.AreEqual(1, _mockHttp.GetMatchCount(spacesPage3Request)); }
public async Task ListSpacesWithGuid_ReturnsNull_WhenStatusCodeIsNotASuccess() { string expectedPath = CfApiClient.listSpacesPath; MockedRequest spacesRequest = _mockHttp.Expect(_fakeCfApiAddress + expectedPath) .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}") .Respond(HttpStatusCode.Unauthorized); _sut = new CfApiClient(_mockUaaClient.Object, _mockHttp.ToHttpClient()); var result = await _sut.ListSpacesForOrg(_fakeCfApiAddress, _fakeAccessToken, "orgGuid"); Assert.IsNull(result); Assert.AreEqual(1, _mockHttp.GetMatchCount(spacesRequest)); }