public async Task ShiftTasksOfPackageAsync_ValidRequest_ShouldReturnVoid() { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var existingPackage = new GetPackagePayload { Id = Guid.NewGuid().ToString(), }; var shiftPackageWithSuccessorsRequest = new ShiftPackageWithSuccessorsRequest(1); var expectedResponse = new HttpResponseMessage(); var packageApi = this.fixture.GetPackageApi(expectedResponse); // Act Func <Task> act = async() => await packageApi.ShiftTasksOfPackageAsync(existingProject.Id, existingPackage.Id, shiftPackageWithSuccessorsRequest); // Assert await act.Should().NotThrowAsync(); }
public async Task ShiftTasksOfPackageAsync_InvalidPackageId_ShouldThrowArgumentNullException(string packageId) { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var shiftPackageWithSuccessorsRequest = new ShiftPackageWithSuccessorsRequest(1); var packageApi = this.fixture.GetPackageApi(); // Act Func <Task> act = async() => await packageApi.ShiftTasksOfPackageAsync(existingProject.Id, packageId, shiftPackageWithSuccessorsRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task ShiftTasksOfPackageAsync_UnsuccessfulRequest_ShouldThrowFactroApiException() { // Arrange var projectId = Guid.NewGuid().ToString(); var packageId = Guid.NewGuid().ToString(); var shiftPackageWithSuccessorsRequest = new ShiftPackageWithSuccessorsRequest(1); 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.ShiftTasksOfPackageAsync(projectId, packageId, shiftPackageWithSuccessorsRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }
public async Task ShiftTasksOfPackageAsync( string projectId, string packageId, ShiftPackageWithSuccessorsRequest shiftPackageWithSuccessorsRequest) { 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 (shiftPackageWithSuccessorsRequest == null) { throw new ArgumentNullException(nameof(shiftPackageWithSuccessorsRequest), $"{nameof(shiftPackageWithSuccessorsRequest)} can not be null."); } var requestRoute = PackageApiEndpoints.ShiftTasksOfPackage.ShiftTasksWithSuccessors(projectId, packageId); var requestString = JsonConvert.SerializeObject(shiftPackageWithSuccessorsRequest, this.jsonSerializerSettings); var requestContent = ApiHelpers.GetStringContent(requestString); var response = await this.httpClient.PostAsync(requestRoute, requestContent); if (!response.IsSuccessStatusCode) { throw new FactroApiException( $"Could not shift package with id '{packageId}' of project with id '{projectId}' by '{shiftPackageWithSuccessorsRequest.DaysDelta.ToString(CultureInfo.InvariantCulture)}' days.", response.RequestMessage.RequestUri.ToString(), response.StatusCode, response.Content == null ? null : await response.Content.ReadAsStringAsync()); } }