public async Task Ok() { var query = new GetCharacterQuery { Id = _character.Id }; var result = await _handler.Handle(query, CancellationToken.None); Assert.NotNull(result); Assert.StrictEqual(_character, result); }
public async Task Get_character_query_handler_should_throw_not_found_exception() { // Arrange var character = new CharacterBuilder().Generate().Build().First(); var query = new GetCharacterQuery { Id = character.Id + 1 }; var queryHandler = new GetCharacterQueryHandler(_testFixture.Context, _testFixture.Mapper); // Act async Task Act() => await queryHandler.Handle(query, CancellationToken.None); var ex = await Record.ExceptionAsync(Act); // Assert ex.ShouldBeOfType <NotFoundException>(); }
public async Task Get_character_query_handler_should_pass() { // Arrange var character = new CharacterBuilder().Generate().Build().First(); var episode = new EpisodeBuilder().Generate().SaveChanges(_testFixture.Context).Build().First(); character.Episodes.Add(new CharacterEpisode { CharacterId = character.Id, EpisodeId = episode.Id }); _testFixture.Context.Characters.Update(character); _testFixture.Context.SaveChanges(); var query = new GetCharacterQuery { Id = character.Id }; var queryHandler = new GetCharacterQueryHandler(_testFixture.Context, _testFixture.Mapper); // Act var response = await queryHandler.Handle(query, CancellationToken.None); // Assert response.Name.ShouldBe(character.Name); response.Episodes.Count.ShouldBe(1); response.Episodes.First().Name.ShouldBe(episode.Name); }