public void EnableFancyForms_FancyFormNotFound_SaveChangesAndDispose()
        {
            // Arrange
            var actualCountSaveChanges = 0;
            var actualDisposeWeb       = false;
            var list = new ShimSPList()
            {
                ParentWebGet = () => new ShimSPWeb()
                {
                    ServerRelativeUrlGet = () => DummyUrl,
                    GetFileString        = strUrl => new ShimSPFile()
                    {
                        GetLimitedWebPartManagerPersonalizationScope = scope => new ShimSPLimitedWebPartManager()
                        {
                            WebPartsGet = () => new ShimSPLimitedWebPartCollection()
                            {
                                ItemGetInt32 = itemId =>
                                {
                                    if (itemId == 0)
                                    {
                                        return(new ShimWebPart(new ShimGridListView().Instance)
                                        {
                                            TitleGet = () => "Fancy Display Form"
                                        });
                                    }

                                    return(new ShimWebPart(new ShimListFormWebPart().Instance));
                                }
                            }
                            .Bind(
                                new WebPart[]
                            {
                                new ShimWebPart(new ShimGridListView().Instance),
                                new ShimWebPart(new ShimListFormWebPart().Instance)
                            }),
                            SaveChangesWebPart = webPartChanged => actualCountSaveChanges++,
                            WebGet             = () => new ShimSPWeb()
                            {
                                Dispose = () => actualDisposeWeb = true
                            }
                        }
                    }
                },
                RootFolderGet = () => new ShimSPFolder()
            };

            // Act
            ListCommands.EnableFancyForms(list);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => actualCountSaveChanges.ShouldBe(2),
                () => actualDisposeWeb.ShouldBeTrue());
        }
        public void EnableFancyForms_FancyFormNotFound_AddChangesAndDispose()
        {
            // Arrange
            var actualCountAddChanges = 0;
            var actualDisposeWeb      = false;
            var list = new ShimSPList()
            {
                ParentWebGet = () => new ShimSPWeb()
                {
                    ServerRelativeUrlGet = () => DummyUrl,
                    GetFileString        = strUrl => null
                },
                RootFolderGet = () => new ShimSPFolder()
                {
                    FilesGet = () => new ShimSPFileCollection()
                    {
                        AddStringSPTemplateFileType = (urlOfFile, templateFileType) => new ShimSPFile()
                        {
                            GetLimitedWebPartManagerPersonalizationScope = scope => new ShimSPLimitedWebPartManager()
                            {
                                AddWebPartWebPartStringInt32 = (webPart, zoneId, zoneIndex) => actualCountAddChanges++,
                                WebGet = () => new ShimSPWeb()
                                {
                                    Dispose = () => actualDisposeWeb = true
                                }
                            }
                        }
                    }
                }
            };

            // Act
            ListCommands.EnableFancyForms(list);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => actualCountAddChanges.ShouldBe(1),
                () => actualDisposeWeb.ShouldBeTrue());
        }
예제 #3
0
        public override bool Perform()
        {
            try
            {
                using (var spSite = new SPSite(Web.Site.ID))
                {
                    foreach (SPWeb spWeb in spSite.AllWebs)
                    {
                        using (SPWeb web = spSite.OpenWeb(spWeb.ID))
                        {
                            LogTitle(GetWebInfo(web), 1);

                            for (int i = 0; i < web.Lists.Count; i++)
                            {
                                SPList list = web.Lists[i];
                                if (list.Hidden)
                                {
                                    continue;
                                }

                                LogTitle(GetListInfo(list), 2);

                                var settings = new GridGanttSettings(list);

                                try
                                {
                                    LogMessage("Enabling fancy forms", 3);

                                    ListCommands.EnableFancyForms(list);

                                    settings.EnableFancyForms = true;
                                    settings.SaveSettings(list);
                                }
                                catch (Exception e)
                                {
                                    LogMessage(e.Message, MessageKind.FAILURE, 4);
                                }

                                try
                                {
                                    LogMessage("Configuring ribbon", 3);

                                    settings.RibbonBehavior = list.Title.Equals("Resources") ? "2" : "1";
                                    settings.SaveSettings(list);
                                }
                                catch (Exception e)
                                {
                                    LogMessage(e.Message, MessageKind.FAILURE, 4);
                                }

                                try
                                {
                                    LogMessage("Enabling reporting", 3);

                                    if (!SocialEngine.Core.Utilities.IsDefaultIgnoredList(list.Title))
                                    {
                                        ListCommands.MapListToReporting(list);
                                    }
                                }
                                catch (Exception e)
                                {
                                    LogMessage(e.Message, MessageKind.FAILURE, 4);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogMessage(e.Message, MessageKind.FAILURE, 2);
            }

            return(true);
        }