public void LoadProfiles_SettingsIsEmpty_ShouldReturnExistentProfilesEnumerable([Content] Item item, CurrentInteraction currentInteraction, ITracker tracker, Profile profile)
    {
      var profileSettingItem = item.Add("profileSetting", new TemplateID(Templates.ProfilingSettings.ID));
      var profileItem = item.Add("profile", new TemplateID(ProfileItem.TemplateID));


      var provider = new ProfileProvider();

      var fakeSiteContext = new FakeSiteContext(new StringDictionary
      {
        {
          "rootPath", "/sitecore"
        },
        {
          "startItem", profileSettingItem.Paths.FullPath.Remove(0, "/sitecore".Length)
        }
      });

      fakeSiteContext.Database = item.Database;

      using (new SiteContextSwitcher(fakeSiteContext))
      {
        provider.GetSiteProfiles().Count().Should().Be(0);
      }
    }
Example #2
0
 public void Close()
 {
     if (CurrentInteraction != null)
     {
         CurrentInteraction.Expire();
     }
 }
Example #3
0
        public void Get_Call_ShouldCombineActiveAndHistoricCampaigns(string site, CurrentInteraction currentInteraction, ITracker tracker, [Frozen] ICampaignRepository campaignRepository, [Greedy] ReferralRepository referralRepository)
        {
            //Arrange
            tracker.Interaction.Returns(currentInteraction);
            tracker.Interaction.ReferringSite.Returns(site);

            campaignRepository.GetCurrent().Returns(new Campaign()
            {
                Title = "camp1"
            });
            campaignRepository.GetHistoric().Returns(new[] { new Campaign()
                                                             {
                                                                 Title = "camp2"
                                                             }, new Campaign()
                                                             {
                                                                 Title = "camp3"
                                                             } });

            using (new TrackerSwitcher(tracker))
            {
                //Act
                var referral = referralRepository.Get();
                //Assert
                referral.TotalNoOfCampaigns.Should().Be(3);
                referral.Campaigns.Select(x => x.Title).Should().Contain(new[] { "camp1", "camp2", "camp3", });
            }
        }
Example #4
0
    public void LoadProfiles_SettingWithProfiles_ShouldReturnExistentProfilesEnumerable(Db db, CurrentInteraction currentInteraction, ITracker tracker, Analytics.Tracking.Profile profile)
    {
      var profileItem = new DbItem("profile", ID.NewID, new TemplateID(ProfileItem.TemplateID));
      db.Add(profileItem);
      var profileSettingItem = new DbItem("profileSetting", ID.NewID, new TemplateID(Templates.ProfilingSettings.ID))
                               {
                                 {Templates.ProfilingSettings.Fields.SiteProfiles, profileItem.ID.ToString()}
                               };
      db.Add(profileSettingItem);

      var provider = new ProfileProvider();

      var fakeSiteContext = new FakeSiteContext(new StringDictionary
                                                {
                                                  {"rootPath", "/sitecore"},
                                                  {"startItem", profileSettingItem.FullPath.Remove(0, "/sitecore".Length)}
                                                })
                            {
                              Database = db.Database
                            };


      using (new SiteContextSwitcher(fakeSiteContext))
      {
        var siteProfiles = provider.GetSiteProfiles();
        siteProfiles.Count().Should().Be(1);
      }
    }
        public Interactions GetInteractions(CurrentInteraction currentInteraction)
        {
            var interactions = new Interactions
            {
                BrowserInfo       = currentInteraction.BrowserInfo,
                CampaignId        = currentInteraction.CampaignId,
                ContactId         = currentInteraction.ContactId,
                ChannelId         = currentInteraction.ChannelId,
                ContactVisitIndex = currentInteraction.ContactVisitIndex,
                CustomValues      = currentInteraction.CustomValues,
                DeviceId          = currentInteraction.DeviceId,
                GeoData           = currentInteraction.GeoData,
                HasGeoIpData      = currentInteraction.HasGeoIpData,
                InteractionId     = currentInteraction.InteractionId,
                Ip         = currentInteraction.Ip,
                Keywords   = currentInteraction.Keywords,
                Language   = currentInteraction.Language,
                Profiles   = currentInteraction.Profiles,
                ScreenInfo = currentInteraction.ScreenInfo,
                SiteName   = currentInteraction.SiteName,
                Value      = currentInteraction.Value
            };


            return(interactions);
        }
Example #6
0
 public void CompleteInteraction(HitInfo hit)
 {
     if (CurrentInteraction.TryComplete(hit))
     {
         CurrentInteraction = null;
     }
 }
