public async Task CreateAsync_given_dto_returns_created_Episode() { using (var connection = await CreateConnectionAsync()) using (var context = await CreateContextAsync(connection)) { var bender = new Character { Name = "Bender", Species = "Robot" }; var fry = new Character { Name = "Fry", Species = "Human" }; context.Characters.AddRange(bender, fry); await context.SaveChangesAsync(); var repository = new EpisodeRepository(context); var dto = new EpisodeCreateUpdateDTO { Title = "Murder on the Planet Express", FirstAired = new DateTime(2013, 8, 21), CharacterIds = new[] { bender.Id, fry.Id } }; var episode = await repository.CreateAsync(dto); Assert.Equal(1, episode.Id); Assert.Equal("Murder on the Planet Express", episode.Title); Assert.Equal(new DateTime(2013, 8, 21), episode.FirstAired); Assert.Equal(new Dictionary <int, string> { { bender.Id, "Bender" }, { fry.Id, "Fry" } }, episode.Characters); } }
public async Task CreateAsync_given_dto_creates_new_Episode() { using (var connection = await CreateConnectionAsync()) using (var context = await CreateContextAsync(connection)) { var bender = new Character { Name = "Bender", Species = "Robot" }; var fry = new Character { Name = "Fry", Species = "Human" }; context.Characters.AddRange(bender, fry); await context.SaveChangesAsync(); var repository = new EpisodeRepository(context); var dto = new EpisodeCreateUpdateDTO { Title = "Murder on the Planet Express", FirstAired = new DateTime(2013, 8, 21), CharacterIds = new[] { bender.Id, fry.Id } }; var episode = await repository.CreateAsync(dto); Assert.Equal(1, episode.Id); var entity = await context.Episodes.FindAsync(episode.Id); Assert.Equal("Murder on the Planet Express", entity.Title); Assert.Equal(new DateTime(2013, 8, 21), entity.FirstAired); var characterIds = await context.EpisodeCharacters.Where(e => e.EpisodeId == episode.Id).Select(c => c.CharacterId).ToListAsync(); Assert.True(new HashSet <int> { bender.Id, fry.Id }.SetEquals(characterIds)); } }