Пример #1
0
        public void EnsureFolderHierarchy_WhenInPagesLibrary_AndNotEnsuredYet_ShouldCreateFolderHierarchy()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange
                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        new FolderInfo("somelevel2path")
                        {
                            Subfolders = new List<FolderInfo>()
                            {
                                new FolderInfo("level3")
                            }
                        },
                        new FolderInfo("somelevel2path alt")
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    var pagesLibrary = testScope.SiteCollection.RootWeb.GetPagesLibrary();

                    // Act
                    folderHelper.EnsureFolderHierarchy(pagesLibrary, rootFolderInfo);

                    // Assert
                    Assert.IsTrue(pagesLibrary.EnableFolderCreation);
                    Assert.AreEqual(2, pagesLibrary.RootFolder.SubFolders.Cast<SPFolder>().Where(folder => folder.Name != "Forms").Count());
                    Assert.AreEqual(3, pagesLibrary.Folders.Count);   // all created folders, exclusing the special Forms folder at library root

                    var lvl2Folder = pagesLibrary.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path");
                    pagesLibrary.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path alt");

                    Assert.AreEqual(1, lvl2Folder.SubFolders.Count);
                    lvl2Folder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "level3");
                }
            }
        }
Пример #2
0
        public void EnsureFolderHierarchy_WhenInPagesLibrary_AndAttemptingToSetDefaultStringValue_ShouldThrownNotSupportedException()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange
                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalNameText",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKeyText",
                    "DescriptionKey",
                    "GroupKey");

                NoteFieldInfo noteFieldInfo = new NoteFieldInfo(
                    "TestInternalNameNote",
                    new Guid("{E315BB24-19C3-4F2E-AABC-9DE5EFC3D5C2}"),
                    "NameKeyNote",
                    "DescriptionKeyAlt",
                    "GroupKey");

                HtmlFieldInfo htmlFieldInfo = new HtmlFieldInfo(
                    "TestInternalNameHtml",
                    new Guid("{D16958E7-CF9A-4C38-A8BB-99FC03BFD913}"),
                    "NameKeyHtml",
                    "DescriptionKeyAlt",
                    "GroupKey");

                var fieldsToEnsure = new List<BaseFieldInfo>()
                {
                    textFieldInfo,
                    noteFieldInfo,
                    htmlFieldInfo
                };

                // We gotta update the ArticlePage Content type with our fields
                var articlePageCT = new ContentTypeInfo(
                    "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D",
                    "UpdatedArticlePageCT",
                    "UpdatedArticlePageCTDescription",
                    "GroupKey")
                {
                    Fields = fieldsToEnsure
                };

                // Default values will be configured further down on the level 2 folder (not on the root folder)
                var folderInfoLvl2 = new FolderInfo("somelevel2path")
                {
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var contentTypeHelper = injectionScope.Resolve<IContentTypeHelper>();

                    // Init the test Pages library (we're in a Pub Site, the Pages lib already exists and we want to add fields to it)
                    SPList list = testScope.SiteCollection.RootWeb.GetPagesLibrary();
                    contentTypeHelper.EnsureContentType(list.ContentTypes, articlePageCT);      // this should add the field to the Pages lib

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act #1: try to set a folder default on a Text field
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(textFieldInfo, "MyTextFolderDefault") };

                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    {
                    }

                    // Act #2: try to set a folder default on a Note field
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(noteFieldInfo, "MyNoteFolderDefault") };

                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    {
                    }

                    // Act #3: try to set a folder default on a Html field
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(noteFieldInfo, "MyHtmlFolderDefault") };

                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    {
                    }
                }
            }
        }
        /// <summary>
        /// Feature activated event
        /// </summary>
        /// <param name="properties">Context properties</param>
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            var web = properties.Feature.Parent as SPWeb;

            using (var featureScope = DesignContainerProxy.BeginFeatureLifetimeScope(properties.Feature))
            {
                var logger = featureScope.Resolve<ILogger>();

                if (web != null && PublishingWeb.IsPublishingWeb(web))
                {
                    var folderHelper = featureScope.Resolve<IFolderHelper>();
                    var homePageConfig = featureScope.Resolve<IHomePageConfig>();
                    var timerJobHelper = featureScope.Resolve<ITimerJobHelper>();

                    // Resolve feature dependency activator
                    // Note: Need to pass the site and web objects to support site and web scoped features.
                    var featureDependencyActivator =
                        featureScope.Resolve<IFeatureDependencyActivator>(
                            new TypedParameter(typeof(SPSite), web.Site),
                            new TypedParameter(typeof(SPWeb), web));

                    // Activate feature dependencies defined in this configuration
                    featureDependencyActivator.EnsureFeatureActivation(homePageConfig as IFeatureDependencyConfig);

                    var pagesLibrary = web.GetPagesLibrary();

                    // Put home page in dummy folder
                    var rootFolder = new FolderInfo();
                    var homePage = homePageConfig.GetHomePageInfoByCulture(web.Locale);

                    rootFolder.Pages.Add(homePage);
                    rootFolder.WelcomePage = homePage;
                    rootFolder.Locale = web.Locale;

                    // Make sure the HomePage CT on the Pages library doesn't have a required Navigation field
                    FixHomePageNavigationFieldToBeNonRequired(pagesLibrary, homePage.PageLayout.AssociatedContentTypeId);

                    // Ensure the home page (this should be done on the variation source web)
                    folderHelper.EnsureFolderHierarchy(pagesLibrary, rootFolder);

                    // If we aren't on root web, assume this is a Variations-enabled scenario
                    var site = web.Site;
                    if (web.ID != web.Site.RootWeb.ID)
                    {
                        // Wait for variations to go through (so that the target home pages get created).
                        timerJobHelper.StartAndWaitForJob(site, BuiltInVariationsTimerJobs.VariationsSpawnSites);        // required for new pages to get created
                        timerJobHelper.StartAndWaitForJob(site, BuiltInVariationsTimerJobs.VariationsPropagatePage);     // required for page updates to get variated

                        // Update the target webs' home page URL
                        foreach (SPWeb firstLevelSubWeb in web.Site.RootWeb.Webs)
                        {
                            if (firstLevelSubWeb.ID != web.ID)
                            {
                                var targetWebRootFolder = firstLevelSubWeb.RootFolder;
                                targetWebRootFolder.WelcomePage = homePage.LibraryRelativePageUrl.ToString();    // home page will have same lib-relative URL once variated
                                targetWebRootFolder.Update();

                                // Ensure the content on the newly variated target home pages
                                var targetRootFolder = new FolderInfo();
                                var targetHomePage = homePageConfig.GetHomePageInfoByCulture(firstLevelSubWeb.Locale);

                                targetHomePage.FileName = homePage.FileName;    // make sure that we use the same file name across all variated pairs (the source's filename)

                                targetRootFolder.Pages.Add(targetHomePage);
                                targetRootFolder.WelcomePage = targetHomePage;
                                targetRootFolder.Locale = firstLevelSubWeb.Locale;

                                // Make sure the HomePage CT on the Pages library doesn't have a required Navigation field
                                FixHomePageNavigationFieldToBeNonRequired(pagesLibrary, homePage.PageLayout.AssociatedContentTypeId);

                                // Ensure the home page info on the target web
                                folderHelper.EnsureFolderHierarchy(firstLevelSubWeb.GetPagesLibrary(), targetRootFolder);
                            }
                        }
                    }
                }
                else
                {
                    logger.Warn("The web {0} is not a Publishing Web. This feature can only be activated on a SharePoint Publishing Web", web.Url);
                }
            }
        }
Пример #4
0
        public void EnsureFolderHierarchy_WhenFolderIsNotInDocumentLibrary_ShouldThrowException()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var folderInfoLvl2 = new FolderInfo("somelevel2path");

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2      // just add one of the three subfolders for now
                    }
                };

                DateTimeFieldInfo dateTimeFieldInfoEmpty = new DateTimeFieldInfo(
                    "TestInternalNameDate",
                    new Guid("{CD09FF50-0CE3-40AE-90ED-AC68961FA980}"),
                    "NameKeyDateTime",
                    "DescriptionKeyDateTimeFormula",
                    "GroupKey");

                var listInfo = new ListInfo("somelistpath", "ListNameKey", "ListDescrKey")
                {
                    // By default, a GenericList/CustomList will be created
                    FieldDefinitions = new List<BaseFieldInfo>() { dateTimeFieldInfoEmpty }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Define some folder defaults on the subfolder
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() 
                    { 
                        new FieldValueInfo(dateTimeFieldInfoEmpty, new DateTime(1990, 5, 20))
                    };

                    // Act
                    folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);

                    // Assert: should throw!!!
                }
            }
        }
Пример #5
0
        public void EnsureFolderHierarchy_WhenNotInPulishingSite_AndPageInfosAreDefined_ShouldThrowException()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var welcomePageLayout = new PageLayoutInfo("WelcomeSplash.aspx", new SPContentTypeId("0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4"));

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Pages = new List<PageInfo>()
                    {
                        new PageInfo("Hello-root-page-path", welcomePageLayout)
                        {
                            FieldValues = new List<FieldValueInfo>()
                            {
                                new FieldValueInfo(PublishingFields.PublishingPageContent, "<div><p>My HTML rocks!!!</p></div>")
                            }
                        }
                    }
                };

                var listInfo = new ListInfo("Pages", "PagesLibNameKey", "PagesLibDescrKey")
                {
                    ListTemplateInfo = BuiltInListTemplates.Pages
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var folderHelper = injectionScope.Resolve<IFolderHelper>();
                    var listHelper = injectionScope.Resolve<IListHelper>();

                    // Create a custom library (not a Pages lib)
                    var customLibrary = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    // Act
                    try
                    {
                        folderHelper.EnsureFolderHierarchy(customLibrary, rootFolderInfo);
                        Assert.Fail("Should've thrown argument exception");
                    }
                    catch (ArgumentException e)
                    {
                        // Assert
                        Assert.IsTrue(e.Message.Contains("Publishing pages cannot be provisionned outside of a Publishing web (choose the Publishing Site or Enterprise Wiki site definition)."));
                    }
                }
            }
        }
Пример #6
0
        public void EnsureFolderHierarchy_ShouldReturnListRootFolderInstance()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        new FolderInfo("somelevel2path")
                        {
                            Subfolders = new List<FolderInfo>()
                            {
                                new FolderInfo("level3")
                            }
                        },
                        new FolderInfo("somelevel2path alt")
                    }
                };

                var listInfo = new ListInfo("somelistparth", "ListNameKey", "ListDescrKey")
                    {
                        ListTemplateInfo = BuiltInListTemplates.DocumentLibrary
                    };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act
                    SPFolder sharePointFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);

                    // Assert
                    Assert.AreEqual(sharePointFolder.UniqueId, list.RootFolder.UniqueId);

                    Assert.AreEqual(2, sharePointFolder.SubFolders.Cast<SPFolder>().Where(folder => folder.Name != "Forms").Count());

                    var lvl2Folder = sharePointFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path");
                    sharePointFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path alt");

                    Assert.AreEqual(1, lvl2Folder.SubFolders.Count);
                    lvl2Folder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "level3");
                }
            }
        }
Пример #7
0
        public void EnsureFolderHierarchy_WhenUpdatingDocLibFolders_AndDefinitionChangedToRemoveSubFolder_ShouldNeverDeleteExistingSubfolder()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        new FolderInfo("somelevel2path")
                        {
                            Subfolders = new List<FolderInfo>()
                            {
                                new FolderInfo("level3")
                            }
                        },
                        new FolderInfo("somelevel2path alt")
                    }
                };

                var listInfo = new ListInfo("somelistparth", "ListNameKey", "ListDescrKey")
                {
                    ListTemplateInfo = BuiltInListTemplates.DocumentLibrary
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var documentLibrary = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Start by ensuring a full folder hierarchy
                    folderHelper.EnsureFolderHierarchy(documentLibrary, rootFolderInfo);

                    // Edit the definition to remove some subfolder
                    rootFolderInfo.Subfolders = rootFolderInfo.Subfolders.Where(f => f.Name != "somelevel2path").ToList();
                    rootFolderInfo.Subfolders.First().Subfolders.Clear();

                    // Act: re-ensure to determine if the existing (and now superfluous) folders stay in place
                    folderHelper.EnsureFolderHierarchy(documentLibrary, rootFolderInfo);

                    // Assert (nothing in the initial tree should've been removed)
                    Assert.IsTrue(documentLibrary.EnableFolderCreation);
                    Assert.AreEqual(2, documentLibrary.RootFolder.SubFolders.Cast<SPFolder>().Where(folder => folder.Name != "Forms").Count());
                    Assert.AreEqual(3, documentLibrary.Folders.Count);   // all created folders, excluding the special Forms folder at library root

                    var lvl2Folder = documentLibrary.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path");
                    documentLibrary.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path alt");

                    Assert.AreEqual(1, lvl2Folder.SubFolders.Count);
                }
            }
        }
