Ejemplo n.º 1
0
        public async Task DeleteAsync_given_existing_episodeId_deletes_cascading()
        {
            using (var connection = await CreateConnectionAsync())
                using (var context = await CreateContextAsync(connection))
                {
                    var entity = new Episode {
                        Title = "The Series Has Landed", EpisodeCharacters = new[] { new EpisodeCharacter {
                                                                                         Character = new Character {
                                                                                             Name = "Bender", Species = "Robot"
                                                                                         }
                                                                                     } }
                    };
                    context.Episodes.Add(entity);
                    await context.SaveChangesAsync();

                    var id = entity.Id;

                    var repository = new EpisodeRepository(context);

                    await repository.DeleteAsync(id);

                    Assert.Null(await context.Episodes.FindAsync(id));
                    Assert.Empty(await context.EpisodeCharacters.ToListAsync());
                    Assert.NotNull(await context.Characters.FirstOrDefaultAsync(c => c.Name == "Bender"));
                }
        }
Ejemplo n.º 2
0
        public async Task DeleteAsync_given_non_existing_episodeId_returns_false()
        {
            using (var connection = await CreateConnectionAsync())
                using (var context = await CreateContextAsync(connection))
                {
                    var repository = new EpisodeRepository(context);

                    var deleted = await repository.DeleteAsync(0);

                    Assert.False(deleted);
                }
        }
Ejemplo n.º 3
0
        public async Task DeleteAsync_given_existing_episodeId_returns_true()
        {
            using (var connection = await CreateConnectionAsync())
                using (var context = await CreateContextAsync(connection))
                {
                    var entity = new Episode {
                        Title = "The Series Has Landed"
                    };
                    context.Episodes.Add(entity);
                    await context.SaveChangesAsync();

                    var id = entity.Id;

                    var repository = new EpisodeRepository(context);

                    var deleted = await repository.DeleteAsync(id);

                    Assert.True(deleted);
                }
        }