예제 #1
0
        public void UpdaterShouldRunOneAtATime()
        {
            // token updater is triggered every 5 seconds
            // however, the slow updater takes 10 seconds to provide a new token
            var tokenCredential = new TokenCredentials("", SlowTokenUpdater);

            // 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(1.2)).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(2)).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(1.2)).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(2)).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(3.6)).Wait();
            Assert.AreEqual("000", tokenCredential.Token);
        }
예제 #2
0
        public void TimerShouldTriggerPeriodically()
        {
            // token updater is triggered every 5 seconds
            var tokenCredential = new TokenCredentials("", FastTokenUpdater);

            // 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(1.2)).Wait();
            Assert.AreEqual("00", tokenCredential.Token);

            // wait until timer triggers for the second time and validate token value, t=12
            Task.Delay(TimeSpan.FromSeconds(1.2)).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(1.2)).Wait();
            Assert.AreEqual("000", tokenCredential.Token);
        }
예제 #3
0
        public async Task ErrorThrownWhenTimerIsTriggered()
        {
            var tokenCredential = new TokenCredentials("0", BrokenTokenUpdater);

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

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

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

            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(1));

            Assert.AreEqual("0", tokenCredential.Token);
        }
예제 #4
0
        public void TokenDispose()
        {
            var token = new TokenCredentials("TOKEN_STRING");

            token.Dispose();
        }