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(); }
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>(); }
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>(); }
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()); } }