Пример #8
0
        public void EnsureFolderHierarchy_WhenInPagesLibrary_ShouldApplyFolderSpecificContentTypesChoicesInRibbonNewPageDropdown()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange

                // Create some content types, children of Article Page, the base Page Layout-based page CT
                var contentTypeId1 = ContentTypeIdBuilder.CreateChild(ContentTypeId.ArticlePage, new Guid("{F8B6FF55-2C9E-4FA2-A705-F55FE3D18777}"));
                var contentTypeId2 = ContentTypeIdBuilder.CreateChild(ContentTypeId.ArticlePage, new Guid("{A7BAA5B7-C57B-4928-9778-818D267505A1}"));

                var pageContentType1 = new ContentTypeInfo(contentTypeId1, "PageCT1NameKey", "PageCT1DescrKey", "GroupKey");
                var pageContentType2 = new ContentTypeInfo(contentTypeId2, "PageCT2NameKey", "PageCT2DescrKey", "GroupKey");

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        new FolderInfo("somelevel2path")
                        {
                            Subfolders = new List<FolderInfo>()
                            {
                                new FolderInfo("level3")
                                {
                                    UniqueContentTypeOrder = new List<ContentTypeInfo>() { pageContentType2 }
                                }
                            },
                            UniqueContentTypeOrder = new List<ContentTypeInfo>() { pageContentType1 }
                        },
                        new FolderInfo("somelevel2path alt")
                    },
                    UniqueContentTypeOrder = new List<ContentTypeInfo>()
                    {
                        // order: 2-1
                        pageContentType2,
                        pageContentType1
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var folderHelper = injectionScope.Resolve<IFolderHelper>();
                    var contentTypeHelper = injectionScope.Resolve<IContentTypeHelper>();

                    var pagesLibrary = testScope.SiteCollection.RootWeb.GetPagesLibrary();

                    // Make sure our CTs are available on lib (this will add CTs to the root web and
                    // associate some child CTs to the list).
                    contentTypeHelper.EnsureContentType(
                        pagesLibrary.ContentTypes, 
                        new List<ContentTypeInfo>() { pageContentType1, pageContentType2 });
                    pagesLibrary.Update();

                    // Act
                    folderHelper.EnsureFolderHierarchy(pagesLibrary, rootFolderInfo);

                    // Assert

                    // root folder should have order 2-1
                    var rootFolder = pagesLibrary.RootFolder;
                    Assert.AreEqual(2, rootFolder.UniqueContentTypeOrder.Count);
                    Assert.IsTrue(pageContentType2.ContentTypeId.IsParentOf(rootFolder.UniqueContentTypeOrder[0].Id));
                    Assert.IsTrue(pageContentType1.ContentTypeId.IsParentOf(rootFolder.UniqueContentTypeOrder[1].Id));

                    // lvl2 folder should have page1CT only
                    var lvl2Folder = pagesLibrary.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path");
                    Assert.AreEqual(1, lvl2Folder.UniqueContentTypeOrder.Count);
                    Assert.IsTrue(pageContentType1.ContentTypeId.IsParentOf(lvl2Folder.UniqueContentTypeOrder[0].Id));

                    // lvl2Alt should inherit root folder
                    var lvl2Alt = pagesLibrary.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path alt");
                    Assert.IsNull(lvl2Alt.UniqueContentTypeOrder);

                    // lvl3 should have page2CT only
                    var lvl3Folder = lvl2Folder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "level3");
                    Assert.AreEqual(1, lvl3Folder.UniqueContentTypeOrder.Count);
                    Assert.IsTrue(pageContentType2.ContentTypeId.IsParentOf(lvl3Folder.UniqueContentTypeOrder[0].Id));
                }
            }
        }
Пример #9
0
        public void EnsureFolderHierarchy_WhenAttemptingToSetLookupFolderDefaultValueInDocLib_ShouldFailWithNotSupportedException()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                LookupFieldInfo lookupFieldInfo = new LookupFieldInfo(
                   "TestInternalNameLookup",
                   new Guid("{62F8127C-4A8C-4217-8BD8-C6712753AFCE}"),
                   "NameKeyLookup",
                   "DescriptionKey",
                   "GroupKey")
                {
                    // ShowField should be Title by default
                };

                LookupFieldInfo lookupFieldInfoAlt = new LookupFieldInfo(
                    "TestInternalNameLookupAlt",
                    new Guid("{1F05DFFA-6396-4AEF-AD23-72217206D35E}"),
                    "NameKeyLookupAlt",
                    "DescriptionKey",
                    "GroupKey")
                {
                    ShowField = "ID"
                };

                LookupMultiFieldInfo lookupMultiFieldInfo = new LookupMultiFieldInfo(
                    "TestInternalNameLookupM",
                    new Guid("{2C9D4C0E-21EB-4742-8C6C-4C30DCD08A05}"),
                    "NameKeyLookupMulti",
                    "DescriptionKeyMulti",
                    "GroupKey")
                {
                };

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey")
                {
                    ListTemplateInfo = BuiltInListTemplates.DocumentLibrary,
                    FieldDefinitions = new List<BaseFieldInfo>() 
                    { 
                        lookupFieldInfo,
                        lookupFieldInfoAlt,
                        lookupMultiFieldInfo
                    }
                };

                var folderInfoLvl2 = new FolderInfo("somelevel2path")
                {
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();

                    // Create the lookup list
                    ListInfo lookupListInfo = new ListInfo("sometestlistpathlookup", "DynamiteTestListNameKeyLookup", "DynamiteTestListDescriptionKeyLookup");

                    // Lookup field ListId setup
                    SPList lookupList = listHelper.EnsureList(testScope.SiteCollection.RootWeb, lookupListInfo);
                    lookupFieldInfo.ListId = lookupList.ID;
                    lookupFieldInfoAlt.ListId = lookupList.ID;
                    lookupMultiFieldInfo.ListId = lookupList.ID;

                    // Create the looked-up items
                    var lookupItem1 = lookupList.Items.Add();
                    lookupItem1["Title"] = "Test Item 1";
                    lookupItem1.Update();

                    var lookupItem2 = lookupList.Items.Add();
                    lookupItem2["Title"] = "Test Item 2";
                    lookupItem2.Update();

                    // Create the test doc lib
                    SPList list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act 1: First lookup field - this should throw NotSupportedException
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(lookupFieldInfo, new LookupValue(1, "Test Item 1")) };
                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    { 
                    }

                    // Act 2: Alternate lookup field - this should throw NotSupportedException
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(lookupFieldInfo, new LookupValue(2, "2")) };
                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    { 
                    }

                    // Act 3: First lookup field - this should throw NotSupportedException
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() 
                    { 
                        new FieldValueInfo(lookupMultiFieldInfo, new LookupValueCollection() { new LookupValue(1, "Test Item 1"), new LookupValue(2, "Test Item 2") }) 
                    };

                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    { 
                    }
                }
            }
        }
Пример #10
0
        public void EnsureFolderHierarchy_WhenAttemptingFALSEDefaultFolderValueInDocLib_AndSPFieldAlreadHasTRUEDefaultValue_ShouldExplodeAndWarnYouThatThisWeirdEdgeCaseIsNotSupported()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                BooleanFieldInfo boolFieldInfoDefaultTrue = new BooleanFieldInfo(
                   "TestInternalNameBoolTrue",
                   new Guid("{0D0289AD-C5FB-495B-96C6-48CC46737D08}"),
                   "NameKeyBoolTrue",
                   "DescriptionKeyBoolTrue",
                   "GroupKey")
                {
                    DefaultValue = true
                };

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey")
                {
                    ListTemplateInfo = BuiltInListTemplates.DocumentLibrary,
                    FieldDefinitions = new List<BaseFieldInfo>() { boolFieldInfoDefaultTrue }
                };

                var folderInfoLvl2 = new FolderInfo("somelevel2path")
                {
                    FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(boolFieldInfoDefaultTrue, false) }
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    
                    // Create the test doc lib
                    SPList list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act: this should throw NotSupportedException
                    var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                }
            }
        }
Пример #11
0
        public void EnsureFolderHierarchy_WhenDocLibFolderDefaultValuesAreRemoved_AndRepeatEnsure_ShouldUpdateFolderAndDropMetadataDefaults()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var folderInfoLvl2 = new FolderInfo("somelevel2path");

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2      // just add one of the three subfolders for now
                    }
                };

                DateTimeFieldInfo dateTimeFieldInfoEmpty = new DateTimeFieldInfo(
                    "TestInternalNameDate",
                    new Guid("{CD09FF50-0CE3-40AE-90ED-AC68961FA980}"),
                    "NameKeyDateTime",
                    "DescriptionKeyDateTimeFormula",
                    "GroupKey");

                DateTimeFieldInfo dateTimeFieldInfoFormula = new DateTimeFieldInfo(
                    "TestInternalNameDateFormula",
                    new Guid("{D23EAD73-9E18-46DB-A426-41B2D47F696C}"),
                    "NameKeyDateTimeFormula",
                    "DescriptionKeyDateTimeFormula",
                    "GroupKey")
                {
                    DefaultFormula = "=[Today]"
                };

                var listInfo = new ListInfo("somelistpath", "ListNameKey", "ListDescrKey")
                {
                    ListTemplateInfo = BuiltInListTemplates.DocumentLibrary,
                    FieldDefinitions = new List<BaseFieldInfo>() { dateTimeFieldInfoEmpty, dateTimeFieldInfoFormula }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var list = (SPDocumentLibrary)listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Define some folder defaults on the root and subfolder
                    rootFolderInfo.FieldDefaultValues = new List<FieldValueInfo>() 
                    { 
                        new FieldValueInfo(dateTimeFieldInfoEmpty, new DateTime(1977, 3, 3)),
                        new FieldValueInfo(dateTimeFieldInfoFormula, new DateTime(1978, 4, 4))
                    };

                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() 
                    { 
                        new FieldValueInfo(dateTimeFieldInfoEmpty, new DateTime(1990, 5, 20)),
                        new FieldValueInfo(dateTimeFieldInfoFormula, new DateTime(2050, 9, 18))
                    };

                    // Ensure a first time with the initial defauls (initially, both root and the 2nd level folder have defaults)
                    var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);

                    // Remove defaults on root folder definition
                    rootFolderInfo.FieldDefaultValues = new List<FieldValueInfo>() 
                    { 
                    };

                    // Remove defaults on the level-2 folder definition
                    folderInfoLvl2.FieldDefaultValues = null;

                    // Act: re-ensure the folder hierarchy with cleared Defaults settings
                    ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);

                    var itemInRootFolder = ensuredRootFolder.Files.Add("SomeRootFile.txt", new byte[0]);
                    itemInRootFolder.Update();

                    var secondLevelEnsuredFolder = ensuredRootFolder.SubFolders["somelevel2path"];

                    var itemInSecondLevelFolder = secondLevelEnsuredFolder.Files.Add("SomeLevel2File.txt", new byte[0]);
                    itemInSecondLevelFolder.Item.Update();

                    // Assert

                    // In root folder, the field definitions should apply
                    Assert.IsNull(itemInRootFolder.Item[dateTimeFieldInfoEmpty.Id]);
                    Assert.AreEqual(DateTime.Today, (DateTime)itemInRootFolder.Item[dateTimeFieldInfoFormula.Id]);

                    // In second-level folder, the list's field definitions should apply as well
                    Assert.IsNull(itemInSecondLevelFolder.Item[dateTimeFieldInfoEmpty.Id]);
                    Assert.AreEqual(DateTime.Today, (DateTime)itemInSecondLevelFolder.Item[dateTimeFieldInfoFormula.Id]);
                }
            }
        }
