public async Task SetPackageContactAsync_ValidRequest_ShouldReturnVoid() { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var existingPackage = new GetPackagePayload { Id = Guid.NewGuid().ToString(), ProjectId = existingProject.Id, }; var existingContact = new GetContactPayload { Id = Guid.NewGuid().ToString(), }; var setContactAssociationRequest = new SetContactAssociationRequest(existingContact.Id); var expectedResponseMessage = new HttpResponseMessage(); var packageApi = this.fixture.GetPackageApi(expectedResponseMessage); // Act Func <Task> act = async() => await packageApi.SetPackageContactAsync(existingProject.Id, existingPackage.Id, setContactAssociationRequest); // Assert await act.Should().NotThrowAsync(); }
public async Task SetPackageContactAsync_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 existingContact = new GetContactPayload { Id = Guid.NewGuid().ToString(), }; var setContactAssociationRequest = new SetContactAssociationRequest(existingContact.Id); var packageApi = this.fixture.GetPackageApi(); // Act Func <Task> act = async() => await packageApi.SetPackageContactAsync(projectId, existingPackage.Id, setContactAssociationRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task SetPackageContactAsync(string projectId, string packageId, SetContactAssociationRequest setContactAssociationRequest) { 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 (setContactAssociationRequest == null) { throw new ArgumentNullException(nameof(setContactAssociationRequest), $"{nameof(setContactAssociationRequest)} can not be null."); } if (string.IsNullOrWhiteSpace(setContactAssociationRequest.ContactId)) { throw new ArgumentNullException(nameof(setContactAssociationRequest), $"{nameof(setContactAssociationRequest.ContactId)} can not be null, empty or whitespace."); } var requestRoute = PackageApiEndpoints.Association.SetContact(projectId, packageId); var requestString = JsonConvert.SerializeObject(setContactAssociationRequest, this.jsonSerializerSettings); var requestContent = ApiHelpers.GetStringContent(requestString); var response = await this.httpClient.PutAsync(requestRoute, requestContent); if (!response.IsSuccessStatusCode) { throw new FactroApiException( $"Could not set contact with id '{setContactAssociationRequest.ContactId}' as contact 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 SetPackageContactAsync_UnsuccessfulRequest_ShouldThrowFactroApiException() { // Arrange var projectId = Guid.NewGuid().ToString(); var packageId = Guid.NewGuid().ToString(); var setContactAssociationRequest = new SetContactAssociationRequest(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.SetPackageContactAsync(projectId, packageId, setContactAssociationRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }