public async Task ShouldUpdateTodoList() { var userId = await RunAsDefaultUserAsync(); var listId = await SendAsync(new CreateTodoListCommand { Title = "New List" }); var command = new UpdateTodoListCommand { Id = listId, Title = "Updated List Title" }; await SendAsync(command); var list = await FindAsync <TodoList>(listId); list.Title.Should().Be(command.Title); list.LastModifiedBy.Should().NotBeNull(); list.LastModifiedBy.Should().Be(userId); list.LastModified.Should().NotBeNull(); list.LastModified.Should().BeCloseTo(DateTime.Now, 1000); }
public async Task ShouldRequireUniqueTitle() { var response = await SendAsync(new CreateTodoListCommand { Title = "New List" }); var listId = response.Data; await SendAsync(new CreateTodoListCommand { Title = "Other List" }); var command = new UpdateTodoListCommand { Id = listId, Title = "Other List" }; FluentActions.Invoking(() => SendAsync(command)) .Should().Throw <ValidationException>().Where(ex => ex.Errors.ContainsKey("Title")) .And.Errors["Title"].Should().Contain("The specified title already exists."); }
public async Task <IActionResult> PutTodoList(int id, UpdateTodoListCommand command) { if (id != command.Id) { return(BadRequest()); } await Sender.Send(command); return(NoContent()); }
public async Task <ActionResult> Update(long id, UpdateTodoListCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public void ShouldRequireValidTodoListId() { var command = new UpdateTodoListCommand { Id = 99, Title = "New Title" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public void Handle_GivenInvalidId_ThrowsException() { var command = new UpdateTodoListCommand { Id = 99, Title = "Bucket List", }; var handler = new UpdateTodoListCommand.UpdateTodoListCommandHandler(Context); Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None)); }
public void IsValid_ShouldBeTrue_WhenListTitleIsUnique() { var command = new UpdateTodoListCommand { Id = 1, Title = "Shopping" }; var validator = new UpdateTodoListCommandValidator(Context); var result = validator.Validate(command); result.IsValid.ShouldBe(true); }
public async Task <IActionResult> Update( [FromBody] UpdateTodoListCommand command) { try { await Mediator.Send(command); } catch (ValidationException ve) { return(BadRequest(ve.Message)); } return(Ok()); }
public TodoListsController( GetTodoListsQuery getTodoListsQuery, GetTodoListByIdQuery getTodoListByIdQuery, GetTodoListItemsQuery getTodoListItemsQuery, CreateTodoListCommand createTodoListCommand, UpdateTodoListCommand updateTodoListCommand, RemoveTodoListCommand removeTodoListCommand ) { this.getTodoListsQuery = getTodoListsQuery; this.getTodoListByIdQuery = getTodoListByIdQuery; this.getTodoListItemsQuery = getTodoListItemsQuery; this.createTodoListCommand = createTodoListCommand; this.updateTodoListCommand = updateTodoListCommand; this.removeTodoListCommand = removeTodoListCommand; }
public async Task Handle_GivenValidId_ShouldUpdatePersistedTodoList() { var command = new UpdateTodoListCommand { Id = 1, Title = "Shopping", }; var handler = new UpdateTodoListCommand.UpdateTodoListCommandHandler(Context); await handler.Handle(command, CancellationToken.None); var entity = Context.TodoLists.Find(command.Id); entity.ShouldNotBeNull(); entity.Title.ShouldBe(command.Title); }
public void IsValid_ShouldBeFalse_WhenListTitleIsNotUnique() { Context.TodoLists.Add(new TodoList { Title = "Shopping" }); Context.SaveChanges(); var command = new UpdateTodoListCommand { Id = 2, Title = "Shopping" }; var validator = new UpdateTodoListCommandValidator(Context); var result = validator.Validate(command); result.IsValid.ShouldBe(false); }
public async void ShouldThrowNotFoundException_WhenIdDoesNotExistInDatabase() { // Arrange var command = new UpdateTodoListCommand { Id = 99, Title = "New Title 31/10/2020" }; // Act var exception = await Record.ExceptionAsync(async() => { await _fixture.SendAsync(command); }); // Assert exception.ShouldBeOfType <NotFoundException>(); exception.Message.ShouldContain("Entity \"TodoList\" (99) was not found."); }
public async Task <HttpResponseData> UpdateTodosList([HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "todolists/{id}")] HttpRequestData req, int id, FunctionContext functionContext) { logger.LogInformation("Called UpdateTodosList"); var todoList = await req.ReadFromJsonAsync <TodoList>(); var request = new UpdateTodoListCommand { Id = id, Title = todoList.Title }; return(await this.processor.ExecuteAsync <UpdateTodoListCommand, Unit>(functionContext, req, request, (r) => req.CreateResponseAsync())); }
public async void ShouldUpdateTodoList_WhenValidListIsSentIn() { var userId = await _fixture.RunAsDefaultUserAsync(); var listId = await _fixture.SendAsync(new CreateTodoListCommand { Title = "New List 17:25" }); var command = new UpdateTodoListCommand { Id = listId, Title = "Updated List Title 17:25" }; await _fixture.SendAsync(command); var list = await _fixture.FindAsync <TodoList>(listId); list.Title.ShouldBe(command.Title); list.LastModified.ShouldNotBeNull(); }
public async void ShouldThrowException_WhenTitleAlreadyExists() { // Arrange var listId = await _fixture.SendAsync(new CreateTodoListCommand { Title = "New List 17:10" }); await _fixture.SendAsync(new CreateTodoListCommand { Title = "Other List 17:12" }); var command = new UpdateTodoListCommand { Id = listId, Title = "Other List 17:12" }; // Act var exception = (ValidationException)await Record.ExceptionAsync(async() => { await _fixture.SendAsync(command); }); // Assert exception.ShouldBeOfType <ValidationException>(); exception.Message.ShouldContain("One or more validation failures have occurred."); var errors = exception.Errors; errors.ShouldNotBeNull(); errors.TryGetValue("Title", out string[] errorText); errorText.ShouldNotBeNull(); errorText.Count().ShouldBe(1); errorText[0].ShouldBe("The specified title already exists."); }
public async Task HandleAsync(UpdateTodoListCommand command, CancellationToken cancellationToken) { var todoList = await repository.GetAsync <TodoList>(command.Id); todoList.Rename(command.Name); }
public async Task <ActionResult> Update(UpdateTodoListCommand command) { await Mediator.Send(command); return(NoContent()); }
public Task UpdateTodoList(UpdateTodoListCommand command) => this.PutJson("api/TodoLists", command);