Пример #12
0
        private SPFolder EnsureFolder(SPList library, SPFolder parentFolder, FolderInfo folderInfo)
        {
            SPFolder folder = null;

            if (parentFolder == null)
            {
                // We are on at the root folder of the library (i.e. no parent folder).
                // Initialize defaults and pages in here, then move on to subfolders (instead of trying to create the folder)
                folder = library.RootFolder;

                // Ensure folder metadata defaults
                bool isDocumentLibrary = library.BaseType == SPBaseType.DocumentLibrary;
                if (folderInfo.FieldDefaultValues != null && folderInfo.FieldDefaultValues.Count > 0)
                {
                    if (!isDocumentLibrary)
                    {
                        throw new ArgumentException("EnsureFolderHierarchy - Impossible to ensure folder MetadataDefaults on a list which is not a Document Library.");
                    }

                    this.valueWriter.WriteValuesToFolderDefaults(folder, folderInfo.FieldDefaultValues.ToList());
                }
                else if (isDocumentLibrary)
                {
                    ClearFolderAllFolderMetadataDefaults(folder);
                }

                // UniqueContentTypeOrder
                EnsureUniqueContentTypeOrder(folder, folderInfo);

                // Create pages
                if (folderInfo.Pages != null && folderInfo.Pages.Count > 0)
                {
                    if ((int)library.BaseTemplate != BuiltInListTemplates.Pages.ListTempateTypeId)
                    {
                        // To provision Publishing Pages, you NEED to be inside the Pages library
                        throw new ArgumentException("Publishing pages cannot be provisionned outside of the Pages library. Remove the PageInfo objects from your FolderInfo, or use this FolderInfo to provision content inside the Pages library instead.");
                    }

                    this.pageHelper.EnsurePage(library, folder, folderInfo.Pages);
                }

                // Create sub folders
                if (folderInfo.Subfolders != null && folderInfo.Subfolders.Count > 0)
                {
                    library.EnableFolderCreation = true;
                    library.Update();

                    foreach (var childFolder in folderInfo.Subfolders)
                    {
                        this.EnsureFolder(library, folder, childFolder);
                    }
                }

                // Set Web HomePage
                if (folderInfo.WelcomePage != null)
                {
                    var rootFolder = library.ParentWeb.RootFolder;
                    rootFolder.WelcomePage = folderInfo.WelcomePage.LibraryRelativePageUrl.ToString();
                    rootFolder.Update();
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(folderInfo.Name))
                {
                    bool isDocumentLibrary = library.BaseType == SPBaseType.DocumentLibrary;

                    try
                    {
                        if (isDocumentLibrary)
                        {
                            folder = parentFolder.SubFolders[folderInfo.Name];
                        }
                        else
                        {
                            string serverRelativeFolderPathToMatch = SPUtility.ConcatUrls(parentFolder.ServerRelativeUrl, folderInfo.Name);
                            folder = library.Folders.Cast<SPListItem>().Single(folderItem => folderItem.Folder.ServerRelativeUrl == serverRelativeFolderPathToMatch).Folder;
                        }

                        this.logger.Info("Skipping folder creation for " + folderInfo.Name +
                                         " because it already exists (will still apply values and default metadata)");
                    }
                    catch (ArgumentException)
                    {
                        this.logger.Info("Creating liubrary folder " + folderInfo.Name);
                    }
                    catch (InvalidOperationException)
                    {
                        this.logger.Info("Creating list folder " + folderInfo.Name);
                    }

                    if (folder == null)
                    {
                        // Add the folder (if it doesn't already exist)
                        if (isDocumentLibrary)
                        {
                            folder = parentFolder.SubFolders.Add(folderInfo.Name);
                        }
                        else
                        {
                            // In a non-doclib list, creating Folders needs to be done in another way (otherwise the SPFolder will not get an associated SPListItem)
                            var folderItem = library.Items.Add(parentFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder);
                            folderItem["Title"] = folderInfo.Name;
                            folderItem.Update();

                            folder = folderItem.Folder;
                        }
                    }

                    // Ensure folder metadata defaults
                    if (folderInfo.FieldDefaultValues != null && folderInfo.FieldDefaultValues.Count > 0)
                    {
                        if (!isDocumentLibrary)
                        {
                            throw new ArgumentException("EnsureFolderHierarchy - Impossible to ensure folder MetadataDefaults on a list which is not a Document Library.");
                        }

                        this.valueWriter.WriteValuesToFolderDefaults(folder, folderInfo.FieldDefaultValues.ToList());
                    }
                    else if (isDocumentLibrary)
                    {
                        ClearFolderAllFolderMetadataDefaults(folder);
                    }

                    // UniqueContentTypeInfo
                    EnsureUniqueContentTypeOrder(folder, folderInfo);

                    // Make sure the folder is published
                    SPModerationInformation folderModerationInfo = folder.Item != null ? folder.Item.ModerationInformation : null;
                    if (folderModerationInfo != null)
                    {
                        folderModerationInfo.Comment = "Automatically approved upon creation through Dynamite's FolderHelper utility.";
                        folderModerationInfo.Status = SPModerationStatusType.Approved;
                        folder.Item.Update();
                    }

                    // Create pages
                    if (folderInfo.Pages != null && folderInfo.Pages.Count > 0)
                    {
                        if ((int)library.BaseTemplate != BuiltInListTemplates.Pages.ListTempateTypeId)
                        {
                            // To provision Publishing Pages, you NEED to be inside the Pages library
                            throw new ArgumentException("Publishing pages cannot be provisionned outside of the Pages library. Remove the PageInfo objects from your FolderInfo, or use this FolderInfo to provision content inside the Pages library instead.");
                        }
                    }

                    this.pageHelper.EnsurePage(library, folder, folderInfo.Pages);
                }

                // Create sub folders
                foreach (var childFolder in folderInfo.Subfolders)
                {
                    this.EnsureFolder(library, folder, childFolder);
                }
            }

            return folder;
        }
Пример #13
0
 /// <summary>
 /// Ensure a folder hierarchy in a list or library
 /// </summary>
 /// <param name="list">The SharePoint list or library</param>
 /// <param name="rootFolderInfo">The metadata that should define the root folder of the list</param>
 /// <returns>The list's root folder instance</returns>
 public SPFolder EnsureFolderHierarchy(SPList list, FolderInfo rootFolderInfo)
 {
     return this.EnsureFolder(list, null, rootFolderInfo);
 }
Пример #14
0
        private static void EnsureUniqueContentTypeOrder(SPFolder folder, FolderInfo folderInfo)
        {
            if (folderInfo.UniqueContentTypeOrder != null && folderInfo.UniqueContentTypeOrder.Count > 0)
            {
                SPContentTypeCollection listContentTypes = folder.ParentWeb.Lists[folder.ParentListId].ContentTypes;
                IList<SPContentType> uniqueOrder = new List<SPContentType>();

                foreach (ContentTypeInfo needToEnsureThisCTInfo in folderInfo.UniqueContentTypeOrder)
                {
                    var foundRealCT = listContentTypes[needToEnsureThisCTInfo.ContentTypeId];

                    if (foundRealCT == null)
                    {
                        // Failed to find CT with direct ID lookup: now let's assume that we were given site collection CT IDs as
                        // input and that we need to inspect the list CTs' parents to find a match.
                        foreach (var listCT in listContentTypes.Cast<SPContentType>())
                        {
                            if (listCT.Id.Parent == needToEnsureThisCTInfo.ContentTypeId)
                            {
                                foundRealCT = listCT;
                                break;
                            }
                        }
                    }

                    uniqueOrder.Add(foundRealCT);
                }

                folder.UniqueContentTypeOrder = uniqueOrder;
                folder.Update();
            }
        }
Пример #15
0
        public void EnsureFolderHierarchy_WhenInPagesLibrary_AndAttemptingToSetDefaultPublishingImageValue_ShouldThrownNotSupportedException()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange
                ImageFieldInfo imageFieldInfo = new ImageFieldInfo(
                    "TestInternalNameImage",
                    new Guid("{6C5B9E77-B621-43AA-BFBF-B333093EFCAE}"),
                    "NameKeyImage",
                    "DescriptionKeyImage",
                    "GroupKey")
                {
                };

                var fieldsToEnsure = new List<BaseFieldInfo>()
                {
                    imageFieldInfo
                };

                // We gotta update the ArticlePage Content type with our fields
                var articlePageCT = new ContentTypeInfo(
                    "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D",
                    "UpdatedArticlePageCT",
                    "UpdatedArticlePageCTDescription",
                    "GroupKey")
                {
                    Fields = fieldsToEnsure
                };

                // Default values configured on the level 2 folder (not on the root folder)
                var folderInfoLvl2 = new FolderInfo("somelevel2path")
                {
                    FieldDefaultValues = new List<FieldValueInfo>() 
                    { 
                        new FieldValueInfo(
                            imageFieldInfo, 
                            new ImageValue()
                            {
                                Hyperlink = "http://github.com/GSoft-SharePoint/",
                                ImageUrl = "/_layouts/15/MyFolder/MyImage.png"
                            })
                    }
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var contentTypeHelper = injectionScope.Resolve<IContentTypeHelper>();

                    // Init the test Pages library (we're in a Pub Site, the Pages lib already exists and we want to add fields to it)
                    SPList list = testScope.SiteCollection.RootWeb.GetPagesLibrary();
                    contentTypeHelper.EnsureContentType(list.ContentTypes, articlePageCT);      // this should add the field to the Pages lib

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act: try to set a folder default on a Publishing Image field
                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    {
                    }
                }
            }
        }
