示例#1
0
        public void FindByName_ShowInDB_ReturnsShow()
        {
            var options = new DbContextOptionsBuilder <EpisodeContext>()
                          .UseInMemoryDatabase(databaseName: "FindByName_ShowInDB_ReturnsShow")
                          .Options;
            TVShow show1 = new TVShow()
            {
                SeriesId            = 281662,
                SeriesName          = "Marvel's Daredevil",
                SeriesNamePreferred = "Daredevil"
            };
            TVShow show2 = new TVShow()
            {
                SeriesId   = 328487,
                SeriesName = "The Orville"
            };

            using (var context = new EpisodeContext(options)) {
                var service = new TVShowService(context);
                context.Database.EnsureCreated();
                service.Add(show1);
                service.Add(show2);
            }
            using (var context = new EpisodeContext(options)) {
                var    service = new TVShowService(context);
                TVShow result  = service.FindByName("marvels daredevil");
                Assert.Equal(2, context.Shows.Count());
                Assert.Equal("Marvel's Daredevil", result.SeriesName);
            }
        }
 public IndividualShowMenu(EpisodeContext context, RenamerFacade facade, TVShowService showService, TVShow show)
 {
     Context     = context;
     Facade      = facade;
     ShowService = showService;
     Show        = show;
 }
示例#3
0
        public void GetSeriesIdsNotInDatabase_IdsNotPresent_ReturnsList()
        {
            var options = new DbContextOptionsBuilder <EpisodeContext>()
                          .UseInMemoryDatabase(databaseName: "GetSeriesIdsNotInDatabase_IdsNotPresent_ReturnsList")
                          .Options;
            TVShow show1 = new TVShow()
            {
                SeriesId            = 281662,
                SeriesName          = "Marvel's Daredevil",
                SeriesNamePreferred = "Daredevil"
            };

            using (var context = new EpisodeContext(options)) {
                var service = new TVShowService(context);
                service.Add(show1);
            }
            List <int> seriesIdsToCheck = new List <int>()
            {
                134, 16690, 281662, 300000
            };
            int expectedCount = 3;

            using (var context = new EpisodeContext(options)) {
                var service = new TVShowService(context);
                var result  = service.GetSeriesIdsNotInDatabase(seriesIdsToCheck);

                Assert.Equal(expectedCount, result.Count);
                Assert.Equal(0, result.Find(c => c == 281662));
            }
        }
示例#4
0
        public void GetSeriesIdsNotInDatabase_AllIdsPresent_ReturnsList()
        {
            var options = new DbContextOptionsBuilder <EpisodeContext>()
                          .UseInMemoryDatabase(databaseName: "GetSeriesIdsNotInDatabase_AllIdsPresent_ReturnsList")
                          .Options;
            TVShow show1 = new TVShow()
            {
                SeriesId            = 281662,
                SeriesName          = "Marvel's Daredevil",
                SeriesNamePreferred = "Daredevil"
            };
            TVShow show2 = new TVShow()
            {
                SeriesId   = 328487,
                SeriesName = "The Orville"
            };

            using (var context = new EpisodeContext(options)) {
                var service = new TVShowService(context);
                service.Add(show1);
                service.Add(show2);
            }
            List <int> seriesIdsToCheck = new List <int>()
            {
                281662, 328487
            };
            int expectedCount = 0;

            using (var context = new EpisodeContext(options)) {
                var service = new TVShowService(context);
                var result  = service.GetSeriesIdsNotInDatabase(seriesIdsToCheck);

                Assert.Equal(expectedCount, result.Count);
            }
        }
