public async Task <IActionResult> Upsert(UpsertCategoryCommand command) { var hasSucceeded = await Mediator.Send(command); if (hasSucceeded) { return(Ok()); } return(BadRequest()); }
public async Task Handle_GivenIdAndDoesntExist_ThrowsNotFoundException() { var id = 10; var command = new UpsertCategoryCommand() { Id = id, Title = "New Category", Description = "New category description" }; await ShouldThrowAsyncExtensions.ShouldThrowAsync <NotFoundException>(() => _handler.Handle(command, CancellationToken.None)); }
public async Task <IActionResult> Upsert(UpsertCategoryCommand command) { if (ModelState.IsValid) { await Mediator.Send(command); return(RedirectToAction(nameof(Index))); } else { return(View(command)); } }
public async Task Handle_GivenIdAndExists_UpdatesCategory() { var id = 1; var newDescription = "I have added this description"; var command = new UpsertCategoryCommand() { Id = id, Title = "Non-empty category", Description = newDescription }; await _handler.Handle(command, CancellationToken.None); var category = await _context.Categories.FindAsync(id); category.Description.ShouldBe(newDescription); }
public async Task Handle_NotGivenId_CreatesCategory() { var categoryName = "New Category"; var categoryDescription = "A brand new category"; var command = new UpsertCategoryCommand() { Title = categoryName, Description = categoryDescription }; await _handler.Handle(command, CancellationToken.None); var category = await _context.Categories.LastOrDefaultAsync(); category.ShouldNotBe(null); category.Title.ShouldBe(categoryName); category.Description.ShouldBe(categoryDescription); }
public async Task <IActionResult> Upsert(UpsertCategoryCommand command) { var id = await Mediator.Send(command); return(Ok(id)); }
public async Task <IActionResult> Upsert([FromBody] UpsertCategoryCommand command) { int categoryId = await Mediator.Send(command); return(Ok(categoryId)); }