Exemple #1
0
        public async Task StartAppWithGuid_ReturnsFalse_WhenAppStateIsNotSTARTED()
        {
            string    fakeAppGuid     = "1234";
            string    expectedPath    = _fakeCfApiAddress + CfApiClient.ListAppsPath + $"/{fakeAppGuid}/actions/start";
            Exception resultException = null;

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

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

            bool startResult = true;

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

            Assert.AreEqual(1, _mockHttp.GetMatchCount(cfStartAppRequest));
            Assert.IsNull(resultException);
            Assert.IsFalse(startResult);
        }
Exemple #2
0
        public async Task StartAppWithGuid_ThrowsException_WhenStatusCodeIsNotASuccess()
        {
            string    fakeAppGuid     = "1234";
            string    expectedPath    = _fakeCfApiAddress + CfApiClient.ListAppsPath + $"/{fakeAppGuid}/actions/start";
            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.StartAppWithGuid(_fakeCfApiAddress, _fakeAccessToken, fakeAppGuid);
            }
            catch (Exception e)
            {
                thrownException = e;
            }

            Assert.IsNotNull(thrownException);
            Assert.IsTrue(thrownException.Message.Contains(CfApiClient.ListAppsPath));
            Assert.AreEqual(1, _mockHttp.GetMatchCount(appsRequest));
        }
Exemple #3
0
        public async Task StartAppWithGuid_ReturnsFalse_WhenStatusCodeIsNotASuccess()
        {
            string    fakeAppGuid     = "1234";
            string    expectedPath    = _fakeCfApiAddress + CfApiClient.listAppsPath + $"/{fakeAppGuid}/actions/start";
            Exception resultException = null;

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

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

            bool startResult = true;

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

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