示例#5
0
        public void Add_ShowInDB_DoesNotWriteToDB()
        {
            var options2 = new DbContextOptionsBuilder <EpisodeContext>()
                           .UseInMemoryDatabase(databaseName: "Add_ShowInDB_DoesNotWriteToDB")
                           .Options;
            TVShow show = new TVShow()
            {
                SeriesId            = 281662,
                SeriesName          = "Marvel's Daredevil",
                SeriesNamePreferred = "Daredevil"
            };
            TVShow sameShow = new TVShow()
            {
                SeriesId            = 281662,
                SeriesName          = "Marvel's Daredevil",
                SeriesNamePreferred = "Beastie"
            };

            using (var context = new EpisodeContext(options2)) {
                var service = new TVShowService(context);
                service.Add(show);
                service.Add(sameShow);
            }
            using (var context = new EpisodeContext(options2)) {
                // Assert.Equal("Not real", context.Shows.First().SeriesNamePreferred);
                var shows = context.Shows.Where(b => b.Id >= 0);
                foreach (var s in shows)
                {
                    output.WriteLine($"{s.Id}: SeriesId: {s.SeriesId}; Name: {s.SeriesName}");
                }
                Assert.Equal(1, context.Shows.Count());
                Assert.Equal("Daredevil", context.Shows.Single().SeriesNamePreferred);
            }
        }
        public void Add_EpNotInDB_WritesToDb()
        {
            Episode ep1 = new Episode()
            {
                SeriesId           = 328487,
                TVDBEpisodeId      = 6089488,
                Season             = 1,
                AiredEpisodeNumber = 1,
                EpisodeName        = "Old Wounds"
            };

            int    expectedEpisodeId   = 6089488;
            string expectedEpisodeName = "Old Wounds";
            var    options             = new DbContextOptionsBuilder <EpisodeContext>()
                                         .UseInMemoryDatabase(databaseName: "Add_EpNotInDB_WritesToDb")
                                         .Options;

            // Act
            using (var context = new EpisodeContext(options)) {
                var service = new EpisodeService(context);
                service.Add(ep1);
            }

            using (var context = new EpisodeContext(options)) {
                var service = new EpisodeService(context);
                var result  = context.Episodes.FirstOrDefault(e => e.TVDBEpisodeId == expectedEpisodeId);
                Assert.NotNull(result);
                Assert.Equal(expectedEpisodeName, result.EpisodeName);
            }
        }
示例#7
0
        static void FindSampleShow(EpisodeContext context)
        {
            var shows = context.Shows
                        .Where(s => s.SeriesId == 328487)
                        .ToList();

            foreach (TVShow s in shows)
            {
                Console.WriteLine($"ID: {s.SeriesId}. Title: {s.SeriesName}");
            }
        }
示例#8
0
        static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console()
                         .WriteTo.File("c:\\temp\\logs\\renamerLog.txt", rollingInterval: RollingInterval.Day)
                         .CreateLogger();
            Log.Information("Started log on {a}", DateTime.Now.ToLongTimeString());

            SetUpVT100();

            string projectRoot = AppContext.BaseDirectory.Substring(0, AppContext.BaseDirectory.LastIndexOf(@"\bin"));
            // PrintDirectories(appRoot);

            var builder = new ConfigurationBuilder()
                          .SetBasePath(projectRoot)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            // IConfigurationRoot configuration = builder.Build();
            Configuration = builder.Build();

            var serviceProvider = new ServiceCollection().AddHttpClient().BuildServiceProvider();

            var httpClientFactory = serviceProvider.GetService <IHttpClientFactory>();

            var options = new DbContextOptionsBuilder <EpisodeContext>()
                          .UseSqlite(Configuration.GetConnectionString("connectionString"))
                          .Options;
            var context = new EpisodeContext(options);

            TVDBRetrieverService retrieverService = new TVDBRetrieverService(httpClientFactory);
            TVShowService        showService      = new TVShowService(context);
            EpisodeService       epService        = new EpisodeService(context);
            LocalMediaService    localService     = new LocalMediaService(Configuration.GetSection("LocalMedia").GetValue <string>("directoryPath"));
            string tvdbInfoPath = GetTVDBInfoFilePath();
            RenamePrompterConsole prompterConsole = new RenamePrompterConsole();
            RenamerFacade         facade          = new RenamerFacade(retrieverService, showService, epService, localService, context, prompterConsole, tvdbInfoPath);

            MainMenu mainMenu = new MainMenu(facade, context, showService);
            await mainMenu.DisplayMenu();

            // await DisplayMenuAndProcessUserInput(facade);
            // SetUpAutomapper();

            // GetNewToken(httpClientFactory);

            // GetApiKey();
            //ReadTVDBInfo();
            // FindSampleShow(context);
            // PauseForInput();
            // Console.WriteLine("Adding show");
            //AddSampleShow(context);
        }
