예제 #1
0
        public void PostCall_SerializedObjectPassedInCall_StringReturned()
        {
            // Arrange
            var httpClient = A.Fake <IHttpClientWrapper>();

            A.CallTo(() => httpClient.Post("https://fake/guestAuth/app/rest/test", A <StringContent> .That.Matches(c => c.ReadAsStringAsync().Result.Contains("testObjectSerialization")), "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.Post <BuildModel, string>("test", new BuildModel {
                BuildTypeId = "testObjectSerialization", FinishDate = _dateUnderTest
            });

            // Assert
            result.Should().NotBeNull()
            .And.Be("testPlainTextResponse");
        }
예제 #2
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");
        }
예제 #3
0
        public void DeleteCall_NothingPassed_CallMade()
        {
            // Arrange
            var httpClient = A.Fake <IHttpClientWrapper>();

            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
            tcApiClient.Delete <string>("test", null);

            // Assert
            A.CallTo(() => httpClient.Delete("https://fake/guestAuth/app/rest/test", A <StringContent> .That.Matches(c => c.ReadAsStringAsync().Result.IsNullOrEmpty()), "text/plain")).MustHaveHappened();
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
0
        public void DeleteCall_SerializedObjectPassedInCall_DeserializedObjectReturned()
        {
            // Arrange
            var httpClient        = A.Fake <IHttpClientWrapper>();
            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
            tcApiClient.Delete("test", new BuildModel {
                BuildTypeId = "testObjectSerialization", FinishDate = _dateUnderTest
            });

            // Assert
            A.CallTo(() => httpClient.Delete("https://fake/guestAuth/app/rest/test",
                                             A <StringContent> .That.Matches(c => c.ReadAsStringAsync().Result.Contains("testObjectSerialization")),
                                             "application/json"))
            .MustHaveHappened();
        }
예제 #7
0
        public void PostCall_StringPassedInCall_DeserializedObjectReturned()
        {
            // Arrange
            var httpClient = A.Fake <IHttpClientWrapper>();

            A.CallTo(() => httpClient.Post("https://fake/guestAuth/app/rest/test", A <StringContent> .That.Matches(c => c.ReadAsStringAsync().Result.Contains("somePlainText")), "application/json"))
            .Returns(_jsonResponseWithOkStatus);
            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.Post <string, BuildModel>("test", "somePlainText");

            // Assert
            result.Should().NotBeNull();
            result.BuildTypeId.Should().Be("test");
            result.FinishDate.Should().Be(_dateUnderTest);
        }
예제 #8
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");
        }