public async Task Edit_character_command_handler_should_throw_not_found_exception() { // Arrange var episode = new EpisodeBuilder().Generate().SaveChanges(_testFixture.Context).Build().First(); var characterToUpdate = new CharacterBuilder().Generate().SaveChanges(_testFixture.Context).Build().First(); var command = new EditCharacterCommand { Id = characterToUpdate.Id + 1, Name = "name", EpisodesIds = new[] { episode.Id }, FriendsIds = new int[] { } }; var commandHandler = new EditCharacterCommandHandler(_testFixture.Context, _testFixture.Mapper); async Task Act() => await commandHandler.Handle(command, CancellationToken.None); var ex = await Record.ExceptionAsync(Act); // Assert ex.ShouldBeOfType <NotFoundException>(); }
public async Task Edit_character_command_handler_should_return_id_of_updated_character() { // Arrange var episode = new EpisodeBuilder().Generate().SaveChanges(_testFixture.Context).Build().First(); var characterToUpdate = new CharacterBuilder().Generate().SaveChanges(_testFixture.Context).Build().First(); var command = new EditCharacterCommand { Id = characterToUpdate.Id, Name = "changed name", EpisodesIds = new[] { episode.Id }, FriendsIds = new int[] {} }; var commandHandler = new EditCharacterCommandHandler(_testFixture.Context, _testFixture.Mapper); // Act var result = await commandHandler.Handle(command, CancellationToken.None); // Assert result.ShouldBeOfType(typeof(int)); result.ShouldBe(characterToUpdate.Id); }