Example #7
0
 public void VisitDetails_TrackerInitialized_ShouldReturnVisitInformation(IContactProfileProvider contact, IProfileProvider profile, ITracker tracker, CurrentInteraction interaction)
 {
   tracker.Interaction.Returns(interaction);
   //arrange
   var controller = new DemoController(contact, profile);
   using (new TrackerSwitcher(tracker))
   {
     controller.VisitDetails().As<ViewResult>().Model.Should().BeOfType<VisitInformation>();
   }
 }
Example #8
0
        protected override void ProcessInputs()
        {
            base.ProcessInputs();

            CurrentInteraction.Act();
            while (CurrentInteraction.NextInteraction != null)
            {
                CurrentInteraction = CurrentInteraction.NextInteraction;
            }
        }
        public string GetCampaign(CurrentInteraction currentInteraction)
        {
            if (currentInteraction.CampaignId.HasValue)
            {
                Item campaign = Sitecore.Context.Database.GetItem(currentInteraction.CampaignId.ToId());
                if (campaign != null)
                {
                    return(campaign.Name);
                }
            }

            return("Current Campaign Empty");
        }
Example #10
0
        public void Get_Call_ShouldReturnReferringSite(string site, CurrentInteraction currentInteraction, ITracker tracker, ICampaignRepository campaignRepository, [Greedy] ReferralRepository referralRepository)
        {
            //Arrange
            tracker.Interaction.Returns(currentInteraction);
            tracker.Interaction.ReferringSite.Returns(site);

            using (new TrackerSwitcher(tracker))
            {
                //Act
                var referral = referralRepository.Get();
                //Assert
                referral.ReferringSite.Should().Be(site);
            }
        }
    public void Get_Call_ShouldReturnReferringSite(string site,CurrentInteraction currentInteraction, ITracker tracker, ICampaignRepository campaignRepository, [Greedy]ReferralRepository referralRepository )
    {
      //Arrange
      tracker.Interaction.Returns(currentInteraction);
      tracker.Interaction.ReferringSite.Returns(site);

      using (new TrackerSwitcher(tracker))
      {
        //Act
        var referral = referralRepository.Get();
        //Assert      
        referral.ReferringSite.Should().Be(site);
      }
    }
Example #12
0
    public void GetCurrent_NoCampaign_RetrunNull(CurrentInteraction currentInteraction, ITracker tracker)
    {
      //Arrange
      tracker.Interaction.Returns(currentInteraction);
      tracker.Interaction.CampaignId = null;
      var campaignRepository = new CampaignRepository();

      using (new TrackerSwitcher(tracker))
      {
        //Act
        var result = campaignRepository.GetCurrent();
        //Assert     
        result.Should().BeNull();
      }
    }
        public void GetCurrent_NoCampaign_RetrunNull(CurrentInteraction currentInteraction, ITracker tracker)
        {
            //Arrange
            tracker.Interaction.Returns(currentInteraction);
            tracker.Interaction.CampaignId = null;
            var campaignRepository = new CampaignRepository();

            using (new TrackerSwitcher(tracker))
            {
                //Act
                var result = campaignRepository.GetCurrent();
                //Assert
                result.Should().BeNull();
            }
        }
Example #14
0
    public void GetCurrent_HasNoGeoIpDAta_ReturnNull(ITracker tracker, CurrentInteraction interaction )
    {
      //Arrange
      interaction.HasGeoIpData.Returns(false);
      tracker.Interaction.Returns(interaction);
      var locationRepository = new LocationRepository();

      using (new TrackerSwitcher(tracker))
      {
        //Act
        var location = locationRepository.GetCurrent();
        //Assert      
        location.Should().BeNull();
      }
    }
Example #15
0
    public void TrackOutcome_ValidOutcome_ShouldRegisterOutcome([Frozen]ID outcomeDefinitionId, [NoAutoProperties] TrackerService trackerService, ITracker tracker, Contact contact, CurrentInteraction interaction)
    {
      tracker.IsActive.Returns(true);
      tracker.Contact.Returns(contact);
      tracker.Interaction.Returns(interaction);
      tracker.Session.Returns(Substitute.For<Session>());
      tracker.Session.CustomData.Returns(new Dictionary<string, object>());

      using (new TrackerSwitcher(tracker))
      {
        trackerService.TrackOutcome(outcomeDefinitionId);

        tracker.GetContactOutcomes().Should().Contain(o => o.DefinitionId == outcomeDefinitionId);
      }
    }
