public void MatchGroups_WithMatchingMultipleGroups_ReturnsTrue() { // Arrange var pickedGroups = new List <IPublishedContent>() { MockPublishedContent(1000, PersonalisationGroupDefinitionMatch.All, PersonalisationGroupDefinitionDuration.Page, new List <PersonalisationGroupDefinitionDetail> { TestHelpers.Definitions.MatchingDayOfWeekDefinition(), TestHelpers.Definitions.MatchingTimeOfDayDefinition(), TestHelpers.Definitions.NonMatchingDayOfWeekDefinition(), }).Object, MockPublishedContent(1001, PersonalisationGroupDefinitionMatch.Any, PersonalisationGroupDefinitionDuration.Page, new List <PersonalisationGroupDefinitionDetail> { TestHelpers.Definitions.NonMatchingDayOfWeekDefinition(), TestHelpers.Definitions.MatchingDayOfWeekDefinition(), }).Object, }; PersonalisationGroupsConfig.Setup(new PersonalisationGroupsConfig()); // Act var result = UmbracoExtensionsHelper.MatchGroups(pickedGroups); // Assert Assert.IsTrue(result); }
/// <summary> /// Determines if the content item should be shown to 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> /// <param name="showIfNoGroupsDefined">Indicates the response to return if groups cannot be found on the content</param> /// <returns>True if content should be shown to visitor</returns> private static bool ShowToVisitor(IList <IPublishedContent> pickedGroups, bool showIfNoGroupsDefined = true) { if (!pickedGroups.Any()) { // No personalisation groups picked or no property for picker, so we return the provided default return(showIfNoGroupsDefined); } return(UmbracoExtensionsHelper.MatchGroups(pickedGroups)); }
public void MatchGroups_WithNoGroups_ReturnsFalse() { // Arrange var pickedGroups = new List <IPublishedContent>(); PersonalisationGroupsConfig.Setup(new PersonalisationGroupsConfig()); // Act var result = UmbracoExtensionsHelper.MatchGroups(pickedGroups); // Assert Assert.IsFalse(result); }
public void MatchGroups_WithPackageDisabled_ReturnsTrue() { // Arrange var pickedGroups = new List <IPublishedContent>(); PersonalisationGroupsConfig.Setup(new PersonalisationGroupsConfig(disablePackage: true)); // Act var result = UmbracoExtensionsHelper.MatchGroups(pickedGroups); // Assert Assert.IsTrue(result); }
public void MatchGroups_WithNoMatchingGroupsUsingAny_ReturnsFalse() { // Arrange var pickedGroups = new List <IPublishedContent>() { MockPublishedContent(1000, PersonalisationGroupDefinitionMatch.Any, PersonalisationGroupDefinitionDuration.Page, new List <PersonalisationGroupDefinitionDetail> { Definitions.NonMatchingDayOfWeekDefinition(), Definitions.NonMatchingDayOfWeekDefinition() }).Object, }; PersonalisationGroupsConfig.Setup(new PersonalisationGroupsConfig()); // Act var result = UmbracoExtensionsHelper.MatchGroups(pickedGroups); // Assert Assert.IsFalse(result); }