public static TodoTaskEntity ToEntity(this CreateTodoTaskCommand command) { return(new TodoTaskEntity { Name = command.Name, Priority = command.Priority, Status = Enum.Parse <TodoTaskEntityStatus>(command.Status.ToString()) }); }
public Task ValidateAndThrow(CreateTodoTaskCommand context) { if (string.IsNullOrWhiteSpace(context.Name)) { throw new TodoListValidationException($"{nameof(CreateTodoTaskCommand.Name)} can't be empty"); } if (context.Priority <= 0) { throw new TodoListValidationException($"{nameof(CreateTodoTaskCommand.Priority)} must be positive"); } return(Task.CompletedTask); }
public void ShouldMapCreateTodoTaskCommandStatus(TodoTaskStatus model, TodoTaskEntityStatus expected) { // Arrange & Act var command = new CreateTodoTaskCommand { Name = "Make a toast", Priority = 3, Status = model }.ToEntity(); // Assert Assert.Equal(expected, command.Status); }
public void ShouldMapCreateTodoTaskCommandPriority(int model, int expected) { // Arrange & Act var result = new CreateTodoTaskCommand { Name = "Make a toast", Priority = model, Status = TodoTaskStatus.NotStarted }.ToEntity(); // Assert Assert.Equal(expected, result.Priority); }
public void ShouldMapCreateTodoTaskCommandName(string model, string expected) { // Arrange & Act var result = new CreateTodoTaskCommand { Name = model, Priority = 1, Status = TodoTaskStatus.NotStarted }.ToEntity(); // Assert Assert.Equal(expected, result.Name); }
public void ShouldRegisterTodoTaskWhenCommandIsValid() { var command = new CreateTodoTaskCommand(); command.Description = "new task"; command.IdUser = 1; Assert.AreEqual(true, command.Valid()); // var handler = new TodoTaskHandler(new FakeTodoTaskRepository()); // var result = handler.Handle(command); // Assert.AreNotEqual(null, result); //Assert.AreEqual(true, handler.) }
public TodoTask Put([FromBody] CreateTodoTaskCommand command) //Criar command { var task = new TodoTask(command.Description, command.IdUser); return(task); }
public Task <ICommandResult> Post([FromBody] CreateTodoTaskCommand command) { return(_handler.Handle(command)); }
public async Task <string> HandleAsync(CreateTodoTaskCommand command) { await validator.ValidateAndThrow(command); return(await repository.CreateAsync(command.ToEntity())); }