public async Task <Episode> FindAsync(Series series, string fileName)
        {
            var noExtension = Path.GetFileNameWithoutExtension(fileName);

            int episodeNumber = FindEpisodeNumber(noExtension);
            int seasonNumber  = FindSeasonNumber(series, noExtension);

            // check the database!
            Episode result = await _repo.FindAsync(episodeNumber, seasonNumber, series.Id);

            if (result != null)
            {
                return(result);
            }

            // check api
            result = await FindWithApi(series, seasonNumber, episodeNumber);

            if (result != null)
            {
                result.Id = await _repo.AddAsync(result);

                return(result);
            }

            return(null);
        }
        public async Task FindAsync_given_id_exists_returns_dto()
        {
            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"
                    };
                    var entity = new Episode
                    {
                        Title             = "Murder on the Planet Express",
                        FirstAired        = new DateTime(2013, 8, 21),
                        EpisodeCharacters = new[]
                        {
                            new EpisodeCharacter {
                                Character = bender
                            },
                            new EpisodeCharacter {
                                Character = fry
                            }
                        }
                    };
                    context.Episodes.Add(entity);
                    await context.SaveChangesAsync();

                    var repository = new EpisodeRepository(context);

                    var episode = await repository.FindAsync(entity.Id);

                    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);
                }
        }