Beispiel #1
0
        /// <summary>
        ///     Create a reply for the given comment, returns the ID of the comment.
        ///     OAuth authentication required.
        /// </summary>
        /// <param name="comment">The comment text, this is what will be displayed.</param>
        /// <param name="galleryItemId">The ID of the item in the gallery that you wish to comment on.</param>
        /// <param name="parentId">The comment id that you are replying to.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <int> CreateReplyAsync(string comment, string galleryItemId, string parentId)
        {
            if (string.IsNullOrWhiteSpace(comment))
            {
                throw new ArgumentNullException(nameof(comment));
            }

            if (string.IsNullOrWhiteSpace(galleryItemId))
            {
                throw new ArgumentNullException(nameof(galleryItemId));
            }

            if (string.IsNullOrWhiteSpace(parentId))
            {
                throw new ArgumentNullException(nameof(parentId));
            }

            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = $"comment/{parentId}";

            using (var request = CommentRequestBuilder.CreateReplyRequest(url, comment, galleryItemId))
            {
                var returnComment = await SendRequestAsync <Comment>(request).ConfigureAwait(false);

                return(returnComment.Id);
            }
        }
        /// <summary>
        ///     Create a reply for the given comment, returns the ID of the comment.
        ///     OAuth authentication required.
        /// </summary>
        /// <param name="comment">The comment text, this is what will be displayed.</param>
        /// <param name="galleryItemId">The ID of the item in the gallery that you wish to comment on.</param>
        /// <param name="parentId">The comment id that you are replying to.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public int CreateReply(string comment, string galleryItemId, string parentId)
        {
            if (string.IsNullOrWhiteSpace(comment))
            {
                throw new ArgumentNullException(nameof(comment));
            }

            if (string.IsNullOrWhiteSpace(galleryItemId))
            {
                throw new ArgumentNullException(nameof(galleryItemId));
            }

            if (string.IsNullOrWhiteSpace(parentId))
            {
                throw new ArgumentNullException(nameof(parentId));
            }

            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = $"comment/{parentId}";

            using (var request = CommentRequestBuilder.CreateReplyRequest(url, comment, galleryItemId))
            {
                var httpResponse = HttpClient.SendAsync(request).Result;
                var jsonString   = httpResponse.Content.ReadAsStringAsync().Result;
                var output       = Newtonsoft.Json.JsonConvert.DeserializeObject <Basic <Comment> >(httpResponse.Content.ReadAsStringAsync().Result.ToString());
                return(output.Data.Id);
            }
        }
Beispiel #3
0
        public void CreateReplyRequest_WithImageIdNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();
            var url            = $"{client.EndpointUrl}comment";

            requestBuilder.CreateReplyRequest(url, "Hello World", null);
        }
Beispiel #4
0
        public void CreateCommentRequest_WithCommentNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();
            var url            = $"{client.EndpointUrl}comment";

            requestBuilder.CreateCommentRequest(url, null, "xYxAbcD", "ABCdef");
        }
Beispiel #5
0
        public void VoteCommentRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}comment/XysioD/vote/up";
            var request = RequestBuilderBase.CreateRequest(HttpMethod.Post, mockUrl);

            Assert.NotNull(request);

            Assert.Equal("https://api.imgur.com/3/comment/XysioD/vote/up", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);
        }
Beispiel #6
0
        public void CreateReplyRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new CommentRequestBuilder();

            var exception = Record.Exception(() => CommentRequestBuilder.CreateReplyRequest(null, "Hello World!", "xYxAbcD"));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
Beispiel #7
0
        public void CreateGalleryItemCommentRequest_WithCommentNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();
            var mockUrl        = $"{client.EndpointUrl}comment";

            var exception = Record.Exception(() => CommentRequestBuilder.CreateGalleryItemCommentRequest(mockUrl, null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "comment");
        }
Beispiel #8
0
        public async Task CreateGalleryItemCommentRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}gallery/XysioD/comment";
            var request = CommentRequestBuilder.CreateGalleryItemCommentRequest(mockUrl, "Hello World!");

            Assert.NotNull(request);
            var expected = "comment=Hello+World%21";

            Assert.Equal(expected, await request.Content.ReadAsStringAsync().ConfigureAwait(false));
            Assert.Equal("https://api.imgur.com/3/gallery/XysioD/comment", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);
        }
Beispiel #9
0
        public async Task CreateCommentRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}comment/XysioD";
            var request = CommentRequestBuilder.CreateCommentRequest(mockUrl, "Hello World!", "xYxAbcD", "ABCdef");

            Assert.NotNull(request);
            var expected = "image_id=xYxAbcD&comment=Hello+World%21&parent_id=ABCdef";

            Assert.Equal(expected, await request.Content.ReadAsStringAsync().ConfigureAwait(false));
            Assert.Equal("https://api.imgur.com/3/comment/XysioD", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);
        }
Beispiel #10
0
        public async Task CreateReplyRequest_AreEqual()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();

            var url     = $"{client.EndpointUrl}comment";
            var request = requestBuilder.CreateReplyRequest(url, "Hello World!", "xYxAbcD");

            Assert.IsNotNull(request);
            var expected = "image_id=xYxAbcD&comment=Hello+World%21";

            Assert.AreEqual(expected, await request.Content.ReadAsStringAsync());
            Assert.AreEqual("https://api.imgur.com/3/comment", request.RequestUri.ToString());
            Assert.AreEqual(HttpMethod.Post, request.Method);
        }
Beispiel #11
0
        public async Task ReportCommentRequest_AreEqual()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();

            var url     = $"{client.EndpointUrl}comment/XysioD/report";
            var request = requestBuilder.ReportCommentRequest(url, ReportReason.Abusive);

            Assert.IsNotNull(request);
            var expected = "reason=3";

            Assert.AreEqual(expected, await request.Content.ReadAsStringAsync());
            Assert.AreEqual("https://api.imgur.com/3/comment/XysioD/report", request.RequestUri.ToString());
            Assert.AreEqual(HttpMethod.Post, request.Method);
        }
        public async Task UseCase_WhenOk_ReturnCommentList()
        {
            var createCommentRequest = new CommentRequestBuilder().BuildCreate();

            var logger         = new Mock <ILogger <AddNewsCommentUseCase> >().Object;
            var validator      = ValidatorFactory.GetValidValidator <CreateCommentRequest>();
            var authorRepoMock = new Mock <IAuthorRepository>();
            var newsRepoMock   = new Mock <INewsRepository>();

            newsRepoMock.Setup(x => x.GetById(createCommentRequest.NewsId))
            .ReturnsAsync(new NewsBuilder(createCommentRequest.NewsId).Build());

            var usecase  = new AddNewsCommentUseCase(logger, validator, authorRepoMock.Object, newsRepoMock.Object);
            var response = await usecase.Execute(createCommentRequest);

            response.Status.Should().Be(UseCaseResponseStatus.Success);
            response.Result.Should().NotBeEmpty();

            authorRepoMock.Verify(v => v.GeyByUserName(createCommentRequest.Author.UserName), Times.Once);
            authorRepoMock.Verify(v => v.Save(It.IsAny <Author>()), Times.Once);
            newsRepoMock.Verify(v => v.GetById(createCommentRequest.NewsId), Times.Once);
            newsRepoMock.Verify(v => v.AddComment(createCommentRequest.NewsId, It.IsAny <Comment>()), Times.Once);
        }
Beispiel #13
0
        public void CreateCommentRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new CommentRequestBuilder();

            requestBuilder.CreateCommentRequest(null, "Hello World!", "xYxAbcD", "ABCdef");
        }