AdjustTest.Pcl.TestActivityHandler.TestDisable C# (CSharp) Method

TestDisable() public method

public TestDisable ( ) : void
return void
        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);
        }