示例#9
0
        static void AddSampleShow(EpisodeContext context)
        {
            TVShow theOrville = new TVShow()
            {
                SeriesId            = 328487,
                SeriesName          = "The Orville",
                SeriesNamePreferred = null,
            };

            context.Add(theOrville);
            context.SaveChanges();
        }
        public void FindByEpisodeForComparingDto_EpInDB_ReturnsEp()
        {
            TVShow show = new TVShow()
            {
                SeriesId   = 328487,
                SeriesName = "The Orville"
            };
            Episode ep1 = new Episode()
            {
                SeriesId           = 328487,
                TVDBEpisodeId      = 6089488,
                Season             = 1,
                AiredEpisodeNumber = 1,
                EpisodeName        = "Old Wounds"
            };
            Episode ep2 = new Episode()
            {
                SeriesId           = 328487,
                TVDBEpisodeId      = 6123044,
                Season             = 1,
                AiredEpisodeNumber = 2,
                EpisodeName        = "Command Performance"
            };

            EpisodeForComparingDto epDto = new EpisodeForComparingDto()
            {
                SeriesName            = "the orville",
                SeasonNumber          = 1,
                EpisodeNumberInSeason = 1
            };

            string expectedEpisodeName = "Old Wounds";

            var options = new DbContextOptionsBuilder <EpisodeContext>()
                          .UseInMemoryDatabase(databaseName: "FindByEpisodeForComparingDto_EpInDB_ReturnsEp")
                          .Options;


            using (var context = new EpisodeContext(options)) {
                var service   = new EpisodeService(context);
                var TVService = new TVShowService(context);
                TVService.Add(show);
                service.Add(ep1);
                service.Add(ep2);
            }

            using (var context = new EpisodeContext(options)) {
                var     service = new EpisodeService(context);
                Episode result  = service.FindByEpisodeForComparingDto(epDto);
                Assert.NotNull(result);
                Assert.Equal(expectedEpisodeName, result.EpisodeName);
            }
        }
示例#11
0
 public RenamerFacade(TVDBRetrieverService retrieverService,
                      TVShowService showService,
                      EpisodeService episodeService,
                      LocalMediaService localService,
                      EpisodeContext context,
                      IRenamePrompter prompter,
                      string tvdbPath)
 {
     _retrieverService = retrieverService;
     _showService      = showService;
     _episodeService   = episodeService;
     _localservice     = localService;
     _context          = context;
     _tvdbInfoFilePath = tvdbPath;
     _prompter         = prompter;
     _tvdbInfo         = TVDBInfo.ReadFromFile(_tvdbInfoFilePath);
 }
        public void AddEpisodeToShow_ShowIsInDB_AddsEp()
        {
            TVShow show = new TVShow()
            {
                SeriesId   = 328487,
                SeriesName = "The Orville"
            };

            Episode ep1 = new Episode()
            {
                SeriesId           = 328487,
                TVDBEpisodeId      = 6089488,
                Season             = 1,
                AiredEpisodeNumber = 1,
                EpisodeName        = "Old Wounds",
                LastUpdated        = DateTimeOffset.FromUnixTimeMilliseconds(1527457806).DateTime.ToLocalTime()
            };

            int    expectedEpisodeId   = 6089488;
            string expectedEpisodeName = "Old Wounds";
            var    options             = new DbContextOptionsBuilder <EpisodeContext>()
                                         .UseInMemoryDatabase(databaseName: "AddEpisodeToShow_ShowIsInDB_AddsEp")
                                         .Options;

            // Act
            using (var context = new EpisodeContext(options)) {
                var service   = new EpisodeService(context);
                var TVService = new TVShowService(context);
                TVService.Add(show);

                service.AddEpisodeToShow(ep1);
            }

            using (var context = new EpisodeContext(options)) {
                var service = new EpisodeService(context);
                var result  = context.Episodes.FirstOrDefault(e => e.TVDBEpisodeId == expectedEpisodeId);

                Assert.NotNull(result);
                Assert.Equal(expectedEpisodeName, result.EpisodeName);
            }
        }
