Ejemplo n.º 1
0
        [Ignore] // TODO Not certain how this test is supposed to work")]
        public async Task ErrorThrownWhenTimerIsTriggered()
        {
            // token updater is triggered every 5 seconds
            TestState       state           = new TestState("0");
            TokenCredential tokenCredential = new TokenCredential("0", BrokenTokenUpdater, state, TimeSpan.FromSeconds(5));

            // make sure the token starts with the right value, t=0
            Assert.AreEqual("0", tokenCredential.Token);

            // wait until timer triggers for the first time and validate token value, t=6
            await Task.Delay(TimeSpan.FromSeconds(6));

            Assert.AreEqual("0", tokenCredential.Token);

            // wait until timer triggers for the second time and validate token value, 6=12
            await Task.Delay(TimeSpan.FromSeconds(6));

            Assert.AreEqual("0", tokenCredential.Token);

            // stop the time and make sure it does not trigger anymore, t=18
            tokenCredential.Dispose();
            await Task.Delay(TimeSpan.FromSeconds(6));

            Assert.AreEqual("0", tokenCredential.Token);
        }
Ejemplo n.º 2
0
        public void UpdaterShouldRunOneAtATime()
        {
            // token updater is triggered every 5 seconds
            // however, the slow updater takes 10 seconds to provide a new token
            TestState       state           = new TestState("0");
            TokenCredential tokenCredential = new TokenCredential("0", SlowTokenUpdater, state, TimeSpan.FromSeconds(5));

            // make sure the token starts with the right value, t=0
            Assert.AreEqual("0", tokenCredential.Token);

            // check on the token while updater is running, t=6
            Task.Delay(TimeSpan.FromSeconds(6)).Wait();
            Assert.AreEqual("0", tokenCredential.Token);

            // check on the token after updater is done for the first time, t=16
            // the first updater should have finished at t=15
            Task.Delay(TimeSpan.FromSeconds(10)).Wait();
            Assert.AreEqual("00", tokenCredential.Token);

            // check on the token while updater is running, t=22
            // the second updater should have been triggered at t=20
            Task.Delay(TimeSpan.FromSeconds(6)).Wait();
            Assert.AreEqual("00", tokenCredential.Token);

            // check on the token after updater is done for the second time, t=32
            // the second updater should have finished at t=30
            Task.Delay(TimeSpan.FromSeconds(10)).Wait();
            Assert.AreEqual("000", tokenCredential.Token);

            // stop the timer and make sure it is not triggered anymore, t=50
            tokenCredential.Dispose();
            Task.Delay(TimeSpan.FromSeconds(18)).Wait();
            Assert.AreEqual("000", tokenCredential.Token);
        }
Ejemplo n.º 3
0
        public void TimerShouldTriggerPeriodically()
        {
            // token updater is triggered every 5 seconds
            TestState       state           = new TestState("0");
            TokenCredential tokenCredential = new TokenCredential("0", FastTokenUpdater, state, TimeSpan.FromSeconds(5));

            // make sure the token starts with the right value, t=0
            Assert.AreEqual("0", tokenCredential.Token);

            // wait until timer triggers for the first time and validate token value, t=6
            Task.Delay(TimeSpan.FromSeconds(6)).Wait();
            Assert.AreEqual("00", tokenCredential.Token);

            // wait until timer triggers for the second time and validate token value, t=12
            Task.Delay(TimeSpan.FromSeconds(6)).Wait();
            Assert.AreEqual("000", tokenCredential.Token);

            // stop the time and make sure it does not trigger anymore, t=18
            tokenCredential.Dispose();
            Task.Delay(TimeSpan.FromSeconds(6)).Wait();
            Assert.AreEqual("000", tokenCredential.Token);
        }
Ejemplo n.º 4
0
        public void TokenDispose()
        {
            TokenCredential token = new TokenCredential("TOKEN_STRING");

            token.Dispose();
        }