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 InsertingEpisode_DataPassed_EpisodeInserted() { var builder = new DbContextOptionsBuilder(); builder.UseInMemoryDatabase("InsertNewEpisode"); using (var context = new StarWarsContext(builder.Options)) { var repository = new EpisodeRepository(context); repository.CreateEpisode(new Episode() { EpisodeName = "test episode" }); await repository.SaveChangesAsync(); }; using (var context2 = new StarWarsContext(builder.Options)) { Assert.Equal(1, context2.Episodes.Count()); } }