示例#13
0
        public void Add_ShowNotInDB_WritesToDB()
        {
            var options = new DbContextOptionsBuilder <EpisodeContext>()
                          .UseInMemoryDatabase(databaseName: "Add_ShowNotInDB_WritesToDB")
                          .Options;
            TVShow show = new TVShow()
            {
                SeriesId            = 281662,
                SeriesName          = "The Orville",
                SeriesNamePreferred = "Orville"
            };

            using (var context = new EpisodeContext(options)) {
                var service = new TVShowService(context);
                service.Add(show);
            }
            using (var context = new EpisodeContext(options)) {
                Assert.Equal(1, context.Shows.Count());
                Assert.Equal("Orville", context.Shows.Single().SeriesNamePreferred);
            }
        }
        public void FindByEpisodeForComparingDto_EpNotInDB_ReturnsNull()
        {
            TVShow show = new TVShow()
            {
                SeriesId   = 328487,
                SeriesName = "The Orville"
            };
            Episode ep1 = new Episode()
            {
                SeriesId           = 328487,
                TVDBEpisodeId      = 6089488,
                Season             = 1,
                AiredEpisodeNumber = 1,
                EpisodeName        = "Old Wounds"
            };

            EpisodeForComparingDto epDto = new EpisodeForComparingDto()
            {
                SeriesName            = "the chilling adventures of sabrina",
                SeasonNumber          = 1,
                EpisodeNumberInSeason = 1
            };

            var options = new DbContextOptionsBuilder <EpisodeContext>()
                          .UseInMemoryDatabase(databaseName: "FindByEpisodeForComparingDto_EpNotInDB_ReturnsNull")
                          .Options;

            using (var context = new EpisodeContext(options)) {
                var service   = new EpisodeService(context);
                var TVService = new TVShowService(context);
                TVService.Add(show);
                service.Add(ep1);
            }

            using (var context = new EpisodeContext(options)) {
                var     service = new EpisodeService(context);
                Episode result  = service.FindByEpisodeForComparingDto(epDto);
                Assert.Null(result);
            }
        }
示例#15
0
        public void FindByName_ShowNotInDB_ReturnsNull()
        {
            var options = new DbContextOptionsBuilder <EpisodeContext>()
                          .UseInMemoryDatabase(databaseName: "FindByName_ShowNotInDB_ReturnsNull")
                          .Options;
            TVShow show1 = new TVShow()
            {
                SeriesId            = 281662,
                SeriesName          = "Marvel's Daredevil",
                SeriesNamePreferred = "Daredevil"
            };

            using (var context = new EpisodeContext(options)) {
                var service = new TVShowService(context);
                service.Add(show1);
            }
            using (var context = new EpisodeContext(options)) {
                var    service = new TVShowService(context);
                TVShow result  = service.FindByName("Counterpart");
                Assert.Null(result);
            }
        }
示例#16
0
 public TVShowMenu(EpisodeContext context, RenamerFacade facade, TVShowService showService)
 {
     Context     = context;
     Facade      = facade;
     ShowService = showService;
 }
示例#17
0
 public EpisodeService(EpisodeContext context)
 {
     _context = context;
 }
 public ComicRepository(EpisodeContext episodeContext)
 {
     EpisodeContext = episodeContext;
 }
示例#19
0
 public MainMenu(RenamerFacade inputFacade, EpisodeContext context, TVShowService showService)
 {
     Facade      = inputFacade;
     Context     = context;
     ShowService = showService;
 }
示例#20
0
 public TVShowService(EpisodeContext context)
 {
     _context = context;
 }