예제 #1
0
        public void GetCall_NoAuthenticationProvidedForNonGuestCall_ExceptionThrown()
        {
            // Arrange
            var settings          = new TeamCityConnectionSettings(new Uri("https://localhost"), false, string.Empty, string.Empty);
            var httpClientFactory = A.Fake <IHttpClientWrapperFactory>();

            A.CallTo(() => httpClientFactory.Create()).Returns(A.Fake <IHttpClientWrapper>());

            var tcApiClient = new TeamCityApiClient(settings, httpClientFactory);

            // Act
            Action action = () => tcApiClient.Get <BuildModel>("test");

            // Assert
            action.ShouldThrow <ArgumentException>().Which.Message.Should().Be("When connecting as guest you must specify username and password");
        }
예제 #2
0
        public void GetCall_ResponseErrorThrowsException()
        {
            // Arrange
            var httpClient = A.Fake <IHttpClientWrapper>();

            A.CallTo(() => httpClient.Get("https://fake/guestAuth/app/rest/test", "application/json"))
            .Returns(_jsonResponseWithErrorStatus);
            var httpClientFactory = A.Fake <IHttpClientWrapperFactory>();

            A.CallTo(() => httpClientFactory.Create()).Returns(httpClient);

            var settings    = new TeamCityConnectionSettings(new Uri("https://fake"), true, "guest", string.Empty, true);
            var tcApiClient = new TeamCityApiClient(settings, httpClientFactory);

            // Act
            Action action = () => tcApiClient.Get <BuildModel>("test");

            // Assert
            action.ShouldThrow <HttpException>().Which.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
예제 #3
0
        public void GetCall_AsAuthenticatedUser_ReturnsDeserializedJsonObject()
        {
            // Arrange
            var httpClient = A.Fake <IHttpClientWrapper>();

            A.CallTo(() => httpClient.Get("https://fake/httpAuth/app/rest/test", "application/json"))
            .Returns(_jsonResponseWithOkStatus);
            var httpClientFactory = A.Fake <IHttpClientWrapperFactory>();

            A.CallTo(() => httpClientFactory.Create()).Returns(httpClient);

            var settings    = new TeamCityConnectionSettings(new Uri("https://fake"), false, "user", "password", true);
            var tcApiClient = new TeamCityApiClient(settings, httpClientFactory);

            // Act
            var result = tcApiClient.Get <BuildModel>("test");

            // Assert
            result.Should().NotBeNull();
            result.BuildTypeId.Should().Be("test");
            result.FinishDate.Should().Be(_dateUnderTest);
        }
예제 #4
0
        public void GetCall_AsGuest_ReturnsPlainTextResponse()
        {
            // Arrange
            var httpClient = A.Fake <IHttpClientWrapper>();

            A.CallTo(() => httpClient.Get("https://fake/guestAuth/app/rest/test", "text/plain"))
            .Returns(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("testPlainTextResponse")
            });
            var httpClientFactory = A.Fake <IHttpClientWrapperFactory>();

            A.CallTo(() => httpClientFactory.Create()).Returns(httpClient);

            var settings    = new TeamCityConnectionSettings(new Uri("https://fake"), true, "guest", string.Empty, true);
            var tcApiClient = new TeamCityApiClient(settings, httpClientFactory);

            // Act
            var result = tcApiClient.Get <string>("test");

            // Assert
            result.Should().NotBeNull()
            .And.Be("testPlainTextResponse");
        }