public async Task Handle_GivenInvalidTopicId_ThrowsBadRequestException() { var command = new UpsertContentCommand() { TopicId = 10 }; await ShouldThrowAsyncExtensions.ShouldThrowAsync <BadRequestException>(() => _handler.Handle(command, CancellationToken.None)); }
public async Task Handle_GivenIdAndDoesntExist_ThrowsNotFoundException() { var id = 10; var command = new UpsertContentCommand() { Id = id, TopicId = validTopicId }; await ShouldThrowAsyncExtensions.ShouldThrowAsync <NotFoundException>(() => _handler.Handle(command, CancellationToken.None)); }
public async Task Handle_NotGivenId_CreatesContent() { var contentName = "New Content"; var contentDescription = "New content description"; var command = new UpsertContentCommand() { Title = contentName, Description = contentDescription, TopicId = validTopicId }; await _handler.Handle(command, CancellationToken.None); var content = await _context.Contents.FindAsync(2); content.ShouldNotBe(null); }
public async Task Handle_GivenIdAndExists_UpdatesContent() { var id = 1; var newDescription = "An updated content description."; var command = new UpsertContentCommand() { Id = id, Title = "Content One", Description = newDescription, TopicId = validTopicId }; await _handler.Handle(command, CancellationToken.None); var content = await _context.Contents.FindAsync(id); content.Description.ShouldBe(newDescription); }
public async Task <IActionResult> Upsert([FromBody] UpsertContentCommand command) { int contentId = await Mediator.Send(command); return(Ok(contentId)); }