public void EnsureProfileProperty_WhenUpdatingDisplayName_GivenUpdatedUserProfilePropertyInfo_ThenUpdatesProperty()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var site = testScope.SiteCollection;
                var userProfilePropertyInfo = new UserProfilePropertyInfo(
                    ProfilePropertyName,
                    "Test Profile Property",
                    PropertyDataType.StringSingleValue);

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site))
                {
                    try
                    {
                        // Act
                        var userProfileHelper = injectionScope.Resolve <IUserProfilePropertyHelper>();
                        userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo);
                        userProfilePropertyInfo.DisplayName = "Test Profile Property Updated";
                        var userProfileProperty = userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo);

                        // Assert
                        Assert.AreEqual(userProfileProperty.DisplayName, "Test Profile Property Updated");
                    }
                    finally
                    {
                        this.TestCleanup();
                    }
                }
            }
        }
        /// <summary>
        /// Cleans up the test data.
        /// </summary>
        public void TestCleanup()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                var site = testScope.SiteCollection;

                var userProfilePropertyInfo = new UserProfilePropertyInfo(
                    ProfilePropertyName,
                    "Test Profile Property",
                    PropertyDataType.StringSingleValue);

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site))
                {
                    // Try removing the test profile property
                    try
                    {
                        var userProfileHelper = injectionScope.Resolve <IUserProfilePropertyHelper>();
                        userProfileHelper.RemoveProfileProperty(site, userProfilePropertyInfo);
                    }
                    catch (Exception)
                    {
                        // Do nothing
                    }
                }
            }
        }
        public void EnsureProfileProperty_WhenUpdatingVisibility_GivenUpdatedUserProfilePropertyInfo_ThenUpdatesProperty()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var site = testScope.SiteCollection;
                var userProfilePropertyInfo = new UserProfilePropertyInfo(
                    ProfilePropertyName,
                    "Test Profile Property",
                    PropertyDataType.StringSingleValue);

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site))
                {
                    try
                    {
                        // Act
                        var userProfileHelper = injectionScope.Resolve <IUserProfilePropertyHelper>();
                        userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo);
                        userProfilePropertyInfo.IsVisibleOnEditor = true;
                        userProfilePropertyInfo.IsVisibleOnViewer = true;
                        userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo);

                        // Assert
                        var profileTypeManager  = userProfileHelper.GetProfileTypePropertyManager(site);
                        var profileTypeProperty = profileTypeManager.GetPropertyByName(userProfilePropertyInfo.Name);
                        Assert.AreEqual(profileTypeProperty.IsVisibleOnEditor, userProfilePropertyInfo.IsVisibleOnEditor);
                        Assert.AreEqual(profileTypeProperty.IsVisibleOnViewer, userProfilePropertyInfo.IsVisibleOnViewer);
                    }
                    finally
                    {
                        this.TestCleanup();
                    }
                }
            }
        }
예제 #4
0
        public void GetTermsAsSimpleLinkNavNodeForTermSet_WhenNoChildTerms_ShouldReturnAllFirstLevelTerms()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var testTermSetInfo = new TermSetInfo(Guid.NewGuid(), "Test Term Set");
                var levelOneTermA   = new SimpleLinkTermInfo(Guid.NewGuid(), "Term A", testTermSetInfo, "URL-A");
                var levelOneTermB   = new SimpleLinkTermInfo(Guid.NewGuid(), "Term B", testTermSetInfo, "URL-B");
                var levelOneTermC   = new SimpleLinkTermInfo(Guid.NewGuid(), "Term C", testTermSetInfo, "URL-C");

                var expecteNumberOfTerms = 3;

                var session = new TaxonomySession(testScope.SiteCollection);
                var defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                var defaultSiteCollectionGroup     = defaultSiteCollectionTermStore.GetSiteCollectionGroup(testScope.SiteCollection);
                var newTermSet = defaultSiteCollectionGroup.CreateTermSet(testTermSetInfo.Label, testTermSetInfo.Id);

                var createdTermA = newTermSet.CreateTerm(levelOneTermA.Label, Language.English.Culture.LCID, levelOneTermA.Id);
                createdTermA.SetLocalCustomProperty(CustomPropertyKey, levelOneTermA.SimpleLinkTarget);

                var createdTermB = newTermSet.CreateTerm(levelOneTermB.Label, Language.English.Culture.LCID, levelOneTermB.Id);
                createdTermB.SetLocalCustomProperty(CustomPropertyKey, levelOneTermB.SimpleLinkTarget);

                var createdTermC = newTermSet.CreateTerm(levelOneTermC.Label, Language.English.Culture.LCID, levelOneTermC.Id);
                createdTermC.SetLocalCustomProperty(CustomPropertyKey, levelOneTermC.SimpleLinkTarget);

                defaultSiteCollectionTermStore.CommitAll();

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var taxonomyService = injectionScope.Resolve <ITaxonomyService>();

                    // Act
                    var retrievedTerms = taxonomyService.GetTermsAsSimpleLinkNavNodeForTermSet(testScope.SiteCollection, defaultSiteCollectionGroup.Name, newTermSet.Name);

                    // Assert
                    Assert.IsNotNull(retrievedTerms);
                    Assert.AreEqual(retrievedTerms.Count, expecteNumberOfTerms);

                    Assert.AreEqual(retrievedTerms[0].SimpleLinkTarget, levelOneTermA.SimpleLinkTarget);
                    Assert.AreEqual(retrievedTerms[0].Label, levelOneTermA.Label);
                    Assert.AreEqual(retrievedTerms[0].ChildTerms.Count(), 0);

                    Assert.AreEqual(retrievedTerms[1].SimpleLinkTarget, levelOneTermB.SimpleLinkTarget);
                    Assert.AreEqual(retrievedTerms[1].Label, levelOneTermB.Label);
                    Assert.AreEqual(retrievedTerms[1].ChildTerms.Count(), 0);

                    Assert.AreEqual(retrievedTerms[2].SimpleLinkTarget, levelOneTermC.SimpleLinkTarget);
                    Assert.AreEqual(retrievedTerms[2].Label, levelOneTermC.Label);
                    Assert.AreEqual(retrievedTerms[2].ChildTerms.Count(), 0);
                }

                // Cleanup term set so that we don't pollute the metadata store
                newTermSet.Delete();
                defaultSiteCollectionTermStore.CommitAll();
            }
        }
        public void EnsureProfileProperty_WhenUpdatingSecurity_GivenUpdatedUserProfilePropertyInfo_ThenUpdatesProperty()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var site = testScope.SiteCollection;
                var userProfilePropertyInfo = new UserProfilePropertyInfo(
                    ProfilePropertyName,
                    "Test Profile Property",
                    PropertyDataType.StringSingleValue)
                {
                    IsUserEditable = true
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site))
                {
                    try
                    {
                        // Act
                        var userProfileHelper = injectionScope.Resolve <IUserProfilePropertyHelper>();
                        userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo);

                        // Make sure the default privacy value is set to private
                        var profileSubtypeManager  = userProfileHelper.GetProfileSubtypePropertyManager(site);
                        var profileSubtypeProperty = profileSubtypeManager.GetPropertyByName(userProfilePropertyInfo.Name);

                        Assert.AreEqual(Privacy.Private, profileSubtypeProperty.DefaultPrivacy);

                        userProfilePropertyInfo.IsUserEditable = false;
                        userProfilePropertyInfo.DefaultPrivacy = Privacy.Public;
                        userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo);

                        profileSubtypeManager  = userProfileHelper.GetProfileSubtypePropertyManager(site);
                        profileSubtypeProperty = profileSubtypeManager.GetPropertyByName(userProfilePropertyInfo.Name);

                        // Assert
                        Assert.AreEqual(profileSubtypeProperty.IsUserEditable, userProfilePropertyInfo.IsUserEditable);
                        Assert.AreEqual(profileSubtypeProperty.DefaultPrivacy, userProfilePropertyInfo.DefaultPrivacy);
                    }
                    finally
                    {
                        this.TestCleanup();
                    }
                }
            }
        }
        public void GetByTitle_WhenGetForNonExistingTitle_ShouldReturnNull()
        {
            // Arrange
            using (var testScope = SiteTestScope.PublishingSite())
            {
                var site = testScope.SiteCollection;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site))
                {
                    var reusableContentHelper = injectionScope.Resolve <IReusableContentHelper>();

                    // Act
                    var copyright = reusableContentHelper.GetByTitle(site, "IDoNotExist");

                    // Assert
                    Assert.IsNull(copyright);
                }
            }
        }
        public void GetAllReusableContentTitles_WhenGetAllOOTBTitles_ShouldReturn3Titles()
        {
            // Arrange
            using (var testScope = SiteTestScope.PublishingSite())
            {
                var site = testScope.SiteCollection;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site))
                {
                    var reusableContentHelper = injectionScope.Resolve <IReusableContentHelper>();

                    // Act
                    var allOOTBTitles = reusableContentHelper.GetAllReusableContentTitles(site);

                    // Assert
                    Assert.AreEqual(3, allOOTBTitles.Count());
                    Assert.IsTrue(allOOTBTitles.Contains("Copyright"));
                }
            }
        }
        public void EnsureProfileProperty_WhenMappedToTermSet_GivenUserProfilePropertyInfo_ThenMapsPropertyToTermSet()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var site                    = testScope.SiteCollection;
                var termSetInfo             = new TermSetInfo(Guid.NewGuid(), TermSetName);
                var userProfilePropertyInfo = new UserProfilePropertyInfo(
                    ProfilePropertyName,
                    "Test Profile Property",
                    PropertyDataType.StringSingleValue)
                {
                    TermSetInfo = termSetInfo
                };

                // Create term set
                var session = new TaxonomySession(site);
                var defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                var defaultSiteCollectionGroup     = defaultSiteCollectionTermStore.GetSiteCollectionGroup(site);
                defaultSiteCollectionGroup.CreateTermSet(termSetInfo.Label, termSetInfo.Id);
                defaultSiteCollectionTermStore.CommitAll();

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site))
                {
                    try
                    {
                        // Act
                        var userProfileHelper   = injectionScope.Resolve <IUserProfilePropertyHelper>();
                        var userProfileProperty = userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo);

                        // Assert
                        Assert.AreEqual(userProfileProperty.TermSet.Id, termSetInfo.Id);
                    }
                    finally
                    {
                        this.TestCleanup();
                    }
                }
            }
        }
예제 #9
0
        public void EnsurePage_WhenUpdatingAPage_GivenNewPageLayoutInfo_ThenExistingPageUsesTheNewPageLayout()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                var pagesLibrary = testScope.SiteCollection.RootWeb.GetPagesLibrary();
                var folder       = pagesLibrary.RootFolder;

                // Prepare the two page layouts. These are default SharePoint page Layouts.
                var initialPageLayoutInfo = new PageLayoutInfo("ArticleLeft.aspx", "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D");
                var finalPageLayoutInfo   = new PageLayoutInfo("ArticleRight.aspx", "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D");

                // Prepare the two page infos. This for one, better simulates running the same code twice, and second we can't change the page layout property directly.
                var pageFileName    = "TestPage";
                var initialPageInfo = new PageInfo(pageFileName, initialPageLayoutInfo);
                var updatedPageInfo = new PageInfo(pageFileName, finalPageLayoutInfo);

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(testScope.SiteCollection))
                {
                    var pageHelper = injectionScope.Resolve <IPageHelper>();

                    // Act

                    // Ensure the page with the initial page layout
                    PublishingPage initialPage = pageHelper.EnsurePage(pagesLibrary, folder, initialPageInfo);

                    // Re ensure the same page with the final pageLayoutInfo
                    PublishingPage updatedPage = pageHelper.EnsurePage(pagesLibrary, folder, updatedPageInfo);

                    // Assert

                    // Make sure the page layout has truely changed.
                    Assert.AreNotEqual(initialPage.Layout.ServerRelativeUrl, updatedPage.Layout.ServerRelativeUrl, "Page layout url should not be the same on the inital page as the updated page.");

                    // Make sure we are truely talking about the same page.
                    Assert.AreEqual(initialPage.Url, updatedPage.Url, "The initial page and updated page should have the same url.");
                }
            }
        }