Пример #16
0
        public void EnsureFolderHierarchy_WhenFolderDefaultValuesAreSpecifiedInPagesLibraryFolder_AndYouCreateAPage_ThenPageShouldHaveDefaultValue()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange
                IntegerFieldInfo integerFieldInfo = new IntegerFieldInfo(
                    "TestInternalNameInteger",
                    new Guid("{12E262D0-C7C4-4671-A266-064CDBD3905A}"),
                    "NameKeyInt",
                    "DescriptionKeyInt",
                    "GroupKey");

                NumberFieldInfo numberFieldInfo = new NumberFieldInfo(
                    "TestInternalNameNumber",
                    new Guid("{5DD4EE0F-8498-4033-97D0-317A24988786}"),
                    "NameKeyNumber",
                    "DescriptionKeyNumber",
                    "GroupKey");

                CurrencyFieldInfo currencyFieldInfo = new CurrencyFieldInfo(
                    "TestInternalNameCurrency",
                    new Guid("{9E9963F6-1EE6-46FB-9599-783BBF4D6249}"),
                    "NameKeyCurrency",
                    "DescriptionKeyCurrency",
                    "GroupKey")
                {
                    LocaleId = 3084 // fr-CA
                };

                DateTimeFieldInfo dateOnlyFieldInfo = new DateTimeFieldInfo(
                    "TestInternalNameDate",
                    new Guid("{D23EAD73-9E18-46DB-A426-41B2D47F696C}"),
                    "NameKeyDate",
                    "DescriptionKeyDate",
                    "GroupKey")
                {
                    // Important that there be no DefaultFormula and no DefaultValue, otherwise the
                    // folder default column value would be ignored.
                    // See related test above: EnsureFolderHierarchy_WhenDateTimeFieldDefaultAlreadyDefined_AndAttemptingToSetFolderDefaultDate_ShouldThrownNotSupportedException
                };

                DateTimeFieldInfo dateTimeFieldInfo = new DateTimeFieldInfo(
                  "TestInternalNameDateTime",
                  new Guid("{526F9055-7472-4CFA-A31D-E2B7BFB1FD7D}"),
                  "NameKeyDateTime",
                  "DescriptionKeyDateTime",
                  "GroupKey")
                {
                    // Important that there be no DefaultFormula and no DefaultValue, otherwise the
                    // folder default column value would be ignored.
                    // See related test above: EnsureFolderHierarchy_WhenDateTimeFieldDefaultAlreadyDefined_AndAttemptingToSetFolderDefaultDate_ShouldThrownNotSupportedException
                    Format = DateTimeFieldFormat.DateTime
                };

                UrlFieldInfo urlFieldInfo = new UrlFieldInfo(
                    "TestInternalNameUrl",
                    new Guid("{208F904C-5A1C-4E22-9A79-70B294FABFDA}"),
                    "NameKeyUrl",
                    "DescriptionKeyUrl",
                    "GroupKey")
                {
                };

                UrlFieldInfo urlFieldInfoImage = new UrlFieldInfo(
                    "TestInternalNameUrlImg",
                    new Guid("{96D22CFF-5B40-4675-B632-28567792E11B}"),
                    "NameKeyUrlImg",
                    "DescriptionKeyUrlImg",
                    "GroupKey")
                {
                    Format = UrlFieldFormat.Image
                };

                MediaFieldInfo mediaFieldInfo = new MediaFieldInfo(
                    "TestInternalNameMedia",
                    new Guid("{A2F070FE-FE33-44FC-9FDF-D18E74ED4D67}"),
                    "NameKeyMedia",
                    "DescriptionKeyMEdia",
                    "GroupKey");

                var testTermSet = new TermSetInfo(Guid.NewGuid(), "Test Term Set"); // keep Ids random because, if this test fails midway, the term
                // set will not be cleaned up and upon next test run we will
                // run into a term set and term ID conflicts.
                var levelOneTermA = new TermInfo(Guid.NewGuid(), "Term A", testTermSet);
                var levelOneTermB = new TermInfo(Guid.NewGuid(), "Term B", testTermSet);
                var levelTwoTermAA = new TermInfo(Guid.NewGuid(), "Term A-A", testTermSet);
                var levelTwoTermAB = new TermInfo(Guid.NewGuid(), "Term A-B", testTermSet);

                TaxonomySession session = new TaxonomySession(testScope.SiteCollection);
                TermStore defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                Group defaultSiteCollectionGroup = defaultSiteCollectionTermStore.GetSiteCollectionGroup(testScope.SiteCollection);
                TermSet newTermSet = defaultSiteCollectionGroup.CreateTermSet(testTermSet.Label, testTermSet.Id);
                Term createdTermA = newTermSet.CreateTerm(levelOneTermA.Label, Language.English.Culture.LCID, levelOneTermA.Id);
                Term createdTermB = newTermSet.CreateTerm(levelOneTermB.Label, Language.English.Culture.LCID, levelOneTermB.Id);
                Term createdTermAA = createdTermA.CreateTerm(levelTwoTermAA.Label, Language.English.Culture.LCID, levelTwoTermAA.Id);
                Term createdTermAB = createdTermA.CreateTerm(levelTwoTermAB.Label, Language.English.Culture.LCID, levelTwoTermAB.Id);
                defaultSiteCollectionTermStore.CommitAll();

                TaxonomyFieldInfo taxoFieldInfo = new TaxonomyFieldInfo(
                    "TestInternalNameTaxo",
                    new Guid("{18CC105F-16C9-43E2-9933-37F98452C038}"),
                    "NameKeyTaxo",
                    "DescriptionKey",
                    "GroupKey")
                {
                    TermStoreMapping = new TaxonomyContext(testTermSet)     // choices limited to all terms in test term set
                };

                TaxonomyMultiFieldInfo taxoMultiFieldInfo = new TaxonomyMultiFieldInfo(
                    "TestInternalNameTaxoMulti",
                    new Guid("{2F49D362-B014-41BB-9959-1000C9A7FFA0}"),
                    "NameKeyTaxoMulti",
                    "DescriptionKey",
                    "GroupKey")
                {
                    TermStoreMapping = new TaxonomyContext(levelOneTermA)   // choices limited to children of a specific term, instead of having full term set choices
                };

                // Create a list that contains all the fields we've prepared
                var fieldsToEnsure = new List<BaseFieldInfo>()
                    {
                        integerFieldInfo,
                        numberFieldInfo,
                        currencyFieldInfo,
                        dateOnlyFieldInfo,
                        dateTimeFieldInfo,
                        urlFieldInfo,
                        urlFieldInfoImage,
                        mediaFieldInfo,
                        taxoFieldInfo,
                        taxoMultiFieldInfo
                    };
                
                // Prepare some MetadataDefaults that we'll apply on the second-level folder
                var fieldDefaultValues = new List<FieldValueInfo>()
                {
                    new FieldValueInfo(integerFieldInfo, 555),
                    new FieldValueInfo(numberFieldInfo, 5.0),
                    new FieldValueInfo(currencyFieldInfo, 535.95),
                    new FieldValueInfo(dateOnlyFieldInfo, new DateTime(1976, 1, 1)),
                    new FieldValueInfo(dateTimeFieldInfo, new DateTime(1977, 1, 1)),
                    new FieldValueInfo(
                        urlFieldInfo, 
                        new UrlValue()
                        {
                            Url = "http://github.com/GSoft-SharePoint/",
                            Description = "patate!"
                        }),
                    new FieldValueInfo(
                        urlFieldInfoImage, 
                        new UrlValue()
                        {
                            Url = "http://github.com/GSoft-SharePoint/",
                            Description = "patate!"
                        }),
                    new FieldValueInfo(
                        mediaFieldInfo, 
                        new MediaValue()
                        {
                            Title = "Some media file title",
                            Url = "/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf",
                            IsAutoPlay = true,
                            IsLoop = true,
                            PreviewImageUrl = "/_layouts/15/Images/logo.png"
                        }),
                    new FieldValueInfo(taxoFieldInfo, new TaxonomyValue(levelOneTermB)),
                    new FieldValueInfo(
                        taxoMultiFieldInfo, 
                        new TaxonomyValueCollection(
                            new List<TaxonomyValue>() 
                                { 
                                    new TaxonomyValue(levelTwoTermAA), 
                                    new TaxonomyValue(levelTwoTermAB)
                                }))
                };

                // We gotta update the ArticlePage Content type with our fields
                var articlePageCT = new ContentTypeInfo(
                    "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D",
                    "UpdatedArticlePageCT",
                    "UpdatedArticlePageCTDescription",
                    "GroupKey")
                    {
                        Fields = fieldsToEnsure
                    };

                // Default values are configured on the level 2 folder (not on the root folder)
                var articleLeftPageLayoutInfo = new PageLayoutInfo("ArticleLeft.aspx", "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D");
                var folderInfoLvl2 = new FolderInfo("somelevel2path")
                {
                    FieldDefaultValues = fieldDefaultValues,
                    Pages = new List<PageInfo>() 
                    { 
                        new PageInfo("DynamiteTestPage", articleLeftPageLayoutInfo),
                        new PageInfo("DynamiteTestPageWithValues", articleLeftPageLayoutInfo)
                        {
                            FieldValues = new List<FieldValueInfo>()
                            {
                                new FieldValueInfo(dateOnlyFieldInfo, new DateTime(1998, 1, 1)),
                                new FieldValueInfo(dateTimeFieldInfo, new DateTime(1999, 1, 1)),
                                new FieldValueInfo(taxoFieldInfo, new TaxonomyValue(levelOneTermA))
                            }
                        }
                    }
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var contentTypeHelper = injectionScope.Resolve<IContentTypeHelper>();

                    // Init the test Pages library (we're in a Pub Site, the Pages lib already exists and we want to add fields to it)
                    SPList list = testScope.SiteCollection.RootWeb.GetPagesLibrary();
                    contentTypeHelper.EnsureContentType(list.ContentTypes, articlePageCT);      // this should add the field to the Pages lib

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act: ensure the folder hierarchy with a page inside 2nd level subfolder which has MetadataDefaults for all possible types
                    var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);

                    // Assert
                    var pubWeb = PublishingWeb.GetPublishingWeb(testScope.SiteCollection.RootWeb);
                    var recursivePagesQuery = new SPQuery() { ViewAttributes = "Scope=\"Recursive\"" };

                    // Fetch all pages. WARNING: all dates will be returned in UTC time, because our SPQuery is modified
                    // by GetPublishingPages to force DatesInUtc=true.
                    var allPages = pubWeb.GetPublishingPages(recursivePagesQuery);
                    var ourPageWithDefaults = allPages["/Pages/somelevel2path/DynamiteTestPage.aspx"];
                    var ourPageWithDefaultsAndValues = allPages["/Pages/somelevel2path/DynamiteTestPageWithValues.aspx"];

                    // In 1st publishing page's list item, all metadata defaults should've been applied
                    Assert.AreEqual(555, ourPageWithDefaults.ListItem["TestInternalNameInteger"]);
                    Assert.AreEqual(5.0, ourPageWithDefaults.ListItem["TestInternalNameNumber"]);
                    Assert.AreEqual(535.95, ourPageWithDefaults.ListItem["TestInternalNameCurrency"]);
                    Assert.AreEqual(new DateTime(1976, 1, 1), ((DateTime)ourPageWithDefaults.ListItem["TestInternalNameDate"]).ToLocalTime());    // SPListItem should normally return DateTime as local time (not UTC), but since we used GetPublishingPage, dates are in UTC
                    Assert.AreEqual(new DateTime(1977, 1, 1), ((DateTime)ourPageWithDefaults.ListItem["TestInternalNameDateTime"]).ToLocalTime());
                    
                    var urlFieldVal = new SPFieldUrlValue(ourPageWithDefaults.ListItem["TestInternalNameUrl"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlFieldVal.Url);
                    Assert.AreEqual("patate!", urlFieldVal.Description);

                    var urlImageFieldVal = new SPFieldUrlValue(ourPageWithDefaults.ListItem["TestInternalNameUrlImg"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlImageFieldVal.Url);
                    Assert.AreEqual("patate!", urlImageFieldVal.Description);

                    var mediaFieldVal = MediaFieldValue.FromString(ourPageWithDefaults.ListItem["TestInternalNameMedia"].ToString());
                    Assert.AreEqual("Some media file title", mediaFieldVal.Title);
                    Assert.AreEqual(HttpUtility.UrlDecode("/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf"), mediaFieldVal.MediaSource);
                    Assert.IsTrue(mediaFieldVal.AutoPlay);
                    Assert.IsTrue(mediaFieldVal.Loop);
                    Assert.AreEqual("/_layouts/15/Images/logo.png", mediaFieldVal.PreviewImageSource);

                    var taxoFieldValue = (TaxonomyFieldValue)ourPageWithDefaults.ListItem["TestInternalNameTaxo"];
                    Assert.AreNotEqual(-1, taxoFieldValue.WssId);
                    Assert.AreEqual(levelOneTermB.Id, new Guid(taxoFieldValue.TermGuid));
                    Assert.AreEqual(levelOneTermB.Label, taxoFieldValue.Label);

                    var taxoFieldValueMulti = (TaxonomyFieldValueCollection)ourPageWithDefaults.ListItem["TestInternalNameTaxoMulti"];
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[0].WssId);
                    Assert.AreEqual(levelTwoTermAA.Id, new Guid(taxoFieldValueMulti[0].TermGuid));
                    Assert.AreEqual(levelTwoTermAA.Label, taxoFieldValueMulti[0].Label);
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[1].WssId);
                    Assert.AreEqual(levelTwoTermAB.Id, new Guid(taxoFieldValueMulti[1].TermGuid));
                    Assert.AreEqual(levelTwoTermAB.Label, taxoFieldValueMulti[1].Label);

                    // In 2nd publishing page's list item, metadata defaults should've been applied everywhere except where we specified item values
                    Assert.AreEqual(5.0, ourPageWithDefaultsAndValues.ListItem["TestInternalNameNumber"]);
                    Assert.AreEqual(535.95, ourPageWithDefaultsAndValues.ListItem["TestInternalNameCurrency"]);
                    Assert.AreEqual(new DateTime(1998, 1, 1), ((DateTime)ourPageWithDefaultsAndValues.ListItem["TestInternalNameDate"]).ToLocalTime());     // PageInfo Value should be applied, not folder MetadataDefaul
                    Assert.AreEqual(new DateTime(1999, 1, 1), ((DateTime)ourPageWithDefaultsAndValues.ListItem["TestInternalNameDateTime"]).ToLocalTime());     // PageInfo Value should be applied, not folder MetadataDefault
                    
                    urlFieldVal = new SPFieldUrlValue(ourPageWithDefaultsAndValues.ListItem["TestInternalNameUrl"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlFieldVal.Url);
                    Assert.AreEqual("patate!", urlFieldVal.Description);     // proper Url description will never be set for Format=Hyperlink

                    urlImageFieldVal = new SPFieldUrlValue(ourPageWithDefaultsAndValues.ListItem["TestInternalNameUrlImg"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlImageFieldVal.Url);
                    Assert.AreEqual("patate!", urlImageFieldVal.Description);     // proper Url description will never be set for Format=Image either

                    mediaFieldVal = MediaFieldValue.FromString(ourPageWithDefaultsAndValues.ListItem["TestInternalNameMedia"].ToString());
                    Assert.AreEqual("Some media file title", mediaFieldVal.Title);
                    Assert.AreEqual(HttpUtility.UrlDecode("/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf"), mediaFieldVal.MediaSource);
                    Assert.IsTrue(mediaFieldVal.AutoPlay);
                    Assert.IsTrue(mediaFieldVal.Loop);
                    Assert.AreEqual("/_layouts/15/Images/logo.png", mediaFieldVal.PreviewImageSource);

                    taxoFieldValue = (TaxonomyFieldValue)ourPageWithDefaultsAndValues.ListItem["TestInternalNameTaxo"];  // PageInfo Value should be applied, not folder MetadataDefault
                    Assert.AreNotEqual(-1, taxoFieldValue.WssId);
                    Assert.AreEqual(levelOneTermA.Id, new Guid(taxoFieldValue.TermGuid));
                    Assert.AreEqual(levelOneTermA.Label, taxoFieldValue.Label);

                    taxoFieldValueMulti = (TaxonomyFieldValueCollection)ourPageWithDefaultsAndValues.ListItem["TestInternalNameTaxoMulti"];
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[0].WssId);
                    Assert.AreEqual(levelTwoTermAA.Id, new Guid(taxoFieldValueMulti[0].TermGuid));
                    Assert.AreEqual(levelTwoTermAA.Label, taxoFieldValueMulti[0].Label);
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[1].WssId);
                    Assert.AreEqual(levelTwoTermAB.Id, new Guid(taxoFieldValueMulti[1].TermGuid));
                    Assert.AreEqual(levelTwoTermAB.Label, taxoFieldValueMulti[1].Label);
                }
            }
        }
