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); } }
public Task <DatabaseStats> GetDatabaseStatsAsync() { return(Task.Run(() => { if (NonFictionBookCount > 0) { Logger.Debug("Retrieving the list of non-fiction table indexes."); List <string> nonFictionIndexes = localDatabase.GetNonFictionIndexList(); Logger.Debug("Checking the index on LastModifiedDateTime column."); CheckAndCreateIndex(nonFictionIndexes, SqlScripts.NON_FICTION_INDEX_PREFIX, "LastModifiedDateTime", null, localDatabase.CreateNonFictionLastModifiedDateTimeIndex); } if (FictionBookCount > 0) { Logger.Debug("Retrieving the list of fiction table indexes."); List <string> fictionIndexes = localDatabase.GetFictionIndexList(); Logger.Debug("Checking the index on LastModifiedDateTime column."); CheckAndCreateIndex(fictionIndexes, SqlScripts.FICTION_INDEX_PREFIX, "LastModifiedDateTime", null, localDatabase.CreateFictionLastModifiedDateTimeIndex); } if (SciMagArticleCount > 0) { Logger.Debug("Retrieving the list of scimag table indexes."); List <string> sciMagIndexes = localDatabase.GetSciMagIndexList(); Logger.Debug("Checking the index on AddedDateTime column."); CheckAndCreateIndex(sciMagIndexes, SqlScripts.SCIMAG_INDEX_PREFIX, "AddedDateTime", null, localDatabase.CreateSciMagAddedDateTimeIndex); } DatabaseStats result = new DatabaseStats { NonFictionBookCount = NonFictionBookCount, FictionBookCount = FictionBookCount, SciMagArticleCount = SciMagArticleCount }; if (result.NonFictionBookCount > 0) { result.NonFictionLastUpdate = localDatabase.GetLastModifiedNonFictionBook()?.LastModifiedDateTime; } if (result.FictionBookCount > 0) { result.FictionLastUpdate = localDatabase.GetLastModifiedFictionBook()?.LastModifiedDateTime; } if (result.SciMagArticleCount > 0) { result.SciMagLastUpdate = localDatabase.GetLastAddedSciMagArticle()?.AddedDateTime; } return result; })); }
public void BasicTest() { using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); db.Games.Add(new List <Game> { new Game("Game 1"), new Game("Steam game 1") { IsInstalled = 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.Games.Add(newGame); Assert.AreEqual(6, stats.Total); Assert.AreEqual(1, stats.Favorite); newGame.IsInstalled = true; db.Games.Update(newGame); Assert.AreEqual(2, stats.Installed); } }