Пример #1
0
        public void GamesTest()
        {
            var path = Path.Combine(PlayniteTests.TempPath, "dbapigames.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase();

            using (db.OpenDatabase(path))
            {
                var dbApi = new DatabaseAPI(db);
                Assert.AreEqual(0, dbApi.GetGames().Count);

                db.AddGames(new List <Game>()
                {
                    new Game()
                    {
                        Name = "Test Name 1"
                    },
                    new Game()
                    {
                        Name = "Test Name 2"
                    }
                });

                Assert.AreEqual(2, dbApi.GetGames().Count);

                dbApi.AddGame(new Game("API Game"));
                Assert.AreEqual(3, dbApi.GetGames().Count);

                dbApi.RemoveGame(dbApi.GetGames()[0].Id);
                var apiGames = dbApi.GetGames();
                Assert.AreEqual(2, apiGames.Count);
                Assert.AreEqual("API Game", apiGames[1].Name);
                Assert.AreEqual("Test Name 2", dbApi.GetGame(apiGames[0].Id).Name);

                apiGames[0].Name = "Changed Name";
                dbApi.UpdateGame(apiGames[0]);
                Assert.AreEqual("Changed Name", dbApi.GetGame(apiGames[0].Id).Name);

                Assert.IsNull(dbApi.GetGame(999));
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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());
            }
        }
Пример #4
0
        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 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);
            }
        }
Пример #7
0
        public async Task IGDBStoreCombinedTest()
        {
            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 = "Game2"
                    },
                    new Game("Game3")
                };

                db.AddGames(games);

                var igdbProvider = new Mock <IMetadataProvider>();
                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($"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 <IMetadataProvider>();
                storeProvider.Setup(x => x.GetMetadata(It.IsAny <Game>())).Returns((Game g) =>
                {
                    callCount++;
                    var gameId       = g.ProviderId;
                    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($"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
                };

                // IGDB over Store
                settings.ConfigureFields(MetadataSource.IGDBOverStore, true);
                await downloader.DownloadMetadataAsync(
                    db.GamesCollection.FindAll().ToList(),
                    db, settings, null, null);

                Assert.AreEqual(4, callCount);

                var dbGames = db.GamesCollection.FindAll().ToList();
                var game1   = dbGames[0];
                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.AreEqual("IGDB backgournd Game1", game1.BackgroundImage);
                Assert.AreEqual($"IGDBIconPathGame1.file", game1.Icon);
                Assert.AreEqual($"IGDBImagePathGame1.file", game1.Image);

                var game2 = dbGames[1];
                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.AreEqual("IGDB backgournd Game2", game2.BackgroundImage);
                Assert.AreEqual($"IGDBIconPathGame2.file", game2.Icon);
                Assert.AreEqual($"IGDBImagePathGame2.file", game2.Image);

                // Store over IGDB
                callCount = 0;
                settings.ConfigureFields(MetadataSource.StoreOverIGDB, true);
                await downloader.DownloadMetadataAsync(
                    db.GamesCollection.FindAll().ToList(),
                    db, settings, null, null);

                Assert.AreEqual(4, callCount);

                dbGames = db.GamesCollection.FindAll().ToList();
                game1   = dbGames[0];
                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.AreEqual("IGDB backgournd Game1", game1.BackgroundImage);
                Assert.AreEqual($"IGDBIconPathGame1.file", game1.Icon);
                Assert.AreEqual($"IGDBImagePathGame1.file", game1.Image);

                game2 = dbGames[1];
                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.AreEqual("Store backgournd Game2", game2.BackgroundImage);
                Assert.AreEqual($"StoreIconPathGame2.file", game2.Icon);
                Assert.AreEqual($"StoreImagePathGame2.file", game2.Image);
            }
        }
Пример #8
0
        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());
            }
        }