Exemple #1
0
        public async Task <AddPostResponse> AddPostAsync(AddPostRequest request)
        {
            var response = new AddPostResponse();

            bool isExists = await _postRepository.IsExistsByUrlAsync(request.Url);

            if (isExists)
            {
                response.StatusCode = (int)HttpStatusCode.Conflict;
                return(response);
            }

            var  entity    = _postMapper.ToEntity(request);
            bool isSuccess = await _postRepository.AddAsync(entity);

            if (!isSuccess)
            {
                response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(response);
            }

            response.Post       = _postMapper.ToModel(entity);
            response.StatusCode = (int)HttpStatusCode.Created;
            return(response);
        }
        public IfPassedANewPostWithATitle()
        {
            _newPost       = AddPostHandlerTests.CreateValidPostForAdding();
            _newPost.Title = Title;

            AddPostHandler handler = AddPostHandlerTests.CreateHandler();

            _response = handler.Handle(new AddPostRequest(_newPost));
        }
Exemple #3
0
 public override Task <AddPostResponse> AddPost(AddPostRequest request, ServerCallContext context)
 {
     try
     {
         var post        = new PostComment.Post();
         var returnValue = post.AddPost((global::PostComment.Post)request.Post);
         var response    = new AddPostResponse {
             Value = returnValue
         };
         return(Task.FromResult(response));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error invoking AddPost");
         throw new RpcException(new Status(StatusCode.Internal, ex.Message));
     }
 }
Exemple #4
0
        public IfPassedAValidNewPost()
        {
            _mockPersistance = new Mock <IRepository>();
            _mockPersistance
            .Setup(m => m.StorePost(It.IsAny <Post>()))
            .Returns <Post>(p =>
            {
                var storedPost = Post.Clone(p);
                storedPost.Id  = NewId;
                _storedPost    = storedPost;
                return(_storedPost.Id);
            });
            _mockPersistance
            .Setup(m => m.GetPost(NewId))
            .Returns(() => _storedPost);

            AddPostHandler handler = AddPostHandlerTests.CreateHandler(_mockPersistance.Object);
            Post           newPost = AddPostHandlerTests.CreateValidPostForAdding();

            _response = handler.Handle(new AddPostRequest(newPost));
        }
Exemple #5
0
        public override Task <AddPostResponse> AddPost(Protos.AddPostRequest request, ServerCallContext context)
        {
            AddPostResponse output = new AddPostResponse();

            Post post = new Post();

            post.Date        = System.DateTime.Parse(request.Date);
            post.Description = request.Date;
            post.Domain      = request.Domain;
            output.BResult   = false;
            if (post == null)
            {
                return(Task.FromResult(output));
            }
            if (post.PostId == 0)
            {
                _context.Posts.Add(post);
                _context.SaveChanges();
                output.BResult = true;
            }

            return(Task.FromResult(output));
        }