public void TestGetCurrentCredential()
        {
            string     dbname = "TestDB";
            Credential currentCredential;
            IAuthorizationDataService service = new MockAuthDataService();
            var manager = AuthorizationManager.Instance;

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

            Credential cred1 = new Credential(dbname, "fredAstaire", "myPwd");

            currentCredential =
                manager.GetCurrentCredential(dbname);

            Assert.IsNull(currentCredential);

            AuthorizationManager.AddCredential(cred1);

            currentCredential =
                manager.GetCurrentCredential(dbname);

            Assert.IsNotNull(currentCredential);

            Assert.AreEqual(dbname, currentCredential.DatabaseName);
        }
        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);
        }
        public void TestAddCredential()
        {
            Assert.AreEqual(0, AuthorizationLock.Credentials.Count);

            Credential cred1 = new Credential("TestDB", "fredAstaire", "myPwd");

            AuthorizationManager.AddCredential(cred1);

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

            Credential cred2 = new Credential("TestDB", "NewUser", "newPwd");

            AuthorizationManager.AddCredential(cred2);

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

            Credential cred3 = new Credential("NewDB", "NewUser", "newPwd");

            AuthorizationManager.AddCredential(cred3);

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

            AuthorizationLock.Credentials.Clear();
        }