コード例 #1
0
        public void EnsureFeatureActivation_WhenSiteScopedFeatureNotActivated_ShouldActivate()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var site = testScope.SiteCollection;

                // Use the "GSoft.Dynamite Javascript Imports" site scoped feature
                var featureDependency = new FeatureDependencyInfo()
                {
                    FeatureId             = new Guid("7ed769f5-b01b-4597-9a91-3cfcdf8cc49a"),
                    FeatureActivationMode = FeatureActivationMode.CurrentSite
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var featureDependencyActivator = injectionScope.Resolve <IFeatureDependencyActivator>(new TypedParameter(typeof(SPSite), site));

                    // Act
                    featureDependencyActivator.EnsureFeatureActivation(featureDependency);

                    // Assert
                    var isFeatureActivated = site.Features.Any(feature => feature.DefinitionId.Equals(featureDependency.FeatureId));
                    Assert.IsTrue(isFeatureActivated);
                }
            }
        }
コード例 #2
0
        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();
                    }
                }
            }
        }
コード例 #3
0
        public void EnsureFeatureActivation_WhenWebScopedFeatureNotActivated_ShouldActivate()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var web = testScope.SiteCollection.RootWeb;

                var featureDependency = new FeatureDependencyInfo()
                {
                    Name                  = "OOTB task list",
                    FeatureId             = new Guid("00BFEA71-A83E-497E-9BA0-7A5C597D0107"),
                    FeatureActivationMode = FeatureActivationMode.CurrentWeb
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var featureDependencyActivator = injectionScope.Resolve <IFeatureDependencyActivator>(new TypedParameter(typeof(SPWeb), web));

                    // Act
                    featureDependencyActivator.EnsureFeatureActivation(featureDependency);

                    // Assert
                    var isFeatureActivated = web.Features.Any(feature => feature.DefinitionId.Equals(featureDependency.FeatureId));
                    Assert.IsTrue(isFeatureActivated);
                }
            }
        }
コード例 #4
0
ファイル: EmailHelperTest.cs プロジェクト: ssrisunt/dynamite
        public void SendEmail_WhenRecipientOverrideDisabled_ShouldSendEmailWithoutManipulatingTheReceiversOrChangingTheEmailContent()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var web            = testScope.SiteCollection.RootWeb;
                var webApplication = testScope.SiteCollection.WebApplication;

                var emailInformation = new EmailInfo();
                emailInformation.To.Add("*****@*****.**");
                emailInformation.To.Add("*****@*****.**");
                emailInformation.CarbonCopy.Add("*****@*****.**");
                emailInformation.BlindCarbonCopy.Add("*****@*****.**");
                emailInformation.Subject = "Quoi faire à Barcelone?";
                emailInformation.Body    = "J'ai un ami qui me propose un hike! :)";

                // Expected values
                string           expectedBody    = emailInformation.Body;
                StringDictionary expectedHeaders = new StringDictionary();
                expectedHeaders.Add("to", string.Join(",", emailInformation.To));
                expectedHeaders.Add("cc", string.Join(",", emailInformation.CarbonCopy));
                expectedHeaders.Add("bcc", string.Join(",", emailInformation.BlindCarbonCopy));
                expectedHeaders.Add("subject", emailInformation.Subject);

                // Actual values
                StringDictionary actualHeaders = null;
                string           actualBody    = null;
                bool?            actualIsRecipientOverrideEnabled = null;

                using (ShimsContext.Create())
                {
                    // Mock the SendEmail method so no emails are actualy sent.
                    ShimSPUtility.SendEmailSPWebStringDictionaryString = (pWeb, pHeaders, pBody) =>
                    {
                        actualHeaders = pHeaders;
                        actualBody    = pBody;
                        return(true);
                    };

                    using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                    {
                        var emailHelper = injectionScope.Resolve <IEmailHelper>();

                        // Act
                        actualIsRecipientOverrideEnabled = emailHelper.IsRecipientOverrideEnabled(webApplication);
                        emailHelper.SendEmail(web, emailInformation);

                        // Assert
                        Assert.IsTrue(actualIsRecipientOverrideEnabled.HasValue && !actualIsRecipientOverrideEnabled.Value, "Recipient override should not have been enabled.");
                        Assert.IsTrue(actualHeaders.Count == expectedHeaders.Count, "The headers should not have changed.");
                        Assert.IsTrue(actualBody == expectedBody, "The email body should not have changed.");

                        foreach (string key in actualHeaders.Keys)
                        {
                            Assert.IsTrue(actualHeaders[key] == expectedHeaders[key], "Header with key '{0}' should not have changed.", key);
                        }
                    }
                }
            }
        }
コード例 #5
0
        /// <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
                    }
                }
            }
        }
コード例 #6
0
        public void EnsureResultSource_WhenNotSortingByRank_ShouldNotApplyARankingModel()
        {
            const string ResultSourceName = "Test Result Source";

            // Arrange
            using (var testScope = SiteTestScope.BlankSite())
            {
                var resultSourceInfo = new ResultSourceInfo()
                {
                    Name           = ResultSourceName,
                    Level          = SearchObjectLevel.SPSite,
                    Query          = "{?{searchTerms} -ContentClass=urn:content-class:SPSPeople}",
                    RankingModelId = BuiltInRankingModels.DefaultSearchModelId,
                    UpdateMode     = ResultSourceUpdateBehavior.OverwriteResultSource
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var searchHelper = injectionScope.Resolve <ISearchHelper>();

                    // Act
                    searchHelper.EnsureResultSource(testScope.SiteCollection, resultSourceInfo);

                    // Assert

                    // Exception should have been thrown already
                    Assert.IsTrue(false);
                }
            }
        }
コード例 #7
0
        public void EnsureFeatureActivation_WhenWebScopedFeatureActivatedOnWrongScope_ShouldThrowInvalidOperationException()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var site = testScope.SiteCollection;

                var featureDependency = new FeatureDependencyInfo()
                {
                    Name                  = "OOTB task list on wrong scope",
                    FeatureId             = new Guid("00BFEA71-A83E-497E-9BA0-7A5C597D0107"),
                    FeatureActivationMode = FeatureActivationMode.CurrentSite
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var featureDependencyActivator = injectionScope.Resolve <IFeatureDependencyActivator>(new TypedParameter(typeof(SPSite), site));

                    // Act
                    featureDependencyActivator.EnsureFeatureActivation(featureDependency);

                    // Assert invalid operation exception
                }
            }
        }
コード例 #8
0
        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();
                    }
                }
            }
        }
コード例 #9
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();
            }
        }
コード例 #10
0
        public void EnsureResultSource_WhenRevertingAppendedQuery_ShouldRevertToPreviousQuery()
        {
            const string ResultSourceName = "Test Result Source";
            const string Query            = "{?{searchTerms} -ContentClass=urn:content-class:SPSPeople}";
            const string AppendedQuery    = "{?{|owstaxidmetadataalltagsinfo:{User.SPSResponsibility}}}";

            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var resultSourceInfo = new ResultSourceInfo()
                {
                    Name       = ResultSourceName,
                    Level      = SearchObjectLevel.SPSite,
                    Query      = Query,
                    UpdateMode = ResultSourceUpdateBehavior.OverwriteResultSource
                };

                var appendedResultSourceInfo = new ResultSourceInfo()
                {
                    Name       = ResultSourceName,
                    Level      = SearchObjectLevel.SPSite,
                    Query      = AppendedQuery,
                    UpdateMode = ResultSourceUpdateBehavior.AppendToQuery
                };

                var revertedResultSourceInfo = new ResultSourceInfo()
                {
                    Name       = ResultSourceName,
                    Level      = SearchObjectLevel.SPSite,
                    Query      = AppendedQuery,
                    UpdateMode = ResultSourceUpdateBehavior.RevertQuery
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var searchHelper      = injectionScope.Resolve <ISearchHelper>();
                    var ssa               = searchHelper.GetDefaultSearchServiceApplication(testScope.SiteCollection);
                    var federationManager = new FederationManager(ssa);
                    var searchOwner       = new SearchObjectOwner(SearchObjectLevel.SPSite, testScope.SiteCollection.RootWeb);

                    // Act
                    searchHelper.EnsureResultSource(testScope.SiteCollection, resultSourceInfo);
                    searchHelper.EnsureResultSource(testScope.SiteCollection, appendedResultSourceInfo);
                    searchHelper.EnsureResultSource(testScope.SiteCollection, revertedResultSourceInfo);

                    // Assert
                    var source = federationManager.GetSourceByName(ResultSourceName, searchOwner);

                    Assert.IsNotNull(source);
                    Assert.IsNotNull(source.QueryTransform);
                    Assert.AreEqual(ResultSourceName, source.Name);
                    Assert.AreEqual(Query, source.QueryTransform.QueryTemplate);
                }
            }
        }
コード例 #11
0
        public void EnsureManagedProperty_WhenNoChangesWanted_ShouldCreateManagedPropertyIfDoesntExist()
        {
            const string ManagedPropertyName = "TestManagedProperty";

            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var owner = new SearchObjectOwner(SearchObjectLevel.Ssa, testScope.SiteCollection.RootWeb);
                var managedPropertyInfo = new ManagedPropertyInfo(ManagedPropertyName, ManagedDataType.Text)
                {
                    Sortable          = true,
                    Refinable         = true,
                    Queryable         = true,
                    CrawledProperties = new Dictionary <string, int>()
                    {
                        { "ows_Title", 1 }
                    },
                    UpdateBehavior = ManagedPropertyUpdateBehavior.NoChangesIfAlreadyExists
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var searchHelper = injectionScope.Resolve <ISearchHelper>();
                    var ssa          = searchHelper.GetDefaultSearchServiceApplication(testScope.SiteCollection);

                    try
                    {
                        // Act
                        var actualManagedProperty          = searchHelper.EnsureManagedProperty(testScope.SiteCollection, managedPropertyInfo);
                        var refetchedActualManagedProperty = ssa.GetManagedProperty(ManagedPropertyName, owner);

                        // Assert
                        Assert.IsNotNull(actualManagedProperty);
                        Assert.AreEqual(true, actualManagedProperty.Sortable);
                        Assert.AreEqual(true, actualManagedProperty.Refinable);
                        Assert.AreEqual(true, actualManagedProperty.Queryable);
                        Assert.IsTrue(actualManagedProperty.GetMappedCrawledProperties(2).Count == 1);
                        Assert.IsTrue(actualManagedProperty.GetMappedCrawledProperties(2)[0].Name == "ows_Title");

                        Assert.IsNotNull(refetchedActualManagedProperty);
                        Assert.AreEqual(true, refetchedActualManagedProperty.Sortable);
                        Assert.AreEqual(true, refetchedActualManagedProperty.Refinable);
                        Assert.AreEqual(true, refetchedActualManagedProperty.Queryable);
                        Assert.IsTrue(ssa.GetManagedPropertyMappings(refetchedActualManagedProperty, owner).Count == 1);
                        Assert.IsTrue(ssa.GetManagedPropertyMappings(refetchedActualManagedProperty, owner)[0].CrawledPropertyName == "ows_Title");
                    }
                    finally
                    {
                        // Clean up
                        searchHelper.DeleteManagedProperty(testScope.SiteCollection, managedPropertyInfo);
                    }
                }
            }
        }
コード例 #12
0
ファイル: EmailHelperTest.cs プロジェクト: ssrisunt/dynamite
        public void SendEmail_WhenRecipientOverrideEnabled_ShouldSendEmailOnlyToRecipientOverrideAddressAndModifyEmailBody()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var web            = testScope.SiteCollection.RootWeb;
                var webApplication = testScope.SiteCollection.WebApplication;

                var RecipientOverrideEmail = "*****@*****.**";
                var emailInformation       = new EmailInfo();
                emailInformation.To.Add("*****@*****.**");
                emailInformation.To.Add("*****@*****.**");
                emailInformation.CarbonCopy.Add("*****@*****.**");
                emailInformation.BlindCarbonCopy.Add("*****@*****.**");
                emailInformation.Subject = "Quoi faire à Barcelone?";
                emailInformation.Body    = "J'ai un ami qui me propose un hike! :)";

                var originalBody = emailInformation.Body;

                // Actual values
                StringDictionary actualHeaders = null;
                string           actualBody    = null;
                bool?            actualIsRecipientOverrideEnabled = null;

                using (ShimsContext.Create())
                {
                    // Mock the SendEmail method so no emails are actualy sent.
                    ShimSPUtility.SendEmailSPWebStringDictionaryString = (pWeb, pHeaders, pBody) =>
                    {
                        actualHeaders = pHeaders;
                        actualBody    = pBody;
                        return(true);
                    };

                    using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                    {
                        var emailHelper = injectionScope.Resolve <IEmailHelper>();

                        // Act
                        emailHelper.EnableRecipientOverride(webApplication, RecipientOverrideEmail);
                        actualIsRecipientOverrideEnabled = emailHelper.IsRecipientOverrideEnabled(webApplication);
                        emailHelper.SendEmail(web, emailInformation);

                        // Assert
                        Assert.IsTrue(actualIsRecipientOverrideEnabled.HasValue && actualIsRecipientOverrideEnabled.Value, "Recipient override should have been enabled.");
                        Assert.IsTrue(actualHeaders["to"] == RecipientOverrideEmail, "The email should have been sent only to the recipient override email address.");
                        Assert.IsTrue(!actualHeaders.ContainsKey("cc"), "No carbon copy should have been in the email headers.");
                        Assert.IsTrue(!actualHeaders.ContainsKey("bcc"), "No blind carbon copy should have been in the email headers.");
                        Assert.IsTrue(actualBody.Length > originalBody.Length, "Text should have been added to the body of the email.");
                    }
                }
            }
        }
コード例 #13
0
        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();
                    }
                }
            }
        }
