Exemple #1
0
        public void ListUpdateTest()
        {
            var path = Path.Combine(Playnite.PlayniteTests.TempPath, "updatedb.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase(null);

            using (db.OpenDatabase(path))
            {
                db.AddGame(new Game()
                {
                    ProviderId = "testid",
                    Name       = "Test Game"
                });

                db.AddGame(new Game()
                {
                    ProviderId = "testid2",
                    Name       = "Test Game 2"
                });

                Assert.AreEqual(2, db.GamesCollection.Count());
            }

            db = new GameDatabase(null);
            using (db.OpenDatabase(path))
            {
                Assert.AreEqual(2, db.GamesCollection.Count());
                db.AddGame(new Game()
                {
                    ProviderId = "testid3",
                    Name       = "Test Game 3"
                });

                var games = db.GamesCollection.FindAll().ToList();
                games[2].Name = "Changed Name";
                db.UpdateGameInDatabase(games[2]);
            }

            db = new GameDatabase(null);
            using (db.OpenDatabase(path))
            {
                var games = db.GamesCollection.FindAll().ToList();
                Assert.AreEqual(3, games.Count);
                Assert.AreEqual("Changed Name", games[2].Name);
                db.DeleteGame(games[1]);
            }

            db = new GameDatabase(null);
            using (db.OpenDatabase(path))
            {
                Assert.AreEqual(2, db.GamesCollection.Count());
            }
        }
Exemple #2
0
        public void DeleteGameImageCleanupTest()
        {
            var path = Path.Combine(Playnite.PlayniteTests.TempPath, "deleteimagecleanuptest.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase(null);

            using (db.OpenDatabase(path))
            {
                db.AddFile("testimage", "testimage.png", new byte[] { 0 });
                db.AddFile("testicon", "testicon.png", new byte[] { 0 });
                Assert.AreEqual(2, db.Database.FileStorage.FindAll().Count());

                var game = new Game()
                {
                    ProviderId = "testid",
                    Name       = "Test Game",
                    Icon       = "testicon",
                    Image      = "testimage"
                };

                db.AddGame(game);
                db.DeleteGame(game);

                Assert.AreEqual(0, db.Database.FileStorage.FindAll().Count());
            }
        }
Exemple #3
0
        public void UpdateOriginGameWithMetadataTest()
        {
            var game = new Game()
            {
                ProviderId = "DR:198070800",
                Name       = "Temp Name",
                Provider   = Provider.Origin
            };

            var path = Path.Combine(Playnite.PlayniteTests.TempPath, "originmetaupdate.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase();

            using (db.OpenDatabase(path))
            {
                db.AddGame(game);
                db.UpdateGameWithMetadata(game);
                Assert.AreNotEqual("Temp Name", game.Name);
                Assert.IsNotNull(game.ReleaseDate);
                Assert.IsNotNull(game.Developers);
                Assert.IsTrue(!string.IsNullOrEmpty(game.Description));
                Assert.IsTrue(!string.IsNullOrEmpty(game.Links.First(a => a.Name == "Forum").Url));
                Assert.IsTrue(!string.IsNullOrEmpty(game.Links.First(a => a.Name == "Store").Url));
                Assert.IsTrue(!string.IsNullOrEmpty(game.Links.First(a => a.Name == "Wiki").Url));
                Assert.IsTrue(!string.IsNullOrEmpty(game.Image));

                var files = db.Database.FileStorage.FindAll();
                Assert.AreEqual(1, files.Count());
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Starting");

            GameDatabase.DatabaseFolder = "C:\\SlitherShark\\database\\processed";
            GameDatabase.LoadGames();

            var frameProcessor = new FrameProcessor(new OutcomeProcessor(new OutcomeScoreProcessor()), new CollisionMapProcessor(new CollisionMapResolutionProcessor(new CollisionSliceProcessor(new FoodSliceProcessor(new CollisionService()), new BadCollisionSliceProcessor(new CollisionService()), new SelfSliceProcessor(new CollisionService()))), new SlitherFrameNormalizer()));
            var gameProcessor  = new GameProcessor(frameProcessor);

            var sourceFolder = "C:\\SlitherShark\\database\\source";

            foreach (var fileName in Directory.GetFiles(sourceFolder))
            {
                Console.WriteLine(fileName);
                var jsonString = File.ReadAllText(fileName);
                var sourceGame = JsonConvert.DeserializeObject <Game>(jsonString, new JsonSerializerSettings
                {
                    TypeNameHandling  = TypeNameHandling.Auto,
                    NullValueHandling = NullValueHandling.Ignore,
                });

                var processedGame = gameProcessor.ProcessGame(sourceGame);
                GameDatabase.AddGame(processedGame);
            }

            Console.WriteLine("Done");
        }
        public void PcPlatformAutoAssignTest()
        {
            var db = new GameDatabase();

            using (db.OpenDatabase(dbPath))
            {
                // Remove PC platform first, might get autogenerated with clean DB
                var pl = db.PlatformsCollection.FindOne(a => a.Name == "PC");
                if (pl != null)
                {
                    db.RemovePlatform(pl);
                    Assert.IsNull(db.PlatformsCollection.FindOne(a => a.Name == "PC"));
                }

                var game = new Game()
                {
                    GameId = "testid",
                    Name   = "Test Game"
                };

                db.AddGame(game);
                db.AssignPcPlatform(game);
                var pcPlatform = db.PlatformsCollection.FindOne(a => a.Name == "PC");
                Assert.IsNotNull(pcPlatform);
                Assert.AreEqual(game.PlatformId, pcPlatform.Id);
            }
        }
Exemple #6
0
        public void EventsArgsNonBufferedTest()
        {
            GamesCollectionChangedEventArgs     gameColArgs        = null;
            GameUpdatedEventArgs                gameUpdateArgs     = null;
            PlatformsCollectionChangedEventArgs platformColArgs    = null;
            PlatformUpdatedEventArgs            platformUpdateArgs = null;

            db.GamesCollectionChanged     += (e, args) => { gameColArgs = args; };
            db.GameUpdated                += (e, args) => { gameUpdateArgs = args; };
            db.PlatformsCollectionChanged += (e, args) => { platformColArgs = args; };
            db.PlatformUpdated            += (e, args) => { platformUpdateArgs = args; };

            var game = new Game("test game");

            db.AddGame(game);
            Assert.AreEqual(1, gameColArgs.AddedGames.Count);
            Assert.AreEqual(game, gameColArgs.AddedGames[0]);
            Assert.AreEqual(0, gameColArgs.RemovedGames.Count);
            db.UpdateGameInDatabase(game);
            Assert.AreEqual(1, gameUpdateArgs.UpdatedGames.Count);
            Assert.AreEqual(game, gameUpdateArgs.UpdatedGames[0].NewData);
            Assert.AreNotEqual(game, gameUpdateArgs.UpdatedGames[0].OldData);
            db.DeleteGame(game);
            Assert.AreEqual(0, gameColArgs.AddedGames.Count);
            Assert.AreEqual(1, gameColArgs.RemovedGames.Count);
            Assert.AreEqual(game, gameColArgs.RemovedGames[0]);

            var platform = new Platform("test platform");

            db.AddPlatform(platform);
            Assert.AreEqual(1, platformColArgs.AddedPlatforms.Count);
            Assert.AreEqual(platform, platformColArgs.AddedPlatforms[0]);
            var platform2 = new Platform("test platform2");

            db.AddPlatform(new List <Platform> {
                platform2
            });
            Assert.AreEqual(1, platformColArgs.AddedPlatforms.Count);
            Assert.AreEqual(platform2, platformColArgs.AddedPlatforms[0]);
            db.UpdatePlatform(platform);
            Assert.AreEqual(1, platformUpdateArgs.UpdatedPlatforms.Count);
            Assert.AreEqual(platform, platformUpdateArgs.UpdatedPlatforms[0].NewData);
            Assert.AreNotEqual(platform, platformUpdateArgs.UpdatedPlatforms[0].OldData);
            db.RemovePlatform(platform);
            Assert.AreEqual(1, platformColArgs.RemovedPlatforms.Count);
            Assert.AreEqual(platform, platformColArgs.RemovedPlatforms[0]);
        }
Exemple #7
0
        public void BasicTest()
        {
            var db = new GameDatabase(null);

            using (db.OpenDatabase(new MemoryStream()))
            {
                db.AddGames(new List <Game>
                {
                    new Game("Game 1"),
                    new Game("Steam game 1")
                    {
                        State = new GameState()
                        {
                            Installed = true
                        },
                        Hidden = true
                    },
                    new Game("Origin game 1")
                    {
                    },
                    new Game("GOG game 1")
                    {
                        Hidden = true
                    },
                    new Game("GOG game 2")
                    {
                        Hidden = false
                    }
                });

                var stats = new DatabaseStats(db);

                Assert.AreEqual(5, stats.Total);
                Assert.AreEqual(1, stats.Installed);
                Assert.AreEqual(2, stats.Hidden);
                Assert.AreEqual(0, stats.Favorite);

                var newGame = new Game("Game 2")
                {
                    Favorite = true
                };
                db.AddGame(newGame);
                Assert.AreEqual(6, stats.Total);
                Assert.AreEqual(1, stats.Favorite);

                newGame.State = new GameState()
                {
                    Installed = true
                };
                db.UpdateGameInDatabase(newGame);
                Assert.AreEqual(2, stats.Installed);
            }
        }
Exemple #8
0
        public void DeleteImageSafeTest()
        {
            var path = Path.Combine(Playnite.PlayniteTests.TempPath, "deleteimagetest.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase(null);

            using (db.OpenDatabase(path))
            {
                db.AddFile("testimage", "testimage.png", new byte[] { 0 });
                Assert.AreEqual(1, db.Database.FileStorage.FindAll().Count());

                db.AddGame(new Game()
                {
                    ProviderId = "testid",
                    Name       = "Test Game",
                    Icon       = "testimage"
                });

                db.AddGame(new Game()
                {
                    ProviderId = "testid2",
                    Name       = "Test Game 2",
                    Icon       = "testimage"
                });

                // Doesn't remove image in use
                var games = db.GamesCollection.FindAll().ToList();
                db.DeleteImageSafe("testimage", games[0]);
                Assert.AreEqual(1, db.Database.FileStorage.FindAll().Count());

                // Removes image
                games[1].Icon = string.Empty;
                db.UpdateGameInDatabase(games[1]);
                db.DeleteImageSafe("testimage", games[0]);
                Assert.AreEqual(0, db.Database.FileStorage.FindAll().Count());
            }
        }
 public void GetAllGames_Test()
 {
     string filename = Path.GetTempFileName();
     IGameDatabase database = new GameDatabase(filename);
     var fakeGameInfo = new Mock<IGameInfo>();
     fakeGameInfo.SetupGet(game => game.Name).Returns("TestGame");
     fakeGameInfo.SetupGet(game => game.UUID).Returns("TESTGAME");
     fakeGameInfo.SetupGet(game => game.PlatformID).Returns("TESTPLATFORM");
     database.AddGame(fakeGameInfo.Object);
     Assert.NotEmpty(database.GetAllGames());
     this.DisposeSqlite();
     File.Delete(filename);
 }
Exemple #10
0
        public bool EndGame(string id)
        {
            Game game;
            bool success = ActiveGameDatabase.ActiveGames.TryRemove(id, out game);

            if (success && game.Frames.Count > 0)
            {
                var processedGame = GameProcessor.ProcessGame(game);
                GameDatabase.AddGame(processedGame);

                string json = JsonConvert.SerializeObject(game);
                File.WriteAllText(DatabaseSourceFolder + "\\" + game.Id + ".json", json, Encoding.UTF8);
            }

            return(success);
        }
Exemple #11
0
        public void PlatformRemovalTest()
        {
            var db = new GameDatabase(null);

            using (db.OpenDatabase(dbPath))
            {
                var platform = new Platform("Test");
                db.AddPlatform(platform);
                var game = new Game("Test")
                {
                    PlatformId = platform.Id
                };

                db.AddGame(game);
                db.RemovePlatform(platform);
                var dbGame = db.GamesCollection.FindById(game.Id);
                Assert.IsNull(dbGame.PlatformId);
                CollectionAssert.IsEmpty(db.PlatformsCollection.Find(a => a.Name == "Test"));
            }
        }
        public SlitherPlayerTests()
        {
            GameDatabase.DatabaseFolder = "C:\\SlitherShark\\test\\processed";
            GameDatabase.LoadGames();

            var jsonString = File.ReadAllText("C:\\SlitherShark\\test\\source\\test.json");

            SourceGame = JsonConvert.DeserializeObject <Game>(jsonString, new JsonSerializerSettings
            {
                TypeNameHandling  = TypeNameHandling.Auto,
                NullValueHandling = NullValueHandling.Ignore,
            });

            SlitherPlayer = new SlitherPlayer(new FrameProcessor(new OutcomeProcessor(new OutcomeScoreProcessor()), new CollisionMapProcessor(new CollisionMapResolutionProcessor(new CollisionSliceProcessor(new FoodSliceProcessor(new CollisionService()), new BadCollisionSliceProcessor(new CollisionService()), new SelfSliceProcessor(new CollisionService()))), new SlitherFrameNormalizer())), new ProcessedFrameMatchAnalyzer(new CollisionMapMatchAnalyzer(new SliceMatchAnalyzer(new CollisionListMatchAnalyzer()))), new SlitherFrameNormalizer());

            var frameProcessor = new FrameProcessor(new OutcomeProcessor(new OutcomeScoreProcessor()), new CollisionMapProcessor(new CollisionMapResolutionProcessor(new CollisionSliceProcessor(new FoodSliceProcessor(new CollisionService()), new BadCollisionSliceProcessor(new CollisionService()), new SelfSliceProcessor(new CollisionService()))), new SlitherFrameNormalizer()));
            var gameProcessor  = new GameProcessor(frameProcessor);
            var processedGame  = gameProcessor.ProcessGame(SourceGame);

            GameDatabase.AddGame(processedGame);
        }
Exemple #13
0
        public void UpdateSteamGameWithMetadataTest()
        {
            var game = new Game()
            {
                ProviderId = "289070",
                Name       = "Temp Name",
                Provider   = Provider.Steam
            };

            var path = Path.Combine(Playnite.PlayniteTests.TempPath, "steammetaupdate.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase();

            using (db.OpenDatabase(path))
            {
                db.AddGame(game);
                db.UpdateGameWithMetadata(game);
                Assert.AreNotEqual("Temp Name", game.Name);
                Assert.IsNotNull(game.ReleaseDate);
                Assert.IsNotNull(game.Genres);
                Assert.IsNotNull(game.Developers);
                Assert.IsFalse(string.IsNullOrEmpty(game.Description));
                Assert.IsFalse(string.IsNullOrEmpty(game.Links.First(a => a.Name == "Forum").Url));
                Assert.IsFalse(string.IsNullOrEmpty(game.Links.First(a => a.Name == "Store").Url));
                Assert.IsFalse(string.IsNullOrEmpty(game.Links.First(a => a.Name == "Wiki").Url));
                Assert.IsFalse(string.IsNullOrEmpty(game.Links.First(a => a.Name == "Workshop").Url));
                Assert.IsFalse(string.IsNullOrEmpty(game.Icon));
                Assert.IsFalse(string.IsNullOrEmpty(game.Image));
                Assert.IsFalse(string.IsNullOrEmpty(game.BackgroundImage));

                var files = db.Database.FileStorage.FindAll();
                Assert.AreEqual(2, files.Count());
            }
        }
Exemple #14
0
 public void AddGame(Game game)
 {
     database.AddGame(game);
 }
        public void RemoveGame_Test()
        {
            string filename = Path.GetTempFileName();
            IGameDatabase database = new GameDatabase(filename);
            var fakeGameInfo = new Mock<IGameInfo>();
            fakeGameInfo.SetupGet(game => game.Name).Returns("TestGame");
            fakeGameInfo.SetupGet(game => game.UUID).Returns("TESTGAME");
            fakeGameInfo.SetupGet(game => game.PlatformID).Returns("TESTPLATFORM");
            database.AddGame(fakeGameInfo.Object);
            Assert.Equal(fakeGameInfo.Object.UUID, database.GetGameByUUID("TESTGAME").UUID);
            Assert.Equal(fakeGameInfo.Object.Name, database.GetGameByUUID("TESTGAME").Name);
            Assert.Equal(fakeGameInfo.Object.PlatformID, database.GetGameByUUID("TESTGAME").PlatformID);

            database.RemoveGame(fakeGameInfo.Object);
            Assert.Null(database.GetGameByUUID(fakeGameInfo.Object.UUID));
            this.DisposeSqlite();
            File.Delete(filename);
        }
Exemple #16
0
        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 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);
            }
        }
Exemple #18
0
        public void ImageReplaceTest()
        {
            var path = Path.Combine(PlayniteUITests.TempPath, "imagereplace.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase(null);

            using (db.OpenDatabase(path))
            {
                var origIcon       = PlayniteUITests.CreateFakeFile();
                var origImage      = PlayniteUITests.CreateFakeFile();
                var origBackground = PlayniteUITests.CreateFakeFile();

                db.AddFile(origIcon.FileName, origIcon.FileName, origIcon.Content);
                db.AddFile(origImage.FileName, origImage.FileName, origImage.Content);
                db.AddFile(origBackground.FileName, origBackground.FileName, origBackground.Content);

                var game = new Game()
                {
                    GameId          = "testid",
                    Name            = "Test Game",
                    CoverImage      = origImage.FileName,
                    Icon            = origIcon.FileName,
                    BackgroundImage = origBackground.FileName
                };

                db.AddGame(game);

                var newIcon       = PlayniteUITests.CreateFakeFile();
                var newImage      = PlayniteUITests.CreateFakeFile();
                var newBackground = PlayniteUITests.CreateFakeFile();

                // Images are replaced
                var model = new GameEditViewModel(game, db, new MockWindowFactory(), new MockDialogsFactory(), new MockResourceProvider(), null);
                model.EditingGame.Icon            = newIcon.FileId;
                model.EditingGame.CoverImage      = newImage.FileId;
                model.EditingGame.BackgroundImage = newBackground.FileId;
                model.ConfirmDialog();

                Assert.AreNotEqual(game.Icon, origIcon.FileName);
                Assert.AreNotEqual(game.CoverImage, origImage.FileName);
                Assert.AreNotEqual(game.BackgroundImage, origBackground.FileName);
                Assert.AreNotEqual(game.Icon, newIcon.FileId);
                Assert.AreNotEqual(game.CoverImage, newImage.FileId);
                Assert.AreNotEqual(game.BackgroundImage, newBackground.FileId);

                var dbFiles = db.Database.FileStorage.FindAll().ToList();
                Assert.AreEqual(3, dbFiles.Count());

                using (var str = db.GetFileStream(game.Icon))
                {
                    CollectionAssert.AreEqual(newIcon.Content, str.ToArray());
                }

                using (var str = db.GetFileStream(game.CoverImage))
                {
                    CollectionAssert.AreEqual(newImage.Content, str.ToArray());
                }

                using (var str = db.GetFileStream(game.BackgroundImage))
                {
                    CollectionAssert.AreEqual(newBackground.Content, str.ToArray());
                }

                // Duplicates are kept and not replaced
                var currentIcon  = game.Icon;
                var currentImage = game.CoverImage;
                var currentBack  = game.BackgroundImage;

                model = new GameEditViewModel(game, db, new MockWindowFactory(), new MockDialogsFactory(), new MockResourceProvider(), null);
                model.EditingGame.Icon            = newIcon.FileId;
                model.EditingGame.CoverImage      = newImage.FileId;
                model.EditingGame.BackgroundImage = newBackground.FileId;
                model.ConfirmDialog();

                dbFiles = db.Database.FileStorage.FindAll().ToList();
                Assert.AreEqual(3, dbFiles.Count());
                Assert.AreEqual(game.Icon, currentIcon);
                Assert.AreEqual(game.CoverImage, currentImage);
                Assert.AreEqual(game.BackgroundImage, currentBack);
            }
        }
Exemple #19
0
        public void ImageReplaceMultiTest()
        {
            var path = Path.Combine(PlayniteUITests.TempPath, "imagereplacemulti.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase(null);

            using (db.OpenDatabase(path))
            {
                var origIcon       = PlayniteUITests.CreateFakeFile();
                var origImage      = PlayniteUITests.CreateFakeFile();
                var origBackground = PlayniteUITests.CreateFakeFile();
                db.AddFile(origIcon.FileName, origIcon.FileName, origIcon.Content);
                db.AddFile(origImage.FileName, origImage.FileName, origImage.Content);
                db.AddFile(origBackground.FileName, origBackground.FileName, origBackground.Content);
                db.AddGame(new Game()
                {
                    GameId          = "testid",
                    Name            = "Test Game",
                    CoverImage      = origImage.FileName,
                    Icon            = origIcon.FileName,
                    BackgroundImage = origBackground.FileName
                });

                origIcon       = PlayniteUITests.CreateFakeFile();
                origImage      = PlayniteUITests.CreateFakeFile();
                origBackground = PlayniteUITests.CreateFakeFile();
                db.AddFile(origIcon.FileName, origIcon.FileName, origIcon.Content);
                db.AddFile(origImage.FileName, origImage.FileName, origImage.Content);
                db.AddFile(origBackground.FileName, origBackground.FileName, origBackground.Content);
                db.AddGame(new Game()
                {
                    GameId          = "testid2",
                    Name            = "Test Game 2",
                    CoverImage      = origImage.FileName,
                    Icon            = origIcon.FileName,
                    BackgroundImage = origBackground.FileName
                });

                Assert.AreEqual(6, db.Database.FileStorage.FindAll().ToList().Count());

                var newIcon       = PlayniteUITests.CreateFakeFile();
                var newImage      = PlayniteUITests.CreateFakeFile();
                var newBackground = PlayniteUITests.CreateFakeFile();

                // Replaces all images for all games
                var games = db.GamesCollection.FindAll().ToList();
                var model = new GameEditViewModel(games, db, new MockWindowFactory(), new MockDialogsFactory(), new MockResourceProvider(), null);
                model.EditingGame.Icon            = newIcon.FileId;
                model.EditingGame.CoverImage      = newImage.FileId;
                model.EditingGame.BackgroundImage = newBackground.FileId;
                model.ConfirmDialog();

                var dbFiles = db.Database.FileStorage.FindAll().ToList();
                Assert.AreEqual(3, dbFiles.Count());

                games = db.GamesCollection.FindAll().ToList();
                foreach (var game in games)
                {
                    StringAssert.StartsWith("images/custom/", game.Icon);
                    StringAssert.StartsWith("images/custom/", game.CoverImage);
                    StringAssert.StartsWith("images/custom/", game.BackgroundImage);
                }

                Assert.AreEqual(games[0].Icon, games[1].Icon);
                Assert.AreEqual(games[0].CoverImage, games[1].CoverImage);
                Assert.AreEqual(games[0].BackgroundImage, games[1].BackgroundImage);

                // Replaces only non-duplicate images
                newIcon       = PlayniteUITests.CreateFakeFile();
                newImage      = PlayniteUITests.CreateFakeFile();
                newBackground = PlayniteUITests.CreateFakeFile();
                db.AddFile(newIcon.FileName, newIcon.FileName, newIcon.Content);
                db.AddFile(newImage.FileName, newImage.FileName, newImage.Content);
                db.AddFile(newBackground.FileName, newBackground.FileName, newBackground.Content);
                games[0].Icon            = newIcon.FileName;
                games[0].CoverImage      = newImage.FileName;
                games[0].BackgroundImage = newBackground.FileName;
                db.UpdateGameInDatabase(games[0]);

                Assert.AreEqual(6, db.Database.FileStorage.FindAll().ToList().Count());

                games = db.GamesCollection.FindAll().ToList();
                model = new GameEditViewModel(games, db, new MockWindowFactory(), new MockDialogsFactory(), new MockResourceProvider(), null);
                model.EditingGame.Icon            = newIcon.FileId;
                model.EditingGame.CoverImage      = newImage.FileId;
                model.EditingGame.BackgroundImage = newBackground.FileId;
                model.ConfirmDialog();

                Assert.AreEqual(3, db.Database.FileStorage.FindAll().ToList().Count());

                games = db.GamesCollection.FindAll().ToList();
                foreach (var game in games)
                {
                    Assert.AreEqual(newIcon.FileName, game.Icon);
                    Assert.AreEqual(newImage.FileName, game.CoverImage);
                    Assert.AreEqual(newBackground.FileName, game.BackgroundImage);
                }
            }
        }