public async Task CreateProjectComment_NullRequestModelText_ShouldThrowArgumentNullException() { // Arrange var projectApi = this.fixture.GetProjectApi(); var createProjectCommentRequest = new CreateProjectCommentRequest(text: null); // Act Func <Task> act = async() => await projectApi.CreateProjectCommentAsync(Guid.NewGuid().ToString(), createProjectCommentRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task CreateProjectComment_InvalidProjectId_ShouldThrowArgumentNullException(string projectId) { // Arrange var text = Guid.NewGuid().ToString(); var createProjectCommentRequest = new CreateProjectCommentRequest(text); var projectApi = this.fixture.GetProjectApi(); // Act Func <Task> act = async() => await projectApi.CreateProjectCommentAsync(projectId, createProjectCommentRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task CreateProjectComment_ValidRequest_ShouldReturnCreatedProjectComment() { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var text = Guid.NewGuid().ToString(); var createProjectCommentRequest = new CreateProjectCommentRequest(text); var expectedProjectComment = new CreateProjectCommentResponse { Text = text, }; var expectedResponseContent = new StringContent(JsonConvert.SerializeObject(expectedProjectComment, this.fixture.JsonSerializerSettings)); var expectedResponse = new HttpResponseMessage { Content = expectedResponseContent, }; var projectApi = this.fixture.GetProjectApi(expectedResponse); var createProjectCommentResponse = default(CreateProjectCommentResponse); // Act Func <Task> act = async() => createProjectCommentResponse = await projectApi.CreateProjectCommentAsync(existingProject.Id, createProjectCommentRequest); // Assert await act.Should().NotThrowAsync(); createProjectCommentResponse.Should().BeEquivalentTo(expectedProjectComment); }
public async Task CreateProjectComment_BadRequest_ShouldReturnProjectApiException() { // Arrange var text = Guid.NewGuid().ToString(); var createProjectRequest = new CreateProjectCommentRequest(text); 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.CreateProjectCommentAsync(Guid.NewGuid().ToString(), createProjectRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }
public async Task <CreateProjectCommentResponse> CreateProjectCommentAsync(string projectId, CreateProjectCommentRequest createProjectCommentRequest) { if (string.IsNullOrWhiteSpace(projectId)) { throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace."); } if (createProjectCommentRequest == null) { throw new ArgumentNullException(nameof(createProjectCommentRequest), $"{nameof(createProjectCommentRequest)} can not be null."); } if (createProjectCommentRequest.Text == null) { throw new ArgumentNullException(nameof(createProjectCommentRequest), $"{nameof(createProjectCommentRequest.Text)} can not be null."); } var requestRoute = ProjectApiEndpoints.Comment.Create(projectId); var requestString = JsonConvert.SerializeObject(createProjectCommentRequest, this.jsonSerializerSettings); var requestContent = ApiHelpers.GetStringContent(requestString); var response = await this.httpClient.PostAsync(requestRoute, requestContent); if (!response.IsSuccessStatusCode) { throw new FactroApiException( $"Could not create comment in project with id '{projectId}'.", response.RequestMessage.RequestUri.ToString(), response.StatusCode, response.Content == null ? null : await response.Content.ReadAsStringAsync()); } var responseContentString = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <CreateProjectCommentResponse>( responseContentString, this.jsonSerializerSettings); return(result); }