public async Task Update_NotFound()
        {
            // Setup
            var id    = "some_id";
            var input = new UpdatePublicationModel
            {
                Content = "some content"
            };

            var serviceMock = new Mock <IPublicationService>();

            serviceMock
            .Setup(s => s.GetByIdAsync(id))
            .ReturnsAsync(default(Publication));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"/publications/{id}/", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
        public async Task Update_NoContent()
        {
            // Setup
            var id    = "some_id";
            var input = new UpdatePublicationModel
            {
                Content = "some content"
            };

            var publication = new Publication(id, input.Content, Enumerable.Empty <string>(), null, DateTimeOffset.Now, DateTimeOffset.Now);

            var serviceMock = new Mock <IPublicationService>();

            serviceMock
            .Setup(s => s.UpdateAsync(id, input.Content))
            .ReturnsAsync(DomainResult.Success());

            serviceMock
            .Setup(s => s.GetByIdAsync(id))
            .ReturnsAsync(publication);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"/publications/{id}/", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
        public async Task <ActionResult> UpdateAsync([FromRoute] string id, [FromBody] UpdatePublicationModel model)
        {
            if (await publicationService.GetByIdAsync(id) == null)
            {
                return(NotFound());
            }

            var result = await publicationService.UpdateAsync(id, model.Content);

            if (!result.Successed)
            {
                return(BadRequest(result.ToProblemDetails()));
            }

            return(NoContent());
        }
        public async Task Update_EmptyContent_BadRequest()
        {
            // Setup
            var id    = "some_id";
            var input = new UpdatePublicationModel
            {
                Content = null
            };

            var serviceMock = new Mock <IPublicationService>();

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"/publications/{id}/", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Exemple #5
0
        public async Task UpdateAsync(string id, string content)
        {
            var model = new UpdatePublicationModel(content);

            await publicationsApi.UpdateAsync(id, model);
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="GhostNetwork.Publications.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="id"></param>
        /// <param name="updatePublicationModel"> (optional)</param>
        /// <returns>ApiResponse of Object(void)</returns>
        public GhostNetwork.Publications.Client.ApiResponse <Object> PublicationsUpdateWithHttpInfo(string id, UpdatePublicationModel updatePublicationModel = default(UpdatePublicationModel))
        {
            // verify the required parameter 'id' is set
            if (id == null)
            {
                throw new GhostNetwork.Publications.Client.ApiException(400, "Missing required parameter 'id' when calling PublicationsApi->PublicationsUpdate");
            }

            GhostNetwork.Publications.Client.RequestOptions localVarRequestOptions = new GhostNetwork.Publications.Client.RequestOptions();

            String[] _contentTypes = new String[] {
                "application/json",
                "text/json",
                "application/_*+json"
            };

            // to determine the Accept header
            String[] _accepts = new String[] {
                "text/plain",
                "application/json",
                "text/json"
            };

            var localVarContentType = GhostNetwork.Publications.Client.ClientUtils.SelectHeaderContentType(_contentTypes);

            if (localVarContentType != null)
            {
                localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
            }

            var localVarAccept = GhostNetwork.Publications.Client.ClientUtils.SelectHeaderAccept(_accepts);

            if (localVarAccept != null)
            {
                localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
            }

            localVarRequestOptions.PathParameters.Add("id", GhostNetwork.Publications.Client.ClientUtils.ParameterToString(id)); // path parameter
            localVarRequestOptions.Data = updatePublicationModel;


            // make the HTTP request
            var localVarResponse = this.Client.Put <Object>("/Publications/{id}", localVarRequestOptions, this.Configuration);

            if (this.ExceptionFactory != null)
            {
                Exception _exception = this.ExceptionFactory("PublicationsUpdate", localVarResponse);
                if (_exception != null)
                {
                    throw _exception;
                }
            }

            return(localVarResponse);
        }
Exemple #7
0
 /// <summary>
 ///
 /// </summary>
 /// <exception cref="GhostNetwork.Publications.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="id"></param>
 /// <param name="updatePublicationModel"> (optional)</param>
 /// <returns></returns>
 public void PublicationsUpdate(string id, UpdatePublicationModel updatePublicationModel = default(UpdatePublicationModel))
 {
     PublicationsUpdateWithHttpInfo(id, updatePublicationModel);
 }
Exemple #8
0
 /// <summary>
 ///
 /// </summary>
 /// <exception cref="GhostNetwork.Publications.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="id"></param>
 /// <param name="updatePublicationModel"> (optional)</param>
 /// <returns>Task of void</returns>
 public async System.Threading.Tasks.Task PublicationsUpdateAsync(string id, UpdatePublicationModel updatePublicationModel = default(UpdatePublicationModel))
 {
     await PublicationsUpdateAsyncWithHttpInfo(id, updatePublicationModel);
 }