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

            FileSystem.DeleteFile(path);

            var db = new GameDatabase();

            using (db.OpenDatabase(path))
            {
                db.AddImage("testimage", "testimage.png", new byte[] { 0 });
                db.AddImage("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 #2
0
        public void DeleteImageSafeTest()
        {
            var path = Path.Combine(Playnite.PlayniteTests.TempPath, "deleteimagetest.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase();

            using (db.OpenDatabase(path))
            {
                db.AddImage("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());
            }
        }