Пример #17
0
        public void EnsureFolderHierarchy_WhenInList_AndNotEnsuredYet_ShouldCreateFolderHierarchy_AndEnableFoldersOnList()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        new FolderInfo("somelevel2path")
                        {
                            Subfolders = new List<FolderInfo>()
                            {
                                new FolderInfo("level3")
                            }
                        },
                        new FolderInfo("somelevel2path alt")
                    }
                };

                var listInfo = new ListInfo("somelistpath", "ListNameKey", "ListDescrKey");

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act
                    folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);

                    // Assert
                    Assert.IsTrue(list.EnableFolderCreation);
                    Assert.AreEqual(2, list.RootFolder.SubFolders.Cast<SPFolder>().Where(folder => folder.Name != "Item" && folder.Name != "Attachments").Count());
                    Assert.AreEqual(3, list.Folders.Count);   // all created folders, excluding the special Item/Attachments folders at list root

                    var lvl2Folder = list.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path");
                    list.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path alt");

                    Assert.AreEqual(1, lvl2Folder.SubFolders.Count);
                    lvl2Folder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "level3");
                }
            }
        }
Пример #18
0
        public void EnsureFolderHierarchy_WhenInList_ShouldApplyFolderSpecificContentTypesChoicesInRibbonNewItemDropdown()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange

                // Create some content types, children of Item CT
                var contentTypeId1 = ContentTypeIdBuilder.CreateChild(SPBuiltInContentTypeId.Item, new Guid("{F8B6FF55-2C9E-4FA2-A705-F55FE3D18777}"));
                var contentTypeId2 = ContentTypeIdBuilder.CreateChild(SPBuiltInContentTypeId.Item, new Guid("{A7BAA5B7-C57B-4928-9778-818D267505A1}"));

                var itemContentType1 = new ContentTypeInfo(contentTypeId1, "itemCT1NameKey", "ItemCT1DescrKey", "GroupKey");
                var itemContentType2 = new ContentTypeInfo(contentTypeId2, "ItemCT2NameKey", "ItemCT2DescrKey", "GroupKey");

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        new FolderInfo("somelevel2path")
                        {
                            Subfolders = new List<FolderInfo>()
                            {
                                new FolderInfo("level3")
                                {
                                    UniqueContentTypeOrder = new List<ContentTypeInfo>() { itemContentType2 }
                                }
                            },
                            UniqueContentTypeOrder = new List<ContentTypeInfo>() { itemContentType1 }
                        },
                        new FolderInfo("somelevel2path alt")
                    },
                    UniqueContentTypeOrder = new List<ContentTypeInfo>()
                    {
                        // order: 2-1
                        itemContentType2,
                        itemContentType1
                    }
                };

                var listInfo = new ListInfo("somelistpath", "ListNameKey", "ListDescrKey")
                {
                    ContentTypes = new List<ContentTypeInfo>() { itemContentType1, itemContentType2 }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var folderHelper = injectionScope.Resolve<IFolderHelper>();
                    var listHelper = injectionScope.Resolve<IListHelper>();

                    // Make sure our CTs are available on list (this will add CTs to the root web and
                    // associate some child CTs to the list).
                    var ensuredList = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    // Act
                    folderHelper.EnsureFolderHierarchy(ensuredList, rootFolderInfo);

                    // Assert

                    // root folder should have order 2-1
                    var rootFolder = ensuredList.RootFolder;
                    Assert.AreEqual(2, rootFolder.UniqueContentTypeOrder.Count);
                    Assert.IsTrue(itemContentType2.ContentTypeId.IsParentOf(rootFolder.UniqueContentTypeOrder[0].Id));
                    Assert.IsTrue(itemContentType1.ContentTypeId.IsParentOf(rootFolder.UniqueContentTypeOrder[1].Id));

                    // lvl2 folder should have page1CT only
                    var lvl2Folder = ensuredList.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path");
                    Assert.AreEqual(1, lvl2Folder.UniqueContentTypeOrder.Count);
                    Assert.IsTrue(itemContentType1.ContentTypeId.IsParentOf(lvl2Folder.UniqueContentTypeOrder[0].Id));

                    // lvl2Alt should inherit root folder
                    var lvl2Alt = ensuredList.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path alt");
                    Assert.IsNull(lvl2Alt.UniqueContentTypeOrder);

                    // lvl3 should have page2CT only
                    var lvl3Folder = lvl2Folder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "level3");
                    Assert.AreEqual(1, lvl3Folder.UniqueContentTypeOrder.Count);
                    Assert.IsTrue(itemContentType2.ContentTypeId.IsParentOf(lvl3Folder.UniqueContentTypeOrder[0].Id));
                }
            }
        }
Пример #19
0
        public void EnsureFolderHierarchy_WhenAttemptingToSetUserFolderDefaultValueInDocLib_ShouldFailWithNotSupportedException()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                var ensuredUser1 = testScope.SiteCollection.RootWeb.EnsureUser(Environment.UserDomainName + "\\" + Environment.UserName);
                var ensuredUser2 = testScope.SiteCollection.RootWeb.EnsureUser("OFFICE\\maxime.boissonneault");

                UserFieldInfo userFieldInfo = new UserFieldInfo(
                    "TestInternalNameUser",
                    new Guid("{5B74DD50-0D2D-4D24-95AF-0C4B8AA3F68A}"),
                    "NameKeyUser",
                    "DescriptionKeyUser",
                    "GroupKey");

                UserMultiFieldInfo userMultiFieldInfo = new UserMultiFieldInfo(
                    "TestInternalNameUserMulti",
                    new Guid("{8C662588-D54E-4905-B232-856C2239B036}"),
                    "NameKeyUserMulti",
                    "DescriptionKeyUserMulti",
                    "GroupKey");

                ListInfo listInfo = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey")
                {
                    ListTemplateInfo = BuiltInListTemplates.DocumentLibrary,
                    FieldDefinitions = new List<BaseFieldInfo>() 
                    { 
                        userFieldInfo,
                        userMultiFieldInfo
                    }
                };

                var folderInfoLvl2 = new FolderInfo("somelevel2path")
                {
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();

                    // Create the test doc lib
                    SPList list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act 1: User field - this should throw NotSupportedException
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(userFieldInfo, new UserValue(ensuredUser1)) };
                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    { 
                    }

                    // Act 2: User Multi field - this should throw NotSupportedException
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(userMultiFieldInfo, new UserValueCollection() { new UserValue(ensuredUser1), new UserValue(ensuredUser2) }) };
                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    { 
                    }
                }
            }
        }