예제 #10
0
        public void GetByTitle_WhenGetForOOTBReusableContent_ShouldReturnReusableContent()
        {
            // Arrange
            using (var testScope = SiteTestScope.PublishingSite())
            {
                var site = testScope.SiteCollection;

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site))
                {
                    var reusableContentHelper = injectionScope.Resolve <IReusableContentHelper>();

                    // Act
                    var copyright = reusableContentHelper.GetByTitle(site, "Copyright");

                    // Assert
                    Assert.IsNotNull(copyright);
                    Assert.AreEqual("None", copyright.Category);
                    Assert.IsTrue(copyright.IsAutomaticUpdate);
                    Assert.IsTrue(copyright.IsShowInRibbon);
                    Assert.IsTrue(copyright.Content.Contains("©"));
                }
            }
        }
        public void EnsureProfileProperty_WhenLocalizing_GivenUserProfilePropertyInfo_ThenAddsLocalizedValues()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var site = testScope.SiteCollection;
                var userProfilePropertyInfo = new UserProfilePropertyInfo(
                    ProfilePropertyName,
                    "Test Profile Property",
                    PropertyDataType.StringSingleValue)
                {
                    Description = "Test property description"
                };

                userProfilePropertyInfo.DisplayNameLocalized.Add(1036, "Propriété de test");
                userProfilePropertyInfo.DescriptionLocalized.Add(1036, "Description propriété de test");

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(site))
                {
                    try
                    {
                        // Act
                        var userProfileHelper   = injectionScope.Resolve <IUserProfilePropertyHelper>();
                        var userProfileProperty = userProfileHelper.EnsureProfileProperty(site, userProfilePropertyInfo);

                        // Assert
                        // 2 values: Default (english and french/1036)
                        Assert.IsTrue(userProfileProperty.DisplayNameLocalized.Count == 2);
                        Assert.IsTrue(userProfileProperty.DescriptionLocalized.Count == 2);
                    }
                    finally
                    {
                        this.TestCleanup();
                    }
                }
            }
        }
예제 #12
0
        public void EnsurePageLayout_WhenSettingTheAssociatedContentType_ThenThePageLayoutIsPublishedWithAMajorVersion()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                // Arrange

                // This page layout normally has article, we will set welcome page to it.
                var pageLayoutInfoWithUpdatedCT = new PageLayoutInfo("ArticleLeft.aspx", "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4");

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(testScope.SiteCollection))
                {
                    var pageHelper = injectionScope.Resolve <IPageHelper>();

                    // Act
                    var actualPageLayout = pageHelper.EnsurePageLayout(testScope.SiteCollection, pageLayoutInfoWithUpdatedCT);

                    // Assert
                    Assert.IsTrue(actualPageLayout != null);

                    var hasCurrentDraft = actualPageLayout.ListItem.Versions.Cast <SPListItemVersion>().Any(v => v.IsCurrentVersion && v.Level == SPFileLevel.Draft);
                    Assert.IsTrue(!hasCurrentDraft, "The page layout should not have a draft version marked as current.");
                }
            }
        }