コード例 #14
0
        public void EnsureFeatureActivation_WhenMultipleFeaturesAreActivated_ShouldActivateAll()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var site = testScope.SiteCollection;
                var web  = testScope.SiteCollection.RootWeb;

                var featureDependencies = new[]
                {
                    new FeatureDependencyInfo()
                    {
                        Name                  = "GSoft.Dynamite Javascript Imports",
                        FeatureId             = new Guid("7ed769f5-b01b-4597-9a91-3cfcdf8cc49a"),
                        FeatureActivationMode = FeatureActivationMode.CurrentSite
                    },
                    new FeatureDependencyInfo()
                    {
                        Name                  = "OOTB task list",
                        FeatureId             = new Guid("00BFEA71-A83E-497E-9BA0-7A5C597D0107"),
                        FeatureActivationMode = FeatureActivationMode.CurrentWeb
                    }
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    // Need to inject site and web since the features are scoped differently
                    var featureDependencyActivator = injectionScope.Resolve <IFeatureDependencyActivator>(
                        new TypedParameter(typeof(SPSite), site),
                        new TypedParameter(typeof(SPWeb), web));

                    // Act
                    foreach (var featureDependency in featureDependencies)
                    {
                        featureDependencyActivator.EnsureFeatureActivation(featureDependency);
                    }

                    // Assert
                    var isSiteFeatureActivated = site.Features.Any(feature => feature.DefinitionId.Equals(featureDependencies[0].FeatureId));
                    var isWebFeatureActivated  = web.Features.Any(feature => feature.DefinitionId.Equals(featureDependencies[1].FeatureId));
                    Assert.IsTrue(isSiteFeatureActivated);
                    Assert.IsTrue(isWebFeatureActivated);
                }
            }
        }
コード例 #15
0
        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);
                }
            }
        }
コード例 #16
0
        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"));
                }
            }
        }
コード例 #17
0
        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();
                    }
                }
            }
        }
コード例 #18
0
        public void EnsureResultSource_WhenSortingByRank_ShouldApplySpecifiedRankingModel()
        {
            const string ResultSourceName = "Test Result Source";

            // Arrange
            using (var testScope = SiteTestScope.BlankSite())
            {
                var resultSourceInfo = new ResultSourceInfo()
                {
                    Name         = ResultSourceName,
                    Level        = SearchObjectLevel.SPSite,
                    Query        = "{?{searchTerms} -ContentClass=urn:content-class:SPSPeople}",
                    SortSettings = new Dictionary <string, SortDirection>()
                    {
                        { BuiltInManagedProperties.Rank.Name, SortDirection.Descending }
                    },
                    RankingModelId = BuiltInRankingModels.DefaultSearchModelId,
                    UpdateMode     = ResultSourceUpdateBehavior.OverwriteResultSource
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var searchHelper      = injectionScope.Resolve <ISearchHelper>();
                    var ssa               = searchHelper.GetDefaultSearchServiceApplication(testScope.SiteCollection);
                    var federationManager = new FederationManager(ssa);
                    var searchOwner       = new SearchObjectOwner(SearchObjectLevel.SPSite, testScope.SiteCollection.RootWeb);

                    // Act
                    searchHelper.EnsureResultSource(testScope.SiteCollection, resultSourceInfo);

                    // Assert
                    var source = federationManager.GetSourceByName(ResultSourceName, searchOwner);

                    Assert.IsNotNull(source);
                    Assert.AreEqual(ResultSourceName, source.Name);
                    Assert.AreEqual(BuiltInRankingModels.DefaultSearchModelId.ToString(), source.QueryTransform.OverrideProperties["RankingModelId"]);
                }
            }
        }
コード例 #19
0
ファイル: PageHelperTest.cs プロジェクト: ssrisunt/dynamite
        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.");
                }
            }
        }
コード例 #20
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("©"));
                }
            }
        }
コード例 #21
0
        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();
                    }
                }
            }
        }
コード例 #22
0
        public void EnsureFeatureActivation_WhenFeatureActivatedWithNoIdSpecified_ShouldThrowArgumentException()
        {
            using (var testScope = SiteTestScope.BlankSite())
            {
                // Arrange
                var site = testScope.SiteCollection;

                var featureDependency = new FeatureDependencyInfo()
                {
                    Name = "Unknown feature because there's no ID",
                    FeatureActivationMode = FeatureActivationMode.CurrentSite
                };

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope())
                {
                    var featureDependencyActivator = injectionScope.Resolve <IFeatureDependencyActivator>(new TypedParameter(typeof(SPSite), site));

                    // Act
                    featureDependencyActivator.EnsureFeatureActivation(featureDependency);

                    // Assert argument exception
                }
            }
        }
コード例 #23
0
ファイル: PageHelperTest.cs プロジェクト: ssrisunt/dynamite
        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.");
                }
            }
        }
コード例 #24
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();
            }
        }