public async Task SetProjectCompanyAsync(string projectId, SetProjectCompanyAssociationRequest setProjectCompanyAssociationRequest) { if (string.IsNullOrWhiteSpace(projectId)) { throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace."); } if (setProjectCompanyAssociationRequest == null) { throw new ArgumentNullException(nameof(setProjectCompanyAssociationRequest), $"{nameof(setProjectCompanyAssociationRequest)} can not be null."); } if (string.IsNullOrWhiteSpace(setProjectCompanyAssociationRequest.CompanyId)) { throw new ArgumentNullException(nameof(setProjectCompanyAssociationRequest), $"{nameof(setProjectCompanyAssociationRequest.CompanyId)} can not be null, empty or whitespace."); } var requestRoute = ProjectApiEndpoints.Association.SetCompany(projectId); var requestString = JsonConvert.SerializeObject(setProjectCompanyAssociationRequest, 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 '{setProjectCompanyAssociationRequest.CompanyId}' as company of project with id '{projectId}'.", response.RequestMessage.RequestUri.ToString(), response.StatusCode, response.Content == null ? null : await response.Content.ReadAsStringAsync()); } }
public async Task SetProjectCompanyAsync_InvalidProjectId_ShouldThrowArgumentNullException(string projectId) { // Arrange var companyId = Guid.NewGuid().ToString(); var setProjectCompanyAssociationRequest = new SetProjectCompanyAssociationRequest(companyId); var expectedResponse = new HttpResponseMessage(); var projectApi = this.fixture.GetProjectApi(expectedResponse); // Act Func <Task> act = async() => await projectApi.SetProjectCompanyAsync(projectId, setProjectCompanyAssociationRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task SetProjectCompanyAsync_NullRequestModelCompanyId_ShouldThrowArgumentNullException() { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var setProjectCompanyAssociationRequest = new SetProjectCompanyAssociationRequest(companyId: null); var expectedResponse = new HttpResponseMessage(); var projectApi = this.fixture.GetProjectApi(expectedResponse); // Act Func <Task> act = async() => await projectApi.SetProjectCompanyAsync(existingProject.Id, setProjectCompanyAssociationRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task SetProjectCompanyAsync_ValidRequest_ShouldReturnVoid() { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var companyId = Guid.NewGuid().ToString(); var setProjectCompanyAssociationRequest = new SetProjectCompanyAssociationRequest(companyId); var expectedResponse = new HttpResponseMessage(); var projectApi = this.fixture.GetProjectApi(expectedResponse); // Act Func <Task> act = async() => await projectApi.SetProjectCompanyAsync(existingProject.Id, setProjectCompanyAssociationRequest); // Assert await act.Should().NotThrowAsync(); }
public async Task SetProjectCompanyAsync_BadRequest_ShouldThrowProjectApiException() { // Arrange var projectId = Guid.NewGuid().ToString(); var companyId = Guid.NewGuid().ToString(); var setProjectCompanyAssociationRequest = new SetProjectCompanyAssociationRequest(companyId); var expectedResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, RequestMessage = new HttpRequestMessage { RequestUri = new Uri("http://www.mock-web-address.com"), }, }; var projectApi = this.fixture.GetProjectApi(expectedResponse); // Act Func <Task> act = async() => await projectApi.SetProjectCompanyAsync(projectId, setProjectCompanyAssociationRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }