public IEnumerable <Profile> GetProfiles(ProfilingTypes profiling) { if (!Tracker.IsActive) { return(Enumerable.Empty <Profile>()); } return(profileProvider.GetSiteProfiles().Where(p => profileProvider.HasMatchingPattern(p, profiling)).Select(x => new Profile { Name = x.NameField, PatternMatches = profileProvider.GetPatternsWithGravityShare(x, profiling) })); }
public void LoadProfiles_SetProfiles_ShouldReturnExistentProfilesEnumerable([Content] Item item, PatternMatch patternMatch, ITracker tracker, IProfileProvider provider) { //arrange tracker.IsActive.Returns(true); var profileItem = item.Add("profile", new TemplateID(ProfileItem.TemplateID)); using (new EditContext(profileItem)) { profileItem.Fields[ProfileItem.FieldIDs.Type].Value = "Average"; profileItem.Fields[ProfileItem.FieldIDs.NameField].Value = profileItem.Name; } provider.GetSiteProfiles().Returns(new[] { new ProfileItem(profileItem) }); provider.HasMatchingPattern(null).ReturnsForAnyArgs(true); provider.GetPatternsWithGravityShare(null).ReturnsForAnyArgs(new [] { patternMatch }); var fakeSiteContext = new FakeSiteContext("fake") { Database = item.Database }; using (new SiteContextSwitcher(fakeSiteContext)) { using (new TrackerSwitcher(tracker)) { var model = new VisitInformation(provider); //act var profiles = model.LoadProfiles().ToArray(); //assert profiles.Count().Should().Be(1); profiles.First().Name.Should().Be(profileItem.Name); profiles.First().PatternMatches.Single().Should().Be(patternMatch); } } }
public void LoadProfiles_SetProfiles_ShouldReturnExistentProfilesEnumerable([Content] Item item, PatternMatch patternMatch, ITracker tracker, IProfileProvider provider) { //arrange tracker.IsActive.Returns(true); var profileItem = item.Add("profile", new TemplateID(ProfileItem.TemplateID)); using (new EditContext(profileItem)) { profileItem.Fields[ProfileItem.FieldIDs.Type].Value = "Average"; profileItem.Fields[ProfileItem.FieldIDs.NameField].Value = profileItem.Name; } provider.GetSiteProfiles().Returns(new[]{new ProfileItem(profileItem)}); provider.HasMatchingPattern(null).ReturnsForAnyArgs(true); provider.GetPatternsWithGravityShare(null).ReturnsForAnyArgs(new [] { patternMatch }); var fakeSiteContext = new FakeSiteContext("fake") { Database = item.Database }; using (new SiteContextSwitcher(fakeSiteContext)) { using (new TrackerSwitcher(tracker)) { var model = new VisitInformation(provider); //act var profiles = model.LoadProfiles().ToArray(); //assert profiles.Count().Should().Be(1); profiles.First().Name.Should().Be(profileItem.Name); profiles.First().PatternMatches.Single().Should().Be(patternMatch); } } }