public async Task GrantProjectWriteRightsToUserAsync_ValidRequest_ShouldReturnWriteRightInformation()
        {
            // Arrange
            var existingProject = new GetProjectPayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var employeeId = Guid.NewGuid().ToString();
            var addProjectWriteRightsForUserRequest = new AddProjectWriteRightsForUserRequest(employeeId);

            var expectedResponseContent = new StringContent(JsonConvert.SerializeObject(addProjectWriteRightsForUserRequest, this.fixture.JsonSerializerSettings));

            var expectedResponse = new HttpResponseMessage
            {
                Content = expectedResponseContent,
            };

            var projectApi = this.fixture.GetProjectApi(expectedResponse);

            var getWriteRightsResponse = new AddProjectWriteRightsForUserResponse();

            // Act
            Func <Task> act = async() => getWriteRightsResponse = await projectApi.GrantProjectWriteRightsToUserAsync(existingProject.Id, addProjectWriteRightsForUserRequest);

            // Assert
            await act.Should().NotThrowAsync();

            getWriteRightsResponse.Should().BeEquivalentTo(addProjectWriteRightsForUserRequest);
        }
        public async Task GrantProjectWriteRightsToUserAsync_InvalidProjectId_ShouldThrowArgumentNullException(string projectId)
        {
            // Arrange
            var employeeId = Guid.NewGuid().ToString();
            var addProjectWriteRightsForUserRequest = new AddProjectWriteRightsForUserRequest(employeeId);

            var projectApi = this.fixture.GetProjectApi();

            // Act
            Func <Task> act = async() => await projectApi.GrantProjectWriteRightsToUserAsync(projectId, addProjectWriteRightsForUserRequest);

            // Assert
            await act.Should().ThrowAsync <ArgumentNullException>();
        }
        public async Task GrantProjectWriteRightsToUserAsync_NullRequestModelEmployeeId_ShouldThrowArgumentNullException()
        {
            // Arrange
            var existingProject = new GetProjectPayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var addProjectWriteRightsForUserRequest = new AddProjectWriteRightsForUserRequest(employeeId: null);

            var projectApi = this.fixture.GetProjectApi();

            // Act
            Func <Task> act = async() => await projectApi.GrantProjectWriteRightsToUserAsync(existingProject.Id, addProjectWriteRightsForUserRequest);

            // Assert
            await act.Should().ThrowAsync <ArgumentNullException>();
        }
Esempio n. 4
0
        public async Task <AddProjectWriteRightsForUserResponse> GrantProjectWriteRightsToUserAsync(
            string projectId,
            AddProjectWriteRightsForUserRequest addProjectWriteRightsForUserRequest)
        {
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace.");
            }

            if (addProjectWriteRightsForUserRequest == null)
            {
                throw new ArgumentNullException(nameof(addProjectWriteRightsForUserRequest), $"{nameof(addProjectWriteRightsForUserRequest)} can not be null.");
            }

            if (string.IsNullOrWhiteSpace(addProjectWriteRightsForUserRequest.EmployeeId))
            {
                throw new ArgumentNullException(nameof(addProjectWriteRightsForUserRequest), $"{nameof(addProjectWriteRightsForUserRequest.EmployeeId)} can not be null, empty or whitespace.");
            }

            var requestRoute = ProjectApiEndpoints.AccessRights.GrantWriteRights(projectId);

            var requestString  = JsonConvert.SerializeObject(addProjectWriteRightsForUserRequest, this.jsonSerializerSettings);
            var requestContent = ApiHelpers.GetStringContent(requestString);

            var response = await this.httpClient.PutAsync(requestRoute, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not grant write rights for project with id '{projectId}' to employee with id '{addProjectWriteRightsForUserRequest.EmployeeId}'.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }

            var responseContentString = await response.Content.ReadAsStringAsync();

            var result =
                JsonConvert.DeserializeObject <AddProjectWriteRightsForUserResponse>(
                    responseContentString,
                    this.jsonSerializerSettings);

            return(result);
        }
        public async Task GrantProjectWriteRightsToUserAsync_BadRequest_ShouldReturnProjectApiException()
        {
            // Arrange
            var projectId = Guid.NewGuid().ToString();
            var addProjectWriteRightsForUserRequest = new AddProjectWriteRightsForUserRequest(Guid.NewGuid().ToString());

            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.GrantProjectWriteRightsToUserAsync(projectId, addProjectWriteRightsForUserRequest);

            // Assert
            await act.Should().ThrowAsync <FactroApiException>();
        }