Captures the details of a campaign to be recorded in analytics.
Наследование: IUrchinActivity, IMeasurementActivity
        public void UrchinActivityTracker_GetParameter_For_CampaignActivity_Returns_Correct_Values()
        {
            var activity = new CampaignActivity("source");

            var parameters = UrchinActivityTracker.GetParameters(activity).ToDictionary(k => k.Key, v => v.Value);

            Assert.AreEqual("source", parameters["utmcsr"]);
        }
        public void UrchinActivityTracker_GetParameter_For_CampaignActivity_Returns_Correct_Keys_When_Not_IsNewVisit()
        {
            var activity = new CampaignActivity("source");

            var results = UrchinActivityTracker.GetParameters(activity).ToDictionary(k => k.Key, v => v);

            var expectedKeys = new[] { "utmcsr", "utmcr" };
            CollectionAssert.AreEquivalent(expectedKeys, results.Keys);
        }
        public void CampaignActivity_Constructor_With_All_Parameters_Sets_Correct_Properties()
        {
            var activity = new CampaignActivity("source");

            Assert.AreEqual("source", activity.Source);

            Assert.IsNull(activity.Name);
            Assert.IsNull(activity.Medium);
            Assert.IsNull(activity.Term);
            Assert.IsNull(activity.Content);
        }
        public void CampaignActivity_Properties_Can_Be_Set()
        {
            var activity = new CampaignActivity("source") {
                Name = "name",
                Medium = "medium",
                Term = "term",
                Content = "content",
                IsNewVisit = true
            };

            Assert.AreEqual("name", activity.Name);
            Assert.AreEqual("medium", activity.Medium);
            Assert.AreEqual("term", activity.Term);
            Assert.AreEqual("content", activity.Content);
            Assert.AreEqual(true, activity.IsNewVisit);
        }
        public void UrchinTrackerActivities_GetParameter_For_CampaignActivity_Returns_Correct_Optional_Values()
        {
            var activity = new CampaignActivity("source")
            {
                Name = "name",
                Medium = "medium",
                Term = "term",
                Content = "content"
            };

            var parameters = UrchinTrackerActivities.GetParameters(activity).ToDictionary(k => k.Key, v => v.Value);

            Assert.AreEqual("name", parameters["utmccn"]);
            Assert.AreEqual("medium", parameters["utmcmd"]);
            Assert.AreEqual("term", parameters["utmctr"]);
            Assert.AreEqual("content", parameters["utmcct"]);
        }
        internal static IEnumerable<KeyValuePair<string, string>> GetParameters(CampaignActivity campaign)
        {
            yield return KeyValuePair.Create("utmcsr", campaign.Source);

            if (!String.IsNullOrEmpty(campaign.Name))
                yield return KeyValuePair.Create("utmccn", campaign.Name);

            if (!String.IsNullOrEmpty(campaign.Medium))
                yield return KeyValuePair.Create("utmcmd", campaign.Medium);

            if (!String.IsNullOrEmpty(campaign.Term))
                yield return KeyValuePair.Create("utmctr", campaign.Term);

            if (!String.IsNullOrEmpty(campaign.Content))
                yield return KeyValuePair.Create("utmcct", campaign.Content);

            yield return KeyValuePair.Create(campaign.IsNewVisit ? "utmcn" : "utmcr", "1");
        }
        public void MeasurementActivityTracker_GetParameter_For_CampaignActivity_Returns_Correct_Values()
        {
            var activity = new CampaignActivity("source")
            {
                Name = "name",
                Medium = "medium",
                Term = "term",
                Content = "content"
            };

            var parameters = MeasurementActivityTracker.GetParameters(activity).ToDictionary(k => k.Key, v => v.Value);

            Assert.AreEqual(5, parameters.Keys.Count);
            Assert.AreEqual("source", parameters["cs"]);
            Assert.AreEqual("name", parameters["cn"]);
            Assert.AreEqual("medium", parameters["cm"]);
            Assert.AreEqual("term", parameters["ck"]);
            Assert.AreEqual("content", parameters["cc"]);
        }
        /// <summary>
        /// Obtain the key/value pairs for a CampaignActivity.
        /// </summary>
        /// <param name="campaign">CampaignActivity to turn into key/value pairs.</param>
        /// <returns>Key/value pairs representing this CampaignActivity.</returns>
        internal static IEnumerable<KeyValuePair<string, string>> GetParameters(CampaignActivity campaign)
        {
            if (!String.IsNullOrEmpty(campaign.Name))
                yield return KeyValuePair.Create("cn", campaign.Name);

            if (!String.IsNullOrEmpty(campaign.Source))
                yield return KeyValuePair.Create("cs", campaign.Source);

            if (!String.IsNullOrEmpty(campaign.Medium))
                yield return KeyValuePair.Create("cm", campaign.Medium);

            if (!String.IsNullOrEmpty(campaign.Term))
                yield return KeyValuePair.Create("ck", campaign.Term);

            if (!String.IsNullOrEmpty(campaign.Content))
                yield return KeyValuePair.Create("cc", campaign.Content);
        }