예제 #1
0
        public async Task MovePackageIntoPackageAsync_ValidRequest_ShouldReturnVoid()
        {
            // Arrange
            var existingProject = new GetProjectPayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var existingPackage = new GetPackagePayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var parentPackage = new GetPackagePayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var setPackageAssociationRequest = new SetPackageAssociationRequest(parentPackage.Id);

            var expectedResponse = new HttpResponseMessage();

            var packageApi = this.fixture.GetPackageApi(expectedResponse);

            // Act
            Func <Task> act = async() => await packageApi.MovePackageIntoPackageAsync(existingProject.Id, existingPackage.Id, setPackageAssociationRequest);

            // Assert
            await act.Should().NotThrowAsync();
        }
예제 #2
0
        public async Task MovePackageIntoPackageAsync_InvalidRequestModelParentPackageId_ShouldThrowArgumentNullException(string packageId)
        {
            // Arrange
            var existingProject = new GetProjectPayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var existingPackage = new GetPackagePayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var setPackageAssociationRequest = new SetPackageAssociationRequest(packageId);

            var expectedResponse = new HttpResponseMessage();

            var packageApi = this.fixture.GetPackageApi(expectedResponse);

            // Act
            Func <Task> act = async() => await packageApi.MovePackageIntoPackageAsync(existingProject.Id, existingPackage.Id, setPackageAssociationRequest);

            // Assert
            await act.Should().ThrowAsync <ArgumentNullException>();
        }
예제 #3
0
        public async Task MovePackageIntoPackageAsync_UnsuccessfulRequest_ShouldThrowFactroApiException()
        {
            // Arrange
            var projectId = Guid.NewGuid().ToString();
            var packageId = Guid.NewGuid().ToString();
            var setPackageAssociationRequest = new SetPackageAssociationRequest(Guid.NewGuid().ToString());

            var expectedResponse = new HttpResponseMessage
            {
                StatusCode     = HttpStatusCode.BadRequest,
                RequestMessage = new HttpRequestMessage
                {
                    RequestUri = new Uri("http://www.mock-web-address.com"),
                },
            };

            var packageApi = this.fixture.GetPackageApi(expectedResponse);

            // Act
            Func <Task> act = async() => await packageApi.MovePackageIntoPackageAsync(projectId, packageId, setPackageAssociationRequest);

            // Assert
            await act.Should().ThrowAsync <FactroApiException>();
        }
예제 #4
0
        public async Task MovePackageIntoPackageAsync(string projectId, string packageId, SetPackageAssociationRequest setPackageAssociationRequest)
        {
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace.");
            }

            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentNullException(nameof(packageId), $"{nameof(packageId)} can not be null, empty or whitespace.");
            }

            if (setPackageAssociationRequest == null)
            {
                throw new ArgumentNullException(nameof(setPackageAssociationRequest), $"{nameof(setPackageAssociationRequest)} can not be null.");
            }

            if (string.IsNullOrWhiteSpace(setPackageAssociationRequest.ParentPackageId))
            {
                throw new ArgumentNullException(nameof(setPackageAssociationRequest), $"{nameof(setPackageAssociationRequest.ParentPackageId)} can not be null, empty or whitespace.");
            }

            var requestRoute = PackageApiEndpoints.Association.MoveIntoPackage(projectId, packageId);

            var requestString  = JsonConvert.SerializeObject(setPackageAssociationRequest, this.jsonSerializerSettings);
            var requestContent = ApiHelpers.GetStringContent(requestString);

            var response = await this.httpClient.PutAsync(requestRoute, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not move package with id '{packageId}' of project with id '{projectId}' into package with id '{setPackageAssociationRequest.ParentPackageId}'.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }
        }