예제 #13
0
        public void GetTermsAsSimpleLinkNavNodeForTermSet_WithChildTermsAndCustomSortOrder_ShouldKeepTheTermsOrder()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                var guidTermA  = Guid.NewGuid();
                var guidTermB  = Guid.NewGuid();
                var guidTermAA = Guid.NewGuid();
                var guidTermAB = Guid.NewGuid();

                // Arrange
                var testTermSetInfo = new TermSetInfo(Guid.NewGuid(), "Test Term Set");
                var levelOneTermA   = new SimpleLinkTermInfo(guidTermA, "Term A", testTermSetInfo, "URL-A");
                var levelOneTermB   = new SimpleLinkTermInfo(guidTermB, "Term B", testTermSetInfo);
                var levelTwoTermAA  = new SimpleLinkTermInfo(guidTermAA, "Term AA", testTermSetInfo);
                var levelTwoTermAB  = new SimpleLinkTermInfo(guidTermAB, "Term AB", testTermSetInfo, "URL-AB");
                var levelTwoTermBA  = new SimpleLinkTermInfo(Guid.NewGuid(), "Term BA", testTermSetInfo, "URL-BA");

                var expecteNumberOfLevelOneTerms = 2;
                var expectedTotalNumberOfTerms   = 5;

                var session = new TaxonomySession(testScope.SiteCollection);
                var defaultSiteCollectionTermStore = session.DefaultSiteCollectionTermStore;
                var defaultSiteCollectionGroup     = defaultSiteCollectionTermStore.GetSiteCollectionGroup(testScope.SiteCollection);
                var newTermSet = defaultSiteCollectionGroup.CreateTermSet(testTermSetInfo.Label, testTermSetInfo.Id);

                var createdTermA = newTermSet.CreateTerm(levelOneTermA.Label, Language.English.Culture.LCID, levelOneTermA.Id);
                createdTermA.SetLocalCustomProperty(CustomPropertyKey, levelOneTermA.SimpleLinkTarget);

                var createdTermAA = createdTermA.CreateTerm(levelTwoTermAA.Label, Language.English.Culture.LCID, levelTwoTermAA.Id);
                var createdTermAB = createdTermA.CreateTerm(levelTwoTermAB.Label, Language.English.Culture.LCID, levelTwoTermAB.Id);
                createdTermAB.SetLocalCustomProperty(CustomPropertyKey, levelTwoTermAB.SimpleLinkTarget);

                var createdTermB  = newTermSet.CreateTerm(levelOneTermB.Label, Language.English.Culture.LCID, levelOneTermB.Id);
                var createdTermBA = createdTermB.CreateTerm(levelTwoTermBA.Label, Language.English.Culture.LCID, levelTwoTermBA.Id);
                createdTermBA.SetLocalCustomProperty(CustomPropertyKey, levelTwoTermBA.SimpleLinkTarget);

                // Create a custom sort order where term B is first, term A is second
                newTermSet.CustomSortOrder = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", guidTermB, guidTermA);

                // Create a custom sort order where term AB is first, term AA is second
                createdTermA.CustomSortOrder = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", guidTermAB, guidTermAA);

                defaultSiteCollectionTermStore.CommitAll();

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var taxonomyService = injectionScope.Resolve <ITaxonomyService>();

                    // Act
                    var retrievedTerms = taxonomyService.GetTermsAsSimpleLinkNavNodeForTermSet(testScope.SiteCollection, defaultSiteCollectionGroup.Name, newTermSet.Name);

                    // Assert
                    Assert.IsNotNull(retrievedTerms);
                    Assert.AreEqual(retrievedTerms.Count, expecteNumberOfLevelOneTerms);

                    var actualTotalNumberOfTermsRetrieved = retrievedTerms.Count + retrievedTerms[0].ChildTerms.Count() + retrievedTerms[1].ChildTerms.Count();
                    Assert.AreEqual(actualTotalNumberOfTermsRetrieved, expectedTotalNumberOfTerms);

                    Assert.AreEqual(retrievedTerms[0].SimpleLinkTarget, levelOneTermB.SimpleLinkTarget);
                    Assert.AreEqual(retrievedTerms[0].Label, levelOneTermB.Label);
                    Assert.AreEqual(retrievedTerms[0].ChildTerms.Count(), 1);

                    Assert.AreEqual(retrievedTerms[1].SimpleLinkTarget, levelOneTermA.SimpleLinkTarget);
                    Assert.AreEqual(retrievedTerms[1].Label, levelOneTermA.Label);
                    Assert.AreEqual(retrievedTerms[1].ChildTerms.Count(), 2);

                    var actualLevelTwoAATerm = retrievedTerms[1].ChildTerms.ElementAt(1);
                    var actualLevelTwoABTerm = retrievedTerms[1].ChildTerms.ElementAt(0);
                    var actualLevelTwoBATerm = retrievedTerms[0].ChildTerms.ElementAt(0);

                    Assert.AreEqual(actualLevelTwoAATerm.SimpleLinkTarget, levelTwoTermAA.SimpleLinkTarget);
                    Assert.AreEqual(actualLevelTwoAATerm.Label, levelTwoTermAA.Label);
                    Assert.AreEqual(actualLevelTwoAATerm.ChildTerms.Count(), 0);

                    Assert.AreEqual(actualLevelTwoABTerm.SimpleLinkTarget, levelTwoTermAB.SimpleLinkTarget);
                    Assert.AreEqual(actualLevelTwoABTerm.Label, levelTwoTermAB.Label);
                    Assert.AreEqual(actualLevelTwoABTerm.ChildTerms.Count(), 0);

                    Assert.AreEqual(actualLevelTwoBATerm.SimpleLinkTarget, levelTwoTermBA.SimpleLinkTarget);
                    Assert.AreEqual(actualLevelTwoBATerm.Label, levelTwoTermBA.Label);
                    Assert.AreEqual(actualLevelTwoBATerm.ChildTerms.Count(), 0);
                }

                // Cleanup term set so that we don't pollute the metadata store
                newTermSet.Delete();
                defaultSiteCollectionTermStore.CommitAll();
            }
        }