public async void AddNewEpisode()
        {
            // Given
            var episode101 = new Episode {
                Id = 101, Title = "Episode101"
            };

            // When
            _episodeRepository.Add(episode101);
            var saved = await _episodeRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var episode = await db.Episodes.FindAsync(101);

                Assert.NotNull(episode);
                Assert.Equal(101, episode.Id);
                Assert.Equal("Episode101", episode.Title);

                // Cleanup
                db.Episodes.Remove(episode);
                await db.SaveChangesAsync();
            }
        }
        public async void UpdateExistingEpisode()
        {
            // Given
            var newhope = await _episodeRepository.Get(4);

            newhope.Title = "Episode4";

            // When
            _episodeRepository.Update(newhope);
            var saved = await _episodeRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var episode = await db.Episodes.FindAsync(4);

                Assert.NotNull(episode);
                Assert.Equal(4, episode.Id);
                Assert.Equal("Episode4", episode.Title);

                // Cleanup
                episode.Title = "NEWHOPE";
                db.Episodes.Update(episode);
                await db.SaveChangesAsync();
            }
        }
        public async void AddNewCharacter()
        {
            // Given
            var character3101 = new Character {
                Id = 3101, Name = "Character3101"
            };

            // When
            _characterRepository.Add(character3101);
            var saved = await _characterRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var character = await db.Characters.FindAsync(3101);

                Assert.NotNull(character);
                Assert.Equal(3101, character.Id);
                Assert.Equal("Character3101", character.Name);

                // Cleanup
                db.Characters.Remove(character);
                await db.SaveChangesAsync();
            }
        }
        public async void DeleteExistingEpisode()
        {
            // Given
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var episode102 = new Episode {
                    Id = 102, Title = "Episode102"
                };
                await db.Episodes.AddAsync(episode102);

                await db.SaveChangesAsync();
            }

            // When
            _episodeRepository.Delete(102);
            var saved = await _episodeRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var deletedEpisode = await db.Episodes.FindAsync(102);

                Assert.Null(deletedEpisode);
            }
        }
        public async void UpdateExistingCharacter()
        {
            // Given
            var threepio = await _characterRepository.Get(2000);

            threepio.Name = "Character2000";

            // When
            _characterRepository.Update(threepio);
            var saved = await _characterRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var character = await db.Characters.FindAsync(2000);

                Assert.NotNull(character);
                Assert.Equal(2000, character.Id);
                Assert.Equal("Character2000", character.Name);

                // Cleanup
                character.Name = "C-3PO";
                db.Characters.Update(character);
                await db.SaveChangesAsync();
            }
        }
        public async void DeleteExistingCharacter()
        {
            // Given
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var character3100 = new Character {
                    Id = 3100, Name = "Character3100"
                };
                await db.Characters.AddAsync(character3100);

                await db.SaveChangesAsync();
            }

            // When
            _characterRepository.Delete(3100);
            var saved = await _characterRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var deletedCharacter = await db.Characters.FindAsync(3100);

                Assert.Null(deletedCharacter);
            }
        }
Exemple #7
0
        public async void UpdateExistingPlanet()
        {
            // Given
            var alderaan = await _planetRepository.Get(2);

            alderaan.Name = "Planet2";

            // When
            _planetRepository.Update(alderaan);
            var saved = await _planetRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var planet = await db.Planets.FindAsync(2);

                Assert.NotNull(planet);
                Assert.Equal(2, planet.Id);
                Assert.Equal("Planet2", planet.Name);

                // Cleanup
                planet.Name = "Alderaan";
                db.Planets.Update(planet);
                await db.SaveChangesAsync();
            }
        }
        public async void AddNewDroid()
        {
            // Given
            var droid2101 = new Droid {
                Id = 2101, Name = "Droid2101", PrimaryFunction = "Function2101"
            };

            // When
            _characterRepository.Add(droid2101);
            var saved = await _characterRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var character = await db.Characters.FindAsync(2101);

                Assert.NotNull(character);
                Assert.IsType <Droid>(character);
                Assert.Equal(2101, character.Id);
                Assert.Equal("Droid2101", character.Name);

                // Cleanup
                db.Characters.Remove(character);
                await db.SaveChangesAsync();
            }
        }
