Inheritance: TimedEventActivity
        public void AutoTimedEventActivity_Constructor_With_All_Parameters_Sets_Correct_Properties()
        {
            var activity = new AutoTimedEventActivity("category", "variable", "label");

            Assert.AreEqual("category", activity.Category);
            Assert.AreEqual("variable", activity.Variable);
            Assert.AreEqual("label", activity.Label);
        }
        public void AutoTimedEventActivity_EndedAt_Property_Can_Be_Nulled()
        {
            var activity = new AutoTimedEventActivity("category", "variable");

            activity.End();
            activity.EndedAt = null;

            Assert.IsNull(activity.EndedAt);
        }
        public void AutoTimedEventActivity_EndedAt_Property_Can_Be_Set()
        {
            var activity = new AutoTimedEventActivity("category", "variable");

            var expectedEndedAt = new DateTimeOffset(2001, 11, 5, 1, 2, 3, 4, TimeSpan.Zero);
            activity.EndedAt = expectedEndedAt;

            Assert.AreEqual(expectedEndedAt, activity.EndedAt);
        }
        public void AutoTimedEventActivity_Starts_At_Correct_Time()
        {
            var earliest = DateTimeOffset.Now;
            var activity = new AutoTimedEventActivity("category", "variable");
            var latest = DateTimeOffset.Now;

            Assert.IsTrue(activity.StartedAt >= earliest, "StartedAt too early expected after {0} found {1}", earliest, activity.StartedAt);
            Assert.IsTrue(activity.StartedAt <= latest, "StartedAt too late expected before {0} found {1}", latest, activity.StartedAt);
        }
Example #5
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            var timeLaunch = new AutoTimedEventActivity("ApplicationLifecycle", "Launching");
            var rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active

            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                // Associate the frame with a SuspensionManager key
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        // Something went wrong restoring state.
                        // Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(GroupedItemsPage), "AllGroups"))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            // You choose *one* of these two techniques - NOT BOTH - depending on whether your property is a site or an app in GA.

            // AutoAnalytics currently uses Urchin API originally designed for web sites
            await AutoAnalytics.StartAsync(new UrchinConfiguration("UA-319000-10", "sample.csharpanalytics.com"));

            // AutoMeasurement uses the Measurement Protocol API that Google's Native SDKs for iOS and Android use
            await AutoMeasurement.StartAsync(new MeasurementConfiguration("UA-319000-8"));
            
            // Ensure the current window is active
            Window.Current.Activate();

            AutoAnalytics.Client.Track(timeLaunch);
            AutoMeasurement.Client.Track(timeLaunch);
        }
        public void MeasurementAnalyticsClient_Track_Ends_AutoTimedEventActivity()
        {
            var client = new MeasurementAnalyticsClient();
            var autoTimedEvent = new AutoTimedEventActivity("Category", "Variable");

            client.Track(autoTimedEvent);

            Assert.IsNotNull(autoTimedEvent.EndedAt);
        }
        public void AutoTimedEventActivity_Constructor_With_Minimal_Parameters_Sets_Correct_Properties()
        {
            var activity = new AutoTimedEventActivity("category", "variable");

            Assert.AreEqual("category", activity.Category);
            Assert.AreEqual("variable", activity.Variable);
            Assert.IsTrue(activity.Time >= TimeSpan.Zero);

            Assert.IsNull(activity.Label);
        }
        public void AnalyticsClient_Track_Ends_Auto_Timed_Events()
        {
            var client = CreateSampleClient(_ => { });

            var timedEvent = new AutoTimedEventActivity("category", "variable");
            Assert.IsNull(timedEvent.EndedAt);

            client.Track(timedEvent);
            Assert.IsNotNull(timedEvent.EndedAt);
            Assert.IsTrue(timedEvent.EndedAt <= DateTimeOffset.Now);
        }
        public void MeasurementAnalyticsClient_OnTrack_Fires_After_AutoTimedEvent_Ended()
        {
            DateTimeOffset? endedAt = null;
            var analyticsClient = new MeasurementAnalyticsClient();
            var autoTimedEvent = new AutoTimedEventActivity("Category", "Variable");

            analyticsClient.OnTrack += (s, e) => { endedAt = ((AutoTimedEventActivity) e).EndedAt; };
            analyticsClient.Track(autoTimedEvent);

            Assert.IsNotNull(endedAt);
        }
        public void AutoTimedEventActivity_Ends_At_Correct_Time()
        {
            var earliest = DateTimeOffset.Now;
            var activity = new AutoTimedEventActivity("category", "variable");

            activity.End();
            var latest = DateTimeOffset.Now;

            Assert.IsNotNull(activity.EndedAt);
            Assert.IsTrue(activity.EndedAt.Value >= earliest, "EndedAt too early expected after {0} found {1}", earliest, activity.EndedAt.Value);
            Assert.IsTrue(activity.EndedAt.Value <= latest, "EndedAt too late expected before {0} found {1}", latest, activity.EndedAt.Value);
        }