private void Database_GamesCollectionChanged(object sender, GamesCollectionChangedEventArgs args) { foreach (var game in args.RemovedGames) { IncrementalUpdate(game, -1); } foreach (var game in args.AddedGames) { IncrementalUpdate(game, 1); } NotifiyAllChanged(); }
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]); }
public void EventsArgsBufferedTest() { 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; }; using (db.BufferedUpdate()) { var game = new Game("test game"); db.AddGame(game); db.UpdateGameInDatabase(game); db.UpdateGameInDatabase(game); db.DeleteGame(game); Assert.IsNull(gameColArgs); Assert.IsNull(gameUpdateArgs); var platform = new Platform("test platform"); var platform2 = new Platform("test platform2"); db.AddPlatform(platform); db.AddPlatform(new List <Platform> { platform2 }); db.UpdatePlatform(platform); db.UpdatePlatform(platform2); db.UpdatePlatform(platform2); db.RemovePlatform(platform); Assert.IsNull(platformColArgs); Assert.IsNull(platformUpdateArgs); } Assert.AreEqual(1, gameColArgs.AddedGames.Count); Assert.AreEqual(1, gameColArgs.RemovedGames.Count); Assert.AreEqual(2, gameUpdateArgs.UpdatedGames.Count); Assert.AreEqual(2, platformColArgs.AddedPlatforms.Count); Assert.AreEqual(1, platformColArgs.RemovedPlatforms.Count); Assert.AreEqual(3, platformUpdateArgs.UpdatedPlatforms.Count); }