コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void Handle_WithNullUpdatingCommand_ShouldThrowException()
        {
            // Arrange
            UpdateTodoItemCommand command = null;

            // Assert
            Assert.Throws <ArgumentNullException>(() => _todoItemsCommandHandler.Handle(command));
        }
コード例 #5
0
        public void ShouldBeRealId()
        {
            var command = new UpdateTodoItemCommand {
                Id = 99
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
コード例 #6
0
        public async Task <IActionResult> UpdateTodoItem(
            [FromBody] UpdateTodoItemCommand command,
            CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            await _mediator.Send(request : command, cancellationToken : cancellationToken);

            return(NoContent());
        }
コード例 #7
0
        public async Task WhenTheUserUpdatesAnExistingItemWithTheName(string p0)
        {
            _updateTodoItemCommand = new UpdateTodoItemCommand
            {
                Id    = _itemId,
                Title = "Updated Item Title"
            };

            await AppHooks.SendAsync(_updateTodoItemCommand);
        }
コード例 #8
0
        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);
            }));
        }
コード例 #9
0
        public async Task <ActionResult> Update(int id, UpdateTodoItemCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }
            await Mediator.Send(command);

            return(NoContent());
        }
コード例 #10
0
        public void ShouldRequireValidTodoItemId()
        {
            var command = new UpdateTodoItemCommand
            {
                Id    = 99,
                Title = "New Title"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
コード例 #11
0
        public async Task <IActionResult> PutTodoItem(long id,
                                                      UpdateTodoItemCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await _mediator.Send(command);

            return(NoContent());
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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());
        }
コード例 #15
0
ファイル: Update.cs プロジェクト: tchigher/CleanArchitecture
        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();
        }
コード例 #16
0
        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();
        }
コード例 #17
0
        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();
        }
コード例 #18
0
        public async Task <ActionResult> Update(UpdateTodoItemCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }
コード例 #19
0
 public async Task UpdateItem(UpdateTodoItemCommand updateCommand)
 {
     await Clients.All.SendAsync("UpdateItem", updateCommand);
 }
コード例 #20
0
 public Task UpdateTodoItem(UpdateTodoItemCommand command) =>
 this.PutJson("api/TodoItems", command);