public ICommandResult CreateTodo([FromBody] CreateTodoCommand command) { command.User = "******"; var result = (ResponseCommand)_handler.Handle(command); return(result); }
public void CreateTodoCommandValid() { var command = new CreateTodoCommand("title", DateTime.Now, "userbygoogle"); command.Validate(); Assert.True(command.Valid); }
public void CreateTodoCommandInvalidTitle() { var command = new CreateTodoCommand("ti", DateTime.Now, "userbygoogle"); command.Validate(); Assert.False(command.Valid); }
public void CreateTodoCommandInvalidUser() { var command = new CreateTodoCommand("title", DateTime.Now, ""); command.Validate(); Assert.False(command.Valid); }
public ActionResult Create(CreateViewModel vm) { var command = new CreateTodoCommand(vm.Id, vm.Title); _bus.Send(command); return(RedirectToAction("Index")); }
public CreateTodoHandlerTests() { _invalidComand = new CreateTodoCommand("", "", DateTime.Now); _validComand = new CreateTodoCommand("criando tarefa", "douglas", DateTime.Now); _handler = new TodoHandler(new FakeTodoRepository()); _result = new GenericCommandResult(); }
public async Task <IActionResult> Post(CreateTodoCommand command, [FromHeader(Name = "user-id")] Guid userId) { command.UserId = userId; await mediator.Send(command); return(StatusCode(StatusCodes.Status201Created)); }
public void Handle(CreateTodoCommand command, IEventPublisher publisher) { if (State != TodoState.CLOSED) { publisher.Publish(new TodoIsCreatedEvent(command.UUID, command.Title)); } }
public void Dado_um_Comando_Invalido_deve_interromper_a_execucao() { var command = new CreateTodoCommand("", "", DateTime.Now); _result = (GenericCommandResult)_handler.Handle(_invalidCommand); Assert.AreEqual(_result.Sucess, false); }
public void CreateTodoCommandInvalid() { var command = new CreateTodoCommand("", DateTime.Now, ""); var result = (GenericCommandResult)_handler.Handle(command); Assert.False(result.Success); }
public GenericCommandResult Create( [FromBody] CreateTodoCommand command, [FromServices] TodoHandler handler) { command.User = User.Claims.FirstOrDefault(x => x.Type == "user_id")?.Value; return((GenericCommandResult)handler.Handle(command)); }
public async Task Handle_WhenUserHasPermission_ShouldCreateTodo() { // Arrange var userId = Guid.NewGuid(); var command = new CreateTodoCommand { UserId = userId, Name = "todo one", IsComplete = true }; var dbOptions = new DbContextOptionsBuilder <TodoDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; long todoId = 0; using (var context = new TodoDbContext(dbOptions)) { var sut = new CreateTodoCommandHandler(context, mapper, rpcNotificationsMock.ServiceClient, rpcPermissionsMock.ServiceClient); // Act todoId = await sut.Handle(command, new CancellationToken(false)); // Assert todoId.ShouldBeGreaterThan(0); var createdTodo = await context.Todos.FirstOrDefaultAsync(t => t.Id == todoId); createdTodo.ShouldNotBeNull(); createdTodo.Name.ShouldBe(command.Name); createdTodo.IsComplete.ShouldBe(command.IsComplete); } }
public async Task Handle_WhenUserDoesNotHavePermission_ShouldThrowException() { // Arrange var userId = Guid.NewGuid(); var command = new CreateTodoCommand { UserId = userId, Name = "todo one", IsComplete = true }; var rpcResponse = new IsUserAllowedResponse { IsAllowed = false }; rpcPermissionsMock.ClientMock.Setup(x => x.IsUserAllowed(It.IsAny <IsUserAllowedRequest>(), It.IsAny <CallOptions>())).Returns(rpcResponse); var dbOptions = new DbContextOptionsBuilder <TodoDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var context = new TodoDbContext(dbOptions)) { // Act var sut = new CreateTodoCommandHandler(context, mapper, rpcNotificationsMock.ServiceClient, rpcPermissionsMock.ServiceClient); try { var result = await sut.Handle(command, new CancellationToken(false)); Assert.True(false, "Should throw exception"); } catch (InvalidOperationException ex) { // Assert Assert.NotNull(ex); } } }
public async Task <ActionResult <TodoReadDTO> > CreateTodo([FromBody] TodoCreateDTO todoCreateDto) { var request = new CreateTodoCommand(User.Identity?.Name, todoCreateDto); var createdTodo = await _mediator.Send(request); return(CreatedAtRoute(nameof(GetTodoById), new { Id = createdTodo.Id }, createdTodo)); }
public void CreateTodoCommand_TodoValido_DeveRetornarTodo() { var command = new CreateTodoCommand("Teste", "kelvin", DateTime.Now); command.Validate(); Assert.True(command.Valid); }
public GenericCommandResult Create( // converte automaticamente em JSON, por causa do FromBody (ModelBind) [FromBody] CreateTodoCommand command, [FromServices] TodoHandler handler) // From services vem do startup, ve o que tem dentro do AddTransient e instancia a dependencia { command.User = "******"; return((GenericCommandResult)handler.Handle(command)); // retorna se O.K ou não }
public GenericCommandResult Create([FromBody] CreateTodoCommand command, [FromServices] TodoHandler todoHandler) { command.User = User.Claims.FirstOrDefault(us => us.Type.Equals("user_id"))?.Value; return((GenericCommandResult)todoHandler.Handle(command)); }
public static TodoAggregateRoot Register(CreateTodoCommand command) { var root = new TodoAggregateRoot(command.AggregateId); root.Create(command); return(root); }
public void Dado_um_Comando_valido_deve_executar() { var command = new CreateTodoCommand("Titulo da Tarefa", "MatheusMunhoz", DateTime.Now); _result = (GenericCommandResult)_handler.Handle(_validCommand); Assert.AreEqual(_result.Sucess, true); }
public void GivenAValidCommand_ShouldCreateTodo() { var command = new CreateTodoCommand("Study CSharp", "leandropicoli", DateTime.Now.AddDays(2)); var result = (GenericCommandResult)_handler.Handle(command); Assert.IsTrue(result.Success); }
public void GivenAnInvalidCommand_ShouldNotCreateTodo() { var command = new CreateTodoCommand("", "", DateTime.Now); var result = (GenericCommandResult)_handler.Handle(command); Assert.IsFalse(result.Success); }
public void CreateTodoCommandValid() { var command = new CreateTodoCommand("title", DateTime.Now, "userbygoogle"); var result = (GenericCommandResult)_handler.Handle(command); Assert.True(result.Success); }
public CreateCommandTests() { _invalidComand = new CreateTodoCommand("", "", DateTime.Now); _invalidComand.Validate(); _validComand = new CreateTodoCommand("criando tarefa", "douglas", DateTime.Now); _validComand.Validate(); }
public void CreateTodoCommand_TodoInvalido_DeveRetornarErros() { var command = new CreateTodoCommand("", "", DateTime.Now); command.Validate(); Assert.False(command.Valid); //testar quantidade de notificações }
public void Dado_um_command_invalido() { var command = new CreateTodoCommand("", DateTime.Now, ""); command.Validate(); Assert.AreEqual(command.Valid, false); }
public GenericCommandResult Create( [FromBody] CreateTodoCommand command, [FromServices] TodoHandler handler ) { command.User = "******"; return((GenericCommandResult)handler.Handle(command)); }
public void DadoUmComandoInvalidoDeveInterromperExecucao() { var command = new CreateTodoCommand("", DateTime.Now, ""); var handle = new TodoHandler(new FakeTodoRepository()); ResponseCommand result = (ResponseCommand)handle.Handle(command); Assert.AreEqual(result.Success, false); }
public void DadoUmComandoValidoDeveCriarTarefa() { var command = new CreateTodoCommand("Titulo da Descrição", DateTime.Now, "Usuário"); var handle = new TodoHandler(new FakeTodoRepository()); ResponseCommand result = (ResponseCommand)handle.Handle(command); Assert.AreEqual(result.Success, true); }
public void Dado_um_command_valido() { var command = new CreateTodoCommand("titulo da tarefa", DateTime.Now, "Matheus Rodrigues"); command.Validate(); Assert.AreEqual(command.Valid, true); }