Пример #20
0
        public void EnsureFolderHierarchy_WhenFolderDefaultValuesAreSpecifiedInDocumentLibraryRootFolder_AndYouUploadADocument_ThenDocumentShouldHaveDefaultValueForAllSupportedFieldTypes()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                IntegerFieldInfo integerFieldInfo = new IntegerFieldInfo(
                    "TestInternalNameInteger",
                    new Guid("{12E262D0-C7C4-4671-A266-064CDBD3905A}"),
                    "NameKeyInt",
                    "DescriptionKeyInt",
                    "GroupKey");

                NumberFieldInfo numberFieldInfo = new NumberFieldInfo(
                    "TestInternalNameNumber",
                    new Guid("{5DD4EE0F-8498-4033-97D0-317A24988786}"),
                    "NameKeyNumber",
                    "DescriptionKeyNumber",
                    "GroupKey");

                CurrencyFieldInfo currencyFieldInfo = new CurrencyFieldInfo(
                    "TestInternalNameCurrency",
                    new Guid("{9E9963F6-1EE6-46FB-9599-783BBF4D6249}"),
                    "NameKeyCurrency",
                    "DescriptionKeyCurrency",
                    "GroupKey")
                {
                    LocaleId = 3084 // fr-CA
                };

                BooleanFieldInfo boolFieldInfoBasic = new BooleanFieldInfo(
                    "TestInternalNameBool",
                    new Guid("{F556AB6B-9E51-43E2-99C9-4A4E551A4BEF}"),
                    "NameKeyBool",
                    "DescriptionKeyBool",
                    "GroupKey");

                BooleanFieldInfo boolFieldInfoDefaultFalse = new BooleanFieldInfo(
                    "TestInternalNameBoolFalse",
                    new Guid("{628181BD-9B0B-4B7E-934F-1CF1796EA4E4}"),
                    "NameKeyBoolFalse",
                    "DescriptionKeyBoolFalse",
                    "GroupKey")
                {
                    // see related test above: EnsureFolderHierarchy_WhenAttemptingFALSEDefaultFolderValue_AndSPFieldAlreadHasTRUEDefaultValue_ShouldExplodeAndWarnYouThatThisWeirdEdgeCaseIsNotSupported
                    DefaultValue = false
                };

                DateTimeFieldInfo dateTimeFieldInfoFormula = new DateTimeFieldInfo(
                    "TestInternalNameDateFormula",
                    new Guid("{D23EAD73-9E18-46DB-A426-41B2D47F696C}"),
                    "NameKeyDateTimeFormula",
                    "DescriptionKeyDateTimeFormula",
                    "GroupKey")
                {
                    DefaultFormula = "=[Today]"
                };

                DateTimeFieldInfo dateTimeFieldInfoDefault = new DateTimeFieldInfo(
                    "TestInternalNameDateDefault",
                    new Guid("{016BF8D9-CEDC-4BF4-BA21-AC6A8F174AD5}"),
                    "NameKeyDateTimeDefault",
                    "DescriptionKeyDateTimeDefault",
                    "GroupKey")
                {
                    DefaultValue = new DateTime(2005, 10, 21)
                };

                TextFieldInfo textFieldInfo = new TextFieldInfo(
                    "TestInternalNameText",
                    new Guid("{0C58B4A1-B360-47FE-84F7-4D8F58AE80F6}"),
                    "NameKeyText",
                    "DescriptionKey",
                    "GroupKey")
                {
                    DefaultValue = "Text default value"
                };

                NoteFieldInfo noteFieldInfo = new NoteFieldInfo(
                    "TestInternalNameNote",
                    new Guid("{E315BB24-19C3-4F2E-AABC-9DE5EFC3D5C2}"),
                    "NameKeyNote",
                    "DescriptionKeyAlt",
                    "GroupKey")
                {
                    DefaultValue = "Note default value"
                };

                HtmlFieldInfo htmlFieldInfo = new HtmlFieldInfo(
                    "TestInternalNameHtml",
                    new Guid("{D16958E7-CF9A-4C38-A8BB-99FC03BFD913}"),
                    "NameKeyHtml",
                    "DescriptionKeyAlt",
                    "GroupKey")
                {
                    DefaultValue = "<p class=\"some-css-class\">HTML default value</p>"
                };

                ImageFieldInfo imageFieldInfo = new ImageFieldInfo(
                    "TestInternalNameImage",
                    new Guid("{6C5B9E77-B621-43AA-BFBF-B333093EFCAE}"),
                    "NameKeyImage",
                    "DescriptionKeyImage",
                    "GroupKey")
                {
                };

                UrlFieldInfo urlFieldInfo = new UrlFieldInfo(
                    "TestInternalNameUrl",
                    new Guid("{208F904C-5A1C-4E22-9A79-70B294FABFDA}"),
                    "NameKeyUrl",
                    "DescriptionKeyUrl",
                    "GroupKey")
                {
                };

                UrlFieldInfo urlFieldInfoImage = new UrlFieldInfo(
                    "TestInternalNameUrlImg",
                    new Guid("{96D22CFF-5B40-4675-B632-28567792E11B}"),
                    "NameKeyUrlImg",
                    "DescriptionKeyUrlImg",
                    "GroupKey")
                {
                    Format = UrlFieldFormat.Image
                };

                MediaFieldInfo mediaFieldInfo = new MediaFieldInfo(
                    "TestInternalNameMedia",
                    new Guid("{A2F070FE-FE33-44FC-9FDF-D18E74ED4D67}"),
                    "NameKeyMedia",
                    "DescriptionKeyMEdia",
                    "GroupKey");

                var testTermSet = new TermSetInfo(Guid.NewGuid(), "Test Term Set"); // keep Ids random because, if this test fails midway, the term
                // set will not be cleaned up and upon next test run we will
                // run into a term set and term ID conflicts.
                var levelOneTermA = new TermInfo(Guid.NewGuid(), "Term A", testTermSet);
                var levelOneTermB = new TermInfo(Guid.NewGuid(), "Term B", testTermSet);
                var levelTwoTermAA = new TermInfo(Guid.NewGuid(), "Term A-A", testTermSet);
                var levelTwoTermAB = new TermInfo(Guid.NewGuid(), "Term A-B", testTermSet);

                TaxonomySession session = new TaxonomySession(testScope.SiteCollection);
                TermStore defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                Group defaultSiteCollectionGroup = defaultSiteCollectionTermStore.GetSiteCollectionGroup(testScope.SiteCollection);
                TermSet newTermSet = defaultSiteCollectionGroup.CreateTermSet(testTermSet.Label, testTermSet.Id);
                Term createdTermA = newTermSet.CreateTerm(levelOneTermA.Label, Language.English.Culture.LCID, levelOneTermA.Id);
                Term createdTermB = newTermSet.CreateTerm(levelOneTermB.Label, Language.English.Culture.LCID, levelOneTermB.Id);
                Term createdTermAA = createdTermA.CreateTerm(levelTwoTermAA.Label, Language.English.Culture.LCID, levelTwoTermAA.Id);
                Term createdTermAB = createdTermA.CreateTerm(levelTwoTermAB.Label, Language.English.Culture.LCID, levelTwoTermAB.Id);
                defaultSiteCollectionTermStore.CommitAll();

                TaxonomyFieldInfo taxoFieldInfo = new TaxonomyFieldInfo(
                    "TestInternalNameTaxo",
                    new Guid("{18CC105F-16C9-43E2-9933-37F98452C038}"),
                    "NameKeyTaxo",
                    "DescriptionKey",
                    "GroupKey")
                {
                    TermStoreMapping = new TaxonomyContext(testTermSet)     // choices limited to all terms in test term set
                };

                TaxonomyMultiFieldInfo taxoMultiFieldInfo = new TaxonomyMultiFieldInfo(
                    "TestInternalNameTaxoMulti",
                    new Guid("{2F49D362-B014-41BB-9959-1000C9A7FFA0}"),
                    "NameKeyTaxoMulti",
                    "DescriptionKey",
                    "GroupKey")
                {
                    TermStoreMapping = new TaxonomyContext(levelOneTermA)   // choices limited to children of a specific term, instead of having full term set choices
                };

                // Create a list that contains all the fields we've prepared
                var fieldsToEnsure = new List<BaseFieldInfo>()
                    {
                        integerFieldInfo,
                        numberFieldInfo,
                        currencyFieldInfo,
                        boolFieldInfoBasic,
                        boolFieldInfoDefaultFalse,
                        dateTimeFieldInfoFormula,
                        dateTimeFieldInfoDefault,
                        textFieldInfo,
                        noteFieldInfo,
                        htmlFieldInfo,
                        imageFieldInfo,
                        urlFieldInfo,
                        urlFieldInfoImage,
                        mediaFieldInfo,
                        taxoFieldInfo,
                        taxoMultiFieldInfo
                    };

                ContentTypeInfo contentTypeWithAllFields = new ContentTypeInfo("0x0101007403019827FD4C68AF50C5F41781D262", "CTNameKey", "CTDescrKey", "GroupKey")
                {
                    Fields = fieldsToEnsure
                };

                ListInfo lookupListInfo = new ListInfo("sometestlistpathlookup", "DynamiteTestListNameKeyLookup", "DynamiteTestListDescriptionKeyLookup");
                ListInfo listInfo1 = new ListInfo("sometestlistpath", "DynamiteTestListNameKey", "DynamiteTestListDescriptionKey")
                {
                    ListTemplateInfo = BuiltInListTemplates.DocumentLibrary,
                    ContentTypes = new List<ContentTypeInfo>() { contentTypeWithAllFields }
                };

                // Prepare some MetadataDefaults that we'll apply on the second-level folder
                var fieldDefaultValues = new List<FieldValueInfo>()
                {
                    new FieldValueInfo(integerFieldInfo, 555),
                    new FieldValueInfo(numberFieldInfo, 5.0),
                    new FieldValueInfo(currencyFieldInfo, 535.95),
                    new FieldValueInfo(boolFieldInfoBasic, true),
                    new FieldValueInfo(boolFieldInfoDefaultFalse, true),
                    new FieldValueInfo(dateTimeFieldInfoFormula, new DateTime(1977, 1, 1)),
                    new FieldValueInfo(dateTimeFieldInfoDefault, new DateTime(1978, 1, 1)),
                    new FieldValueInfo(textFieldInfo, "TextAltDefaultValue"),
                    new FieldValueInfo(noteFieldInfo, "NoteAltDefaultValue"),
                    new FieldValueInfo(htmlFieldInfo, "HtmlAltDefaultValue"),
                    new FieldValueInfo(
                        imageFieldInfo, 
                        new ImageValue()
                        {
                            Hyperlink = "http://github.com/GSoft-SharePoint/",
                            ImageUrl = "/_layouts/15/MyFolder/MyImage.png"
                        }),
                    new FieldValueInfo(
                        urlFieldInfo, 
                        new UrlValue()
                        {
                            Url = "http://github.com/GSoft-SharePoint/",
                            Description = "patate!"
                        }),
                    new FieldValueInfo(
                        urlFieldInfoImage, 
                        new UrlValue()
                        {
                            Url = "http://github.com/GSoft-SharePoint/",
                            Description = "patate!"
                        }),
                    new FieldValueInfo(
                        mediaFieldInfo, 
                        new MediaValue()
                        {
                            Title = "Some media file title",
                            Url = "/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf",
                            IsAutoPlay = true,
                            IsLoop = true,
                            PreviewImageUrl = "/_layouts/15/Images/logo.png"
                        }),
                    new FieldValueInfo(taxoFieldInfo, new TaxonomyValue(levelOneTermB)),
                    new FieldValueInfo(
                        taxoMultiFieldInfo, 
                        new TaxonomyValueCollection(
                            new List<TaxonomyValue>() 
                                { 
                                    new TaxonomyValue(levelTwoTermAA), 
                                    new TaxonomyValue(levelTwoTermAB)
                                }))
                };

                // Default values are configured on the root folder (not on the 2nd level folder)
                var folderInfoLvl2 = new FolderInfo("somelevel2path");
                var rootFolderInfo = new FolderInfo("somepath")
                {
                    FieldDefaultValues = fieldDefaultValues,
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();

                    // Create the test doc lib
                    SPList list = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo1);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act: ensure the folder hierarchy with 2nd level subfolder which has MetadataDefaults for all possible types
                    var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);

                    var itemInRootFolder = ensuredRootFolder.Files.Add("SomeRootFile.txt", new byte[0]);
                    itemInRootFolder.Update();

                    var secondLevelEnsuredFolder = ensuredRootFolder.SubFolders["somelevel2path"];

                    var itemInSecondLevelFolder = secondLevelEnsuredFolder.Files.Add("SomeLevel2File.txt", new byte[0]);
                    itemInSecondLevelFolder.Update();

                    // Assert

                    // In root folder, our MetadataDefaults should've been applied
                    Assert.AreEqual(555, itemInRootFolder.Item["TestInternalNameInteger"]);
                    Assert.AreEqual(5.0, itemInRootFolder.Item["TestInternalNameNumber"]);
                    Assert.AreEqual(535.95, itemInRootFolder.Item["TestInternalNameCurrency"]);
                    Assert.IsTrue((bool)itemInRootFolder.Item["TestInternalNameBool"]);
                    Assert.IsTrue((bool)itemInRootFolder.Item["TestInternalNameBoolFalse"]);
                    Assert.AreEqual(new DateTime(1977, 1, 1), itemInRootFolder.Item["TestInternalNameDateFormula"]);
                    Assert.AreEqual(new DateTime(1978, 1, 1), itemInRootFolder.Item["TestInternalNameDateDefault"]);
                    Assert.AreEqual("TextAltDefaultValue", itemInRootFolder.Item["TestInternalNameText"]);
                    Assert.AreEqual("NoteAltDefaultValue", itemInRootFolder.Item["TestInternalNameNote"]);
                    Assert.AreEqual("HtmlAltDefaultValue", itemInRootFolder.Item["TestInternalNameHtml"]);

                    var imageFieldVal = (ImageFieldValue)itemInRootFolder.Item["TestInternalNameImage"];
                    Assert.IsNotNull(imageFieldVal);
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", imageFieldVal.Hyperlink);
                    Assert.AreEqual("/_layouts/15/MyFolder/MyImage.png", imageFieldVal.ImageUrl);

                    var urlFieldVal = new SPFieldUrlValue(itemInRootFolder.Item["TestInternalNameUrl"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlFieldVal.Url);
                    Assert.AreEqual("patate!", urlFieldVal.Description);

                    var urlImageFieldVal = new SPFieldUrlValue(itemInRootFolder.Item["TestInternalNameUrlImg"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlImageFieldVal.Url);
                    Assert.AreEqual("patate!", urlImageFieldVal.Description);

                    var mediaFieldVal = MediaFieldValue.FromString(itemInRootFolder.Item["TestInternalNameMedia"].ToString());
                    Assert.AreEqual("Some media file title", mediaFieldVal.Title);
                    Assert.AreEqual(HttpUtility.UrlDecode("/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf"), mediaFieldVal.MediaSource);
                    Assert.IsTrue(mediaFieldVal.AutoPlay);
                    Assert.IsTrue(mediaFieldVal.Loop);
                    Assert.AreEqual("/_layouts/15/Images/logo.png", mediaFieldVal.PreviewImageSource);

                    var taxoFieldValue = (TaxonomyFieldValue)itemInRootFolder.Item["TestInternalNameTaxo"];
                    Assert.AreNotEqual(-1, taxoFieldValue.WssId);
                    Assert.AreEqual(levelOneTermB.Id, new Guid(taxoFieldValue.TermGuid));
                    Assert.AreEqual(levelOneTermB.Label, taxoFieldValue.Label);

                    var taxoFieldValueMulti = (TaxonomyFieldValueCollection)itemInRootFolder.Item["TestInternalNameTaxoMulti"];
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[0].WssId);
                    Assert.AreEqual(levelTwoTermAA.Id, new Guid(taxoFieldValueMulti[0].TermGuid));
                    Assert.AreEqual(levelTwoTermAA.Label, taxoFieldValueMulti[0].Label);
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[1].WssId);
                    Assert.AreEqual(levelTwoTermAB.Id, new Guid(taxoFieldValueMulti[1].TermGuid));
                    Assert.AreEqual(levelTwoTermAB.Label, taxoFieldValueMulti[1].Label);
                    
                    // In second-level folder, our MetadataDefaults should've been applied as well (inherited from root folder)
                    Assert.AreEqual(5.0, itemInSecondLevelFolder.Item["TestInternalNameNumber"]);
                    Assert.AreEqual(535.95, itemInSecondLevelFolder.Item["TestInternalNameCurrency"]);
                    Assert.IsTrue((bool)itemInSecondLevelFolder.Item["TestInternalNameBool"]);
                    Assert.IsTrue((bool)itemInSecondLevelFolder.Item["TestInternalNameBoolFalse"]);
                    Assert.AreEqual(new DateTime(1977, 1, 1), itemInSecondLevelFolder.Item["TestInternalNameDateFormula"]);
                    Assert.AreEqual(new DateTime(1978, 1, 1), itemInSecondLevelFolder.Item["TestInternalNameDateDefault"]);
                    Assert.AreEqual("TextAltDefaultValue", itemInSecondLevelFolder.Item["TestInternalNameText"]);
                    Assert.AreEqual("NoteAltDefaultValue", itemInSecondLevelFolder.Item["TestInternalNameNote"]);
                    Assert.AreEqual("HtmlAltDefaultValue", itemInSecondLevelFolder.Item["TestInternalNameHtml"]);

                    imageFieldVal = (ImageFieldValue)itemInSecondLevelFolder.Item["TestInternalNameImage"];
                    Assert.IsNotNull(imageFieldVal);
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", imageFieldVal.Hyperlink);
                    Assert.AreEqual("/_layouts/15/MyFolder/MyImage.png", imageFieldVal.ImageUrl);

                    urlFieldVal = new SPFieldUrlValue(itemInSecondLevelFolder.Item["TestInternalNameUrl"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlFieldVal.Url);
                    Assert.AreEqual("patate!", urlFieldVal.Description);

                    urlImageFieldVal = new SPFieldUrlValue(itemInSecondLevelFolder.Item["TestInternalNameUrlImg"].ToString());
                    Assert.AreEqual("http://github.com/GSoft-SharePoint/", urlImageFieldVal.Url);
                    Assert.AreEqual("patate!", urlImageFieldVal.Description);

                    mediaFieldVal = MediaFieldValue.FromString(itemInSecondLevelFolder.Item["TestInternalNameMedia"].ToString());
                    Assert.AreEqual("Some media file title", mediaFieldVal.Title);
                    Assert.AreEqual(HttpUtility.UrlDecode("/sites/test/SiteAssets/01_01_ASP.NET%20MVC%203%20Fundamentals%20Intro%20-%20Overview.asf"), mediaFieldVal.MediaSource);
                    Assert.IsTrue(mediaFieldVal.AutoPlay);
                    Assert.IsTrue(mediaFieldVal.Loop);
                    Assert.AreEqual("/_layouts/15/Images/logo.png", mediaFieldVal.PreviewImageSource);

                    taxoFieldValue = (TaxonomyFieldValue)itemInSecondLevelFolder.Item["TestInternalNameTaxo"];
                    Assert.AreNotEqual(-1, taxoFieldValue.WssId);
                    Assert.AreEqual(levelOneTermB.Id, new Guid(taxoFieldValue.TermGuid));
                    Assert.AreEqual(levelOneTermB.Label, taxoFieldValue.Label);

                    taxoFieldValueMulti = (TaxonomyFieldValueCollection)itemInSecondLevelFolder.Item["TestInternalNameTaxoMulti"];
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[0].WssId);
                    Assert.AreEqual(levelTwoTermAA.Id, new Guid(taxoFieldValueMulti[0].TermGuid));
                    Assert.AreEqual(levelTwoTermAA.Label, taxoFieldValueMulti[0].Label);
                    Assert.AreNotEqual(-1, taxoFieldValueMulti[1].WssId);
                    Assert.AreEqual(levelTwoTermAB.Id, new Guid(taxoFieldValueMulti[1].TermGuid));
                    Assert.AreEqual(levelTwoTermAB.Label, taxoFieldValueMulti[1].Label);
                }
            }
        }
