public void Seed(SmartObjectContext context) { if (DataSettings.DatabaseIsInstalled()) { DataMigrator.CreateSystemMenus(context); } }
private void LoadDataFromExcelFiles(object sender, RoutedEventArgs e) { DataMigrator dataMigrator = new DataMigrator(); dataMigrator.MigrateDataFromExcelFiles(); MessageBox.Show("Zip file to MS SQL Server Magic !!!"); }
public void Seed(SmartObjectContext context) { context.MigrateLocaleResources(MigrateLocaleResources); context.SaveChanges(); DataMigrator.MoveCustomerFields(context); }
public void Seed(SmartObjectContext context) { if (DataSettings.DatabaseIsInstalled()) { DataMigrator.AddRuleSets(context); } }
public void Seed(SmartObjectContext context) { context.MigrateLocaleResources(MigrateLocaleResources); DataMigrator.ImportAddressFormats(context); context.SaveChanges(); }
public void Seed(SmartObjectContext context) { if (DataSettings.DatabaseIsInstalled()) { DataMigrator.AddGranularPermissions(context); } }
public Create(Interpreter interpreter, SchemaComparer schemaComparer, DataMigrator dataMigrator) { _interpreter = interpreter; _schemaComparer = schemaComparer; _dataMigrator = dataMigrator; }
public override void OnBeforeSaveCompleted() { foreach (var product in _products) { DataMigrator.FixProductMainPictureId(_rsProduct.Context, product); } _products.Clear(); }
public void Seed(SmartObjectContext context) { // Perf var numDeletedAttrs = DataMigrator.DeleteGuestCustomerGenericAttributes(context, TimeSpan.FromDays(30)); var numDeletedCustomers = DataMigrator.DeleteGuestCustomers(context, TimeSpan.FromDays(30)); var candidates = new[] { "Gender", "VatNumberStatusId", "TimeZoneId", "TaxDisplayTypeId", "LastForumVisit", "LastUserAgent", "LastUserDeviceType" }; var numUpdatedCustomers = DataMigrator.MoveCustomerFields(context, UpdateCustomer, candidates); }
public void Seed(SmartObjectContext context) { if (!HostingEnvironment.IsHosted) { return; } DataMigrator.SetDownloadProductId(context); }
public void Seed(SmartObjectContext context) { context.MigrateLocaleResources(MigrateLocaleResources); context.SaveChanges(); if (DataSettings.DatabaseIsInstalled()) { DataMigrator.AddGranularPermissions(context); } }
public static void Bootstrap() { Setup(); using (var db = ObjectFactory.GetInstance <SqlConnection>()) { db.Open(); DataMigrator.RunMigrations(db); } }
public void Seed(SmartObjectContext context) { context.MigrateLocaleResources(MigrateLocaleResources); // Perf var numDeletedAttrs = DataMigrator.DeleteGuestCustomerGenericAttributes(context, TimeSpan.FromDays(30)); var numDeletedCustomers = DataMigrator.DeleteGuestCustomers(context, TimeSpan.FromDays(30)); var candidates = new[] { "Title", "FirstName", "LastName", "Company", "CustomerNumber", "DateOfBirth" }; var numUpdatedCustomers = DataMigrator.MoveCustomerFields(context, UpdateCustomer, candidates); }
private void frmMigrationBuilder_Load(object sender, EventArgs e) { _migrator = new DataMigrator(SavedConnections); _migrator.Progress += ShowProgress; _migrator.ConsoleMessage += delegate(object sender2, string message) { consoleTextBox1.Insert(message); }; InitBinding(); }
public void Seed(SmartObjectContext context) { if (!HostingEnvironment.IsHosted) { return; } // Move the whole media folder to new location at first MoveMediaFolder(); // Reorganize files (root > Storage/{subfolder}) DataMigrator.MoveFsMedia(context); }
private void PopulateProducts() { var products = _data.Products(); SaveRange(products); // Fix MainPictureId DataMigrator.FixProductMainPictureIds(_ctx); PopulateUrlRecordsFor(products); _data.AssignGroupedProducts(products); }
public async Task ApplyMigratonsFromDefaultAssembly_ExpectsOk() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.CreateIfNotExists(); var migrator = new DataMigrator(ctx, new DataMigrationOptions()); await migrator.MigrateAsync(); var applied = await migrator.GetAppliedMigrationsAsync(); Assert.Equal(new[] { nameof(D0000001_InitialDataMigration), AddDummyCustomer.MigrationId }, applied); } }
private async Task PopulateProducts() { var products = _data.Products(); await SaveRange(products); _data.AddDownloads(products); // Fix MainPictureId await DataMigrator.FixProductMainPictureIds(_db); await PopulateUrlRecordsFor(products); _data.AssignGroupedProducts(products); }
public async Task ApplyMigratonsWithSurroundingTransactionRollback_ExpectsEmptyDb() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.Create(); var migrator = new DataMigrator(ctx, new DataMigrationOptions()); using (var transaction = ctx.Database.BeginTransaction()) { await migrator.MigrateAsync(); } var applied = await migrator.GetAppliedMigrationsAsync(); Assert.Empty(applied); } }
public async Task <IActionResult> Migrate([FromHeader] string key) { if (!Validate(key)) { return(Unauthorized()); } try { var userManager = serviceProvider.GetService <UserManager <ApplicationUser> >(); await DataMigrator.MigrateV1(dbContext, userManager, configuration.GetConnectionString("ClimbV1")); return(Ok()); } catch (Exception exception) { logger.LogError("Failed migrating data.", exception); return(StatusCode(500, exception)); } }
public async Task ApplyMigratonsWithSurroundingTransaction_ExpectsOk() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.Create(); var migrator = new DataMigrator(ctx, new DataMigrationOptions()); using (var transaction = ctx.Database.BeginTransaction()) { await migrator.MigrateAsync(); transaction.Commit(); } var applied = await migrator.GetAppliedMigrationsAsync(); Assert.Equal(new[] { nameof(D0000001_InitialDataMigration), AddDummyCustomer.MigrationId }, applied); } }
public async Task ApplyMigratonsFromExternalAssembly_ExpectsOk() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.CreateIfNotExists(); var migrator = new DataMigrator(ctx, new DataMigrationOptions { MigrationAssembly = "Extensions.EntityFramework.Migration" }); await migrator.MigrateAsync(); var applied = await migrator.GetAppliedMigrationsAsync(); var data = await ctx.Currencies.ToListAsync(); Assert.Equal(new[] { nameof(ExternalMigration) }, applied); Assert.Single(data); Assert.Equal("CHF", data[0].IsoCode); } }
public async Task ApplyMigratonsFromDefaultAndExternalAssembly_ExpectsOk() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.CreateIfNotExists(); var migrator = new DataMigrator(ctx, new DataMigrationOptions()); await migrator.MigrateAsync(); var migratorExternal = new DataMigrator(ctx, new DataMigrationOptions { MigrationAssembly = "Extensions.EntityFramework.Migration" }); await migratorExternal.MigrateAsync(); var applied = await migrator.GetAppliedMigrationsAsync(); applied = applied.Concat(await migratorExternal.GetAppliedMigrationsAsync()); Assert.Equal(new[] { nameof(D0000001_InitialDataMigration), AddDummyCustomer.MigrationId, nameof(ExternalMigration) }, applied); } }
private void PopulateProducts() { var products = _data.Products(); SaveRange(products); // Fix MainPictureId DataMigrator.FixProductMainPictureIds(_ctx); // Search engine names products.Each(x => { Save(new UrlRecord { EntityId = x.Id, EntityName = "Product", LanguageId = 0, Slug = ValidateSeName(x, x.Name), IsActive = true }); }); _data.AssignGroupedProducts(products); }
/// <summary> /// Start the application context /// </summary> public static bool Start(A.Content.Context launcherActivity, A.Content.Context context, A.App.Application application) { var retVal = new AndroidApplicationContext(); retVal.Context = context; retVal.m_configurationManager = new ConfigurationManager(); retVal.AndroidApplication = application; // Not configured if (!retVal.ConfigurationManager.IsConfigured) { NoConfiguration?.Invoke(null, EventArgs.Empty); return(false); } else { // load configuration try { // Set master application context ApplicationContext.Current = retVal; retVal.CurrentActivity = launcherActivity; try { retVal.ConfigurationManager.Load(); retVal.ConfigurationManager.Backup(); } catch { if (retVal.ConfigurationManager.HasBackup() && retVal.Confirm(Strings.err_configuration_invalid_restore_prompt)) { retVal.ConfigurationManager.Restore(); retVal.ConfigurationManager.Load(); } else { throw; } } retVal.AddServiceProvider(typeof(AndroidBackupService)); retVal.m_tracer = Tracer.GetTracer(typeof(AndroidApplicationContext), retVal.ConfigurationManager.Configuration); // Is there a backup, and if so, does the user want to restore from that backup? var backupSvc = retVal.GetService <IBackupService>(); if (backupSvc.HasBackup(BackupMedia.Public) && retVal.Configuration.GetAppSetting("ignore.restore") == null && retVal.Confirm(Strings.locale_confirm_restore)) { backupSvc.Restore(BackupMedia.Public); } // Ignore restoration if (!retVal.Configuration.GetSection <ApplicationConfigurationSection>().AppSettings.Any(o => o.Key == "ignore.restore")) { retVal.Configuration.GetSection <ApplicationConfigurationSection>().AppSettings.Add(new AppSettingKeyValuePair() { Key = "ignore.restore", Value = "true" }); } // HACK: For some reason the PCL doesn't do this automagically //var connectionString = retVal.Configuration.GetConnectionString("openIzWarehouse"); //if (!File.Exists(connectionString.Value)) //{ // retVal.m_tracer.TraceInfo("HAX: Creating warehouse file since PCL can't... {0}", connectionString.Value); // SqliteConnection.CreateFile(connectionString.Value); //} // Load configured applets var configuredApplets = retVal.Configuration.GetSection <AppletConfigurationSection>().Applets; retVal.SetProgress(context.GetString(Resource.String.startup_configuration), 0.2f); var appletManager = retVal.GetService <IAppletManagerService>(); // Load all user-downloaded applets in the data directory foreach (var appletInfo in configuredApplets)// Directory.GetFiles(this.m_configuration.GetSection<AppletConfigurationSection>().AppletDirectory)) { { try { retVal.m_tracer.TraceInfo("Loading applet {0}", appletInfo); String appletPath = Path.Combine(retVal.Configuration.GetSection <AppletConfigurationSection>().AppletDirectory, appletInfo.Id); if (!File.Exists(appletPath)) // reinstall { retVal.Configuration.GetSection <AppletConfigurationSection>().Applets.Clear(); retVal.SaveConfiguration(); retVal.Alert(Strings.locale_restartRequired); throw new AppDomainUnloadedException(); } // Load using (var fs = File.OpenRead(appletPath)) { AppletManifest manifest = AppletManifest.Load(fs); // Is this applet in the allowed applets // public key token match? if (appletInfo.PublicKeyToken != manifest.Info.PublicKeyToken) { retVal.m_tracer.TraceWarning("Applet {0} failed validation", appletInfo); ; // TODO: Raise an error } appletManager.LoadApplet(manifest); } } catch (AppDomainUnloadedException) { throw; } } catch (Exception e) { retVal.m_tracer.TraceError("Applet Load Error: {0}", e); if (retVal.Confirm(String.Format(Strings.err_applet_corrupt_reinstall, appletInfo.Id))) { String appletPath = Path.Combine(retVal.Configuration.GetSection <AppletConfigurationSection>().AppletDirectory, appletInfo.Id); if (File.Exists(appletPath)) { File.Delete(appletPath); } } else { retVal.m_tracer.TraceError("Loading applet {0} failed: {1}", appletInfo, e.ToString()); throw; } } // Are we going to deploy applets // Upgrade applets from our app manifest foreach (var itm in context.Assets.List("Applets")) { try { retVal.m_tracer.TraceVerbose("Loading {0}", itm); AppletPackage pkg = AppletPackage.Load(context.Assets.Open(String.Format("Applets/{0}", itm))); // Write data to assets directory #if !DEBUG if (appletManager.GetApplet(pkg.Meta.Id) == null || new Version(appletManager.GetApplet(pkg.Meta.Id).Info.Version) < new Version(pkg.Meta.Version)) #endif appletManager.Install(pkg, true); } catch (Exception e) { retVal.m_tracer?.TraceError(e.ToString()); } } // Ensure data migration exists try { // If the DB File doesn't exist we have to clear the migrations if (!File.Exists(retVal.Configuration.GetConnectionString(retVal.Configuration.GetSection <DataConfigurationSection>().MainDataSourceConnectionStringName).Value)) { retVal.m_tracer.TraceWarning("Can't find the OpenIZ database, will re-install all migrations"); retVal.Configuration.GetSection <DataConfigurationSection>().MigrationLog.Entry.Clear(); } retVal.SetProgress(context.GetString(Resource.String.startup_data), 0.6f); DataMigrator migrator = new DataMigrator(); migrator.Ensure(); // Set the entity source EntitySource.Current = new EntitySource(retVal.GetService <IEntitySourceProvider>()); ApplicationServiceContext.Current = ApplicationContext.Current; ApplicationServiceContext.HostType = OpenIZHostType.MobileClient; } catch (Exception e) { retVal.m_tracer.TraceError(e.ToString()); throw; } finally { retVal.ConfigurationManager.Save(); } // Is there a backup manager? If no then we will use the default backup manager // Start daemons ApplicationContext.Current.GetService <IUpdateManager>().AutoUpdate(); retVal.GetService <IThreadPoolService>().QueueNonPooledWorkItem(o => { retVal.Start(); }, null); // Set the tracer writers for the PCL goodness! foreach (var itm in retVal.Configuration.GetSection <DiagnosticsConfigurationSection>().TraceWriter) { OpenIZ.Core.Diagnostics.Tracer.AddWriter(itm.TraceWriter, itm.Filter); } }
/// <summary> /// Start the application context /// </summary> public static bool Start(ConsoleParameters consoleParms) { var retVal = new MiniApplicationContext(); retVal.m_configurationManager = new MiniConfigurationManager(); // Not configured if (!retVal.ConfigurationManager.IsConfigured) { return(false); } else { // load configuration try { // Set master application context ApplicationContext.Current = retVal; retVal.ConfigurationManager.Load(); retVal.AddServiceProvider(typeof(XamarinBackupService)); retVal.m_tracer = Tracer.GetTracer(typeof(MiniApplicationContext), retVal.ConfigurationManager.Configuration); var appService = retVal.GetService <IAppletManagerService>(); retVal.SetProgress("Loading configuration", 0.2f); if (consoleParms.References != null) { // Load references foreach (var appletInfo in consoleParms.References)// Directory.GetFiles(this.m_configuration.GetSection<AppletConfigurationSection>().AppletDirectory)) { { try { retVal.m_tracer.TraceInfo("Loading applet {0}", appletInfo); String appletPath = appletInfo; if (!Path.IsPathRooted(appletInfo)) { appletPath = Path.Combine(Environment.CurrentDirectory, appletPath); } using (var fs = File.OpenRead(appletPath)) { var package = AppletPackage.Load(fs); retVal.m_tracer.TraceInfo("Loading {0} v{1}", package.Meta.Id, package.Meta.Version); // Is this applet in the allowed applets appService.LoadApplet(package.Unpack()); } } catch (Exception e) { retVal.m_tracer.TraceError("Loading applet {0} failed: {1}", appletInfo, e.ToString()); throw; } } } // Does openiz.js exist as an asset? var oizJs = appService.Applets.ResolveAsset("/org.openiz.core/js/openiz.js"); // Load all user-downloaded applets in the data directory foreach (var appletDir in consoleParms.AppletDirectories)// Directory.GetFiles(this.m_configuration.GetSection<AppletConfigurationSection>().AppletDirectory)) { { try { if (!Directory.Exists(appletDir) || !File.Exists(Path.Combine(appletDir, "manifest.xml"))) { continue; } retVal.m_tracer.TraceInfo("Loading applet {0}", appletDir); String appletPath = Path.Combine(appletDir, "manifest.xml"); using (var fs = File.OpenRead(appletPath)) { AppletManifest manifest = AppletManifest.Load(fs); (appService as MiniAppletManagerService).m_appletBaseDir.Add(manifest, appletDir); // Is this applet in the allowed applets // public key token match? appService.LoadApplet(manifest); } } catch (Exception e) { retVal.m_tracer.TraceError("Loading applet {0} failed: {1}", appletDir, e.ToString()); throw; } } if (oizJs?.Content != null) { oizJs.Content = oizJs.Content.ToString() + (appService as MiniAppletManagerService).GetShimMethods(); } // Ensure data migration exists try { // If the DB File doesn't exist we have to clear the migrations if (!File.Exists(retVal.Configuration.GetConnectionString(retVal.Configuration.GetSection <DataConfigurationSection>().MainDataSourceConnectionStringName).Value)) { retVal.m_tracer.TraceWarning("Can't find the OpenIZ database, will re-install all migrations"); retVal.Configuration.GetSection <DataConfigurationSection>().MigrationLog.Entry.Clear(); } retVal.SetProgress("Migrating databases", 0.6f); DataMigrator migrator = new DataMigrator(); migrator.Ensure(); // Set the entity source EntitySource.Current = new EntitySource(retVal.GetService <IEntitySourceProvider>()); // Prepare clinical protocols //retVal.GetService<ICarePlanService>().Repository = retVal.GetService<IClinicalProtocolRepositoryService>(); ApplicationServiceContext.Current = ApplicationContext.Current; ApplicationServiceContext.HostType = OpenIZHostType.OtherClient; } catch (Exception e) { retVal.m_tracer.TraceError(e.ToString()); throw; } finally { retVal.ConfigurationManager.Save(); } if (!retVal.Configuration.GetSection <DiagnosticsConfigurationSection>().TraceWriter.Any(o => o.TraceWriterClassXml.Contains("Console"))) { retVal.Configuration.GetSection <DiagnosticsConfigurationSection>().TraceWriter.Add(new TraceWriterConfiguration() { TraceWriter = new ConsoleTraceWriter(EventLevel.Warning, "") }); } // Set the tracer writers for the PCL goodness! foreach (var itm in retVal.Configuration.GetSection <DiagnosticsConfigurationSection>().TraceWriter) { OpenIZ.Core.Diagnostics.Tracer.AddWriter(itm.TraceWriter, itm.Filter); } // Start daemons retVal.GetService <IThreadPoolService>().QueueUserWorkItem(o => { retVal.Start(); }); //retVal.Start(); } catch (Exception e) { retVal.m_tracer?.TraceError(e.ToString()); //ApplicationContext.Current = null; retVal.m_configurationManager = new MiniConfigurationManager(MiniConfigurationManager.GetDefaultConfiguration()); throw; } return(true); } }
private void PopulateCountriesAndStates() { SaveRange(_data.Countries().Where(x => x != null)); DataMigrator.ImportAddressFormats(_ctx); }
private void PopulateMenus() { DataMigrator.CreateSystemMenus(_ctx); }
public void MigrateUsersStorageProviderData() { var mocks = new MockRepository(); var source = mocks.StrictMock <IUsersStorageProviderV30>(); var destination = mocks.StrictMock <IUsersStorageProviderV30>(); // Setup SOURCE -------------------- // User groups var g1 = new UserGroup("G1", "G1", source); var g2 = new UserGroup("G2", "G2", source); Expect.Call(source.GetUserGroups()).Return(new[] { g1, g2 }); // Users var u1 = new UserInfo("U1", "U1", "*****@*****.**", true, DateTime.Now, source); var u2 = new UserInfo("U2", "U2", "*****@*****.**", true, DateTime.Now, source); var u3 = new UserInfo("U3", "U3", "*****@*****.**", true, DateTime.Now, source); Expect.Call(source.GetUsers()).Return(new[] { u1, u2, u3 }); // Membership g1.Users = new[] { u1.Username, u2.Username }; g2.Users = new[] { u2.Username, u3.Username }; u1.Groups = new[] { g1.Name }; u2.Groups = new[] { g1.Name, g2.Name }; u3.Groups = new[] { g2.Name }; // User data IDictionary <string, string> u1Data = new Dictionary <string, string> { { "Key1", "Value1" }, { "Key2", "Value2" } }; Expect.Call(source.RetrieveAllUserData(u1)).Return(u1Data); Expect.Call(source.RetrieveAllUserData(u2)).Return(new Dictionary <string, string>()); Expect.Call(source.RetrieveAllUserData(u3)).Return(new Dictionary <string, string>()); // Setup DESTINATION ------------------ // User groups var g1Out = new UserGroup(g1.Name, g1.Description, destination); var g2Out = new UserGroup(g2.Name, g2.Description, destination); Expect.Call(destination.AddUserGroup(g1.Name, g1.Description)).Return(g1Out); Expect.Call(destination.AddUserGroup(g2.Name, g2.Description)).Return(g2Out); // Users var u1Out = new UserInfo(u1.Username, u1.DisplayName, u1.Email, u1.Active, u1.DateTime, destination); var u2Out = new UserInfo(u2.Username, u2.DisplayName, u2.Email, u2.Active, u2.DateTime, destination); var u3Out = new UserInfo(u3.Username, u3.DisplayName, u3.Email, u3.Active, u3.DateTime, destination); Expect.Call(destination.AddUser(u1.Username, u1.DisplayName, null, u1.Email, u1.Active, u1.DateTime)) .Return(u1Out) .Constraints( RMC.Is.Equal(u1.Username), RMC.Is.Equal(u1.DisplayName), RMC.Is.Anything(), RMC.Is.Equal(u1.Email), RMC.Is.Equal(u1.Active), RMC.Is.Equal(u1.DateTime)); Expect.Call(destination.AddUser(u2.Username, u2.DisplayName, null, u2.Email, u2.Active, u2.DateTime)) .Return(u2Out) .Constraints( RMC.Is.Equal(u2.Username), RMC.Is.Equal(u2.DisplayName), RMC.Is.Anything(), RMC.Is.Equal(u2.Email), RMC.Is.Equal(u2.Active), RMC.Is.Equal(u2.DateTime)); Expect.Call(destination.AddUser(u3.Username, u3.DisplayName, null, u3.Email, u3.Active, u3.DateTime)) .Return(u3Out) .Constraints( RMC.Is.Equal(u3.Username), RMC.Is.Equal(u3.DisplayName), RMC.Is.Anything(), RMC.Is.Equal(u3.Email), RMC.Is.Equal(u3.Active), RMC.Is.Equal(u3.DateTime)); // Membership Expect.Call(destination.SetUserMembership(u1Out, u1.Groups)).Return(u1Out); Expect.Call(destination.SetUserMembership(u2Out, u2.Groups)).Return(u2Out); Expect.Call(destination.SetUserMembership(u3Out, u3.Groups)).Return(u3Out); // User data Expect.Call(destination.StoreUserData(u1Out, "Key1", "Value1")).Return(true); Expect.Call(destination.StoreUserData(u1Out, "Key2", "Value2")).Return(true); // Delete source data Expect.Call(source.RemoveUser(u1)).Return(true); Expect.Call(source.RemoveUser(u2)).Return(true); Expect.Call(source.RemoveUser(u3)).Return(true); Expect.Call(source.RemoveUserGroup(g1)).Return(true); Expect.Call(source.RemoveUserGroup(g2)).Return(true); mocks.Replay(source); mocks.Replay(destination); DataMigrator.MigrateUsersStorageProviderData(source, destination, false); mocks.Verify(source); mocks.Verify(destination); }
public void MigratePagesStorageProviderData() { var mocks = new MockRepository(); var source = mocks.StrictMock <IPagesStorageProviderV30>(); var destination = mocks.StrictMock <IPagesStorageProviderV30>(); // Setup SOURCE ------------------------- // Setup snippets var s1 = new Snippet("S1", "Blah1", source); var s2 = new Snippet("S2", "Blah2", source); Expect.Call(source.GetSnippets()).Return(new[] { s1, s2 }); // Setup content templates var ct1 = new ContentTemplate("CT1", "Template 1", source); var ct2 = new ContentTemplate("CT2", "Template 2", source); Expect.Call(source.GetContentTemplates()).Return(new[] { ct1, ct2 }); // Setup namespaces var ns1 = new NamespaceInfo("NS1", source, null); var ns2 = new NamespaceInfo("NS2", source, null); Expect.Call(source.GetNamespaces()).Return(new[] { ns1, ns2 }); // Setup pages var p1 = new PageInfo("Page", source, DateTime.Now); var p2 = new PageInfo(NameTools.GetFullName(ns1.Name, "Page"), source, DateTime.Now); var p3 = new PageInfo(NameTools.GetFullName(ns1.Name, "Page1"), source, DateTime.Now); Expect.Call(source.GetPages(null)).Return(new[] { p1 }); Expect.Call(source.GetPages(ns1)).Return(new[] { p2, p3 }); Expect.Call(source.GetPages(ns2)).Return(new PageInfo[0]); // Set default page for NS1 ns1.DefaultPage = p2; // Setup categories/bindings var c1 = new CategoryInfo("Cat", source); c1.Pages = new[] { p1.FullName }; var c2 = new CategoryInfo(NameTools.GetFullName(ns1.Name, "Cat"), source); c2.Pages = new[] { p2.FullName }; var c3 = new CategoryInfo(NameTools.GetFullName(ns1.Name, "Cat1"), source); c3.Pages = new string[0]; Expect.Call(source.GetCategories(null)).Return(new[] { c1 }); Expect.Call(source.GetCategories(ns1)).Return(new[] { c2, c3 }); Expect.Call(source.GetCategories(ns2)).Return(new CategoryInfo[0]); // Setup drafts var d1 = new PageContent(p1, "Draft", "NUnit", DateTime.Now, "Comm", "Cont", new[] { "k1", "k2" }, "Descr"); Expect.Call(source.GetDraft(p1)).Return(d1); Expect.Call(source.GetDraft(p2)).Return(null); Expect.Call(source.GetDraft(p3)).Return(null); // Setup content var ctn1 = new PageContent(p1, "Title1", "User1", DateTime.Now, "Comm1", "Cont1", null, "Descr1"); var ctn2 = new PageContent(p2, "Title2", "User2", DateTime.Now, "Comm2", "Cont2", null, "Descr2"); var ctn3 = new PageContent(p3, "Title3", "User3", DateTime.Now, "Comm3", "Cont3", null, "Descr3"); Expect.Call(source.GetContent(p1)).Return(ctn1); Expect.Call(source.GetContent(p2)).Return(ctn2); Expect.Call(source.GetContent(p3)).Return(ctn3); // Setup backups Expect.Call(source.GetBackups(p1)).Return(new[] { 0, 1 }); Expect.Call(source.GetBackups(p2)).Return(new[] { 0 }); Expect.Call(source.GetBackups(p3)).Return(new int[0]); var bak1_0 = new PageContent(p1, "K1_0", "U1_0", DateTime.Now, "", "Cont", null, null); var bak1_1 = new PageContent(p1, "K1_1", "U1_1", DateTime.Now, "", "Cont", null, null); var bak2_0 = new PageContent(p2, "K2_0", "U2_0", DateTime.Now, "", "Cont", null, null); Expect.Call(source.GetBackupContent(p1, 0)).Return(bak1_0); Expect.Call(source.GetBackupContent(p1, 1)).Return(bak1_1); Expect.Call(source.GetBackupContent(p2, 0)).Return(bak2_0); // Messages var m1 = new Message(1, "User1", "Subject1", DateTime.Now, "Body1"); m1.Replies = new[] { new Message(2, "User2", "Subject2", DateTime.Now, "Body2") }; Message[] p1m = { m1 }; var p2m = new Message[0]; var p3m = new Message[0]; Expect.Call(source.GetMessages(p1)).Return(p1m); Expect.Call(source.GetMessages(p2)).Return(p2m); Expect.Call(source.GetMessages(p3)).Return(p3m); // Setup navigation paths var n1 = new NavigationPath("N1", source); n1.Pages = new[] { p1.FullName }; var n2 = new NavigationPath(NameTools.GetFullName(ns1.Name, "N1"), source); n2.Pages = new[] { p2.FullName, p3.FullName }; Expect.Call(source.GetNavigationPaths(null)).Return(new[] { n1 }); Expect.Call(source.GetNavigationPaths(ns1)).Return(new[] { n2 }); Expect.Call(source.GetNavigationPaths(ns2)).Return(new NavigationPath[0]); // Setup DESTINATION -------------------------- // Snippets Expect.Call(destination.AddSnippet(s1.Name, s1.Content)) .Return(new Snippet(s1.Name, s1.Content, destination)); Expect.Call(source.RemoveSnippet(s1.Name)).Return(true); Expect.Call(destination.AddSnippet(s2.Name, s2.Content)) .Return(new Snippet(s2.Name, s2.Content, destination)); Expect.Call(source.RemoveSnippet(s2.Name)).Return(true); // Content templates Expect.Call(destination.AddContentTemplate(ct1.Name, ct1.Content)) .Return(new ContentTemplate(ct1.Name, ct1.Name, destination)); Expect.Call(source.RemoveContentTemplate(ct1.Name)).Return(true); Expect.Call(destination.AddContentTemplate(ct2.Name, ct2.Content)) .Return(new ContentTemplate(ct2.Name, ct2.Name, destination)); Expect.Call(source.RemoveContentTemplate(ct2.Name)).Return(true); // Namespaces var ns1Out = new NamespaceInfo(ns1.Name, destination, null); var ns2Out = new NamespaceInfo(ns2.Name, destination, null); Expect.Call(destination.AddNamespace(ns1.Name)).Return(ns1Out); Expect.Call(source.RemoveNamespace(ns1)).Return(true); Expect.Call(destination.AddNamespace(ns2.Name)).Return(ns2Out); Expect.Call(source.RemoveNamespace(ns2)).Return(true); // Pages/drafts/content/backups/messages var p1Out = new PageInfo(p1.FullName, destination, p1.CreationDateTime); Expect.Call(destination.AddPage(null, p1.FullName, p1.CreationDateTime)).Return(p1Out); Expect.Call(destination.ModifyPage(p1Out, ctn1.Title, ctn1.User, ctn1.LastModified, ctn1.Comment, ctn1.Content, ctn1.Keywords, ctn1.Description, SaveMode.Normal)).Return(true); Expect.Call(destination.ModifyPage(p1Out, d1.Title, d1.User, d1.LastModified, d1.Comment, d1.Content, d1.Keywords, d1.Description, SaveMode.Draft)).Return(true); Expect.Call(destination.SetBackupContent(bak1_0, 0)).Return(true); Expect.Call(destination.SetBackupContent(bak1_1, 1)).Return(true); Expect.Call(destination.BulkStoreMessages(p1Out, p1m)).Return(true); Expect.Call(source.RemovePage(p1)).Return(true); var p2Out = new PageInfo(p2.FullName, destination, p2.CreationDateTime); Expect.Call(destination.AddPage(p2.Namespace, p2.Name, p2.CreationDateTime)).Return(p2Out); Expect.Call(destination.ModifyPage(p2Out, ctn2.Title, ctn2.User, ctn2.LastModified, ctn2.Comment, ctn2.Content, ctn2.Keywords, ctn2.Description, SaveMode.Normal)).Return(true); Expect.Call(destination.SetBackupContent(bak2_0, 0)).Return(true); Expect.Call(destination.BulkStoreMessages(p2Out, p2m)).Return(true); Expect.Call(source.RemovePage(p2)).Return(true); var p3Out = new PageInfo(p3.FullName, destination, p3.CreationDateTime); Expect.Call(destination.AddPage(p3.Namespace, p3.Name, p3.CreationDateTime)).Return(p3Out); Expect.Call(destination.ModifyPage(p3Out, ctn3.Title, ctn3.User, ctn3.LastModified, ctn3.Comment, ctn3.Content, ctn3.Keywords, ctn3.Description, SaveMode.Normal)).Return(true); Expect.Call(destination.BulkStoreMessages(p3Out, p3m)).Return(true); Expect.Call(source.RemovePage(p3)).Return(true); // Categories/bindings var c1Out = new CategoryInfo(c1.FullName, destination); var c2Out = new CategoryInfo(c2.FullName, destination); var c3Out = new CategoryInfo(c3.FullName, destination); Expect.Call(destination.AddCategory(null, c1.FullName)).Return(c1Out); Expect.Call(destination.AddCategory(NameTools.GetNamespace(c2.FullName), NameTools.GetLocalName(c2.FullName))) .Return(c2Out); Expect.Call(destination.AddCategory(NameTools.GetNamespace(c3.FullName), NameTools.GetLocalName(c3.FullName))) .Return(c3Out); Expect.Call(destination.RebindPage(p1Out, new[] { c1.FullName })).Return(true); Expect.Call(destination.RebindPage(p2Out, new[] { c2.FullName })).Return(true); Expect.Call(destination.RebindPage(p3Out, new string[0])).Return(true); Expect.Call(source.RemoveCategory(c1)).Return(true); Expect.Call(source.RemoveCategory(c2)).Return(true); Expect.Call(source.RemoveCategory(c3)).Return(true); // Navigation paths var n1Out = new NavigationPath(n1.FullName, destination); n1Out.Pages = n1.Pages; var n2Out = new NavigationPath(n2.FullName, destination); n2Out.Pages = n2.Pages; Expect.Call(destination.AddNavigationPath(null, n1.FullName, new[] { p1 })).Return(n1Out).Constraints( RMC.Is.Null(), RMC.Is.Equal(n1.FullName), RMC.Is.Matching(delegate(PageInfo[] array) { return(array[0].FullName == p1.FullName); })); Expect.Call(destination.AddNavigationPath(NameTools.GetNamespace(n2.FullName), NameTools.GetLocalName(n2.FullName), new[] { p2, p3 })).Return(n2Out).Constraints( RMC.Is.Equal(NameTools.GetNamespace(n2.FullName)), RMC.Is.Equal(NameTools.GetLocalName(n2.FullName)), RMC.Is.Matching( delegate(PageInfo[] array) { return(array[0].FullName == p2.FullName && array[1].FullName == p3.FullName); })); Expect.Call(source.RemoveNavigationPath(n1)).Return(true); Expect.Call(source.RemoveNavigationPath(n2)).Return(true); Expect.Call(destination.SetNamespaceDefaultPage(ns1Out, p2Out)).Return(ns1Out); Expect.Call(destination.SetNamespaceDefaultPage(ns2Out, null)).Return(ns2Out); // Used for navigation paths Expect.Call(destination.GetPages(null)).Return(new[] { p1Out }); Expect.Call(destination.GetPages(ns1Out)).Return(new[] { p2Out, p3Out }); Expect.Call(destination.GetPages(ns2Out)).Return(new PageInfo[0]); mocks.Replay(source); mocks.Replay(destination); DataMigrator.MigratePagesStorageProviderData(source, destination); mocks.Verify(source); mocks.Verify(destination); }