Esempio n. 1
0
        public void TestSessions()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Info);

            // adjust the session intervals for testing
            AdjustFactory.SetSessionInterval(new TimeSpan(0,0,0,0,4000));
            AdjustFactory.SetSubsessionInterval(new TimeSpan(0,0,0,0,1000));

            // create the config to start the session
            AdjustConfig config = new AdjustConfig("123456789012", AdjustConfig.EnvironmentSandbox);

            // start activity handler with config
            ActivityHandler activityHandler = GetActivityHandler(config);

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests("sandbox", "Info", false);

            // test first session start
            CheckFirstSession();

            // trigger a new sub session session
            activityHandler.TrackSubsessionStart();

            // and end it
            activityHandler.TrackSubsessionEnd();

            DeviceUtil.Sleep(5000);

            // test the new sub session
            CheckSubsession(
                sessionCount: 1,
                subsessionCount: 2,
                timerAlreadyStarted: true);

            // test the end of the subsession
            CheckEndSession();

            // trigger a new session
            activityHandler.TrackSubsessionStart();

            DeviceUtil.Sleep(1000);

            // new session
            CheckNewSession(
                paused:false,
                sessionCount: 2,
                eventCount: 0,
                timerAlreadyStarted: true);

            // end the session
            activityHandler.TrackSubsessionEnd();

            DeviceUtil.Sleep(1000);

            // 2 session packages
            Assert.AreEqual(2, MockPackageHandler.PackageQueue.Count);

            ActivityPackage firstSessionActivityPackage = MockPackageHandler.PackageQueue[0];

            // create activity package test
            TestActivityPackage testFirstSessionActivityPackage = new TestActivityPackage(firstSessionActivityPackage);

            // test first session
            testFirstSessionActivityPackage.TestSessionPackage(1);

            // get second session package
            ActivityPackage secondSessionActivityPackage = MockPackageHandler.PackageQueue[1];

            // create second session test package
            TestActivityPackage testSecondSessionActivityPackage = new TestActivityPackage(secondSessionActivityPackage);

            // check if it saved the second subsession in the new package
            testSecondSessionActivityPackage.SubsessionCount = 2;

            // test second session
            testSecondSessionActivityPackage.TestSessionPackage(2);
        }
Esempio n. 2
0
        public void TestFirstSession()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: null);

            // create the config to start the session
            AdjustConfig config = new AdjustConfig("123456789012", AdjustConfig.EnvironmentSandbox);

            // start activity handler with config
            ActivityHandler activityHandler = GetActivityHandler(config);

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests(AdjustConfig.EnvironmentSandbox, "Info", false);

            // test first session start
            CheckFirstSession();

            // checking the default values of the first session package
            // should only have one package
            Assert.AreEqual(1, MockPackageHandler.PackageQueue.Count);

            ActivityPackage activityPackage = MockPackageHandler.PackageQueue[0];

            // create activity package test
            TestActivityPackage testActivityPackage = new TestActivityPackage(activityPackage);

            // set first session
            testActivityPackage.TestSessionPackage(1);
        }