Пример #21
0
        public void EnsureFolderHierarchy_WhenBooleanTRUEDefaultValuesAreSpecifiedInPagesLibraryFolder_ShouldThrownNotSupportedException()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange
                BooleanFieldInfo boolFieldInfoBasic = new BooleanFieldInfo(
                    "TestInternalNameBool",
                    new Guid("{F556AB6B-9E51-43E2-99C9-4A4E551A4BEF}"),
                    "NameKeyBool",
                    "DescriptionKeyBool",
                    "GroupKey");

                BooleanFieldInfo boolFieldInfoDefaultTrue = new BooleanFieldInfo(
                   "TestInternalNameBoolTrue",
                   new Guid("{0D0289AD-C5FB-495B-96C6-48CC46737D08}"),
                   "NameKeyBoolTrue",
                   "DescriptionKeyBoolTrue",
                   "GroupKey")
                {
                    DefaultValue = true
                };

                BooleanFieldInfo boolFieldInfoDefaultFalse = new BooleanFieldInfo(
                    "TestInternalNameBoolFalse",
                    new Guid("{628181BD-9B0B-4B7E-934F-1CF1796EA4E4}"),
                    "NameKeyBoolFalse",
                    "DescriptionKeyBoolFalse",
                    "GroupKey")
                {
                    DefaultValue = false
                };

                var fieldsToEnsure = new List<BaseFieldInfo>()
                {
                    boolFieldInfoBasic,
                    boolFieldInfoDefaultTrue,
                    boolFieldInfoDefaultFalse
                };

                // We gotta update the ArticlePage Content type with our fields
                var articlePageCT = new ContentTypeInfo(
                    "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D",
                    "UpdatedArticlePageCT",
                    "UpdatedArticlePageCTDescription",
                    "GroupKey")
                {
                    Fields = fieldsToEnsure
                };

                // Default values will be  configured further down on the level 2 folder (not on the root folder)
                var folderInfoLvl2 = new FolderInfo("somelevel2path")
                {
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var contentTypeHelper = injectionScope.Resolve<IContentTypeHelper>();

                    // Init the test Pages library (we're in a Pub Site, the Pages lib already exists and we want to add fields to it)
                    SPList list = testScope.SiteCollection.RootWeb.GetPagesLibrary();
                    contentTypeHelper.EnsureContentType(list.ContentTypes, articlePageCT);      // this should add the field to the Pages lib

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act #1: try to set a TRUE folder default value on a default-less Boolean field
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(boolFieldInfoBasic, true) };

                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    {
                    }

                    // Act #2: try to set a TRUE folder default value on a TRUE-default Boolean field
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(boolFieldInfoDefaultTrue, true) };

                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    {
                    }

                    // Act #3: try to set a TRUE folder default value on a FALSE-default Boolean field
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(boolFieldInfoDefaultFalse, true) };

                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    {
                    }
                }
            }
        }
Пример #22
0
        public void EnsureFolderHierarchy_WhenInPagesLibrary_AndNotEnsuredYet_ShouldCreatePublishingPages()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange
                var articleLeftPageLayout = new PageLayoutInfo("ArticleLeft.aspx", new SPContentTypeId("0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D"));
                var welcomePageLayout = new PageLayoutInfo("WelcomeSplash.aspx", new SPContentTypeId("0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4"));

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        new FolderInfo("somelevel2path")
                        {
                            Subfolders = new List<FolderInfo>()
                            {
                                new FolderInfo("level3")
                                {
                                    Pages = new List<PageInfo>()
                                    {
                                        new PageInfo("Hello-lvl-3-page-path", articleLeftPageLayout)
                                        {
                                            FieldValues = new List<FieldValueInfo>()
                                            {
                                                new FieldValueInfo(PublishingFields.PublishingPageContent, "<div><p>Hi LVL 3!!! My HTML rocks!!!</p></div>")
                                            }
                                        },
                                        new PageInfo("Hello-lvl-3-page-path-bis", articleLeftPageLayout)
                                        {
                                            FieldValues = new List<FieldValueInfo>()
                                            {
                                                new FieldValueInfo(PublishingFields.PublishingPageContent, "<div><p>Hi LVL 3 AGAIN!!! My HTML rocks!!!</p></div>")
                                            }
                                        },
                                    }
                                }
                            },
                            Pages = new List<PageInfo>()
                            {
                                new PageInfo("Hello-lvl-2-page-path", articleLeftPageLayout)
                                {
                                    FieldValues = new List<FieldValueInfo>()
                                    {
                                        new FieldValueInfo(PublishingFields.PublishingPageContent, "<div><p>Hi LVL 2!!! My HTML rocks!!!</p></div>")
                                    }
                                }
                            }
                        }
                    },
                    Pages = new List<PageInfo>()
                    {
                        new PageInfo("Hello-root-page-path", welcomePageLayout)
                        {
                            FieldValues = new List<FieldValueInfo>()
                            {
                                new FieldValueInfo(PublishingFields.PublishingPageContent, "<div><p>My HTML rocks!!!</p></div>")
                            }
                        }
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    var pagesLibrary = testScope.SiteCollection.RootWeb.GetPagesLibrary();

                    // Act
                    folderHelper.EnsureFolderHierarchy(pagesLibrary, rootFolderInfo);

                    // Assert
                    var publishingSite = new PublishingSite(pagesLibrary.ParentWeb.Site);
                    var publishingWeb = PublishingWeb.GetPublishingWeb(pagesLibrary.ParentWeb);
                    var recursivePagesQuery = new SPQuery() { ViewAttributes = "Scope=\"Recursive\"" };
                    var publishingPages = publishingWeb.GetPublishingPages(recursivePagesQuery);

                    Assert.AreEqual(4, publishingPages.Cast<PublishingPage>().Where(p => p.Name.StartsWith("Hello")).Count());

                    var ensuredWelcomePage = publishingPages.Cast<PublishingPage>().Single(p => p.Name.StartsWith("Hello-root-page-path"));
                    Assert.IsTrue(ensuredWelcomePage.ContentType.Id.IsChildOf(welcomePageLayout.AssociatedContentTypeId));

                    var ensuredLevel2Page = publishingPages.Cast<PublishingPage>().Single(p => p.Name.StartsWith("Hello-lvl-2-page-path"));
                    Assert.IsTrue(ensuredLevel2Page.ContentType.Id.IsChildOf(articleLeftPageLayout.AssociatedContentTypeId));
                    Assert.AreEqual("<div><p>Hi LVL 2!!! My HTML rocks!!!</p></div>", ensuredLevel2Page.ListItem[PublishingFields.PublishingPageContent.Id].ToString());
                }
            }
        }
Пример #23
0
        public void EnsureFolderHierarchy_WhenDateTimeFieldDefaultAlreadyDefined_AndAttemptingToSetFolderDefaultDate_ShouldThrownNotSupportedException()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange
                DateTimeFieldInfo dateTimeFieldInfoFormula = new DateTimeFieldInfo(
                   "TestInternalNameDateFormula",
                   new Guid("{D23EAD73-9E18-46DB-A426-41B2D47F696C}"),
                   "NameKeyDateTimeFormula",
                   "DescriptionKeyDateTimeFormula",
                   "GroupKey")
                {
                    DefaultFormula = "=[Today]"
                };

                DateTimeFieldInfo dateTimeFieldInfoDefault = new DateTimeFieldInfo(
                    "TestInternalNameDateDefault",
                    new Guid("{016BF8D9-CEDC-4BF4-BA21-AC6A8F174AD5}"),
                    "NameKeyDateTimeDefault",
                    "DescriptionKeyDateTimeDefault",
                    "GroupKey")
                {
                    DefaultValue = new DateTime(2005, 10, 21)
                };

                var fieldsToEnsure = new List<BaseFieldInfo>()
                {
                    dateTimeFieldInfoFormula,
                    dateTimeFieldInfoDefault
                };

                // We gotta update the ArticlePage Content type with our fields
                var articlePageCT = new ContentTypeInfo(
                    "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D",
                    "UpdatedArticlePageCT",
                    "UpdatedArticlePageCTDescription",
                    "GroupKey")
                {
                    Fields = fieldsToEnsure
                };

                // Default values will be configured further down on the level 2 folder (not on the root folder)
                var folderInfoLvl2 = new FolderInfo("somelevel2path")
                {
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var contentTypeHelper = injectionScope.Resolve<IContentTypeHelper>();

                    // Init the test Pages library (we're in a Pub Site, the Pages lib already exists and we want to add fields to it)
                    SPList list = testScope.SiteCollection.RootWeb.GetPagesLibrary();
                    contentTypeHelper.EnsureContentType(list.ContentTypes, articlePageCT);      // this should add the field to the Pages lib

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Act #1: try to set a DateTime folder default on a field which already has a formula
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(dateTimeFieldInfoFormula, new DateTime(2003, 12, 31)) };

                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    {
                    }

                    // Act #2: try to set a DateTime folder default value on a field which already has a default value
                    folderInfoLvl2.FieldDefaultValues = new List<FieldValueInfo>() { new FieldValueInfo(dateTimeFieldInfoDefault, new DateTime(2003, 12, 31)) };

                    try
                    {
                        var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);
                        Assert.Fail("Should've thrown NotSupportedException");
                    }
                    catch (NotSupportedException)
                    {
                    }
                }
            }
        }