Example #16
0
        public void GetCurrent_NoCampaign_ReturnsNull(CurrentInteraction currentInteraction, ITracker tracker, ITaxonomyManagerProvider taxonomyManagerProvider, IDefinitionManager <ICampaignActivityDefinition> definitionManager)
        {
            //Arrange
            tracker.Interaction.Returns(currentInteraction);
            tracker.Interaction.CampaignId = null;
            var campaignRepository = new CampaignRepository(taxonomyManagerProvider, definitionManager);

            using (new TrackerSwitcher(tracker))
            {
                //Act
                var result = campaignRepository.GetCurrent();
                //Assert
                result.Should().BeNull();
            }
        }
        public void GetCurrent_HasNoGeoIpDAta_ReturnNull(ITracker tracker, CurrentInteraction interaction)
        {
            //Arrange
            interaction.HasGeoIpData.Returns(false);
            tracker.Interaction.Returns(interaction);
            var locationRepository = new LocationRepository();

            using (new TrackerSwitcher(tracker))
            {
                //Act
                var location = locationRepository.GetCurrent();
                //Assert
                location.Should().BeNull();
            }
        }
Example #18
0
        /// <summary>
        /// Creates the and initialize page.
        /// Modifictaion: If the page is a wildcard page, start the pipeline to resolve the correct item
        /// </summary>
        /// <param name="visit">The visit.</param>
        private void CreateAndInitializePage(CurrentInteraction visit)
        {
            IPageContext empty = visit.CreatePage();

            empty.SetUrl(WebUtil.GetRawUrl());

            DeviceItem device = Context.Device;

            if (device == null)
            {
                empty.SitecoreDevice.Id   = Guid.Empty;
                empty.SitecoreDevice.Name = string.Empty;
            }
            else
            {
                empty.SitecoreDevice.Id   = device.ID.Guid;
                empty.SitecoreDevice.Name = device.Name;
            }

            Item item = Context.Item;

            if (item.IsWildcard())
            {
                //// If you are actually using wildcard items then you can throw in your pipeline to resolve it. More information can be found online ;) Referencing an old blog from an old-coworker.
                ////var wildCardItem = ResolveWildcardItemPipeline.Run(item);

                ////if (wildCardItem != null)
                ////{
                ////    item = wildCardItem;
                ////}
            }

            if (item == null)
            {
                //// This is really important for every Sitecore platform, rule out your api's in your XDB data... Need to share this with the Sitecore Community @ Achmea
                if (empty.Url.Path.StartsWith($"/{Events.Constants.API_BASEPATH}/"))
                {
                    visit.CurrentPage.Cancel();
                }

                return;
            }

            empty.SetItemProperties(item.ID.Guid, item.Language.Name, item.Version.Number);
        }
    public void Get_Call_ShouldCombineActiveAndHistoricCampaigns(string site, CurrentInteraction currentInteraction, ITracker tracker, [Frozen]ICampaignRepository campaignRepository, [Greedy]ReferralRepository referralRepository)
    {
      //Arrange
      tracker.Interaction.Returns(currentInteraction);
      tracker.Interaction.ReferringSite.Returns(site);

      campaignRepository.GetCurrent().Returns(new Campaign() {Title = "camp1"});
      campaignRepository.GetHistoric().Returns(new[] {new Campaign() {Title = "camp2"}, new Campaign() {Title = "camp3"}});

      using (new TrackerSwitcher(tracker))
      {
        //Act
        var referral = referralRepository.Get();
        //Assert      
        referral.TotalNoOfCampaigns.Should().Be(3);
        referral.Campaigns.Select(x => x.Title).Should().Contain(new[] {"camp1", "camp2", "camp3",});
      }
    }
Example #20
0
        public static bool UpdateGeoIpFromCookie(CurrentInteraction interaction)
        {
            bool html5Geolocation = Settings.GetBoolSetting("Analytics.HTML5Geolocation.Enabled", true);

            bool html5GeolocationSuccess = false;

            if (html5Geolocation && HttpContext.Current.Request.Cookies.AllKeys.Contains("Analytics.HTML5ReverseLookupResult"))
            {
                Log.Info("Analytics - Trying to resolve address by HTML5 geolocation cookie.", typeof(GeoIpHelper));

                var geolocationCookie = HttpContext.Current.Request.Cookies["Analytics.HTML5ReverseLookupResult"];

                if (geolocationCookie != null && !string.IsNullOrEmpty(geolocationCookie.Value))
                {
                    var cookieValue = WebUtility.UrlDecode(geolocationCookie.Value);

                    try
                    {
                        dynamic geoData = JObject.Parse(cookieValue);

                        var whois = new WhoIsInformation
                        {
                            Latitude   = geoData.Lat,
                            Longitude  = geoData.Long,
                            PostalCode = geoData.PostalCode,
                            Country    = geoData.Country,
                            City       = geoData.City,
                            Region     = geoData.Region
                        };

                        interaction.SetGeoData(whois);

                        html5GeolocationSuccess = true;
                    }
                    catch (Exception e)
                    {
                        Log.Error("Analytics - Error during HTML5 geolocation", e, typeof(GeoIpHelper));
                    }
                }
            }

            return(html5GeolocationSuccess);
        }
Example #21
0
    public void GetCurrent_NullLongitude_ReturnNull(double? latitude, ITracker tracker, CurrentInteraction interaction, WhoIsInformation whoIsInformation)
    {
      //Arrange
      whoIsInformation.Latitude = latitude;
      whoIsInformation.Longitude = null;
      interaction.HasGeoIpData.Returns(true);
      interaction.GeoData.Returns(new ContactLocation(() => whoIsInformation));
      tracker.Interaction.Returns(interaction);

      var locationRepository = new LocationRepository();

      using (new TrackerSwitcher(tracker))
      {
        //Act
        var location = locationRepository.GetCurrent();
        //Assert      
        location.Should().BeNull();
      }
    }
        private void CreateAndInitializePage(HttpContextBase httpContext, CurrentInteraction visit)
        {
            var empty = visit.CreatePage();

            empty.SetUrl(WebUtil.GetRawUrl());

            var device = Context.Device;

            if (device == null)
            {
                empty.SitecoreDevice.Id   = Guid.Empty;
                empty.SitecoreDevice.Name = string.Empty;
            }
            else
            {
                empty.SitecoreDevice.Id   = device.ID.Guid;
                empty.SitecoreDevice.Name = device.Name;
            }

            // Default Sitecore implementation
            var item = Context.Item;

            // If the current item is a wildcard
            if (item != null && item.IsWilcard())
            {
                // Perform a call to the logic which resolves the correct item
                var resolvedItem = this.ResolveWildcardItem(httpContext, item);

                if (resolvedItem != null)
                {
                    item = resolvedItem;
                }
            }

            // Resume the default behaviour
            if (item == null)
            {
                return;
            }

            empty.SetItemProperties(item.ID.Guid, item.Language.Name, item.Version.Number);
        }
Example #23
0
    public void GetCurrent_Call_ReturnCityAndCountry(string city, string country, ITracker tracker, CurrentInteraction interaction, WhoIsInformation whoIsInformation)
    {
      //Arrange
      whoIsInformation.City = city;
      whoIsInformation.Country = country;
      interaction.HasGeoIpData.Returns(true);
      interaction.GeoData.Returns(new ContactLocation(() => whoIsInformation));
      tracker.Interaction.Returns(interaction);

      var locationRepository = new LocationRepository();

      using (new TrackerSwitcher(tracker))
      {
        //Act
        var location = locationRepository.GetCurrent();
        //Assert      
        location.Should().NotBeNull();
        location.City.Should().Be(city);
        location.Country.Should().Be(country);
      }
    }
Example #24
0
        public void ExperienceData_InitializedTracker_ReturnExperienceData(
            IKeyBehaviorCache keyBehaviorCache,
            Session session,
            CurrentInteraction currentInteraction,
            ITracker tracker,
            [Frozen] IContactProfileProvider contactProfileProvider,
            [Frozen] IProfileProvider profileProvider,
            [Greedy] DemoController sut)
        {
            tracker.Interaction.Returns(currentInteraction);
            tracker.Session.Returns(session);
            var attachments = new Dictionary <string, object>()
            {
                ["KeyBehaviorCache"] = new Sitecore.Analytics.Tracking.KeyBehaviorCache(keyBehaviorCache)
            };

            tracker.Contact.Attachments.Returns(attachments);

            using (new TrackerSwitcher(tracker))
            {
                sut.ExperienceData().Should().BeOfType <ViewResult>().Which.Model.Should().BeOfType <ExperienceData>();
            }
        }
Example #25
0
        public void ExperienceData_InitializedTrackerAndPreviewMode_ReturnEmptyResult(IKeyBehaviorCache keyBehaviorCache, Session session, CurrentInteraction currentInteraction, ITracker tracker, [Frozen] IContactProfileProvider contactProfileProvider, [Frozen] IProfileProvider profileProvider, [Greedy] DemoController sut)
        {
            //TODO: Fix;
            //tracker.Interaction.Returns(currentInteraction);
            //tracker.Session.Returns(session);
            //var attachments = new Dictionary<string, object>
            //{
            //  ["KeyBehaviorCache"] = new Analytics.Tracking.KeyBehaviorCache(keyBehaviorCache)
            //};
            //tracker.Contact.Attachments.Returns(attachments);

            //var fakeSite = new FakeSiteContext(new StringDictionary
            //                                   {
            //                                     {"mode", "edit"}
            //                                   }) as SiteContext;

            //using (new SiteContextSwitcher(fakeSite))
            //{
            //  using (new TrackerSwitcher(tracker))
            //  {
            //    sut.ExperienceData().Should().BeOfType<ViewResult>().Which.Model.Should().BeOfType<EmptyResult>();
            //  }
            //}
        }
Example #26
0
        public void ExperienceData_InitializedTrackerAndNormalMode_ReturnExperienceData(IKeyBehaviorCache keyBehaviorCache, Session session, CurrentInteraction currentInteraction, ITracker tracker, Contact contact, [Frozen] IProfileProvider profileProvider, [Frozen] IDemoStateService demoState, [Frozen] IExperienceDataFactory dataFactory, [Greedy] DemoController sut)
        {
            demoState.IsDemoEnabled.Returns(true);
            dataFactory.Get().Returns(new ExperienceData());
            tracker.Interaction.Returns(currentInteraction);
            tracker.Session.Returns(session);
            var attachments = new Dictionary <string, object>
            {
                ["KeyBehaviorCache"] = new Analytics.Tracking.KeyBehaviorCache(keyBehaviorCache)
            };

            contact.Attachments.Returns(attachments);
            tracker.Contact.Returns(contact);

            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                { "displayMode", "normal" }
            }) as SiteContext;

            using (new SiteContextSwitcher(fakeSite))
            {
                using (new TrackerSwitcher(tracker))
                {
                    var result = sut.ExperienceData();
                    result.Should().BeOfType <ViewResult>().Which.Model.Should().BeOfType <ExperienceData>();
                }
            }
        }
Example #27
0
        public void ExperienceData_InitializedTrackerAndPreviewMode_ReturnEmptyResult(IKeyBehaviorCache keyBehaviorCache, Session session, CurrentInteraction currentInteraction, ITracker tracker, Contact contact, [Frozen] IProfileProvider profileProvider, [Frozen] IDemoStateService demoState, [Greedy] DemoController sut)
        {
            demoState.IsDemoEnabled.Returns(true);
            tracker.Interaction.Returns(currentInteraction);
            tracker.Session.Returns(session);
            var attachments = new Dictionary <string, object>
            {
                ["KeyBehaviorCache"] = new Analytics.Tracking.KeyBehaviorCache(keyBehaviorCache)
            };

            contact.Attachments.Returns(attachments);
            tracker.Contact.Returns(contact);

            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                { "enablePreview", "true" },
                { "masterDatabase", "master" }
            }) as SiteContext;

            using (new SiteContextSwitcher(fakeSite))
            {
                Sitecore.Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Remember);
                using (new TrackerSwitcher(tracker))
                {
                    sut.ExperienceData().Should().BeOfType <EmptyResult>();
                }
            }
        }
Example #28
0
        public void ExperienceData_InitializedTrackerAndNormalMode_ReturnExperienceData(IKeyBehaviorCache keyBehaviorCache, Session session, CurrentInteraction currentInteraction, ITracker tracker, [Frozen] IContactProfileProvider contactProfileProvider, [Frozen] IProfileProvider profileProvider, [Greedy] DemoController sut)
        {
            tracker.Interaction.Returns(currentInteraction);
            tracker.Session.Returns(session);
            var attachments = new Dictionary<string, object>
                              {
                                  ["KeyBehaviorCache"] = new Analytics.Tracking.KeyBehaviorCache(keyBehaviorCache)
                              };
            tracker.Contact.Attachments.Returns(attachments);

            var fakeSite = new FakeSiteContext(new StringDictionary
                                               {
                                                   {"displayMode", "normal"}
                                               }) as SiteContext;

            using (new SiteContextSwitcher(fakeSite))
            {
                using (new TrackerSwitcher(tracker))
                {
                    sut.ExperienceData().Should().BeOfType<ViewResult>().Which.Model.Should().BeOfType<ExperienceData>();
                }
            }
        }
