public async Task SetPackageCompanyAsync_ValidRequest_ShouldReturnVoid() { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var existingPackage = new GetPackagePayload { Id = Guid.NewGuid().ToString(), ProjectId = existingProject.Id, }; var existingCompany = new GetCompanyPayload { Id = Guid.NewGuid().ToString(), }; var setCompanyAssociationRequest = new SetCompanyAssociationRequest(existingCompany.Id); var expectedResponseMessage = new HttpResponseMessage(); var packageApi = this.fixture.GetPackageApi(expectedResponseMessage); // Act Func <Task> act = async() => await packageApi.SetPackageCompanyAsync(existingProject.Id, existingPackage.Id, setCompanyAssociationRequest); // Assert await act.Should().NotThrowAsync(); }
public async Task SetPackageCompanyAsync_InvalidProjectId_ShouldThrowArgumentNullException(string projectId) { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var existingPackage = new GetPackagePayload { Id = Guid.NewGuid().ToString(), ProjectId = existingProject.Id, }; var existingCompany = new GetCompanyPayload { Id = Guid.NewGuid().ToString(), }; var setCompanyAssociationRequest = new SetCompanyAssociationRequest(existingCompany.Id); var packageApi = this.fixture.GetPackageApi(); // Act Func <Task> act = async() => await packageApi.SetPackageCompanyAsync(projectId, existingPackage.Id, setCompanyAssociationRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task SetPackageCompanyAsync(string projectId, string packageId, SetCompanyAssociationRequest setCompanyAssociationRequest) { 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 (setCompanyAssociationRequest == null) { throw new ArgumentNullException(nameof(setCompanyAssociationRequest), $"{nameof(setCompanyAssociationRequest)} can not be null."); } if (string.IsNullOrWhiteSpace(setCompanyAssociationRequest.CompanyId)) { throw new ArgumentNullException(nameof(setCompanyAssociationRequest), $"{nameof(setCompanyAssociationRequest.CompanyId)} can not be null, empty or whitespace."); } var requestRoute = PackageApiEndpoints.Association.SetCompany(projectId, packageId); var requestString = JsonConvert.SerializeObject(setCompanyAssociationRequest, this.jsonSerializerSettings); var requestContent = ApiHelpers.GetStringContent(requestString); var response = await this.httpClient.PutAsync(requestRoute, requestContent); if (!response.IsSuccessStatusCode) { throw new FactroApiException( $"Could not set company with id '{setCompanyAssociationRequest.CompanyId}' as company of package with id '{packageId}' of project with id '{projectId}'.", response.RequestMessage.RequestUri.ToString(), response.StatusCode, response.Content == null ? null : await response.Content.ReadAsStringAsync()); } }
public async Task SetPackageCompanyAsync_UnsuccessfulRequest_ShouldThrowFactroApiException() { // Arrange var projectId = Guid.NewGuid().ToString(); var packageId = Guid.NewGuid().ToString(); var setCompanyAssociationRequest = new SetCompanyAssociationRequest(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.SetPackageCompanyAsync(projectId, packageId, setCompanyAssociationRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }