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

TestOfflineMode() public method

public TestOfflineMode ( ) : void
return void
        public void TestOfflineMode()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: null);

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

            // 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);

            // put SDK offline
            activityHandler.SetOfflineMode(true);

            DeviceUtil.Sleep(3000);

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

            // test init values
            InitTests();

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

            // test end session logs
            CheckEndSession();

            // disable the SDK
            activityHandler.SetEnabled(false);

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

            DeviceUtil.Sleep(1000);

            // writing activity state after disabling
            Assert.Debug("Wrote Activity state: ec:0 sc:1 ssc:1");

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

            DeviceUtil.Sleep(1000);

            // test end session logs
            CheckEndSession(updateActivityState: false);

            // put SDK back online
            activityHandler.SetOfflineMode(false);

            Assert.Info("Package and attribution handler remain paused because the SDK is disabled");

            DeviceUtil.Sleep(1000);

            // test the update status, still paused
            Assert.NotTest("AttributionHandler PauseSending");
            Assert.NotTest("PackageHandler PauseSending");

            DeviceUtil.Sleep(3000);

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

            DeviceUtil.Sleep(1000);

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

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

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

            // enable the SDK again
            activityHandler.SetEnabled(true);

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

            DeviceUtil.Sleep(1000);

            // test that is not paused anymore
            CheckNewSession(paused: false, sessionCount: 2);
        }