Example #29
0
        public void ExperienceData_InitializedTrackerAndPreviewMode_ReturnEmptyResult(IKeyBehaviorCache keyBehaviorCache, Session session, CurrentInteraction currentInteraction, ITracker tracker, [Frozen] IContactProfileProvider contactProfileProvider, [Frozen] IProfileProvider profileProvider, [Greedy] DemoController sut)
        {
            //TODO: Fix;
            //tracker.Interaction.Returns(currentInteraction);
            //tracker.Session.Returns(session);
            //var attachments = new Dictionary<string, object>
            //{
            //  ["KeyBehaviorCache"] = new Analytics.Tracking.KeyBehaviorCache(keyBehaviorCache)
            //};
            //tracker.Contact.Attachments.Returns(attachments);

            //var fakeSite = new FakeSiteContext(new StringDictionary
            //                                   {
            //                                     {"mode", "edit"}
            //                                   }) as SiteContext;

            //using (new SiteContextSwitcher(fakeSite))
            //{
            //  using (new TrackerSwitcher(tracker))
            //  {
            //    sut.ExperienceData().Should().BeOfType<ViewResult>().Which.Model.Should().BeOfType<EmptyResult>();
            //  }
            //}
        }
        public void LoadProfiles_SettingWithProfiles_ShouldReturnExistentProfilesEnumerable(Db db, CurrentInteraction currentInteraction, ITracker tracker, Analytics.Tracking.Profile profile)
        {
            var profileItem = new DbItem("profile", ID.NewID, new TemplateID(ProfileItem.TemplateID));

            db.Add(profileItem);
            var profileSettingItem = new DbItem("profileSetting", ID.NewID, new TemplateID(Templates.ProfilingSettings.ID))
            {
                { Templates.ProfilingSettings.Fields.SiteProfiles, profileItem.ID.ToString() }
            };

            db.Add(profileSettingItem);

            var provider = new ProfileProvider();

            var fakeSiteContext = new FakeSiteContext(new StringDictionary
            {
                { "rootPath", "/sitecore" },
                { "startItem", profileSettingItem.FullPath.Remove(0, "/sitecore".Length) }
            })
            {
                Database = db.Database
            };


            using (new SiteContextSwitcher(fakeSiteContext))
            {
                var siteProfiles = provider.GetSiteProfiles();
                siteProfiles.Count().Should().Be(1);
            }
        }
Example #31
0
    public void HasMatchingPattern_ItemExists_ShouldReturnTrue([Content] Item profileItem, CurrentInteraction currentInteraction, ITracker tracker, Profile profile)
    {
      tracker.Interaction.Returns(currentInteraction);
      currentInteraction.Profiles[null].ReturnsForAnyArgs(profile);

      var pattern = profileItem.Add("fakePattern", new TemplateID(PatternCardItem.TemplateID));
      profile.PatternId = pattern.ID.Guid;
      var fakeSiteContext = new FakeSiteContext("fake")
      {
        Database = Database.GetDatabase("master")
      };


      using (new TrackerSwitcher(tracker))
      {
        using (new SiteContextSwitcher(fakeSiteContext))
        {
          var provider = new ProfileProvider();
          provider.HasMatchingPattern(new ProfileItem(profileItem)).Should().BeTrue();
        }
      }
    }
        public void TrackOutcome_ValidOutcome_ShouldRegisterOutcome([Frozen] ID outcomeDefinitionId, [NoAutoProperties] TrackerService trackerService, ITracker tracker, Contact contact, CurrentInteraction interaction)
        {
            tracker.IsActive.Returns(true);
            tracker.Contact.Returns(contact);
            tracker.Interaction.Returns(interaction);
            tracker.Session.Returns(Substitute.For <Session>());
            tracker.Session.CustomData.Returns(new Dictionary <string, object>());

            using (new TrackerSwitcher(tracker))
            {
                trackerService.TrackOutcome(outcomeDefinitionId);

                tracker.GetContactOutcomes().Should().Contain(o => o.DefinitionId == outcomeDefinitionId);
            }
        }
Example #33
0
    public void HasMatchingPattern_TrackerReturnsNull_ShouldReturnFalse([Content] Item profileItem, CurrentInteraction currentInteraction, ITracker tracker, Analytics.Tracking.Profile profile)
    {
      tracker.Interaction.Returns(currentInteraction);
      currentInteraction.Profiles[null].ReturnsForAnyArgs((Analytics.Tracking.Profile)null);


      var fakeSiteContext = new FakeSiteContext("fake")
      {
        Database = Database.GetDatabase("master")
      };


      using (new TrackerSwitcher(tracker))
      {
        using (new SiteContextSwitcher(fakeSiteContext))
        {
          var provider = new ProfileProvider();
          provider.HasMatchingPattern(new ProfileItem(profileItem), ProfilingTypes.Active).Should().BeFalse();
        }
      }
    }
Example #34
0
 public BeaconEntity StopTracking(string contactId = "", bool killContact = false, string endTime = "")
 {
     if (this.httpContextBase != null && this.httpContextBase.Session != null)
     {
         string arg;
         if (!this.TryGetSessionId(out arg))
         {
             HttpExceptionHelper.InternetServerError("Unexpected server error", "Session could not be initialized.");
         }
         this.logger.Debug(string.Format("[StopTracking]: CID: {0} SID: {1}", contactId, arg), null);
         HttpRequestBase httpRequestBase = this.httpContextBase.Request;
         if (!base.Request.Headers.Referrer.Host.Equals(base.Request.RequestUri.Host))
         {
             SpoofedHttpRequestBase spoofedHttpRequestBase = new SpoofedHttpRequestBase(this.httpContextBase.Request);
             spoofedHttpRequestBase.SetUrl(base.Request.Headers.Referrer);
             httpRequestBase = spoofedHttpRequestBase;
             IDomainMatcher domainMatcher;
             Language       language;
             if (!this.trackingManager.DomainIsValid(httpRequestBase, out domainMatcher, out language))
             {
                 throw new HttpResponseException(HttpStatusCode.BadRequest);
             }
             TrackPageVisitArgs args = new TrackPageVisitArgs(this.sitecoreContext, this.trackerProvider, this.httpContextBase.Request, this.httpContextBase.Response, httpRequestBase, new PageVisitParameters(this.httpContextBase.Request.Url, null, contactId), domainMatcher, false);
             InitializeTrackingCookieProcessor initializeTrackingCookieProcessor = new InitializeTrackingCookieProcessor();
             initializeTrackingCookieProcessor.Process(args);
             InitializeExternalTrackingProcessor initializeExternalTrackingProcessor = new InitializeExternalTrackingProcessor();
             initializeExternalTrackingProcessor.Process(args);
             InitializeContextSiteProcessor initializeContextSiteProcessor = new InitializeContextSiteProcessor();
             initializeContextSiteProcessor.Process(args);
         }
         else
         {
             Tracker.Initialize();
             Tracker.Current.Session.SetClassification(0, 0, false);
         }
         if (!string.IsNullOrWhiteSpace(endTime))
         {
             DateTime           dateTime    = DateTime.Parse(endTime, DateTimeFormatInfo.InvariantInfo);
             CurrentInteraction interaction = this.trackerProvider.Current.Interaction;
             Assert.IsNotNull(interaction, "interaction");
             TimeSpan t = DateTime.UtcNow - DateUtil.ToUniversalTime(dateTime);
             interaction.EndDateTime    = dateTime;
             interaction.StartDateTime -= t;
             Page[] pages = interaction.Pages;
             for (int i = 0; i < pages.Length; i++)
             {
                 Page page = pages[i];
                 page.DateTime -= t;
             }
         }
         this.httpContextBase.Session.Abandon();
         this.httpContextBase.Response.Cookies.Clear();
         if (killContact)
         {
             DateTime expires = new DateTime(1979, 1, 1, 0, 0, 0, DateTimeKind.Utc);
             string[] allKeys = this.httpContextBase.Request.Cookies.AllKeys;
             for (int j = 0; j < allKeys.Length; j++)
             {
                 string     text   = allKeys[j];
                 HttpCookie cookie = new HttpCookie(text)
                 {
                     Expires = expires,
                     Value   = string.Empty,
                     Domain  = this.httpContextBase.Request.Cookies.GetSafely(text).Domain
                 };
                 this.httpContextBase.Response.Cookies.Add(cookie);
             }
             this.httpContextBase.Response.Cookies.Add(new HttpCookie("SC_ANALYTICS_GLOBAL_COOKIE")
             {
                 Domain  = "." + this.httpContextBase.Request.Url.Host,
                 Value   = string.Empty,
                 Expires = expires
             });
         }
     }
     return(new BeaconEntity
     {
         Id = "TBC",
         ContactId = string.Empty,
         SessionId = string.Empty,
         Url = string.Empty
     });
 }
Example #35
0
        public void HasMatchingPattern_ItemExists_ShouldReturnTrue([Content] Item profileItem, CurrentInteraction currentInteraction, ITracker tracker, Analytics.Tracking.Profile profile)
        {
            tracker.Interaction.Returns(currentInteraction);
            currentInteraction.Profiles[null].ReturnsForAnyArgs(profile);

            var pattern = profileItem.Add("fakePattern", new TemplateID(PatternCardItem.TemplateID));

            profile.PatternId = pattern.ID.Guid;
            var fakeSiteContext = new FakeSiteContext("fake")
            {
                Database = Database.GetDatabase("master")
            };


            using (new TrackerSwitcher(tracker))
            {
                using (new SiteContextSwitcher(fakeSiteContext))
                {
                    var provider = new ProfileProvider();
                    provider.HasMatchingPattern(new ProfileItem(profileItem), ProfilingTypes.Active).Should().BeTrue();
                }
            }
        }
Example #36
0
    public void HasMatchingPattern_TrackerReturnsProfileWithoutID_ShouldReturnFalse([Content] Item profileItem, CurrentInteraction currentInteraction, ITracker tracker, Profile profile)
    {
      tracker.Interaction.Returns(currentInteraction);
      currentInteraction.Profiles[null].ReturnsForAnyArgs(profile);
      profile.PatternId = null;

      var fakeSiteContext = new FakeSiteContext("fake")
      {
        Database = Database.GetDatabase("master")
      };


      using (new TrackerSwitcher(tracker))
      {
        using (new SiteContextSwitcher(fakeSiteContext))
        {
          var provider = new ProfileProvider();
          provider.HasMatchingPattern(new ProfileItem(profileItem)).Should().BeFalse();
        }
      }
    }
