public void TrackContentView_Tracks_ContentView()
        {
            var          url         = new Uri("http://csharpanalytics.com/doc");
            const string title       = "CSharpAnalytics docs";
            const string description = "Documentation for CSharpAnalaytics";
            const string path        = "/docs";
            const string hostName    = "docs.csharpanalytics.com";

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackContentView(url, title, description, path, hostName);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=pageview");
            CollectionAssert.Contains(parameters, "dl=" + url);
            CollectionAssert.Contains(parameters, "dt=" + title);
            CollectionAssert.Contains(parameters, "cd=" + description);
            CollectionAssert.Contains(parameters, "dp=" + path);
            CollectionAssert.Contains(parameters, "dh=" + hostName);
        }
        public void AppViewExtension_Tracks_AppView()
        {
            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackAppView("SomeScreenName");

            Assert.AreEqual(1, list.Count);
            StringAssert.Contains(list[0].OriginalString, "t=appview");
        }
        public void MeasurementAnalyticsClient_SetCustomMetric_Int_Is_Sent()
        {
            var actual = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            client.SetCustomMetric(6, 6060);
            client.TrackScreenView("Test View");

            Assert.AreEqual(1, actual.Count);
            StringAssert.Contains(actual[0].Query, "cm6=6060");
        }
        public void MeasurementAnalyticsClient_SetCustomDimension_By_Enum_Is_Sent()
        {
            var actual = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            client.SetCustomDimension(CustomDimensions.Eight, "DimensionEight");
            client.TrackScreenView("Test View");

            Assert.AreEqual(1, actual.Count);
            StringAssert.Contains(actual[0].Query, "cd8=DimensionEight");
        }
        public void MeasurementAnalyticsClient_Replays_Tracked_Activities_After_Configured()
        {
            var actual = new List <Uri>();

            var client = new MeasurementAnalyticsClient();

            client.Track(new ScreenViewActivity("The Big Screen"));
            client.Track(new ScreenViewActivity("Silk Screen"));

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            Assert.AreEqual(2, actual.Count);
        }
        public void MeasurementAnalyticsClient_SetCustomMetric_Decimal_Is_Sent()
        {
            var actual = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            client.SetCustomMetric(8, 123456.78m);
            client.TrackAppView("Test View");

            Assert.AreEqual(1, actual.Count);
            StringAssert.Contains(actual[0].Query, "cm8=123456.78");
        }
        public void MeasurementAnalyticsClient_SetCustomMetric_Timespan_Is_Sent()
        {
            var actual         = new List <Uri>();
            var actualTimespan = new TimeSpan(4, 1, 2, 3);
            var client         = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, actual.Add);

            client.SetCustomMetric(7, actualTimespan);
            client.TrackScreenView("Test View");

            Assert.AreEqual(1, actual.Count);
            StringAssert.Contains(actual[0].Query, "cm7=" + (int)actualTimespan.TotalSeconds);
        }
        public void TrackException_Tracks_Exception()
        {
            const string description = "Some action";

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackException(description);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=exception");
            CollectionAssert.Contains(parameters, "exd=" + description);
            CollectionAssert.Contains(parameters, "exf=0");
        }
        public void TrackSocial_Tracks_Social()
        {
            const string action  = "Poke";
            const string network = "FriendFace";
            const string target  = "Clown";

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackSocial(action, network, target);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=social");
            CollectionAssert.Contains(parameters, "sa=" + action);
            CollectionAssert.Contains(parameters, "sn=" + network);
            CollectionAssert.Contains(parameters, "st=" + target);
        }
        public void TrackTimedEvent_Tracks_TimedEvent()
        {
            const string category = "A category";
            const string variable = "Some variable";
            var          time     = TimeSpan.FromMilliseconds(12345);
            const string label    = "Blue";

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackTimedEvent(category, variable, time, label);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=timing");
            CollectionAssert.Contains(parameters, "utc=" + category);
            CollectionAssert.Contains(parameters, "utv=" + variable);
            CollectionAssert.Contains(parameters, "utt=" + time.TotalMilliseconds);
            CollectionAssert.Contains(parameters, "utl=" + label);
        }
        public void TrackEvent_Tracks_Event()
        {
            const string action   = "Some action";
            const string category = "Category Z";
            const string label    = "I am a label";
            const int    value    = 55;

            var list   = new List <Uri>();
            var client = new MeasurementAnalyticsClient();

            MeasurementTestHelpers.ConfigureForTest(client, list.Add);

            client.TrackEvent(action, category, label, value, true);

            Assert.AreEqual(1, list.Count);
            var parameters = list[0].GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            CollectionAssert.Contains(parameters, "t=event");
            CollectionAssert.Contains(parameters, "ea=" + action);
            CollectionAssert.Contains(parameters, "ec=" + category);
            CollectionAssert.Contains(parameters, "el=" + label);
            CollectionAssert.Contains(parameters, "ev=" + value);
            CollectionAssert.Contains(parameters, "ni=1");
        }