Ejemplo n.º 1
0
        public void PlatformGeneratorTest()
        {
            var path = Path.Combine(Playnite.PlayniteTests.TempPath, "defaultplatforms.db");

            FileSystem.DeleteFile(path);
            var db = new GameDatabase(null);

            using (db.OpenDatabase(path))
            {
                var platforms = db.PlatformsCollection.FindAll().ToList();
                CollectionAssert.IsNotEmpty(platforms);
                db.RemovePlatform(platforms);
                CollectionAssert.IsEmpty(db.PlatformsCollection.FindAll());
                db.AddPlatform(new Platform("Test"));
                db.AddPlatform(new Platform("Test2"));
            }

            using (db.OpenDatabase(path))
            {
                var platforms = db.PlatformsCollection.FindAll().ToList();
                Assert.AreEqual(2, platforms.Count);
                Assert.AreEqual("Test", platforms[0].Name);
                Assert.AreEqual("Test2", platforms[1].Name);
            }
        }
Ejemplo n.º 2
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]);
        }
Ejemplo n.º 3
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"));
            }
        }
Ejemplo n.º 4
0
 public void AddPlatform(Platform platform)
 {
     database.AddPlatform(platform);
 }