示例#1
0
        public async Task GrantProjectReadRightsToUserAsync_ValidRequest_ShouldReturnReadRightInformation()
        {
            // Arrange
            var existingProject = new GetProjectPayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var employeeId = Guid.NewGuid().ToString();
            var addProjectReadRightsForUserRequest = new AddProjectReadRightsForUserRequest(employeeId);

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

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

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

            var getReadRightsResponse = new AddProjectReadRightsForUserResponse();

            // Act
            Func <Task> act = async() => getReadRightsResponse = await projectApi.GrantProjectReadRightsToUserAsync(existingProject.Id, addProjectReadRightsForUserRequest);

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

            getReadRightsResponse.Should().BeEquivalentTo(addProjectReadRightsForUserRequest);
        }
示例#2
0
        public async Task GrantProjectReadRightsToUserAsync_InvalidProjectId_ShouldThrowArgumentNullException(string projectId)
        {
            // Arrange
            var employeeId = Guid.NewGuid().ToString();
            var addProjectReadRightsForUserRequest = new AddProjectReadRightsForUserRequest(employeeId);

            var projectApi = this.fixture.GetProjectApi();

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

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

            var addProjectReadRightsForUserRequest = new AddProjectReadRightsForUserRequest(employeeId: null);

            var projectApi = this.fixture.GetProjectApi();

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

            // Assert
            await act.Should().ThrowAsync <ArgumentNullException>();
        }
        public async Task <AddProjectReadRightsForUserResponse> GrantProjectReadRightsToUserAsync(
            string projectId,
            AddProjectReadRightsForUserRequest addProjectReadRightsForUserRequest)
        {
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace.");
            }

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

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

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

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

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

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not grant read rights for project with id '{projectId}' to employee with id '{addProjectReadRightsForUserRequest.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 <AddProjectReadRightsForUserResponse>(
                    responseContentString,
                    this.jsonSerializerSettings);

            return(result);
        }
示例#5
0
        public async Task GrantProjectReadRightsToUserAsync_BadRequest_ShouldReturnProjectApiException()
        {
            // Arrange
            var projectId = Guid.NewGuid().ToString();
            var addProjectReadRightsForUserRequest = new AddProjectReadRightsForUserRequest(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.GrantProjectReadRightsToUserAsync(projectId, addProjectReadRightsForUserRequest);

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