Esempio n. 3
0
        public void TestEventsBuffered()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Verbose);

            // create the config to start the session
            AdjustConfig config = new AdjustConfig("123456789012", AdjustConfig.EnvironmentSandbox);

            // buffer events
            config.EventBufferingEnabled = true;

            // start activity handler with config
            ActivityHandler activityHandler = GetActivityHandler(config);

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests(AdjustConfig.EnvironmentSandbox, "Verbose", true);

            // test first session start
            CheckFirstSession();

            // create the first Event
            AdjustEvent firstEvent = new AdjustEvent("event1");

            // add callback parameters
            firstEvent.AddCallbackParameter("keyCall", "valueCall");
            firstEvent.AddCallbackParameter("keyCall", "valueCall2");
            firstEvent.AddCallbackParameter("fooCall", "barCall");

            // add partner paramters
            firstEvent.AddPartnerParameter("keyPartner", "valuePartner");
            firstEvent.AddPartnerParameter("keyPartner", "valuePartner2");
            firstEvent.AddPartnerParameter("fooPartner", "barPartner");

            // add revenue
            firstEvent.SetRevenue(0.001, "EUR");

            // track event
            activityHandler.TrackEvent(firstEvent);

            // create the second Event
            AdjustEvent secondEvent = new AdjustEvent("event2");

            // add empty revenue
            secondEvent.SetRevenue(0, "USD");

            // track second event
            activityHandler.TrackEvent(secondEvent);

            // create third Event
            AdjustEvent thirdEvent = new AdjustEvent("event3");

            // track third event
            activityHandler.TrackEvent(thirdEvent);

            DeviceUtil.Sleep(3000);

            // test first event
            // check that callback parameter was overwritten
            Assert.Warn("key keyCall was overwritten");

            // check that partner parameter was overwritten
            Assert.Warn("key keyPartner was overwritten");

            // check that event package was added
            Assert.Test("PackageHandler AddPackage");

            // check that event was buffered
            Assert.Info("Buffered event (0.00100 EUR, 'event1')");

            // and not sent to package handler
            Assert.NotTest("PackageHandler SendFirstPackage");

            // after tracking the event it should write the activity state
            Assert.Debug("Wrote Activity state");

            // test second event
            // check that event package was added
            Assert.Test("PackageHandler AddPackage");

            // check that event was buffered
            Assert.Info("Buffered event (0.00000 USD, 'event2')");

            // and not sent to package handler
            Assert.NotTest("PackageHandler SendFirstPackage");

            // after tracking the event it should write the activity state
            Assert.Debug("Wrote Activity state");

            // test third event
            // check that event package was added
            Assert.Test("PackageHandler AddPackage");

            // check that event was buffered
            Assert.Info("Buffered event 'event3'");

            // and not sent to package handler
            Assert.NotTest("PackageHandler SendFirstPackage");

            // after tracking the event it should write the activity state
            Assert.Debug("Wrote Activity state");

            // check the number of activity packages
            // 1 session + 3 events
            Assert.AreEqual(4, MockPackageHandler.PackageQueue.Count);

            ActivityPackage firstSessionPackage = MockPackageHandler.PackageQueue[0];

            // create activity package test
            TestActivityPackage testFirstSessionPackage = new TestActivityPackage(firstSessionPackage);

            // set first session
            testFirstSessionPackage.TestSessionPackage(1);

            // first event
            ActivityPackage firstEventPackage = MockPackageHandler.PackageQueue[1];

            // create event package test
            TestActivityPackage testFirstEventPackage = new TestActivityPackage(firstEventPackage);

            // set event test parameters
            testFirstEventPackage.EventCount = "1";
            testFirstEventPackage.Suffix = "(0.00100 EUR, 'event1')";
            testFirstEventPackage.RevenueString = "0.00100";
            testFirstEventPackage.Currency = "EUR";
            testFirstEventPackage.CallbackParams = "{\"fooCall\":\"barCall\",\"keyCall\":\"valueCall2\"}";
            testFirstEventPackage.PartnerParams = "{\"keyPartner\":\"valuePartner2\",\"fooPartner\":\"barPartner\"}";

            // test first event
            testFirstEventPackage.TestEventPackage("event1");

            // second event
            ActivityPackage secondEventPackage = MockPackageHandler.PackageQueue[2];

            // create event package test
            TestActivityPackage testSecondEventPackage = new TestActivityPackage(secondEventPackage);

            // set event test parameters
            testSecondEventPackage.EventCount = "2";
            testSecondEventPackage.Suffix = "(0.00000 USD, 'event2')";
            testSecondEventPackage.RevenueString = "0.00000";
            testSecondEventPackage.Currency = "USD";

            // test second event
            testSecondEventPackage.TestEventPackage("event2");

            // third event
            ActivityPackage thirdEventPackage = MockPackageHandler.PackageQueue[3];

            // create event package test
            TestActivityPackage testThirdEventPackage = new TestActivityPackage(thirdEventPackage);

            // set event test parameters
            testThirdEventPackage.EventCount = "3";
            testThirdEventPackage.Suffix = "'event3'";

            // test third event
            testThirdEventPackage.TestEventPackage("event3");
        }
Esempio n. 4
0
        public void TestFinishedTrackingActivity()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Verbose);

            // create the config to start the session
            AdjustConfig config = new AdjustConfig(appToken: "123456789012", environment: AdjustConfig.EnvironmentProduction);

            config.AttributionChanged = (attribution) => MockLogger.Test("AttributionChanged: {0}", attribution);

            // start activity handler with config
            ActivityHandler activityHandler = GetActivityHandler(config);

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests(environment: "production" , logLevel: "Assert");

            // test first session start
            CheckFirstSession();

            Dictionary<string, string> responseNull = null;

            activityHandler.FinishedTrackingActivity(responseNull);
            DeviceUtil.Sleep(1000);

            // if the response is null
            Assert.NotError("Malformed deeplink");
            Assert.NotInfo("Open deep link");

            // set package handler to respond with a valid attribution
            var malformedDeeplinkResponse = new Dictionary<string, string> {{"deeplink" , "<malformedUrl>"}};

            activityHandler.FinishedTrackingActivity(malformedDeeplinkResponse);
            DeviceUtil.Sleep(1000);

            // check that it was unable to open the url
            Assert.Error("Malformed deeplink '<malformedUrl>'");

            // checking the default values of the first session package
            // should only have one package
            Assert.AreEqual(1, MockPackageHandler.PackageQueue.Count);

            ActivityPackage activityPackage = MockPackageHandler.PackageQueue[0];

            // create activity package test
            TestActivityPackage testActivityPackage = new TestActivityPackage(activityPackage)
            {
                NeedsAttributionData = true,
                Environment = "production",
            };

            // set first session
            testActivityPackage.TestSessionPackage(sessionCount: 1);
        }
