public void PlatformRegionIdHandlingTest() { using (var temp = TempDirectory.Create()) using (var db = new TestGameDatabase(temp.TempPath)) { db.OpenDatabase(); db.ClearPlatforms(); db.ClearRegions(); var testPlugin = GetTestPlugin(); testPlugin.SetSupportedFields(new List<MetadataField> { MetadataField.Platform, MetadataField.Region }); var addedGame = db.ImportGame(new GameMetadata { Name = "Game1" }); var downloader = new MetadataDownloader(db, new List<MetadataPlugin> { testPlugin }, new List<LibraryPlugin>()); var settings = new MetadataDownloaderSettings { SkipExistingValues = false }; settings.ConfigureFields(new List<Guid> { testPlugin.Id }, true); testPlugin.ReturnMetadata.Platforms = new HashSet<MetadataProperty> { new MetadataSpecProperty("pc_windows") }; testPlugin.ReturnMetadata.Regions = new HashSet<MetadataProperty> { new MetadataSpecProperty("world") }; downloader.DownloadMetadataAsync( db.Games.ToList(), settings, new PlayniteSettings(), null, new CancellationTokenSource().Token).GetAwaiter().GetResult(); Assert.AreEqual("pc_windows", db.Platforms.First().SpecificationId); Assert.AreEqual("pc_windows", addedGame.Platforms[0].SpecificationId); Assert.AreEqual("PC (Windows)", addedGame.Platforms[0].Name); Assert.AreEqual("world", db.Regions.First().SpecificationId); Assert.AreEqual("world", addedGame.Regions[0].SpecificationId); Assert.AreEqual("World", addedGame.Regions[0].Name); } }
public async Task SkipExistingTest() { var path = Path.Combine(PlayniteTests.TempPath, "metadownload.db"); FileSystem.DeleteFile(path); var db = new GameDatabase(null); using (db.OpenDatabase(path)) { db.AddGame(new Game("Game1") { Description = "Description", Developers = new ComparableList <string>() { "Developers" }, Genres = new ComparableList <string>() { "Genres" }, Links = new ObservableCollection <Link>() { new Link("Link", "URL") }, Publishers = new ComparableList <string>() { "Publishers" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new ComparableList <string>() { "Tags" }, Icon = "Icon", Image = "Image", BackgroundImage = "BackgroundImage", UserScore = 1, CommunityScore = 2, CriticScore = 3 }); var igdbProvider = new MockMetadataProvider { GetSupportsIdSearchHandler = () => false, GetGameDataHandler = gameId => { var game = new Game("IGDB Game " + gameId) { Description = $"IGDB Description {gameId}", Developers = new ComparableList <string>() { $"IGDB Developer {gameId}" }, Genres = new ComparableList <string>() { $"IGDB Genre {gameId}" }, Links = new ObservableCollection <Link>() { new Link($"IGDB link {gameId}", $"IGDB link url {gameId}") }, Publishers = new ComparableList <string>() { $"IGDB publisher {gameId}" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new ComparableList <string>() { $"IGDB Tag {gameId}" } }; var icon = new FileDefinition($"IGDBIconPath{gameId}.file", $"IGDBIconName{gameId}.file", randomFile); var image = new FileDefinition($"IGDBImagePath{gameId}.file", $"IGDBImageName{gameId}.file", randomFile); return(new GameMetadata(game, icon, image, $"IGDB backgournd {gameId}")); }, SearchGamesHandler = gameName => { return(new List <MetadataSearchResult>() { new MetadataSearchResult("igdbid1", "Game1", DateTime.Now) }); } }; var downloader = new MockMetadataDownloader(null, null, null, null, igdbProvider); var settings = new MetadataDownloaderSettings() { SkipExistingValues = true }; // No download - all values are kept settings.ConfigureFields(MetadataSource.IGDB, true); await downloader.DownloadMetadata( db.GamesCollection.FindAll().ToList(), db, settings); var dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(0, downloader.CallCount); var game1 = dbGames[0]; Assert.AreEqual("Description", game1.Description); Assert.AreEqual("Developers", game1.Developers[0]); Assert.AreEqual("Genres", game1.Genres[0]); Assert.AreEqual("Link", game1.Links[0].Name); Assert.AreEqual("URL", game1.Links[0].Url); Assert.AreEqual("Publishers", game1.Publishers[0]); Assert.AreEqual("Tags", game1.Tags[0]); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.AreEqual("BackgroundImage", game1.BackgroundImage); Assert.AreEqual("Icon", game1.Icon); Assert.AreEqual("Image", game1.Image); // Single download - values are changed even when present settings.SkipExistingValues = false; await downloader.DownloadMetadata( db.GamesCollection.FindAll().ToList(), db, settings); dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(1, downloader.CallCount); game1 = dbGames[0]; Assert.AreEqual("IGDB Description igdbid1", game1.Description); Assert.AreEqual("IGDB Developer igdbid1", game1.Developers[0]); Assert.AreEqual("IGDB Genre igdbid1", game1.Genres[0]); Assert.AreEqual("IGDB link igdbid1", game1.Links[0].Name); Assert.AreEqual("IGDB link url igdbid1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher igdbid1", game1.Publishers[0]); Assert.AreEqual("IGDB Tag igdbid1", game1.Tags[0]); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.AreEqual("IGDB backgournd igdbid1", game1.BackgroundImage); Assert.AreEqual($"IGDBIconPathigdbid1.file", game1.Icon); Assert.AreEqual($"IGDBImagePathigdbid1.file", game1.Image); // Single download - values are changed when skip enabled and values are not present downloader.CallCount = 0; settings.SkipExistingValues = true; db.DeleteGame(game1); db.AddGame(new Game("Game1")); await downloader.DownloadMetadata( db.GamesCollection.FindAll().ToList(), db, settings); dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(1, downloader.CallCount); game1 = dbGames[0]; Assert.AreEqual("IGDB Description igdbid1", game1.Description); Assert.AreEqual("IGDB Developer igdbid1", game1.Developers[0]); Assert.AreEqual("IGDB Genre igdbid1", game1.Genres[0]); Assert.AreEqual("IGDB link igdbid1", game1.Links[0].Name); Assert.AreEqual("IGDB link url igdbid1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher igdbid1", game1.Publishers[0]); Assert.AreEqual("IGDB Tag igdbid1", game1.Tags[0]); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.AreEqual("IGDB backgournd igdbid1", game1.BackgroundImage); Assert.AreEqual($"IGDBIconPathigdbid1.file", game1.Icon); Assert.AreEqual($"IGDBImagePathigdbid1.file", game1.Image); } }
public async Task MissingDataTest() { // Test that downloader doesn't change existing values to null when missing by provider var path = Path.Combine(PlayniteTests.TempPath, "metadownload.db"); FileSystem.DeleteFile(path); var db = new GameDatabase(null); using (db.OpenDatabase(path)) { var games = new List <Game>() { new Game("Game") { Provider = Provider.Steam, ProviderId = "storeId", Genres = new ComparableList <string>() { "Genre" }, ReleaseDate = new DateTime(2012, 6, 6), Developers = new ComparableList <string>() { "Developer" }, Publishers = new ComparableList <string>() { "Publisher" }, Tags = new ComparableList <string>() { "Tag" }, Description = "Description", Links = new ObservableCollection <Link>() { new Link() }, Icon = "icon", Image = "image", BackgroundImage = "backImage" } }; db.AddGames(games); var igdbProvider = new MockMetadataProvider(); var storeProvider = new MockMetadataProvider { GetSupportsIdSearchHandler = () => true, GetGameDataHandler = (gameId) => { return(new GameMetadata(new Game("Store Game " + gameId), null, null, null)); } }; var downloader = new MockMetadataDownloader(storeProvider, storeProvider, storeProvider, storeProvider, igdbProvider); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; var dbGames = db.GamesCollection.FindAll().ToList(); var f = dbGames[0].ReleaseDate; var s = games[0].ReleaseDate; settings.ConfigureFields(MetadataSource.Store, true); await downloader.DownloadMetadata( db.GamesCollection.FindAll().ToList(), db, settings); dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(1, downloader.CallCount); var game = dbGames[0]; Assert.AreEqual("Description", game.Description); Assert.AreEqual("icon", game.Icon); Assert.AreEqual("image", game.Image); Assert.AreEqual("backImage", game.BackgroundImage); Assert.AreEqual("Developer", game.Developers[0]); Assert.AreEqual("Publisher", game.Publishers[0]); Assert.AreEqual("Genre", game.Genres[0]); CollectionAssert.IsNotEmpty(game.Links); Assert.AreEqual("Tag", game.Tags[0]); Assert.AreEqual(2012, game.ReleaseDate.Value.Year); } }
public async Task IGDBSourceTest() { var path = Path.Combine(PlayniteTests.TempPath, "metadownload.db"); FileSystem.DeleteFile(path); var db = new GameDatabase(null); using (db.OpenDatabase(path)) { var games = new List <Game>() { new Game("Game1"), new Game("Game2") { Provider = Provider.Steam, ProviderId = "Game2" }, new Game("Game3") // just to test that nonexistent game doesn't throw exception }; db.AddGames(games); var igdbProvider = new MockMetadataProvider { GetSupportsIdSearchHandler = () => false, GetGameDataHandler = gameId => { var game = new Game("IGDB Game " + gameId) { Description = $"IGDB Description {gameId}", Developers = new ComparableList <string>() { $"IGDB Developer {gameId}" }, Genres = new ComparableList <string>() { $"IGDB Genre {gameId}" }, Links = new ObservableCollection <Link>() { new Link($"IGDB link {gameId}", $"IGDB link url {gameId}") }, Publishers = new ComparableList <string>() { $"IGDB publisher {gameId}" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new ComparableList <string>() { $"IGDB Tag {gameId}" } }; var icon = new FileDefinition($"IGDBIconPath{gameId}.file", $"IGDBIconName{gameId}.file", randomFile); var image = new FileDefinition($"IGDBImagePath{gameId}.file", $"IGDBImageName{gameId}.file", randomFile); return(new GameMetadata(game, icon, image, $"IGDB backgournd {gameId}")); }, SearchGamesHandler = gameName => { return(new List <MetadataSearchResult>() { new MetadataSearchResult("igdbid1", "Game1", DateTime.Now), new MetadataSearchResult("igdbid2", "Game2", DateTime.Now) }); } }; var storeProvider = new MockMetadataProvider { GetSupportsIdSearchHandler = () => true, GetGameDataHandler = (gameId) => { var game = new Game(gameId); return(new GameMetadata(game, null, null, string.Empty)); } }; var downloader = new MockMetadataDownloader(storeProvider, storeProvider, storeProvider, storeProvider, igdbProvider); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; settings.ConfigureFields(MetadataSource.IGDB, true); await downloader.DownloadMetadata( db.GamesCollection.FindAll().ToList(), db, settings); var dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(3, downloader.CallCount); var game1 = dbGames[0]; Assert.AreEqual("IGDB Description igdbid1", game1.Description); Assert.AreEqual("IGDB Developer igdbid1", game1.Developers[0]); Assert.AreEqual("IGDB Genre igdbid1", game1.Genres[0]); Assert.AreEqual("IGDB link igdbid1", game1.Links[0].Name); Assert.AreEqual("IGDB link url igdbid1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher igdbid1", game1.Publishers[0]); Assert.AreEqual("IGDB Tag igdbid1", game1.Tags[0]); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.AreEqual("IGDB backgournd igdbid1", game1.BackgroundImage); Assert.AreEqual($"IGDBIconPathigdbid1.file", game1.Icon); Assert.AreEqual($"IGDBImagePathigdbid1.file", game1.Image); var game2 = dbGames[1]; Assert.AreEqual("IGDB Description igdbid2", game2.Description); Assert.AreEqual(4, db.Database.FileStorage.FindAll().Count()); } }
public async Task StoreSourceTest() { var path = Path.Combine(PlayniteTests.TempPath, "metadownload.db"); FileSystem.DeleteFile(path); var db = new GameDatabase(null); using (db.OpenDatabase(path)) { var games = new List <Game>() { new Game("Game1"), new Game("Game2") { Provider = Provider.Steam, ProviderId = "storeId" }, new Game("Game3") // just to test that nonexistent game doesn't throw exception }; db.AddGames(games); var igdbProvider = new MockMetadataProvider(); var storeProvider = new MockMetadataProvider { GetSupportsIdSearchHandler = () => true, GetGameDataHandler = (gameId) => { var game = new Game("Store Game " + gameId) { Description = $"Store Description {gameId}", Developers = new ComparableList <string>() { $"Store Developer {gameId}" }, Genres = new ComparableList <string>() { $"Store Genre {gameId}" }, Links = new ObservableCollection <Link>() { new Link($"Store link {gameId}", $"Store link url {gameId}") }, Publishers = new ComparableList <string>() { $"Store publisher {gameId}" }, ReleaseDate = new DateTime(2016, 2, 2), Tags = new ComparableList <string>() { $"Store Tag {gameId}" } }; var icon = new FileDefinition($"StoreIconPath{gameId}.file", $"StoreIconName{gameId}.file", randomFile); var image = new FileDefinition($"StoreImagePath{gameId}.file", $"StoreImageName{gameId}.file", randomFile); return(new GameMetadata(game, icon, image, $"Store backgournd {gameId}")); } }; var downloader = new MockMetadataDownloader(storeProvider, storeProvider, storeProvider, storeProvider, igdbProvider); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; settings.ConfigureFields(MetadataSource.Store, true); await downloader.DownloadMetadata( db.GamesCollection.FindAll().ToList(), db, settings); var dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(1, downloader.CallCount); var game2 = dbGames[1]; Assert.AreEqual("Store Description storeId", game2.Description); Assert.AreEqual("Store Developer storeId", game2.Developers[0]); Assert.AreEqual("Store Genre storeId", game2.Genres[0]); Assert.AreEqual("Store link storeId", game2.Links[0].Name); Assert.AreEqual("Store link url storeId", game2.Links[0].Url); Assert.AreEqual("Store publisher storeId", game2.Publishers[0]); Assert.AreEqual("Store Tag storeId", game2.Tags[0]); Assert.AreEqual(2016, game2.ReleaseDate.Value.Year); Assert.AreEqual("Store backgournd storeId", game2.BackgroundImage); Assert.AreEqual($"StoreIconPathstoreId.file", game2.Icon); Assert.AreEqual($"StoreImagePathstoreId.file", game2.Image); var game1 = dbGames[0]; Assert.IsNull(game1.Description); Assert.AreEqual(2, db.Database.FileStorage.FindAll().Count()); } }
public async Task SkipExistingTest() { // Tests that existing data are not overriden even if metadata provider has them. var testPlugin = GetTestPlugin(); testPlugin.SetSupportedFields(new List <MetadataField> { MetadataField.Description, MetadataField.Icon, MetadataField.CoverImage, MetadataField.BackgroundImage, MetadataField.Links, MetadataField.Publishers, MetadataField.Developers, MetadataField.Tags, MetadataField.Genres, MetadataField.ReleaseDate }); var gameId = "Game1"; var icon = new MetadataFile($"IGDBIconName{gameId}.file", randomFile); var image = new MetadataFile($"IGDBImageName{gameId}.file", randomFile); var background = new MetadataFile($"IGDB backgournd {gameId}"); testPlugin.ReturnMetadata = new GameMetadata(new GameInfo() { Name = "IGDB Game " + gameId, Description = $"IGDB Description {gameId}", Developers = new List <string>() { $"IGDB Developer {gameId}" }, Genres = new List <string>() { $"IGDB Genre {gameId}" }, Links = new List <Link>() { new Link($"IGDB link {gameId}", $"IGDB link url {gameId}") }, Publishers = new List <string>() { $"IGDB publisher {gameId}" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new List <string>() { $"IGDB Tag {gameId}" } }, icon, image, background); List <MetadataPlugin> metadataDownloaders = new List <MetadataPlugin>() { testPlugin }; using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); Game.DatabaseReference = db; var addedGame = db.ImportGame(new GameInfo() { Name = "Game1", Description = "Description", Developers = new List <string>() { "Developers" }, Genres = new List <string>() { "Genres" }, Links = new List <Link>() { new Link("Link", "URL") }, Publishers = new List <string>() { "Publishers" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new List <string>() { "Tags" }, UserScore = 1, CommunityScore = 2, CriticScore = 3 }); addedGame.Icon = "Icon"; addedGame.CoverImage = "Image"; addedGame.BackgroundImage = "BackgroundImage"; var downloader = new MetadataDownloader(db, metadataDownloaders, new List <LibraryPlugin>()); var settings = new MetadataDownloaderSettings() { SkipExistingValues = true }; // No download - all values are kept settings.ConfigureFields(new List <Guid> { testPlugin.Id }, true); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, new PlayniteSettings(), null, null); var dbGames = db.Games.ToList(); Assert.AreEqual(0, testPlugin.CallCount); var game1 = dbGames[0]; Assert.AreEqual("Description", game1.Description); Assert.AreEqual("Developers", game1.Developers[0].Name); Assert.AreEqual("Genres", game1.Genres[0].Name); Assert.AreEqual("Link", game1.Links[0].Name); Assert.AreEqual("URL", game1.Links[0].Url); Assert.AreEqual("Publishers", game1.Publishers[0].Name); Assert.AreEqual("Tags", game1.Tags[0].Name); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.IsNotEmpty(game1.BackgroundImage); Assert.IsNotEmpty(game1.Icon); Assert.IsNotEmpty(game1.CoverImage); // Single download - values are changed even when present settings.SkipExistingValues = false; await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, new PlayniteSettings(), null, null); dbGames = db.Games.ToList(); Assert.AreEqual(1, testPlugin.CallCount); game1 = dbGames[0]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.AreEqual("IGDB Developer Game1", game1.Developers[0].Name); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0].Name); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0].Name); Assert.AreEqual("IGDB Tag Game1", game1.Tags[0].Name); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.IsNotEmpty(game1.BackgroundImage); Assert.IsNotEmpty(game1.Icon); Assert.IsNotEmpty(game1.CoverImage); // Single download - values are changed when skip enabled and values are not present testPlugin.CallCount = 0; settings.SkipExistingValues = true; db.Games.Remove(game1); db.Games.Add(new Game("Game1")); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, new PlayniteSettings(), null, null); dbGames = db.Games.ToList(); Assert.AreEqual(1, testPlugin.CallCount); game1 = dbGames[0]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.AreEqual("IGDB Developer Game1", game1.Developers[0].Name); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0].Name); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0].Name); Assert.AreEqual("IGDB Tag Game1", game1.Tags[0].Name); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.IsNotEmpty(game1.BackgroundImage); Assert.IsNotEmpty(game1.Icon); Assert.IsNotEmpty(game1.CoverImage); } }
public async Task MissingDataTest() { // Tests that existing data are not overriden by empty metadata from external providers. var storeId = Guid.NewGuid(); var storeDownloader = GetTestLibraryProvider(); storeDownloader.ReturnMetadata = GameMetadata.GetEmptyData(); var testPlugin = GetTestPlugin(); testPlugin.ReturnMetadata = GameMetadata.GetEmptyData(); testPlugin.SetSupportedFields(new List <MetadataField> { MetadataField.Description, MetadataField.Icon, MetadataField.CoverImage, MetadataField.BackgroundImage, MetadataField.Links, MetadataField.Publishers, MetadataField.Developers, MetadataField.Tags, MetadataField.Genres, MetadataField.ReleaseDate }); List <MetadataPlugin> metadataDownloaders = new List <MetadataPlugin>() { testPlugin }; Dictionary <Guid, LibraryMetadataProvider> libraryDownloaders = new Dictionary <Guid, LibraryMetadataProvider>() { { storeId, storeDownloader } }; using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); Game.DatabaseReference = db; var importedGame = db.ImportGame(new GameInfo() { Name = "Game", GameId = "storeId", Genres = new List <string>() { "Genre" }, ReleaseDate = new DateTime(2012, 6, 6), Developers = new List <string>() { "Developer" }, Publishers = new List <string>() { "Publisher" }, Tags = new List <string>() { "Tag" }, Description = "Description", Links = new List <Link>() { new Link() } }); importedGame.PluginId = storeId; importedGame.Icon = "icon"; importedGame.CoverImage = "image"; importedGame.BackgroundImage = "backImage"; db.Games.Update(importedGame); var downloader = new MetadataDownloader(db, metadataDownloaders, libraryDownloaders); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; var dbGames = db.Games.ToList(); var f = dbGames[0].ReleaseDate; var s = importedGame.ReleaseDate; settings.ConfigureFields(new List <Guid> { testPlugin.Id, Guid.Empty }, true); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, new PlayniteSettings(), null, null); dbGames = db.Games.ToList(); Assert.AreEqual(1, testPlugin.CallCount); Assert.AreEqual(1, storeDownloader.CallCount); var game = dbGames[0]; Assert.AreEqual("Description", game.Description); Assert.AreEqual("icon", game.Icon); Assert.AreEqual("image", game.CoverImage); Assert.AreEqual("backImage", game.BackgroundImage); Assert.AreEqual("Developer", game.Developers[0].Name); Assert.AreEqual("Publisher", game.Publishers[0].Name); Assert.AreEqual("Genre", game.Genres[0].Name); CollectionAssert.IsNotEmpty(game.Links); Assert.AreEqual("Tag", game.Tags[0].Name); Assert.AreEqual(2012, game.ReleaseDate.Value.Year); } }
public async Task SkipExistingTest() { var db = new GameDatabase(null); using (db.OpenDatabase(new MemoryStream())) { int callCount = 0; db.AddGame(new Game("Game1") { Description = "Description", Developers = new ComparableList <string>() { "Developers" }, Genres = new ComparableList <string>() { "Genres" }, Links = new ObservableCollection <Link>() { new Link("Link", "URL") }, Publishers = new ComparableList <string>() { "Publishers" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new ComparableList <string>() { "Tags" }, Icon = "Icon", CoverImage = "Image", BackgroundImage = "BackgroundImage", UserScore = 1, CommunityScore = 2, CriticScore = 3 }); var igdbProvider = new Mock <ILibraryMetadataProvider>(); igdbProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; var gameId = g.Name; var game = new Game("IGDB Game " + gameId) { Description = $"IGDB Description {gameId}", Developers = new ComparableList <string>() { $"IGDB Developer {gameId}" }, Genres = new ComparableList <string>() { $"IGDB Genre {gameId}" }, Links = new ObservableCollection <Link>() { new Link($"IGDB link {gameId}", $"IGDB link url {gameId}") }, Publishers = new ComparableList <string>() { $"IGDB publisher {gameId}" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new ComparableList <string>() { $"IGDB Tag {gameId}" } }; var icon = new MetadataFile($"IGDBIconPath{gameId}.file", $"IGDBIconName{gameId}.file", randomFile); var image = new MetadataFile($"IGDBImagePath{gameId}.file", $"IGDBImageName{gameId}.file", randomFile); return(new GameMetadata(game, icon, image, $"IGDB backgournd {gameId}")); }); var downloader = new MetadataDownloader(igdbProvider.Object, null); var settings = new MetadataDownloaderSettings() { SkipExistingValues = true }; // No download - all values are kept settings.ConfigureFields(MetadataSource.IGDB, true); await downloader.DownloadMetadataAsync( db.GamesCollection.FindAll().ToList(), db, settings, null, null); var dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(0, callCount); var game1 = dbGames[0]; Assert.AreEqual("Description", game1.Description); Assert.AreEqual("Developers", game1.Developers[0]); Assert.AreEqual("Genres", game1.Genres[0]); Assert.AreEqual("Link", game1.Links[0].Name); Assert.AreEqual("URL", game1.Links[0].Url); Assert.AreEqual("Publishers", game1.Publishers[0]); Assert.AreEqual("Tags", game1.Tags[0]); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.AreEqual("BackgroundImage", game1.BackgroundImage); Assert.AreEqual("Icon", game1.Icon); Assert.AreEqual("Image", game1.CoverImage); // Single download - values are changed even when present settings.SkipExistingValues = false; await downloader.DownloadMetadataAsync( db.GamesCollection.FindAll().ToList(), db, settings, null, null); dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(1, callCount); game1 = dbGames[0]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.AreEqual("IGDB Developer Game1", game1.Developers[0]); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0]); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0]); Assert.AreEqual("IGDB Tag Game1", game1.Tags[0]); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.AreEqual("IGDB backgournd Game1", game1.BackgroundImage); Assert.AreEqual($"IGDBIconPathGame1.file", game1.Icon); Assert.AreEqual($"IGDBImagePathGame1.file", game1.CoverImage); // Single download - values are changed when skip enabled and values are not present callCount = 0; settings.SkipExistingValues = true; db.DeleteGame(game1); db.AddGame(new Game("Game1")); await downloader.DownloadMetadataAsync( db.GamesCollection.FindAll().ToList(), db, settings, null, null); dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(1, callCount); game1 = dbGames[0]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.AreEqual("IGDB Developer Game1", game1.Developers[0]); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0]); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0]); Assert.AreEqual("IGDB Tag Game1", game1.Tags[0]); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.AreEqual("IGDB backgournd Game1", game1.BackgroundImage); Assert.AreEqual($"IGDBIconPathGame1.file", game1.Icon); Assert.AreEqual($"IGDBImagePathGame1.file", game1.CoverImage); } }
public async Task IGDBSourceTest() { var db = new GameDatabase(null); using (db.OpenDatabase(new MemoryStream())) { int callCount = 0; var storeCalled = false; var games = new List <Game>() { new Game("Game1"), new Game("Game2") { PluginId = storePluginId, GameId = "Game2" }, new Game("Game3") }; db.AddGames(games); var igdbProvider = new Mock <ILibraryMetadataProvider>(); igdbProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; if (g.Name == "Game3") { return(GameMetadata.GetEmptyData()); } var gameId = g.Name; var game = new Game("IGDB Game " + gameId) { Description = $"IGDB Description {gameId}", Developers = new ComparableList <string>() { $"IGDB Developer {gameId}" }, Genres = new ComparableList <string>() { $"IGDB Genre {gameId}" }, Links = new ObservableCollection <Link>() { new Link($"IGDB link {gameId}", $"IGDB link url {gameId}") }, Publishers = new ComparableList <string>() { $"IGDB publisher {gameId}" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new ComparableList <string>() { $"IGDB Tag {gameId}" } }; var icon = new MetadataFile($"IGDBIconPath{gameId}.file", $"IGDBIconName{gameId}.file", randomFile); var image = new MetadataFile($"IGDBImagePath{gameId}.file", $"IGDBImageName{gameId}.file", randomFile); return(new GameMetadata(game, icon, image, $"IGDB backgournd {gameId}")); }); var storeProvider = new Mock <ILibraryMetadataProvider>(); storeProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; storeCalled = true; return(GameMetadata.GetEmptyData()); }); var downloader = new MetadataDownloader(igdbProvider.Object, GetLibraryPlugins(storeProvider.Object, storePluginId)); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; settings.ConfigureFields(MetadataSource.IGDB, true); await downloader.DownloadMetadataAsync( db.GamesCollection.FindAll().ToList(), db, settings, null, null); var dbGames = db.GamesCollection.FindAll().ToList(); Assert.IsFalse(storeCalled); Assert.AreEqual(3, callCount); var game1 = dbGames[0]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.AreEqual("IGDB Developer Game1", game1.Developers[0]); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0]); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0]); Assert.AreEqual("IGDB Tag Game1", game1.Tags[0]); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.AreEqual("IGDB backgournd Game1", game1.BackgroundImage); Assert.AreEqual($"IGDBIconPathGame1.file", game1.Icon); Assert.AreEqual($"IGDBImagePathGame1.file", game1.CoverImage); var game2 = dbGames[1]; Assert.AreEqual("IGDB Description Game2", game2.Description); Assert.AreEqual(4, db.Database.FileStorage.FindAll().Count()); } }
public async Task MissingDataTest() { var db = new GameDatabase(null); using (db.OpenDatabase(new MemoryStream())) { int callCount = 0; var games = new List <Game>() { new Game("Game") { PluginId = storePluginId, GameId = "storeId", Genres = new ComparableList <string>() { "Genre" }, ReleaseDate = new DateTime(2012, 6, 6), Developers = new ComparableList <string>() { "Developer" }, Publishers = new ComparableList <string>() { "Publisher" }, Tags = new ComparableList <string>() { "Tag" }, Description = "Description", Links = new ObservableCollection <Link>() { new Link() }, Icon = "icon", CoverImage = "image", BackgroundImage = "backImage" } }; db.AddGames(games); var igdbProvider = new Mock <ILibraryMetadataProvider>(); igdbProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; return(GameMetadata.GetEmptyData()); }); var storeProvider = new Mock <ILibraryMetadataProvider>(); storeProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; var gameId = g.GameId; return(new GameMetadata(new Game("Store Game " + gameId), null, null, null)); }); var downloader = new MetadataDownloader(igdbProvider.Object, GetLibraryPlugins(storeProvider.Object, storePluginId)); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; var dbGames = db.GamesCollection.FindAll().ToList(); var f = dbGames[0].ReleaseDate; var s = games[0].ReleaseDate; settings.ConfigureFields(MetadataSource.Store, true); await downloader.DownloadMetadataAsync( db.GamesCollection.FindAll().ToList(), db, settings, null, null); dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(1, callCount); var game = dbGames[0]; Assert.AreEqual("Description", game.Description); Assert.AreEqual("icon", game.Icon); Assert.AreEqual("image", game.CoverImage); Assert.AreEqual("backImage", game.BackgroundImage); Assert.AreEqual("Developer", game.Developers[0]); Assert.AreEqual("Publisher", game.Publishers[0]); Assert.AreEqual("Genre", game.Genres[0]); CollectionAssert.IsNotEmpty(game.Links); Assert.AreEqual("Tag", game.Tags[0]); Assert.AreEqual(2012, game.ReleaseDate.Value.Year); } }
public async Task IGDBStoreCombinedTest() { using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); int callCount = 0; var games = new List <Game>() { new Game("Game1"), new Game("Game2") { PluginId = storePluginId, GameId = "Game2" }, new Game("Game3") }; db.Games.Add(games); var igdbProvider = new Mock <ILibraryMetadataProvider>(); igdbProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; var gameId = g.Name; var game = new Game("IGDB Game " + gameId); game.Description = $"IGDB Description {gameId}"; game.Genres = new ComparableList <string>() { $"IGDB Genre {gameId}" }; game.Links = new ObservableCollection <Link>() { new Link($"IGDB link {gameId}", $"IGDB link url {gameId}") }; game.Publishers = new ComparableList <string>() { $"IGDB publisher {gameId}" }; game.ReleaseDate = new DateTime(2012, 6, 6); var icon = new MetadataFile($"IGDBIconName{gameId}.file", randomFile); var image = new MetadataFile($"IGDBImageName{gameId}.file", randomFile); return(new GameMetadata(game, icon, image, $"IGDB backgournd {gameId}")); }); var storeProvider = new Mock <ILibraryMetadataProvider>(); storeProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; var gameId = g.GameId; var game = new Game(gameId); game.Description = $"Store Description {gameId}"; game.Developers = new ComparableList <string>() { $"Store Developer {gameId}" }; game.Links = new ObservableCollection <Link>() { new Link($"Store link {gameId}", $"Store link url {gameId}") }; game.Publishers = new ComparableList <string>() { $"Store publisher {gameId}" }; game.ReleaseDate = new DateTime(2016, 2, 2); var icon = new MetadataFile($"StoreIconName{gameId}.file", randomFile); var image = new MetadataFile($"StoreImageName{gameId}.file", randomFile); return(new GameMetadata(game, icon, image, $"Store backgournd {gameId}")); }); var downloader = new MetadataDownloader(db, igdbProvider.Object, GetLibraryPlugins(storeProvider.Object, storePluginId)); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; // IGDB over Store settings.ConfigureFields(MetadataSource.IGDBOverStore, true); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, null, null); Assert.AreEqual(4, callCount); var game1 = db.Games[games[0].Id]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.IsNull(game1.Developers); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0]); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0]); Assert.IsNull(game1.Tags); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.IsNotEmpty(game1.BackgroundImage); Assert.IsNotEmpty(game1.Icon); Assert.IsNotEmpty(game1.CoverImage); var game2 = db.Games[games[1].Id]; Assert.AreEqual("IGDB Description Game2", game2.Description); Assert.AreEqual("Store Developer Game2", game2.Developers[0]); Assert.AreEqual("IGDB Genre Game2", game2.Genres[0]); Assert.AreEqual("IGDB link Game2", game2.Links[0].Name); Assert.AreEqual("IGDB link url Game2", game2.Links[0].Url); Assert.AreEqual("IGDB publisher Game2", game2.Publishers[0]); Assert.IsNull(game2.Tags); Assert.AreEqual(2012, game2.ReleaseDate.Value.Year); Assert.IsNotEmpty(game2.BackgroundImage); Assert.IsNotEmpty(game2.Icon); Assert.IsNotEmpty(game2.CoverImage); // Store over IGDB callCount = 0; settings.ConfigureFields(MetadataSource.StoreOverIGDB, true); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, null, null); Assert.AreEqual(4, callCount); game1 = db.Games[games[0].Id]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.IsNull(game1.Developers); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0]); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0]); Assert.IsNull(game1.Tags); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.IsNotEmpty(game1.BackgroundImage); Assert.IsNotEmpty(game1.Icon); Assert.IsNotEmpty(game1.CoverImage); game2 = db.Games[games[1].Id]; Assert.AreEqual("Store Description Game2", game2.Description); Assert.AreEqual("Store Developer Game2", game2.Developers[0]); Assert.AreEqual("IGDB Genre Game2", game2.Genres[0]); Assert.AreEqual("Store link Game2", game2.Links[0].Name); Assert.AreEqual("Store link url Game2", game2.Links[0].Url); Assert.AreEqual("Store publisher Game2", game2.Publishers[0]); Assert.IsNull(game2.Tags); Assert.AreEqual(2016, game2.ReleaseDate.Value.Year); Assert.IsNotEmpty(game2.BackgroundImage); Assert.IsNotEmpty(game2.Icon); Assert.IsNotEmpty(game2.CoverImage); } }
public async Task StoreSourceTest() { using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); int callCount = 0; var igdbCalled = false; var games = new List <Game>() { new Game("Game1"), new Game("Game2") { PluginId = storePluginId, GameId = "storeId" }, new Game("Game3") }; db.Games.Add(games); var igdbProvider = new Mock <ILibraryMetadataProvider>(); igdbProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; igdbCalled = true; return(GameMetadata.GetEmptyData()); }); var storeProvider = new Mock <ILibraryMetadataProvider>(); storeProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; var gameId = g.GameId; var game = new Game("Store Game " + gameId) { Description = $"Store Description {gameId}", Developers = new ComparableList <string>() { $"Store Developer {gameId}" }, Genres = new ComparableList <string>() { $"Store Genre {gameId}" }, Links = new ObservableCollection <Link>() { new Link($"Store link {gameId}", $"Store link url {gameId}") }, Publishers = new ComparableList <string>() { $"Store publisher {gameId}" }, ReleaseDate = new DateTime(2016, 2, 2), Tags = new ComparableList <string>() { $"Store Tag {gameId}" } }; var icon = new MetadataFile($"StoreIconName{gameId}.file", randomFile); var image = new MetadataFile($"StoreImageName{gameId}.file", randomFile); return(new GameMetadata(game, icon, image, $"Store backgournd {gameId}")); }); var downloader = new MetadataDownloader(db, igdbProvider.Object, GetLibraryPlugins(storeProvider.Object, storePluginId)); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; settings.ConfigureFields(MetadataSource.Store, true); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, null, null); Assert.AreEqual(1, callCount); Assert.IsFalse(igdbCalled); var game2 = db.Games[games[1].Id]; Assert.AreEqual("Store Description storeId", game2.Description); Assert.AreEqual("Store Developer storeId", game2.Developers[0]); Assert.AreEqual("Store Genre storeId", game2.Genres[0]); Assert.AreEqual("Store link storeId", game2.Links[0].Name); Assert.AreEqual("Store link url storeId", game2.Links[0].Url); Assert.AreEqual("Store publisher storeId", game2.Publishers[0]); Assert.AreEqual("Store Tag storeId", game2.Tags[0]); Assert.AreEqual(2016, game2.ReleaseDate.Value.Year); Assert.IsNotEmpty(game2.BackgroundImage); Assert.IsNotEmpty(game2.Icon); Assert.IsNotEmpty(game2.CoverImage); var game1 = db.Games[games[0].Id]; Assert.IsNull(game1.Description); Assert.AreEqual(2, Directory.GetFiles(db.GetFileStoragePath(game2.Id)).Count()); Assert.AreEqual(0, Directory.GetFiles(db.GetFileStoragePath(game1.Id)).Count()); } }
public async Task StoreSourceTest() { var db = new GameDatabase(null); using (db.OpenDatabase(new MemoryStream())) { int callCount = 0; var games = new List <Game>() { new Game("Game1"), new Game("Game2") { Provider = Provider.Steam, ProviderId = "storeId" }, new Game("Game3") }; db.AddGames(games); var igdbProvider = new Mock <IMetadataProvider>(); igdbProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; return(GameMetadata.Empty); }); var storeProvider = new Mock <IMetadataProvider>(); storeProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; var gameId = g.ProviderId; var game = new Game("Store Game " + gameId) { Description = $"Store Description {gameId}", Developers = new ComparableList <string>() { $"Store Developer {gameId}" }, Genres = new ComparableList <string>() { $"Store Genre {gameId}" }, Links = new ObservableCollection <Link>() { new Link($"Store link {gameId}", $"Store link url {gameId}") }, Publishers = new ComparableList <string>() { $"Store publisher {gameId}" }, ReleaseDate = new DateTime(2016, 2, 2), Tags = new ComparableList <string>() { $"Store Tag {gameId}" } }; var icon = new MetadataFile($"StoreIconPath{gameId}.file", $"StoreIconName{gameId}.file", randomFile); var image = new MetadataFile($"StoreImagePath{gameId}.file", $"StoreImageName{gameId}.file", randomFile); return(new GameMetadata(game, icon, image, $"Store backgournd {gameId}")); }); var downloader = new MetadataDownloader(storeProvider.Object, storeProvider.Object, storeProvider.Object, storeProvider.Object, igdbProvider.Object); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; settings.ConfigureFields(MetadataSource.Store, true); await downloader.DownloadMetadataAsync( db.GamesCollection.FindAll().ToList(), db, settings, null, null); var dbGames = db.GamesCollection.FindAll().ToList(); Assert.AreEqual(1, callCount); var game2 = dbGames[1]; Assert.AreEqual("Store Description storeId", game2.Description); Assert.AreEqual("Store Developer storeId", game2.Developers[0]); Assert.AreEqual("Store Genre storeId", game2.Genres[0]); Assert.AreEqual("Store link storeId", game2.Links[0].Name); Assert.AreEqual("Store link url storeId", game2.Links[0].Url); Assert.AreEqual("Store publisher storeId", game2.Publishers[0]); Assert.AreEqual("Store Tag storeId", game2.Tags[0]); Assert.AreEqual(2016, game2.ReleaseDate.Value.Year); Assert.AreEqual("Store backgournd storeId", game2.BackgroundImage); Assert.AreEqual($"StoreIconPathstoreId.file", game2.Icon); Assert.AreEqual($"StoreImagePathstoreId.file", game2.Image); var game1 = dbGames[0]; Assert.IsNull(game1.Description); Assert.AreEqual(2, db.Database.FileStorage.FindAll().Count()); } }
public async Task SkipExistingTest() { using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); Game.DatabaseReference = db; int callCount = 0; var addedGame = db.ImportGame(new GameInfo() { Name = "Game1", Description = "Description", Developers = new List <string>() { "Developers" }, Genres = new List <string>() { "Genres" }, Links = new List <Link>() { new Link("Link", "URL") }, Publishers = new List <string>() { "Publishers" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new List <string>() { "Tags" }, UserScore = 1, CommunityScore = 2, CriticScore = 3 }); addedGame.Icon = "Icon"; addedGame.CoverImage = "Image"; addedGame.BackgroundImage = "BackgroundImage"; var igdbProvider = new Mock <LibraryMetadataProvider>(); igdbProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; var gameId = g.Name; var game = new GameInfo() { Name = "IGDB Game " + gameId, Description = $"IGDB Description {gameId}", Developers = new List <string>() { $"IGDB Developer {gameId}" }, Genres = new List <string>() { $"IGDB Genre {gameId}" }, Links = new List <Link>() { new Link($"IGDB link {gameId}", $"IGDB link url {gameId}") }, Publishers = new List <string>() { $"IGDB publisher {gameId}" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new List <string>() { $"IGDB Tag {gameId}" } }; var icon = new MetadataFile($"IGDBIconName{gameId}.file", randomFile); var image = new MetadataFile($"IGDBImageName{gameId}.file", randomFile); var background = new MetadataFile($"IGDB backgournd {gameId}"); return(new GameMetadata(game, icon, image, background)); }); var downloader = new MetadataDownloader(db, igdbProvider.Object, null); var settings = new MetadataDownloaderSettings() { SkipExistingValues = true }; // No download - all values are kept settings.ConfigureFields(MetadataSource.IGDB, true); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, null, null); var dbGames = db.Games.ToList(); Assert.AreEqual(0, callCount); var game1 = dbGames[0]; Assert.AreEqual("Description", game1.Description); Assert.AreEqual("Developers", game1.Developers[0].Name); Assert.AreEqual("Genres", game1.Genres[0].Name); Assert.AreEqual("Link", game1.Links[0].Name); Assert.AreEqual("URL", game1.Links[0].Url); Assert.AreEqual("Publishers", game1.Publishers[0].Name); Assert.AreEqual("Tags", game1.Tags[0].Name); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.IsNotEmpty(game1.BackgroundImage); Assert.IsNotEmpty(game1.Icon); Assert.IsNotEmpty(game1.CoverImage); // Single download - values are changed even when present settings.SkipExistingValues = false; await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, null, null); dbGames = db.Games.ToList(); Assert.AreEqual(1, callCount); game1 = dbGames[0]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.AreEqual("IGDB Developer Game1", game1.Developers[0].Name); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0].Name); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0].Name); Assert.AreEqual("IGDB Tag Game1", game1.Tags[0].Name); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.IsNotEmpty(game1.BackgroundImage); Assert.IsNotEmpty(game1.Icon); Assert.IsNotEmpty(game1.CoverImage); // Single download - values are changed when skip enabled and values are not present callCount = 0; settings.SkipExistingValues = true; db.Games.Remove(game1); db.Games.Add(new Game("Game1")); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, null, null); dbGames = db.Games.ToList(); Assert.AreEqual(1, callCount); game1 = dbGames[0]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.AreEqual("IGDB Developer Game1", game1.Developers[0].Name); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0].Name); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0].Name); Assert.AreEqual("IGDB Tag Game1", game1.Tags[0].Name); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.IsNotEmpty(game1.BackgroundImage); Assert.IsNotEmpty(game1.Icon); Assert.IsNotEmpty(game1.CoverImage); } }
public async Task IGDBSourceTest() { using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); Game.DatabaseReference = db; int callCount = 0; var storeCalled = false; var games = new List <Game>() { new Game("Game1"), new Game("Game2") { PluginId = storePluginId, GameId = "Game2" }, new Game("Game3") }; db.Games.Add(games); var igdbProvider = new Mock <LibraryMetadataProvider>(); igdbProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; if (g.Name == "Game3") { return(GameMetadata.GetEmptyData()); } var gameId = g.Name; var game = new GameInfo() { Name = "IGDB Game " + gameId, Description = $"IGDB Description {gameId}", Developers = new List <string>() { $"IGDB Developer {gameId}" }, Genres = new List <string>() { $"IGDB Genre {gameId}" }, Links = new List <Link>() { new Link($"IGDB link {gameId}", $"IGDB link url {gameId}") }, Publishers = new List <string>() { $"IGDB publisher {gameId}" }, ReleaseDate = new DateTime(2012, 6, 6), Tags = new List <string>() { $"IGDB Tag {gameId}" } }; var icon = new MetadataFile($"IGDBIconName{gameId}.file", randomFile); var image = new MetadataFile($"IGDBImageName{gameId}.file", randomFile); var background = new MetadataFile($"IGDB backgournd {gameId}"); return(new GameMetadata(game, icon, image, background)); }); var storeProvider = new Mock <LibraryMetadataProvider>(); storeProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; storeCalled = true; return(GameMetadata.GetEmptyData()); }); var downloader = new MetadataDownloader(db, igdbProvider.Object, GetLibraryPlugins(storeProvider.Object, storePluginId)); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; settings.Name.Import = false; settings.ConfigureFields(MetadataSource.IGDB, true); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, null, null); Assert.IsFalse(storeCalled); Assert.AreEqual(3, callCount); var game1 = db.Games[games[0].Id]; Assert.AreEqual("IGDB Description Game1", game1.Description); Assert.AreEqual("IGDB Developer Game1", game1.Developers[0].Name); Assert.AreEqual("IGDB Genre Game1", game1.Genres[0].Name); Assert.AreEqual("IGDB link Game1", game1.Links[0].Name); Assert.AreEqual("IGDB link url Game1", game1.Links[0].Url); Assert.AreEqual("IGDB publisher Game1", game1.Publishers[0].Name); Assert.AreEqual("IGDB Tag Game1", game1.Tags[0].Name); Assert.AreEqual(2012, game1.ReleaseDate.Value.Year); Assert.IsNotEmpty(game1.BackgroundImage); Assert.IsNotEmpty(game1.Icon); Assert.IsNotEmpty(game1.CoverImage); var game2 = db.Games[games[1].Id]; Assert.AreEqual("IGDB Description Game2", game2.Description); Assert.AreEqual(2, Directory.GetFiles(db.GetFileStoragePath(game1.Id)).Count()); Assert.AreEqual(2, Directory.GetFiles(db.GetFileStoragePath(game2.Id)).Count()); } }
public async Task MissingDataTest() { using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); Game.DatabaseReference = db; int callCount = 0; var importedGame = db.ImportGame(new GameInfo() { Name = "Game", GameId = "storeId", Genres = new List <string>() { "Genre" }, ReleaseDate = new DateTime(2012, 6, 6), Developers = new List <string>() { "Developer" }, Publishers = new List <string>() { "Publisher" }, Tags = new List <string>() { "Tag" }, Description = "Description", Links = new List <Link>() { new Link() } }); importedGame.PluginId = storePluginId; importedGame.Icon = "icon"; importedGame.CoverImage = "image"; importedGame.BackgroundImage = "backImage"; db.Games.Update(importedGame); var igdbProvider = new Mock <LibraryMetadataProvider>(); igdbProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; return(GameMetadata.GetEmptyData()); }); var storeProvider = new Mock <LibraryMetadataProvider>(); storeProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) => { callCount++; var gameId = g.GameId; return(new GameMetadata(new GameInfo() { Name = "Store Game " + gameId }, null, null, null)); }); var downloader = new MetadataDownloader(db, igdbProvider.Object, GetLibraryPlugins(storeProvider.Object, storePluginId)); var settings = new MetadataDownloaderSettings() { SkipExistingValues = false }; var dbGames = db.Games.ToList(); var f = dbGames[0].ReleaseDate; var s = importedGame.ReleaseDate; settings.ConfigureFields(MetadataSource.Store, true); await downloader.DownloadMetadataAsync( db.Games.ToList(), settings, null, null); dbGames = db.Games.ToList(); Assert.AreEqual(1, callCount); var game = dbGames[0]; Assert.AreEqual("Description", game.Description); Assert.AreEqual("icon", game.Icon); Assert.AreEqual("image", game.CoverImage); Assert.AreEqual("backImage", game.BackgroundImage); Assert.AreEqual("Developer", game.Developers[0].Name); Assert.AreEqual("Publisher", game.Publishers[0].Name); Assert.AreEqual("Genre", game.Genres[0].Name); CollectionAssert.IsNotEmpty(game.Links); Assert.AreEqual("Tag", game.Tags[0].Name); Assert.AreEqual(2012, game.ReleaseDate.Value.Year); } }