Esempio n. 1
0
        public async Task StopAppWithGuid_ThrowsException_WhenStatusCodeIsNotASuccess()
        {
            string    fakeAppGuid     = "1234";
            string    expectedPath    = _fakeCfApiAddress + CfApiClient.ListAppsPath + $"/{fakeAppGuid}/actions/stop";
            Exception thrownException = null;

            MockedRequest appsRequest = _mockHttp.Expect(expectedPath)
                                        .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}")
                                        .Respond(HttpStatusCode.Unauthorized);

            _sut = new CfApiClient(_mockUaaClient.Object, _mockHttp.ToHttpClient());

            try
            {
                await _sut.StopAppWithGuid(_fakeCfApiAddress, _fakeAccessToken, fakeAppGuid);
            }
            catch (Exception e)
            {
                thrownException = e;
            }

            Assert.IsNotNull(thrownException);
            Assert.IsTrue(thrownException.Message.Contains(CfApiClient.ListAppsPath));
            Assert.AreEqual(1, _mockHttp.GetMatchCount(appsRequest));
        }
Esempio n. 2
0
        public async Task StopAppWithGuid_ReturnsFalse_WhenAppStateIsNotSTOPPED()
        {
            string    fakeAppGuid     = "1234";
            string    expectedPath    = _fakeCfApiAddress + CfApiClient.ListAppsPath + $"/{fakeAppGuid}/actions/stop";
            Exception resultException = null;

            MockedRequest cfStopAppRequest = _mockHttp.Expect(expectedPath)
                                             .Respond("application/json", JsonConvert.SerializeObject(new App {
                State = "fake state != STOPPED"
            }));

            _sut = new CfApiClient(_mockUaaClient.Object, _mockHttp.ToHttpClient());

            bool stopResult = true;

            try
            {
                stopResult = await _sut.StopAppWithGuid(_fakeCfApiAddress, _fakeAccessToken, fakeAppGuid);
            }
            catch (Exception e)
            {
                resultException = e;
            }

            Assert.AreEqual(1, _mockHttp.GetMatchCount(cfStopAppRequest));
            Assert.IsNull(resultException);
            Assert.IsFalse(stopResult);
        }
Esempio n. 3
0
        public async Task StopAppWithGuid_ReturnsFalse_WhenStatusCodeIsNotASuccess()
        {
            string    fakeAppGuid     = "1234";
            string    expectedPath    = _fakeCfApiAddress + CfApiClient.listAppsPath + $"/{fakeAppGuid}/actions/stop";
            Exception resultException = null;

            MockedRequest appsRequest = _mockHttp.Expect(expectedPath)
                                        .WithHeaders("Authorization", $"Bearer {_fakeAccessToken}")
                                        .Respond(HttpStatusCode.Unauthorized);

            _sut = new CfApiClient(_mockUaaClient.Object, _mockHttp.ToHttpClient());

            bool stopResult = true;

            try
            {
                stopResult = await _sut.StopAppWithGuid(_fakeCfApiAddress, _fakeAccessToken, fakeAppGuid);
            }
            catch (Exception e)
            {
                resultException = e;
            }

            Assert.AreEqual(1, _mockHttp.GetMatchCount(appsRequest));
            Assert.IsNull(resultException);
            Assert.IsFalse(stopResult);
        }