Esempio n. 1
0
        public void ScoreGroups_WithMatchingMultipleGroups_ReturnsScore()
        {
            // Arrange
            var pickedGroups = new List <IPublishedContent>()
            {
                MockPublishedContent(1000,
                                     PersonalisationGroupDefinitionMatch.All,
                                     PersonalisationGroupDefinitionDuration.Page,
                                     new List <PersonalisationGroupDefinitionDetail>
                {
                    TestHelpers.Definitions.MatchingDayOfWeekDefinition(),
                    TestHelpers.Definitions.MatchingTimeOfDayDefinition(),
                }, 50).Object,
                MockPublishedContent(1001,
                                     PersonalisationGroupDefinitionMatch.Any,
                                     PersonalisationGroupDefinitionDuration.Page,
                                     new List <PersonalisationGroupDefinitionDetail>
                {
                    TestHelpers.Definitions.NonMatchingDayOfWeekDefinition(),
                    TestHelpers.Definitions.MatchingDayOfWeekDefinition(),
                }, 40).Object,
            };

            PersonalisationGroupsConfig.Setup(new PersonalisationGroupsConfig());

            // Act
            var result = UmbracoExtensionsHelper.ScoreGroups(pickedGroups);

            // Assert
            Assert.AreEqual(90, result);
        }
        /// <summary>
        /// Scores the content item for the current site visitor, based on the personalisation groups associated with it.
        /// </summary>
        /// <param name="pickedGroups">List of IPublishedContent items that are the groups you want to check against.</param>
        /// <returns>True if content should be shown to visitor</returns>
        private static int ScoreForVisitor(IList <IPublishedContent> pickedGroups)
        {
            if (!pickedGroups.Any())
            {
                // No personalisation groups picked or no property for picker, so we score zero
                return(0);
            }

            return(UmbracoExtensionsHelper.ScoreGroups(pickedGroups));
        }
Esempio n. 3
0
        public void ScoreGroups_WithPackageDisabled_ReturnsDefaultScore()
        {
            // Arrange
            var pickedGroups = new List <IPublishedContent>();

            PersonalisationGroupsConfig.Setup(new PersonalisationGroupsConfig(disablePackage: true));

            // Act
            var result = UmbracoExtensionsHelper.ScoreGroups(pickedGroups);

            // Assert
            Assert.AreEqual(0, result);
        }