Exemple #9
0
        public async void DeleteExistingPlanet()
        {
            // Given
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var planet102 = new Planet {
                    Id = 102, Name = "Planet102"
                };
                await db.Planets.AddAsync(planet102);

                await db.SaveChangesAsync();
            }

            // When
            _planetRepository.Delete(102);
            var saved = await _planetRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var deletedPlanet = await db.Planets.FindAsync(102);

                Assert.Null(deletedPlanet);
            }
        }
Exemple #10
0
        public async void AddNewPlanet()
        {
            // Given
            var planet101 = new Planet {
                Id = 101, Name = "Planet101"
            };

            // When
            _planetRepository.Add(planet101);
            var saved = await _planetRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var planet = await db.Planets.FindAsync(101);

                Assert.NotNull(planet);
                Assert.Equal(101, planet.Id);
                Assert.Equal("Planet101", planet.Name);

                // Cleanup
                db.Planets.Remove(planet);
                await db.SaveChangesAsync();
            }
        }
Exemple #11
0
        public async void AddNewHuman()
        {
            // Given
            var human10101 = new Human {
                Id = 10101, Name = "Human10101"
            };

            // When
            _humanRepository.Add(human10101);
            var saved = await _humanRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var human = await db.Humans.FindAsync(10101);

                Assert.NotNull(human);
                Assert.Equal(10101, human.Id);
                Assert.Equal("Human10101", human.Name);

                // Cleanup
                db.Humans.Remove(human);
                await db.SaveChangesAsync();
            }
        }
Exemple #12
0
        public async void DeleteExistingHuman()
        {
            // Given
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var human10102 = new Human {
                    Id = 10102, Name = "Human10102"
                };
                await db.Humans.AddAsync(human10102);

                await db.SaveChangesAsync();
            }

            // When
            _humanRepository.Delete(10102);
            var saved = await _humanRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var deletedHuman = await db.Humans.FindAsync(10101);

                Assert.Null(deletedHuman);
            }
        }
Exemple #13
0
        public async void UpdateExistingHuman()
        {
            // Given
            var vader = await _humanRepository.Get(1001);

            vader.Name = "Human1001";

            // When
            _humanRepository.Update(vader);
            var saved = await _humanRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var human = await db.Humans.FindAsync(1001);

                Assert.NotNull(human);
                Assert.Equal(1001, human.Id);
                Assert.Equal("Human1001", human.Name);

                // Cleanup
                human.Name = "Darth Vader";
                db.Humans.Update(human);
                await db.SaveChangesAsync();
            }
        }
        public async void UpdateExistingDroid()
        {
            // Given
            var threepio = await _droidRepository.Get(2000);

            threepio.PrimaryFunction = "Function2000";

            // When
            _droidRepository.Update(threepio);
            var saved = await _droidRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var droid = await db.Droids.FindAsync(2000);

                Assert.NotNull(droid);
                Assert.Equal(2000, droid.Id);
                Assert.Equal("Function2000", droid.PrimaryFunction);

                // Cleanup
                droid.PrimaryFunction = "Protocol";
                db.Droids.Update(droid);
                await db.SaveChangesAsync();
            }
        }
        public async void DeleteExistingDroid()
        {
            // Given
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var droid2100 = new Droid {
                    Id = 2100, Name = "Droid2100", PrimaryFunction = "Function2100"
                };
                await db.Droids.AddAsync(droid2100);

                await db.SaveChangesAsync();
            }

            // When
            _droidRepository.Delete(2100);
            var saved = await _droidRepository.SaveChangesAsync();

            // Then
            Assert.True(saved);
            using (var db = new AmstramgramContext(_options, _dbLogger.Object))
            {
                var deletedDroid = await db.Droids.FindAsync(2100);

                Assert.Null(deletedDroid);
            }
        }