public async Task Handle_GivenInvalidCategoryId_ThrowsBadRequestException() { var command = new UpsertTopicCommand() { CategoryId = 10 }; await ShouldThrowAsyncExtensions.ShouldThrowAsync <BadRequestException>(() => _handler.Handle(command, CancellationToken.None)); }
public async Task Handle_GivenIdAndDoesntExist_ThrowsNotFoundException() { var id = 10; var command = new UpsertTopicCommand() { Id = id, CategoryId = 1 }; await ShouldThrowAsyncExtensions.ShouldThrowAsync <NotFoundException>(() => _handler.Handle(command, CancellationToken.None)); }
public async Task Handle_NotGivenId_CreatesTopic() { var topicName = "New Topic"; var topicDescription = "Nice new topic description"; var command = new UpsertTopicCommand() { Title = topicName, Description = topicDescription, CategoryId = 1 }; await _handler.Handle(command, CancellationToken.None); var topic = await _context.Topics.FindAsync(3); topic.ShouldNotBe(null); }
public async Task Handle_GivenIdAndExists_UpdatesTopic() { var id = 1; var newDescription = "A brand new topic description"; var command = new UpsertTopicCommand() { Id = id, CategoryId = 1, Description = newDescription, Title = "Non-empty Topic" }; await _handler.Handle(command, CancellationToken.None); var topic = await _context.Topics.FindAsync(id); topic.Description.ShouldBe(newDescription); }
public async Task <IActionResult> Upsert([FromBody] UpsertTopicCommand command) { int topicId = await Mediator.Send(command); return(Ok(topicId)); }