예제 #1
0
        public void CopySettingsStorageProviderData()
        {
            MockRepository mocks = new MockRepository();

            ISettingsStorageProviderV30 source      = mocks.StrictMock <ISettingsStorageProviderV30>();
            ISettingsStorageProviderV30 destination = mocks.StrictMock <ISettingsStorageProviderV30>();
            IAclManager sourceAclManager            = mocks.StrictMock <IAclManager>();
            IAclManager destinationAclManager       = mocks.StrictMock <IAclManager>();

            // Setup SOURCE ---------------------

            // Settings
            Dictionary <string, string> settings = new Dictionary <string, string>()
            {
                { "Set1", "Value1" },
                { "Set2", "Value2" }
            };

            Expect.Call(source.GetAllSettings()).Return(settings);

            // Meta-data (global)
            Expect.Call(source.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null)).Return("AAM");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null)).Return("PRM");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.LoginNotice, null)).Return("");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageChangeMessage, null)).Return("PCM");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null)).Return("DCM");

            // Meta-data (root)
            Expect.Call(source.GetMetaDataItem(MetaDataItem.EditNotice, null)).Return("");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Footer, null)).Return("FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Header, null)).Return("HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.HtmlHead, null)).Return("HTML");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageFooter, null)).Return("P_FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageHeader, null)).Return("P_HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Sidebar, null)).Return("SIDEBAR");

            // Meta-data ("NS" namespace)
            Expect.Call(source.GetMetaDataItem(MetaDataItem.EditNotice, "NS")).Return("NS_EDIT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Footer, "NS")).Return("NS_FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Header, "NS")).Return("NS_HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.HtmlHead, "NS")).Return("NS_HTML");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageFooter, "NS")).Return("NS_P_FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageHeader, "NS")).Return("NS_P_HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Sidebar, "NS")).Return("NS_SIDEBAR");

            // Plugin assemblies
            byte[] asm1 = new byte[] { 1, 2, 3, 4, 5 };
            byte[] asm2 = new byte[] { 6, 7, 8, 9, 10, 11, 12 };
            Expect.Call(source.ListPluginAssemblies()).Return(new string[] { "Plugins1.dll", "Plugins2.dll" });
            Expect.Call(source.RetrievePluginAssembly("Plugins1.dll")).Return(asm1);
            Expect.Call(source.RetrievePluginAssembly("Plugins2.dll")).Return(asm2);

            // Plugin status
            Expect.Call(source.GetPluginStatus("Test1.Plugin1")).Return(true);
            Expect.Call(source.GetPluginStatus("Test2.Plugin2")).Return(false);

            // Plugin config
            Expect.Call(source.GetPluginConfiguration("Test1.Plugin1")).Return("Config1");
            Expect.Call(source.GetPluginConfiguration("Test2.Plugin2")).Return("");

            // Outgoing links
            Dictionary <string, string[]> outgoingLinks = new Dictionary <string, string[]>()
            {
                { "Page1", new string[] { "Page2", "Page3" } },
                { "Page2", new string[] { "Page3" } },
                { "Page3", new string[] { "Page4", "Page3" } }
            };

            Expect.Call(source.GetAllOutgoingLinks()).Return(outgoingLinks);

            // ACLs
            Expect.Call(source.AclManager).Return(sourceAclManager);
            AclEntry[] entries = new AclEntry[] {
                new AclEntry("Res1", "Act1", "Subj1", Value.Grant),
                new AclEntry("Res2", "Act2", "Subj2", Value.Deny)
            };
            Expect.Call(sourceAclManager.RetrieveAllEntries()).Return(entries);

            // Setup DESTINATION -----------------

            // Settings
            destination.BeginBulkUpdate();
            LastCall.On(destination).Repeat.Once();
            foreach (KeyValuePair <string, string> pair in settings)
            {
                Expect.Call(destination.SetSetting(pair.Key, pair.Value)).Return(true);
            }
            destination.EndBulkUpdate();
            LastCall.On(destination).Repeat.Once();

            // Meta-data (global)
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.AccountActivationMessage, null, "AAM")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null, "PRM")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.LoginNotice, null, "")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageChangeMessage, null, "PCM")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null, "DCM")).Return(true);

            // Meta-data (root)
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.EditNotice, null, "")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Footer, null, "FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Header, null, "HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.HtmlHead, null, "HTML")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageFooter, null, "P_FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageHeader, null, "P_HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Sidebar, null, "SIDEBAR")).Return(true);

            // Meta-data ("NS" namespace)
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.EditNotice, "NS", "NS_EDIT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Footer, "NS", "NS_FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Header, "NS", "NS_HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.HtmlHead, "NS", "NS_HTML")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageFooter, "NS", "NS_P_FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageHeader, "NS", "NS_P_HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Sidebar, "NS", "NS_SIDEBAR")).Return(true);

            // Plugin assemblies
            Expect.Call(destination.StorePluginAssembly("Plugins1.dll", asm1)).Return(true);
            Expect.Call(destination.StorePluginAssembly("Plugins2.dll", asm2)).Return(true);

            // Plugin status
            Expect.Call(destination.SetPluginStatus("Test1.Plugin1", true)).Return(true);
            Expect.Call(destination.SetPluginStatus("Test2.Plugin2", false)).Return(true);

            // Plugin config
            Expect.Call(destination.SetPluginConfiguration("Test1.Plugin1", "Config1")).Return(true);
            Expect.Call(destination.SetPluginConfiguration("Test2.Plugin2", "")).Return(true);

            // Outgoing links
            foreach (KeyValuePair <string, string[]> pair in outgoingLinks)
            {
                Expect.Call(destination.StoreOutgoingLinks(pair.Key, pair.Value)).Return(true);
            }

            // ACLs
            Expect.Call(destination.AclManager).Return(destinationAclManager).Repeat.Any();
            foreach (AclEntry e in entries)
            {
                Expect.Call(destinationAclManager.StoreEntry(e.Resource, e.Action, e.Subject, e.Value)).Return(true);
            }

            mocks.ReplayAll();

            DataMigrator.CopySettingsStorageProviderData(source, destination,
                                                         new string[] { "NS" }, new string[] { "Test1.Plugin1", "Test2.Plugin2" });

            mocks.VerifyAll();
        }
