Ejemplo n.º 1
0
        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);
        }