Пример #24
0
        public void EnsureFolderHierarchy_WhenPagesAlreadyEnsured_AndPageInfoIsRenamed_ShouldNotDeleteExistingPage_AndCreateABrandNewPage()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange
                var articleLeftPageLayout = new PageLayoutInfo("ArticleLeft.aspx", new SPContentTypeId("0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D"));
                var welcomePageLayout = new PageLayoutInfo("WelcomeSplash.aspx", new SPContentTypeId("0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4"));

                var level1PageInfo = new PageInfo("Hello-root-page-path", welcomePageLayout)
                {
                    FieldValues = new List<FieldValueInfo>()
                        {
                            new FieldValueInfo(PublishingFields.PublishingPageContent, "<div><p>My HTML rocks!!!</p></div>")
                        }
                };

                var level2PageInfo = new PageInfo("Hello-lvl-2-page-path", articleLeftPageLayout)
                {
                    FieldValues = new List<FieldValueInfo>()
                        {
                            new FieldValueInfo(PublishingFields.PublishingPageContent, "<div><p>Hi LVL 2!!! My HTML rocks!!!</p></div>")
                        }
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        new FolderInfo("somelevel2path")
                        {
                            Pages = new List<PageInfo>()
                            {
                                level2PageInfo
                            }
                        }
                    },
                    Pages = new List<PageInfo>()
                    {
                        level1PageInfo
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    var pagesLibrary = testScope.SiteCollection.RootWeb.GetPagesLibrary();

                    // Ensure the hierarchy a first time with the initial page values
                    folderHelper.EnsureFolderHierarchy(pagesLibrary, rootFolderInfo);

                    // Edit the PageInfos slightly
                    level1PageInfo.FileName = "Hello-welcome-page-renamed";
                    level2PageInfo.FileName = "Hello-level-2-page-renamed";

                    // Act: re-ensure the same hierarchy
                    folderHelper.EnsureFolderHierarchy(pagesLibrary, rootFolderInfo);

                    // Assert: new pages should've been created and the old ones should still be there
                    var publishingSite = new PublishingSite(pagesLibrary.ParentWeb.Site);
                    var publishingWeb = PublishingWeb.GetPublishingWeb(pagesLibrary.ParentWeb);
                    var recursivePagesQuery = new SPQuery() { ViewAttributes = "Scope=\"Recursive\"" };
                    var publishingPages = publishingWeb.GetPublishingPages(recursivePagesQuery);

                    Assert.AreEqual(4, publishingPages.Cast<PublishingPage>().Where(p => p.Name.StartsWith("Hello")).Count());

                    var ensuredWelcomePage = publishingPages.Cast<PublishingPage>().Single(p => p.Name.StartsWith("Hello-root-page-path"));
                    var ensuredLevel2Page = publishingPages.Cast<PublishingPage>().Single(p => p.Name.StartsWith("Hello-lvl-2-page-path"));

                    var extraEnsuredWelcomePage = publishingPages.Cast<PublishingPage>().Single(p => p.Name.StartsWith("Hello-welcome-page-renamed"));
                    var extraEnsuredLevel2Page = publishingPages.Cast<PublishingPage>().Single(p => p.Name.StartsWith("Hello-level-2-page-renamed"));
                }
            }
        }
Пример #25
0
        public void EnsureFolderHierarchy_WhenUpdatingDocLibFolders_ShouldUpdateFolderHierarchyWithAddedSubfolders()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var folderInfoLvl3 = new FolderInfo("level3");
                var folderInfoLvl2 = new FolderInfo("somelevel2path");
                var folderInfoLvl2Alt = new FolderInfo("somelevel2path alt");

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    Subfolders = new List<FolderInfo>()
                    {
                        folderInfoLvl2      // just add one of the three subfolders for now
                    }
                };

                var listInfo = new ListInfo("somelistpath", "ListNameKey", "ListDescrKey")
                {
                    ListTemplateInfo = BuiltInListTemplates.DocumentLibrary
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var documentLibrary = listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();

                    // Ensure the initial (partial) folder hierarchy
                    folderHelper.EnsureFolderHierarchy(documentLibrary, rootFolderInfo);

                    // Modify the folder hierarchy to add the 2 missing subfolders
                    folderInfoLvl2.Subfolders.Add(folderInfoLvl3);
                    rootFolderInfo.Subfolders.Add(folderInfoLvl2Alt);

                    // Act: re-ensure the hierarchy with update definition
                    folderHelper.EnsureFolderHierarchy(documentLibrary, rootFolderInfo);

                    // Assert
                    Assert.IsTrue(documentLibrary.EnableFolderCreation);
                    Assert.AreEqual(2, documentLibrary.RootFolder.SubFolders.Cast<SPFolder>().Where(folder => folder.Name != "Forms").Count());
                    Assert.AreEqual(3, documentLibrary.Folders.Count);   // all created folders, excluding the special Forms folder at library root

                    var lvl2Folder = documentLibrary.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path");
                    documentLibrary.RootFolder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "somelevel2path alt");

                    Assert.AreEqual(1, lvl2Folder.SubFolders.Count);
                    lvl2Folder.SubFolders.Cast<SPFolder>().Single(f => f.Name == "level3");
                }
            }
        }
Пример #26
0
        public void EnsureFolderHierarchy_WhenDocLibFolderDefaultValuesAreSpecified_AndFirstEnsure_AndInRootFolder_ShouldInitializeFolderMetadataDefaults()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var folderInfoLvl2 = new FolderInfo("somelevel2path");

                DateTimeFieldInfo dateTimeFieldInfoEmpty = new DateTimeFieldInfo(
                    "TestInternalNameDate",
                    new Guid("{CD09FF50-0CE3-40AE-90ED-AC68961FA980}"),
                    "NameKeyDateTime",
                    "DescriptionKeyDateTimeFormula",
                    "GroupKey");

                DateTimeFieldInfo dateTimeFieldInfoFormula = new DateTimeFieldInfo(
                    "TestInternalNameDateFormula",
                    new Guid("{D23EAD73-9E18-46DB-A426-41B2D47F696C}"),
                    "NameKeyDateTimeFormula",
                    "DescriptionKeyDateTimeFormula",
                    "GroupKey")
                {
                    DefaultFormula = "=[Today]"
                };

                var rootFolderInfo = new FolderInfo("somepath")
                {
                    FieldDefaultValues = new List<FieldValueInfo>() 
                    { 
                        new FieldValueInfo(dateTimeFieldInfoEmpty, new DateTime(1990, 5, 20)),
                        new FieldValueInfo(dateTimeFieldInfoFormula, new DateTime(2050, 9, 18))
                    }
                };

                var listInfo = new ListInfo("somelistpath", "ListNameKey", "ListDescrKey")
                {
                    ListTemplateInfo = BuiltInListTemplates.DocumentLibrary,
                    FieldDefinitions = new List<BaseFieldInfo>() { dateTimeFieldInfoEmpty, dateTimeFieldInfoFormula }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var listHelper = injectionScope.Resolve<IListHelper>();
                    var list = (SPDocumentLibrary)listHelper.EnsureList(testScope.SiteCollection.RootWeb, listInfo);

                    var folderHelper = injectionScope.Resolve<IFolderHelper>();
                    
                    // Act
                    var ensuredRootFolder = folderHelper.EnsureFolderHierarchy(list, rootFolderInfo);

                    var itemInRootFolder = ensuredRootFolder.Files.Add("SomeRootFile.txt", new byte[0]);
                    itemInRootFolder.Update();

                    // Assert

                    // In root folder, both fields' metadata defaults should apply
                    Assert.AreEqual(new DateTime(1990, 5, 20), (DateTime)itemInRootFolder.Item[dateTimeFieldInfoEmpty.Id]);
                    Assert.AreEqual(new DateTime(2050, 9, 18), (DateTime)itemInRootFolder.Item[dateTimeFieldInfoFormula.Id]);
                }
            }
        }
Пример #27
0
        public void FolderInfo_ShouldSupportStringSerializationAndDeserialization()
        {
            var serializer = this.GetSerializer();
            var articleLeftPageLayout = new PageLayoutInfo("ArticleLeft.aspx", new SPContentTypeId("0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D"));
            var welcomePageLayout = new PageLayoutInfo("WelcomeSplash.aspx", new SPContentTypeId("0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4"));

            var objectToSerialize = new FolderInfo("somepath")
            {
                Subfolders = new List<FolderInfo>()
                    {
                        new FolderInfo("somelevel2path")
                        {
                            Pages = new List<PageInfo>()
                            {
                                new PageInfo("Hello-lvl-2-page-path", articleLeftPageLayout)
                                {
                                    FieldValues = new List<FieldValueInfo>()
                                    {
                                        new FieldValueInfo(PublishingFields.PublishingPageContent, "<div><p>Hi LVL 2!!! My HTML rocks!!!</p></div>")
                                    },
                                    WebParts = new[] 
                                    {
                                        new WebPartInfo("Main", new ContentEditorWebPart(), 5),
                                        new WebPartInfo("Main", new ContentEditorWebPart(), 10),
                                    }
                                }
                            }
                        }
                    },
                Pages = new List<PageInfo>()
                    {
                        new PageInfo("Hello-root-page-path", welcomePageLayout)
                        {
                            FieldValues = new List<FieldValueInfo>()
                            {
                                new FieldValueInfo(PublishingFields.PublishingPageContent, "<div><p>My HTML rocks!!!</p></div>")
                            }
                        }
                    }
            };

            string serializedRepresentation = serializer.Serialize(objectToSerialize);

            var deserializedObject = serializer.Deserialize<FolderInfo>(serializedRepresentation);

            Assert.AreEqual(objectToSerialize.Name, deserializedObject.Name);

            Assert.AreEqual(objectToSerialize.Pages.Count, deserializedObject.Pages.Count);
            Assert.AreEqual(objectToSerialize.Pages.ElementAt(0).FileName, deserializedObject.Pages.ElementAt(0).FileName);
            Assert.AreEqual(objectToSerialize.Pages.ElementAt(0).FieldValues.Count, deserializedObject.Pages.ElementAt(0).FieldValues.Count);
            Assert.AreEqual(
                objectToSerialize.Pages.ElementAt(0).FieldValues.ElementAt(0).FieldInfo.InternalName, 
                deserializedObject.Pages.ElementAt(0).FieldValues.ElementAt(0).FieldInfo.InternalName);
            Assert.AreEqual(
                objectToSerialize.Pages.ElementAt(0).FieldValues.ElementAt(0).FieldInfo.AssociatedValueType,
                deserializedObject.Pages.ElementAt(0).FieldValues.ElementAt(0).FieldInfo.AssociatedValueType);
            Assert.AreEqual(
                objectToSerialize.Pages.ElementAt(0).FieldValues.ElementAt(0).Value,
                deserializedObject.Pages.ElementAt(0).FieldValues.ElementAt(0).Value);
            Assert.AreEqual(
                objectToSerialize.Pages.ElementAt(0).PageLayout.AssociatedContentTypeId,
                deserializedObject.Pages.ElementAt(0).PageLayout.AssociatedContentTypeId);

            Assert.AreEqual(objectToSerialize.Subfolders.Count, deserializedObject.Subfolders.Count);
            Assert.AreEqual(
                objectToSerialize.Subfolders.ElementAt(0).Pages.ElementAt(0).WebParts.Count,
                deserializedObject.Subfolders.ElementAt(0).Pages.ElementAt(0).WebParts.Count);
        }