public void Tracking_GetInheritedEngine()
        {
            var engine = TrackingEngine.GetEngine(() => Tracking_GetInheritedEngine());

            Assert.IsNotNull(engine);
            Assert.IsInstanceOfType(engine, typeof(UniversalAnalytics));
        }
        public void Tracking_SetUserAgent()
        {
            var engine = TrackingEngine.GetEngine(() => Tracking_SetUserAgent());

            Assert.IsNotNull(engine);
            Assert.IsInstanceOfType(engine, typeof(UniversalAnalytics));

            var oldUserAgent = engine.UserAgent;

            engine.UpdateUserAgent("SierraLib.Analytics.Test", "1.0.0", "CustomUA");
            Assert.IsTrue(engine.UserAgent.IndexOf("CustomUA") != -1, "Custom UserAgent not propagated");
            engine.UserAgent = oldUserAgent;
            Assert.AreEqual(oldUserAgent, engine.UserAgent);
        }
        public void Tracking_Serialization()
        {
            var engine  = TrackingEngine.GetEngine(() => Tracking_Serialization()) as UniversalAnalytics;
            var request = new RestRequest()
            {
                Resource = "/collect",
                Method   = Method.POST
            };

            request.AddParameter("q", "Test", ParameterType.GetOrPost);
            request.AddParameter("r", "Yargh!", ParameterType.GetOrPost);
            var pendingRequest = new PreparedTrackingRequest(engine, request, Array.Empty <Implementation.ITrackingFinalize>());
            var formatter      = new BinaryFormatter();

            PreparedTrackingRequest deserialized = null;

            using (var ms = new MemoryStream())
            {
                formatter.Serialize(ms, pendingRequest);
                ms.Seek(0, SeekOrigin.Begin);
                deserialized = formatter.Deserialize(ms) as PreparedTrackingRequest;
            }

            Assert.IsNotNull(deserialized);
            Assert.IsNotNull(deserialized.Request);
            Assert.AreEqual(pendingRequest.Generated, deserialized.Generated);
            Assert.AreEqual(pendingRequest.Engine, deserialized.Engine);

            Assert.AreEqual(pendingRequest.Request.Parameters.Count, request.Parameters.Count);
            for (int i = 0; i < pendingRequest.Request.Parameters.Count; i++)
            {
                var got      = pendingRequest.Request.Parameters[i];
                var expected = request.Parameters[i];
                Assert.AreEqual(expected.Type, got.Type);
                Assert.AreEqual(expected.Name, got.Name);
                Assert.AreEqual(expected.Value, got.Value);
            }
        }