Esempio n. 5
0
        public void TestDisable()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Error);

            // adjust the session intervals for testing
            AdjustFactory.SetSessionInterval(new TimeSpan(0,0,0,0,4000));
            AdjustFactory.SetSubsessionInterval(new TimeSpan(0,0,0,0,1000));

            // create the config to start the session
            AdjustConfig config = new AdjustConfig(appToken: "123456789012", environment: AdjustConfig.EnvironmentSandbox);

            // start activity handler with config
            ActivityHandler activityHandler = GetActivityHandler(config);

            // check that is true by default
            Assert.IsTrue(activityHandler.IsEnabled());

            // disable sdk
            activityHandler.SetEnabled(false);

            // check that it is disabled
            Assert.IsFalse(activityHandler.IsEnabled());

            // not writing activity state because it did not had time to start
            Assert.NotDebug("Wrote Activity state");

            // check if message the disable of the SDK
            Assert.Info("Pausing package and attribution handler to disable the SDK");

            // it's necessary to sleep the activity for a while after each handler call
            // to let the internal queue act
            DeviceUtil.Sleep(2000);

            // test init values
            InitTests(environment: "sandbox", logLevel: "Error");

            // test first session start without attribution handler
            CheckFirstSession(paused: true);

            // test end session of disable
            CheckEndSession();

            // try to do activities while SDK disabled
            activityHandler.TrackSubsessionStart();
            activityHandler.TrackEvent(new AdjustEvent("event1"));

            DeviceUtil.Sleep(3000);

            // check that timer was not executed
            CheckTimerIsFired(false);

            // check that it did not resume
            Assert.NotTest("PackageHandler ResumeSending");

            // check that it did not wrote activity state from new session or subsession
            Assert.NotDebug("Wrote Activity state");

            // check that it did not add any event package
            Assert.NotTest("PackageHandler AddPackage");

            // only the first session package should be sent
            Assert.AreEqual(1, MockPackageHandler.PackageQueue.Count);

            // put in offline mode
            activityHandler.SetOfflineMode(true);

            // pausing due to offline mode
            Assert.Info("Pausing package and attribution handler to put in offline mode");

            // wait to update status
            DeviceUtil.Sleep(6000);

            // test end session of offline
            CheckEndSession(updateActivityState: false);

            // re-enable the SDK
            activityHandler.SetEnabled(true);

            // check that it is enabled
            Assert.IsTrue(activityHandler.IsEnabled());

            // check message of SDK still paused
            Assert.Info("Package and attribution handler remain paused due to the SDK is offline");

            activityHandler.TrackSubsessionStart();
            DeviceUtil.Sleep(1000);

            CheckNewSession(paused: true, sessionCount: 2);

            // and that the timer is not fired
            CheckTimerIsFired(false);

            // track an event
            activityHandler.TrackEvent(new AdjustEvent("event1"));

            // and that the timer is not fired
            DeviceUtil.Sleep(1000);

            // check that it did add the event package
            Assert.Test("PackageHandler AddPackage");

            // and send it
            Assert.Test("PackageHandler SendFirstPackage");

            // it should have the second session and the event
            Assert.AreEqual(3, MockPackageHandler.PackageQueue.Count);

            ActivityPackage secondSessionPackage = MockPackageHandler.PackageQueue[1];

            // create activity package test
            TestActivityPackage testSecondSessionPackage = new TestActivityPackage(secondSessionPackage);

            // set the sub sessions
            testSecondSessionPackage.SubsessionCount = 1;

            // test second session
            testSecondSessionPackage.TestSessionPackage(sessionCount: 2);

            ActivityPackage eventPackage = MockPackageHandler.PackageQueue[2];

            // create activity package test
            TestActivityPackage testEventPackage = new TestActivityPackage(eventPackage);

            testEventPackage.Suffix = "'event1'";

            // test event
            testEventPackage.TestEventPackage(eventToken: "event1");

            // put in online mode
            activityHandler.SetOfflineMode(false);

            // message that is finally resuming
            Assert.Info("Resuming package and attribution handler to put in online mode");

            DeviceUtil.Sleep(6000);

            // check status update
            Assert.Test("AttributionHandler ResumeSending");
            Assert.Test("PackageHandler ResumeSending");

            // track sub session
            activityHandler.TrackSubsessionStart();

            DeviceUtil.Sleep(1000);

            // test session not paused
            CheckNewSession(paused: false, sessionCount: 3, eventCount: 1, timerAlreadyStarted: true);
        }