Example #1
0
        /// <summary>
        ///     Sets the timer to reset the user credentials.
        /// </summary>
        /// <externalUnit/>
        /// <revision revisor="dev14" date="3/9/2010" version="1.1.7.01">
        ///     Member Created
        /// </revision>
        /// <revision revisor="dev14" date="4/8/2010" version="1.1.7">
        ///     Removed Logging of timer set
        /// </revision>
        private void SetTimer()
        {
            // TODO: Change this so it is not so easily changed - dev14 3/3
            // get the timeout from the web config
            Int32.TryParse(
                ConfigurationManager.AppSettings["AuthorizationTimeout"],
                out this.timeoutMinutes);

            // convert the timeout minutes to milliseconds
            int interval = this.timeoutMinutes * MIN_TO_MSEC;

            // add the reset timer
            resetTimer = new AuthorizationReset(dataService, 0, interval);
        }
        public void TestCreateTimer()
        {
            const int wait     = 0;
            const int interval = 1000;

            string dbname   = "TestDB";
            string username = "******";
            string password = "******";

            // lock the authorization
            Assert.IsTrue(AuthorizationLock.Credentials.Count == 0);

            var cred1 = new Credential(dbname, username, password);

            AuthorizationManager.AddCredential(cred1);

            Assert.AreEqual(1, AuthorizationLock.Credentials.Count);

            // create a timer
            var reset = new AuthorizationReset(new AuthorizationDataService(), wait, interval);

            // make sure timer created
            Assert.IsNotNull(reset);

            var savedCredential = AuthorizationLock.Credentials[0];

            Assert.AreEqual(dbname, savedCredential.DatabaseName);
            Assert.AreEqual(username, savedCredential.CurrentUser);
            Assert.AreEqual(password, savedCredential.CurrentPassword);

            // sleep the given time before timer should fire
            Thread.Sleep(interval);

            // assert that the authorization is not still locked
            var newCredential = AuthorizationLock.Credentials[0];

            Assert.AreEqual(dbname, newCredential.DatabaseName);
            Assert.AreNotEqual(username, newCredential.CurrentUser);
        }