public async Task Task_Create() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { using (var context = new AppcentTodoContext(options)) { var service = new AddTodoCommandHandler(context, TestHelper.GetMapperInstance()); var command = new AddTodoCommand(); command.Data = new AddTodoRequest { UserName = "******", Name = "Task test", CategoryId = 1, TaskPriority = TaskPriority.P1, TaskStatus = Models.EntityModels.TaskStatus.Todo }; var result = await service.Execute(command); Assert.True(result.Result.IsSuccess); } using (var context = new AppcentTodoContext(options)) { var count = context.AcTasks.Where(e => e.Name == "Task test"); Assert.Equal(1, count.Count()); } } finally { connection.Close(); } }
public async Task <IActionResult> AddTodo([FromBody] AddTodoCommand command) { var todo = await _mediator.Send(command); if (todo == null) { return(BadRequest("Failed saving")); } return(Ok(todo)); }
public async Task <ActionResult> AddTodo([FromBody] AddTodoDto viewRequest) { if (!TryValidateModel(viewRequest)) { return(BadRequest(ValidationHelper.GetModelErrors(ModelState))); } var request = this._mapper.Map <AddTodoRequest>(viewRequest); request.UserName = HttpContext.User.Identity.Name; var command = new AddTodoCommand { Data = request }; return(await Go(command)); }
public async Task WhenAddingTodoWithNoTitle_ThenTheRequestShouldFail() { fixture.Reset(); // Arrange var command = new AddTodoCommand { Title = null }; // Act Func <Task> act = () => fixture.Mediator.Send(command); // Assert await act.Should().ThrowAsync <ValidationException>().WithMessage("*'Title' must not be empty.*"); }
public async Task WhenAddingAValidTodo_ThenTheCommandShouldSucceed() { fixture.Reset(); // Arrange var command = new AddTodoCommand { Title = "My test todo" }; // Act var response = await fixture.Mediator.Send(command); // Assert response.Id.Should().BeGreaterThan(0); fixture.UnitOfWorkMock.Verify(uow => uow.CompleteAsync(It.IsAny <CancellationToken>()), Times.Once()); }
public async Task <IActionResult> AddTodo(AddTodoCommand request) { var response = await _mediator.Send(request); return(Created(Url.Action(nameof(GetTodo), new { id = response.Id }), response)); }
public async Task <IActionResult> Add([FromBody] AddTodoCommand command) { await mediator.Send(command); return(Ok()); }
public Task <IActionResult> Add(AddTodoCommand command) => _mediator.Send(command).ToActionResult();
private static EitherAsync <TodoFailure, TodoItem> Validate(AddTodoCommand request) => TodoItem.New(Guid.NewGuid(), request.IsDone, request.Content) .ToEither().ToAsync() .MapLeft(TodoFailureCon.Validation);
public async Task <Either <TodoFailure, Unit> > Handle(AddTodoCommand request, CancellationToken cancellationToken) => await (from item in Validate(request) from _ in _todoItemRepository.Add(item) select _).ToEither();