Example #37
0
        public void HasMatchingPattern_TrackerReturnsNull_ShouldReturnFalse([Content] Item profileItem, CurrentInteraction currentInteraction, ITracker tracker, Profile profile)
        {
            tracker.Interaction.Returns(currentInteraction);
            currentInteraction.Profiles[null].ReturnsForAnyArgs((Profile)null);


            var fakeSiteContext = new FakeSiteContext("fake")
            {
                Database = Database.GetDatabase("master")
            };


            using (new TrackerSwitcher(tracker))
            {
                using (new SiteContextSwitcher(fakeSiteContext))
                {
                    var provider = new ProfileProvider();
                    provider.HasMatchingPattern(new ProfileItem(profileItem)).Should().BeFalse();
                }
            }
        }
        public void GetCurrent_Call_ReturnCityAndCountry(string city, string country, ITracker tracker, CurrentInteraction interaction, WhoIsInformation whoIsInformation)
        {
            //Arrange
            whoIsInformation.City    = city;
            whoIsInformation.Country = country;
            interaction.HasGeoIpData.Returns(true);
            interaction.GeoData.Returns(new ContactLocation(() => whoIsInformation));
            tracker.Interaction.Returns(interaction);

            var locationRepository = new LocationRepository();

            using (new TrackerSwitcher(tracker))
            {
                //Act
                var location = locationRepository.GetCurrent();
                //Assert
                location.Should().NotBeNull();
                location.City.Should().Be(city);
                location.Country.Should().Be(country);
            }
        }
        public void HasMatchingPattern_TrackerReturnsProfileWithoutID_ShouldReturnFalse([Content] Item profileItem, CurrentInteraction currentInteraction, ITracker tracker, Analytics.Tracking.Profile profile)
        {
            tracker.Interaction.Returns(currentInteraction);
            currentInteraction.Profiles[null].ReturnsForAnyArgs(profile);
            profile.PatternId = null;

            var fakeSiteContext = new FakeSiteContext("fake")
            {
                Database = Database.GetDatabase("master")
            };


            using (new TrackerSwitcher(tracker))
            {
                using (new SiteContextSwitcher(fakeSiteContext))
                {
                    var provider = new ProfileProvider();
                    provider.HasMatchingPattern(new ProfileItem(profileItem), ProfilingTypes.Active).Should().BeFalse();
                }
            }
        }
        public void GetCurrent_NullLongitude_ReturnNull(double?latitude, ITracker tracker, CurrentInteraction interaction, WhoIsInformation whoIsInformation)
        {
            //Arrange
            whoIsInformation.Latitude  = latitude;
            whoIsInformation.Longitude = null;
            interaction.HasGeoIpData.Returns(true);
            interaction.GeoData.Returns(new ContactLocation(() => whoIsInformation));
            tracker.Interaction.Returns(interaction);

            var locationRepository = new LocationRepository();

            using (new TrackerSwitcher(tracker))
            {
                //Act
                var location = locationRepository.GetCurrent();
                //Assert
                location.Should().BeNull();
            }
        }
        public void LoadProfiles_SettingsIsEmpty_ShouldReturnExistentProfilesEnumerable([Content] Item item, CurrentInteraction currentInteraction, ITracker tracker, Analytics.Tracking.Profile profile)
        {
            var profileSettingItem = item.Add("profileSetting", new TemplateID(Templates.ProfilingSettings.ID));
            var profileItem        = item.Add("profile", new TemplateID(ProfileItem.TemplateID));


            var provider = new ProfileProvider();

            var fakeSiteContext = new FakeSiteContext(new StringDictionary
            {
                {
                    "rootPath", "/sitecore"
                },
                {
                    "startItem", profileSettingItem.Paths.FullPath.Remove(0, "/sitecore".Length)
                }
            });

            fakeSiteContext.Database = item.Database;

            using (new SiteContextSwitcher(fakeSiteContext))
            {
                provider.GetSiteProfiles().Count().Should().Be(0);
            }
        }
Example #42
0
        public void VisitDetails_TrackerInitialized_ShouldReturnVisitInformation(IContactProfileProvider contact, IProfileProvider profile, ITracker tracker, CurrentInteraction interaction)
        {
            tracker.Interaction.Returns(interaction);
            //arrange
            var controller = new DemoController(contact, profile);

            using (new TrackerSwitcher(tracker))
            {
                controller.VisitDetails().As <ViewResult>().Model.Should().BeOfType <VisitInformation>();
            }
        }