Пример #1
0
        public async Task AddTagToProjectAsync(string projectId, AddProjectTagAssociationRequest addProjectTagAssociationRequest)
        {
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace.");
            }

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

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

            var requestRoute = ProjectApiEndpoints.Tag.AddToProject(projectId);

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

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

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not add tag with id '{addProjectTagAssociationRequest.TagId}' to project with id '{projectId}'.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }
        }
        public async Task AddTagToProjectAsync_BadRequest_ShouldThrowProjectApiException()
        {
            // Arrange
            var existingProject = new GetProjectPayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var existingProjectTag = new GetProjectTagPayload
            {
                Id   = Guid.NewGuid().ToString(),
                Name = Guid.NewGuid().ToString(),
            };

            var addProjectTagAssociationRequest = new AddProjectTagAssociationRequest(existingProjectTag.Name);

            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.AddTagToProjectAsync(existingProject.Id, addProjectTagAssociationRequest);

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

            var existingProjectTag = new GetProjectTagPayload
            {
                Id   = Guid.NewGuid().ToString(),
                Name = Guid.NewGuid().ToString(),
            };

            var addProjectTagAssociationRequest = new AddProjectTagAssociationRequest(existingProjectTag.Name);

            var expectedResponse = new HttpResponseMessage();

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

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

            // Assert
            await act.Should().NotThrowAsync();
        }
        public async Task AddTagToProjectAsync_InvalidTagId_ShouldThrowArgumentNullException(string tagId)
        {
            // Arrange
            var existingProject = new GetProjectPayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var addProjectTagAssociationRequest = new AddProjectTagAssociationRequest(tagId);

            var projectApi = this.fixture.GetProjectApi();

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

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