public void Event_WhenMigrationCompletesAndNoMigrationRequired_OnMigrationCompletedEventNotRaised() { //---------------Set up test pack------------------- itsDbMigrator.SetSettingsStorer(_itsSettings); _itsSettings.GetString(DBMigrator.DatabaseVersionSetting).Returns("2"); DBMigrator eventMigrator = null; DBMigratorEventArgs eventArgs = null; var onDbMigrationCompletedCalled = false; itsDbMigrator.OnDbMigrationCompleted += (s, e) => { onDbMigrationCompletedCalled = true; eventMigrator = s as DBMigrator; eventArgs = e; }; //---------------Assert Precondition---------------- Assert.IsNull(eventMigrator); Assert.IsNull(eventArgs); Assert.IsFalse(onDbMigrationCompletedCalled); //---------------Execute Test ---------------------- itsDbMigrator.MigrateTo(2); //---------------Test Result ----------------------- Assert.IsFalse(onDbMigrationCompletedCalled); Assert.IsNull(eventMigrator); Assert.IsNull(eventArgs); _itsSettings.DidNotReceive().SetString(DBMigrator.DatabaseVersionSetting, Arg.Any <string>()); }
public void Event_WhenMigrationCompletesAndMigrationIsRequired_OnMigrationCompletedEventRaised() { //---------------Set up test pack------------------- itsDbMigrator.SetSettingsStorer(_itsSettings); _itsSettings.GetString(DBMigrator.DatabaseVersionSetting).Returns("1"); DBMigrator eventMigrator = null; DBMigratorEventArgs eventArgs = null; itsDbMigrator.OnDbMigrationCompleted += (s, e) => { eventMigrator = s as DBMigrator; eventArgs = e; }; //---------------Assert Precondition---------------- Assert.IsNull(eventMigrator); Assert.IsNull(eventArgs); //---------------Execute Test ---------------------- itsDbMigrator.MigrateTo(2); //---------------Test Result ----------------------- Assert.IsNotNull(eventMigrator); Assert.AreEqual(itsDbMigrator, eventMigrator); Assert.IsNotNull(eventArgs); Assert.AreEqual(2, eventArgs.CurrentStep); _itsSettings.Received().SetString(DBMigrator.DatabaseVersionSetting, "2"); itsConn.Received().ExecuteSql(new SqlStatement(itsConn, "migration2;")); }
public void Constructor_SetsPercentageCompleteToCorrectValue(int start, int step, int total, decimal expectedPercentage) { //---------------Set up test pack------------------- var conn = Substitute.For <IDatabaseConnection>(); var migrator = new DBMigrator(conn); //---------------Assert Precondition---------------- Assert.IsNotNull(migrator); //---------------Execute Test ---------------------- var e = new DBMigratorEventArgs((uint)start, (uint)step, (uint)total); var propVal = e.PercentageComplete; //---------------Test Result ----------------------- Assert.AreEqual(expectedPercentage, propVal); }
public void SetupFixture() { GlobalRegistry.ApplicationName = appName; GlobalRegistry.ApplicationVersion = appVersion; GlobalRegistry.DatabaseVersion = dbVersion; GlobalRegistry.Settings = settings; GlobalRegistry.UIExceptionNotifier = exNotifier; itsConn = Substitute.For <IDatabaseConnection>(); itsDbMigrator = new DBMigrator(itsConn); itsDbMigrator.AddMigration(1, "migration1;"); itsDbMigrator.AddMigration(2, "migration2;"); itsDbMigrator.AddMigration(3, "migration3;"); _itsSettings = Substitute.For <ISettings>(); }
public void Constructor_SetsCurrentStepToSpecifiedStep() { //---------------Set up test pack------------------- var conn = Substitute.For <IDatabaseConnection>(); var migrator = new DBMigrator(conn); var step = (uint)TestUtil.GetRandomInt(1, 50); var totalSteps = (uint)TestUtil.GetRandomInt((int)step, (int)step + 50); //---------------Assert Precondition---------------- Assert.AreNotEqual(0, step); Assert.IsNotNull(migrator); //---------------Execute Test ---------------------- var e = new DBMigratorEventArgs(1, step, totalSteps); var propVal = e.CurrentStep; //---------------Test Result ----------------------- Assert.AreEqual(step, propVal); }
public void RestoreDatabase(string tmpPathDatabase) { dellAppDB.Dispose(); //check downloaded database for version string tmpDBConnectionString = "Data Source=isostore:/" + tmpPathDatabase; // Create the database if it does not exist. using (DBClass tmpDB = new DBClass(tmpDBConnectionString)) { if (tmpDB.DatabaseExists() == true) { using (DBMigrator migrator = new DBMigrator(tmpDBConnectionString, App.DB_VERSION)) { try { if (migrator.hasToMigrate()) { migrator.MigrateDatabase(); } } catch (Exception e) { throw new Exception("Error during migration. Migration failed."); } } // version are equal or db was migrated -> replace database files tmpDB.Dispose(); IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); iso.CopyFile(tmpPathDatabase, AppResources.DatabaseName + ".sdf", true); iso.Dispose(); } else { MessageBox.Show("Restore failed because the downloaded file is no database for this app."); } } this.ConnectDB(); }
public void MigrateToLast() { var migrator = new DBMigrator(new Connections()); migrator.UpdateDatabase(); }
public void UseILogger() { var dbmigrator = new DBMigrator(new ConsoleLogger()); dbmigrator.Migrate(); }
// OCP - Open closed principle // Open for extension, but closed for modification // DBMigration is closed for modification, but open to extension via interface ! static void Main(string[] args) { var migrator = new DBMigrator(new FileLogger("C:\\Users\\Roman\\Documents\\Programmierung\\VS\\Udemy\\CSharpIntermediate\\Tutorials\\Udemy.Intermediate.Tutorials\\log.txt")); migrator.Migrate(); }
static void Main(string[] args) { var dbMigrator = new DBMigrator(new FileLogger("C:\\Projects\\log.txt")); dbMigrator.Migrate(); }
/// <summary> /// Constructor for the Application object. /// </summary> public App() { // Global handler for uncaught exceptions. UnhandledException += Application_UnhandledException; // Standard XAML initialization InitializeComponent(); // Phone-specific initialization InitializePhoneApplication(); // Language display initialization InitializeLanguage(); // Show graphics profiling information while debugging. if (Debugger.IsAttached) { // Display the current frame rate counters. Application.Current.Host.Settings.EnableFrameRateCounter = true; // Show the areas of the app that are being redrawn in each frame. //Application.Current.Host.Settings.EnableRedrawRegions = true; // Enable non-production analysis visualization mode, // which shows areas of a page that are handed off to GPU with a colored overlay. //Application.Current.Host.Settings.EnableCacheVisualization = true; // Prevent the screen from turning off while under the debugger by disabling // the application's idle detection. // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run // and consume battery power when the user is not using the phone. PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; } // Specify the local database connection string. string DBConnectionString = "Data Source=isostore:/" + AppResources.DatabaseName + ".sdf"; // old database name : DellApp.sdf string oldDatabasename = "DellApp.sdf"; // Create the database if it does not exist. using (DBClass db = new DBClass(DBConnectionString)) { if (db.DatabaseExists() == false) { string oldConnectionString = "Data Source=isostore:/" + oldDatabasename ; using (DBClass oldDB = new DBClass(oldConnectionString)) { if (oldDB.DatabaseExists() == true) { // in case old database exists use this IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); iso.CopyFile(oldDatabasename , AppResources.DatabaseName + ".sdf"); } else { //Create the database db.CreateDatabase(); db.DeferredLoadingEnabled = true; #if DEBUG fillDummyDataInDatabase(db); #else fillTutorialDataInDatabase(db); #endif DatabaseSchemaUpdater dbNewUpdater = db.CreateDatabaseSchemaUpdater(); dbNewUpdater.DatabaseSchemaVersion = DB_VERSION; dbNewUpdater.Execute(); } } } using (DBMigrator migrator = new DBMigrator(DBConnectionString , DB_VERSION )) { try { if (migrator.hasToMigrate()) { migrator.MigrateDatabase(); } } catch { throw new Exception("Database error in Timecard App: Connectionstring doesn't point to a existing database. Migration failed."); } } } // Create the ViewModel object. appViewModel = new AppViewModel(DBConnectionString); }