public async Task ShouldUpdateTodoItem() { var categoryId = await SendAsync(new CreateTodoCategoryCommand { CategoryTitle = "Belajar" }); var itemId = await SendAsync(new CreateTodoItemCommand { CategoryId = categoryId, ActivityTitle = "Belajar Sejarah" }); var command = new UpdateTodoItemCommand { Id = itemId, Done = true }; await SendAsync(command); var item = await FindAsync <TodoItem>(itemId); item.Should().NotBeNull(); item.Done.Should().Be(command.Done); }
public async Task ShouldUpdateTodoItem() { var userId = await RunAsDefaultUserAsync(); var listId = await SendAsync(new CreateTodoListCommand { Title = "New List" }); var itemId = await SendAsync(new CreateTodoItemCommand { ListId = listId, Title = "New Item" }); var command = new UpdateTodoItemCommand { Id = itemId, Title = "Updated Item Title" }; await SendAsync(command); var item = await FindAsync <TodoItem>(itemId); item.Title.Should().Be(command.Title); item.LastModifiedBy.Should().NotBeNull(); item.LastModifiedBy.Should().Be(userId); item.LastModified.Should().NotBeNull(); item.LastModified.Should().BeCloseTo(DateTime.Now, 1000); }
public bool Handle(UpdateTodoItemCommand command) { if (command == null) { throw new ArgumentNullException("UpdateTodoItemCommand can not be null"); } var currentItem = _todoRepository.Get <TodoItem>(command.Id); if (currentItem == null) { throw new NullReferenceException("Not found"); } currentItem.Completed = command.Completed; currentItem.Title = command.Title; currentItem.UpdatedAt = DateTime.Now; try { _todoRepository.Update(currentItem); } catch (Exception e) { return(false); } return(true); }
public void Handle_WithNullUpdatingCommand_ShouldThrowException() { // Arrange UpdateTodoItemCommand command = null; // Assert Assert.Throws <ArgumentNullException>(() => _todoItemsCommandHandler.Handle(command)); }
public void ShouldBeRealId() { var command = new UpdateTodoItemCommand { Id = 99 }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <IActionResult> UpdateTodoItem( [FromBody] UpdateTodoItemCommand command, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); await _mediator.Send(request : command, cancellationToken : cancellationToken); return(NoContent()); }
public async Task WhenTheUserUpdatesAnExistingItemWithTheName(string p0) { _updateTodoItemCommand = new UpdateTodoItemCommand { Id = _itemId, Title = "Updated Item Title" }; await AppHooks.SendAsync(_updateTodoItemCommand); }
public Task <SimpleResponseDto <bool> > Put(Guid id, [FromBody] UpdateTodoItemCommand command) { command.Id = id; Task task = commandBus.Send(command); return(task.ContinueWith(t => { return SimpleResponseDto <bool> .OK(true); })); }
public async Task <ActionResult> Update(int id, UpdateTodoItemCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public void ShouldRequireValidTodoItemId() { var command = new UpdateTodoItemCommand { Id = 99, Title = "New Title" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <IActionResult> PutTodoItem(long id, UpdateTodoItemCommand command) { if (id != command.Id) { return(BadRequest()); } await _mediator.Send(command); return(NoContent()); }
public async Task <Unit> Handle(UpdateTodoItemCommand request, CancellationToken cancellationToken) { var todoItem = await todoItemContext.TodoItem.FindAsync(request.Id); todoItem.Update(request.Name, request.State, request.Deadline); todoItemContext.TodoItem.Update(todoItem); await SaveAndPublish(todoItem, cancellationToken); return(Unit.Value); }
public void Handle_GivenInvalidId_ThrowsException() { var command = new UpdateTodoItemCommand { Id = 99, Title = "This item doesn't exist.", Done = false }; var sut = new UpdateTodoItemCommand.UpdateTodoItemCommandHandler(Context); Should.ThrowAsync <NotFoundException>(() => sut.Handle(command, CancellationToken.None)); }
public async Task <ActionResult> Update(int id, UpdateTodoItemCommand command, [FromServices] IHubContext <TodoHub> hubctx) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); await hubctx.Clients.All.SendAsync("UpdateItem", command); return(NoContent()); }
public async Task GivenValidUpdateTodoItemCommand_ReturnsSuccessCode() { var client = await _factory.GetAuthenticatedClientAsync(); var command = new UpdateTodoItemCommand { Id = 1, Name = "Do this thing.", IsComplete = true }; var content = IntegrationTestHelper.GetRequestContent(command); var response = await client.PutAsync($"/api/todoitems/{command.Id}", content); response.EnsureSuccessStatusCode(); }
public async Task Handle_GivenValidId_ShouldUpdatePersistedTodoItem() { var command = new UpdateTodoItemCommand { Id = 1, Title = "This thing is also done.", Done = true }; var handler = new UpdateTodoItemCommand.UpdateTodoItemCommandHandler(Context); await handler.Handle(command, CancellationToken.None); var entity = Context.TodoItems.Find(command.Id); entity.ShouldNotBeNull(); entity.Title.ShouldBe(command.Title); entity.Done.ShouldBeTrue(); }
public async Task Handle_GivenValidId_ShouldUpdatePersistedTodoItem() { var command = new UpdateTodoItemCommand { Id = 1, Name = "This thing is also done.", IsComplete = true }; var sut = new UpdateTodoItemCommand.UpdateTodoItemCommandHandler(Context); await sut.Handle(command, CancellationToken.None); var entity = Context.TodoItems.Find(command.Id); entity.ShouldNotBeNull(); entity.Name.ShouldBe(command.Name); entity.IsComplete.ShouldBeTrue(); }
public async Task <ActionResult> Update(UpdateTodoItemCommand command) { await Mediator.Send(command); return(NoContent()); }
public async Task UpdateItem(UpdateTodoItemCommand updateCommand) { await Clients.All.SendAsync("UpdateItem", updateCommand); }
public Task UpdateTodoItem(UpdateTodoItemCommand command) => this.PutJson("api/TodoItems", command);