public void TestMigratingOldDatabase() { string tmpPath = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ()); string homePath = Path.Combine (tmpPath, "LongoMatch"); string dbPath = Path.Combine (homePath, "db"); string lmdbPath = Path.Combine (dbPath, "longomatch.ldb"); string teamsPath = Path.Combine (dbPath, "teams"); string dashboardsPath = Path.Combine (dbPath, "analysis"); Directory.CreateDirectory (tmpPath); Directory.CreateDirectory (homePath); Directory.CreateDirectory (dbPath); Directory.CreateDirectory (lmdbPath); Directory.CreateDirectory (teamsPath); Directory.CreateDirectory (dashboardsPath); Utils.SaveResource ("spain.ltt", teamsPath); Utils.SaveResource ("france.ltt", teamsPath); Utils.SaveResource ("basket.lct", dashboardsPath); Utils.SaveResource ("spain_france_test.lgm", lmdbPath); // Create an empty project file that shouldn't be converter File.Open (Path.Combine (lmdbPath, "empty.lgm"), FileMode.Create); Directory.CreateDirectory (tmpPath); Environment.SetEnvironmentVariable ("LONGOMATCH_HOME", tmpPath); Environment.SetEnvironmentVariable ("LGM_UNINSTALLED", "1"); App.Init (); CoreServices.Init (); CoreServices.Start (guiToolkitMock.Object, multimediaToolkitMock.Object); Assert.AreEqual (0, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.AreEqual (2, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.CategoriesTemplatesProvider.Templates.Count); DatabaseMigration dbMigration = new DatabaseMigration (Mock.Of<IProgressReport> ()); dbMigration.Start (); App.Current.DatabaseManager.SetActiveByName ("longomatch"); Assert.AreEqual (4, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (2, App.Current.CategoriesTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.IsTrue (File.Exists (Path.Combine (dbPath, "templates", "backup", "spain.ltt"))); Assert.IsTrue (File.Exists (Path.Combine (dbPath, "templates", "backup", "france.ltt"))); Assert.IsTrue (File.Exists (Path.Combine (dbPath, "templates", "backup", "basket.lct"))); Assert.IsTrue (File.Exists (Path.Combine (dbPath, "old", "longomatch.ldb", "spain_france_test.lgm"))); CoreServices.Stop (); }
public void TestNoOldDatabaseToMigrate() { string tmpPath = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ()); string homePath = Path.Combine (tmpPath, "LongoMatch"); string dbPath = Path.Combine (homePath, "db"); string lmdbPath = Path.Combine (dbPath, "longomatch.ldb"); string teamsPath = Path.Combine (dbPath, "teams"); string dashboardsPath = Path.Combine (dbPath, "analysis"); Directory.CreateDirectory (tmpPath); Directory.CreateDirectory (homePath); Environment.SetEnvironmentVariable ("LONGOMATCH_HOME", tmpPath); Environment.SetEnvironmentVariable ("LGM_UNINSTALLED", "1"); App.Init (); CoreServices.Init (); CoreServices.Start (guiToolkitMock.Object, multimediaToolkitMock.Object); Assert.AreEqual (0, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.AreEqual (2, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.CategoriesTemplatesProvider.Templates.Count); DatabaseMigration dbMigration = new DatabaseMigration (Mock.Of<IProgressReport> ()); dbMigration.Start (); Assert.AreEqual (0, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.AreEqual (2, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.CategoriesTemplatesProvider.Templates.Count); // Directory exists but it's empty Directory.CreateDirectory (dbPath); Directory.CreateDirectory (lmdbPath); Directory.CreateDirectory (teamsPath); Directory.CreateDirectory (dashboardsPath); dbMigration = new DatabaseMigration (Mock.Of<IProgressReport> ()); dbMigration.Start (); Assert.AreEqual (0, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.AreEqual (2, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.CategoriesTemplatesProvider.Templates.Count); CoreServices.Stop (); }