예제 #2
0
        /// <summary>
        /// Copies the settings from a Provider to another.
        /// </summary>
        /// <param name="source">The source Provider.</param>
        /// <param name="destination">The destination Provider.</param>
        /// <param name="knownNamespaces">The currently known page namespaces.</param>
        /// <param name="knownPlugins">The currently known plugins.</param>
        public static void CopySettingsStorageProviderData(ISettingsStorageProviderV30 source, ISettingsStorageProviderV30 destination,
                                                           string[] knownNamespaces, string[] knownPlugins)
        {
            // Settings
            destination.BeginBulkUpdate();
            foreach (KeyValuePair <string, string> pair in source.GetAllSettings())
            {
                destination.SetSetting(pair.Key, pair.Value);
            }
            destination.EndBulkUpdate();

            // Meta-data (global)
            destination.SetMetaDataItem(MetaDataItem.AccountActivationMessage, null,
                                        source.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null));
            destination.SetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null,
                                        source.GetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null));
            destination.SetMetaDataItem(MetaDataItem.LoginNotice, null,
                                        source.GetMetaDataItem(MetaDataItem.LoginNotice, null));
            destination.SetMetaDataItem(MetaDataItem.PageChangeMessage, null,
                                        source.GetMetaDataItem(MetaDataItem.PageChangeMessage, null));
            destination.SetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null,
                                        source.GetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null));

            // Meta-data (ns-specific)
            List <string> namespacesToProcess = new List <string>();

            namespacesToProcess.Add(null);
            namespacesToProcess.AddRange(knownNamespaces);
            foreach (string nspace in namespacesToProcess)
            {
                destination.SetMetaDataItem(MetaDataItem.EditNotice, nspace,
                                            source.GetMetaDataItem(MetaDataItem.EditNotice, nspace));
                destination.SetMetaDataItem(MetaDataItem.Footer, nspace,
                                            source.GetMetaDataItem(MetaDataItem.Footer, nspace));
                destination.SetMetaDataItem(MetaDataItem.Header, nspace,
                                            source.GetMetaDataItem(MetaDataItem.Header, nspace));
                destination.SetMetaDataItem(MetaDataItem.HtmlHead, nspace,
                                            source.GetMetaDataItem(MetaDataItem.HtmlHead, nspace));
                destination.SetMetaDataItem(MetaDataItem.PageFooter, nspace,
                                            source.GetMetaDataItem(MetaDataItem.PageFooter, nspace));
                destination.SetMetaDataItem(MetaDataItem.PageHeader, nspace,
                                            source.GetMetaDataItem(MetaDataItem.PageHeader, nspace));
                destination.SetMetaDataItem(MetaDataItem.Sidebar, nspace,
                                            source.GetMetaDataItem(MetaDataItem.Sidebar, nspace));
            }

            // Plugin assemblies
            string[] assemblies = source.ListPluginAssemblies();
            foreach (string asm in assemblies)
            {
                destination.StorePluginAssembly(asm,
                                                source.RetrievePluginAssembly(asm));
            }

            // Plugin status and config
            foreach (string plug in knownPlugins)
            {
                destination.SetPluginStatus(plug,
                                            source.GetPluginStatus(plug));

                destination.SetPluginConfiguration(plug,
                                                   source.GetPluginConfiguration(plug));
            }

            // Outgoing links
            IDictionary <string, string[]> allLinks = source.GetAllOutgoingLinks();

            foreach (KeyValuePair <string, string[]> link in allLinks)
            {
                destination.StoreOutgoingLinks(link.Key, link.Value);
            }

            // ACLs
            AclEntry[] allEntries = source.AclManager.RetrieveAllEntries();
            foreach (AclEntry entry in allEntries)
            {
                destination.AclManager.StoreEntry(entry.Resource, entry.Action, entry.Subject, entry.Value);
            }
        }