private TodoComment CreateDomainModelFromInput(CreateCommentInput input) { var mapper = CreateAutoMapper(); var domainModel = mapper.Map <TodoComment>(input); return(domainModel); }
public Guid Create(CreateCommentInput message) { var entity = _mapper.Map <CommentEntityFrameworkModel>(message); _dbContext.Comments.Add(entity); return(entity.Id); }
public async Task CreateCommentAsync(CreateCommentInput input) { var @post = await _postManager.GetAsync(input.PostId); var @comment = Comment.Create(@post, AbpSession.GetUserId(), input.Text); await _postManager.CreateCommentAsync(@comment); }
public IHttpActionResult Execute([FromBody] CreateCommentInput input) { var presenter = CreatePresenter(); _usecase.Execute(input, presenter); return(presenter.Render()); }
private CreateCommentOutput Persist(CreateCommentInput input) { var id = _repository.Create(input); _repository.Persist(); return(new CreateCommentOutput { Id = id }); }
public async Task Comment([FromBody] CreateCommentInput input) { await Repository.AddAsync(new EditorInteractionComment { UserId = JwtReader.GetUserId(), ObjectId = input.ObjectId, ObjectTypeEnum = input.ObjectTypeEnum, InteractionId = input.InteractionId, Message = input.Message, ParentId = input.ParentId }); await Context.SaveChangesAsync(); }
public void Execute_WhenTodoItemIdNotFound_ShouldReturnError() { //---------------Arrange------------------- var testContext = new CreateCommentUseCaseTestDataBuilder().WithTodoItemTo(null).Build(); var usecase = testContext.UseCase; var input = new CreateCommentInput { TodoItemId = Guid.NewGuid(), Comment = "a comment" }; var presenter = new PropertyPresenter <CreateCommentOutput, ErrorOutputMessage>(); //---------------Act---------------------- usecase.Execute(input, presenter); //---------------Assert----------------------- Assert.IsTrue(presenter.ErrorContent.HasErrors); Assert.AreEqual("Invalid item Id", presenter.ErrorContent.Errors[0]); }
public void Execute_WhenNullOrWhitespaceComment_ShouldReturnUnprocessableEntity(string comment) { //---------------Arrange------------------- var requestUri = "comment/create"; var inputMessage = new CreateCommentInput { TodoItemId = Guid.NewGuid(), Comment = comment }; using (var testServer = CreateTestServer()) { var client = TestHttpClientFactory.CreateClient(testServer); //---------------Act------------------- var response = client.PostAsJsonAsync(requestUri, inputMessage).Result; //---------------Assert------------------- Assert.AreEqual((HttpStatusCode)422, response.StatusCode); } }
public void Execute_WhenValidTodoItemId_ShouldReturnSuccess() { //---------------Arrange------------------- var requestUri = "comment/create"; var inputMessage = new CreateCommentInput { TodoItemId = Guid.NewGuid(), Comment = "a comment" }; using (var testServer = CreateTestServer()) { var client = TestHttpClientFactory.CreateClient(testServer); //---------------Act------------------- var response = client.PostAsJsonAsync(requestUri, inputMessage).Result; //---------------Assert------------------- Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); } }
public void Execute_WhenValidTodoItemId_ShouldReturnSuccess() { //---------------Arrange------------------- var commentId = Guid.NewGuid(); var itemId = Guid.NewGuid(); var testContext = new CreateCommentUseCaseTestDataBuilder().WithCommentId(commentId).Build(); var usecase = testContext.UseCase; var input = new CreateCommentInput { TodoItemId = itemId, Comment = "a comment" }; var presenter = new PropertyPresenter <CreateCommentOutput, ErrorOutputMessage>(); //---------------Act---------------------- usecase.Execute(input, presenter); //---------------Assert----------------------- Assert.AreEqual(commentId, presenter.SuccessContent.Id); testContext.Repository.Received(1).Persist(); }
public void Execute(CreateCommentInput inputTo, IRespondWithSuccessOrError <CreateCommentOutput, ErrorOutputMessage> presenter) { var domainEntity = CreateDomainModelFromInput(inputTo); if (InvalidTodoItemId(domainEntity)) { RespondWithErrorMessage("Invalid item Id", presenter); return; } if (InvalidComment(domainEntity)) { RespondWithErrorMessage("Missing comment", presenter); return; } var output = Persist(inputTo); RespondWithSuccess(output, presenter); }
public void Create_WhenValidInputModel_ShouldInsertEntity() { //---------------Arrange------------------- var todoItemId = Guid.NewGuid(); using (var wrapper = CreateTransactionalWrapper()) { var repositoryDbContext = CreateDbContext(wrapper); var assertContext = CreateDbContext(wrapper); var comments = CreateCommentRepository(repositoryDbContext); var comment = new CreateCommentInput { Comment = "a comment", TodoItemId = todoItemId }; AddTodoItem(repositoryDbContext, todoItemId); //---------------Act------------------- comments.Create(comment); comments.Persist(); //---------------Assert------------------- var entity = assertContext.Comments.FirstOrDefault(); Assert.AreNotEqual(Guid.Empty, entity.Id); } }
private StreamComment CreateComment(String text, String contentKey, String contentRecordType, String commentListKey, int principalCommentId) { try { CommentApi commentApi = new CommentApi(session.GetApiClient()); CommentV2Record commentRecord = new CommentV2Record(); commentRecord.ContentKey = contentKey; if (principalCommentId > 0) { commentRecord.CommentPID = principalCommentId; } if (commentListKey != null) { commentRecord.CommentListKey = commentListKey; } commentRecord.Text = text; CreateCommentInput createCommentInput = new CreateCommentInput(contentKey, commentRecord); CreateCommentResult createCommentResult = commentApi.CreateComment(createCommentInput); if (createCommentResult.Hdr.Rc == 0) { CommentV2Record createdComment = createCommentResult.Comment; StreamComment comment = new StreamComment(createdComment, contentRecordType); return(comment); } else { throw new Exception("Error creating comment. Rc=" + createCommentResult.Hdr.Rc); } } catch (Exception ex) { throw new Exception("Error creating comment", ex); } }
public async Task Comment(CreateCommentInput input) { var comment = input.MapTo <Comment>(); await interactionManager.CreateCommentAsync(comment); }
public virtual async Task <CommentDto> CreateAsync(string entityType, string entityId, CreateCommentInput input) { var user = await CmsUserLookupService.GetByIdAsync(CurrentUser.GetId()); if (input.RepliedCommentId.HasValue) { await CommentRepository.GetAsync(input.RepliedCommentId.Value); } var comment = await CommentRepository.InsertAsync( await CommentManager.CreateAsync( user, entityType, entityId, input.Text, input.RepliedCommentId ) ); await UnitOfWorkManager.Current.SaveChangesAsync(); await DistributedEventBus.PublishAsync(new CreatedCommentEvent { Id = comment.Id }); return(ObjectMapper.Map <Comment, CommentDto>(comment)); }
public Task <CommentDto> CreateAsync(string entityType, string entityId, CreateCommentInput input) { return(CommentPublicAppService.CreateAsync(entityType, entityId, input)); }
public async Task Create(CreateCommentInput input) { Models.Comment output = Mapper.Map <CreateCommentInput, Models.Comment>(input); await _commentManager.Create(output); }
public virtual async Task <CommentDto> CreateAsync(string entityType, string entityId, CreateCommentInput input) { return(await RequestAsync <CommentDto>(nameof(CreateAsync), new ClientProxyRequestTypeValue { { typeof(string), entityType }, { typeof(string), entityId }, { typeof(CreateCommentInput), input } })); }