Пример #1
0
        public void ImageReplaceMultiTest()
        {
            using (var temp = TempDirectory.Create())
            {
                var db = new GameDatabase(temp.TempPath);
                db.OpenDatabase();

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

                var origIcon       = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                var origImage      = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                var origBackground = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                game.Icon            = origIcon;
                game.CoverImage      = origImage;
                game.BackgroundImage = origBackground;
                db.Games.Add(game);

                game = new Game()
                {
                    GameId = "testid2",
                    Name   = "Test Game 2"
                };

                origIcon             = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                origImage            = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                origBackground       = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                game.Icon            = origIcon;
                game.CoverImage      = origImage;
                game.BackgroundImage = origBackground;
                db.Games.Add(game);

                var newIcon       = PlayniteTests.GenerateFakeFile();
                var newImage      = PlayniteTests.GenerateFakeFile();
                var newBackground = PlayniteTests.GenerateFakeFile();

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

                Assert.AreEqual(3, Directory.GetFiles(db.GetFileStoragePath(games[0].Id)).Count());
                Assert.AreEqual(3, Directory.GetFiles(db.GetFileStoragePath(games[1].Id)).Count());

                CollectionAssert.AreEqual(newIcon.Content, File.ReadAllBytes(db.GetFullFilePath(games[0].Icon)));
                CollectionAssert.AreEqual(newImage.Content, File.ReadAllBytes(db.GetFullFilePath(games[0].CoverImage)));
                CollectionAssert.AreEqual(newBackground.Content, File.ReadAllBytes(db.GetFullFilePath(games[0].BackgroundImage)));

                CollectionAssert.AreEqual(newIcon.Content, File.ReadAllBytes(db.GetFullFilePath(games[1].Icon)));
                CollectionAssert.AreEqual(newImage.Content, File.ReadAllBytes(db.GetFullFilePath(games[1].CoverImage)));
                CollectionAssert.AreEqual(newBackground.Content, File.ReadAllBytes(db.GetFullFilePath(games[1].BackgroundImage)));
            }
        }
Пример #2
0
 public void AddFileTest()
 {
     using (var temp = TempDirectory.Create())
     {
         var db = new GameDatabase(temp.TempPath);
         db.OpenDatabase();
         var file    = PlayniteTests.GenerateFakeFile();
         var testId  = Guid.NewGuid();
         var addedId = db.AddFile(file.FileName, file.Content, testId);
         FileAssert.Exists(Path.Combine(temp.TempPath, "files", addedId));
     }
 }
        public void ImageReplaceTest()
        {
            using (var temp = TempDirectory.Create())
            {
                var db = new GameDatabase(temp.TempPath);
                db.OpenDatabase();
                var game = new Game()
                {
                    GameId = "testid",
                    Name   = "Test Game"
                };

                var origIcon       = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                var origImage      = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                var origBackground = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                game.Icon            = origIcon;
                game.CoverImage      = origImage;
                game.BackgroundImage = origBackground;
                db.Games.Add(game);

                var newIcon       = PlayniteTests.GenerateFakeFile();
                var newImage      = PlayniteTests.GenerateFakeFile();
                var newBackground = PlayniteTests.GenerateFakeFile();
                File.WriteAllBytes(Path.Combine(temp.TempPath, newIcon.FileName), newIcon.Content);
                File.WriteAllBytes(Path.Combine(temp.TempPath, newImage.FileName), newImage.Content);
                File.WriteAllBytes(Path.Combine(temp.TempPath, newBackground.FileName), newBackground.Content);

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

                Assert.AreNotEqual(game.Icon, origIcon);
                Assert.AreNotEqual(game.CoverImage, origImage);
                Assert.AreNotEqual(game.BackgroundImage, origBackground);

                var dbFiles = Directory.GetFiles(db.GetFileStoragePath(game.Id));
                Assert.AreEqual(3, dbFiles.Count());
                CollectionAssert.AreEqual(newIcon.Content, File.ReadAllBytes(db.GetFullFilePath(game.Icon)));
                CollectionAssert.AreEqual(newImage.Content, File.ReadAllBytes(db.GetFullFilePath(game.CoverImage)));
                CollectionAssert.AreEqual(newBackground.Content, File.ReadAllBytes(db.GetFullFilePath(game.BackgroundImage)));
            }
        }
Пример #4
0
        public void DeleteGameImageCleanupTest()
        {
            using (var temp = TempDirectory.Create())
            {
                var db = new GameDatabase(temp.TempPath);
                db.OpenDatabase();
                var game = new Game("Test");
                db.Games.Add(game);
                game.Icon            = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                game.BackgroundImage = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);
                game.CoverImage      = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id);

                Assert.IsNotEmpty(game.Icon);
                Assert.IsNotEmpty(game.BackgroundImage);
                Assert.IsNotEmpty(game.CoverImage);

                var files = Directory.GetFiles(db.GetFileStoragePath(game.Id));
                Assert.AreEqual(3, files.Count());

                db.Games.Remove(game);
                files = Directory.GetFiles(db.GetFileStoragePath(game.Id));
                Assert.AreEqual(0, files.Count());
            }
        }