public void an_exception_should_be_throw()
            {
                StateManager.ResetStateManager();

                var lockedClientAccount = new LockedClientAccount { ClientAccountId = 123, MethodCalled = "test" };

                StateManager.LockClientAccount(lockedClientAccount);

                var newClientAccountLockRequest = new LockedClientAccount { ClientAccountId = 123, MethodCalled = "test" };

                Assert.Throws<ArgumentException>(() => StateManager.LockClientAccount(newClientAccountLockRequest));
            }
        public static void LockClientAccount(LockedClientAccount clientAccount)
        {
            if (clientAccount == null)
                throw new ArgumentNullException("clientAccount", "clientAccount cannot be null");

            if (_clientAccounts == null)
                _clientAccounts = new Dictionary<int, LockedClientAccount>();

            if (_clientAccounts.ContainsKey(clientAccount.ClientAccountId))
                throw new ArgumentException(string.Format("ClientAccountID {0} is already locked", clientAccount.ClientAccountId), "clientAccount");

            _clientAccounts.Add(clientAccount.ClientAccountId, clientAccount);
        }
            public void the_client_account_should_be_locked_during_and_unlocked_after()
            {
                StateManager.ResetStateManager();

                using (var lockedClientAccount = new ClientAccountLock(123))
                {
                    Assert.NotNull(lockedClientAccount);

                    Assert.True(StateManager.IsClientAccountIDLocked(lockedClientAccount.ClientAccountId));

                    var newLock = new LockedClientAccount { ClientAccountId = 123, MethodCalled = "Test" };

                    Assert.Throws<ArgumentException>(() => StateManager.LockClientAccount(newLock));
                }

                Assert.False(StateManager.IsClientAccountIDLocked(123));
            }
            public void true_will_be_returned_for_a_client_account_that_is_locked()
            {
                StateManager.ResetStateManager();

                var clientAccount = new LockedClientAccount { ClientAccountId = 123, ClientName = "Test", MethodCalled = "Testmethod" };

                StateManager.LockClientAccount(clientAccount);

                Assert.True(StateManager.IsClientAccountIDLocked(123));
            }
            public void return_true_without_exception()
            {
                StateManager.ResetStateManager();

                var clientAccount = new LockedClientAccount { ClientAccountId = 123, ClientName = "Test" };

                var result = false;

                Assert.DoesNotThrow(() => result = StateManager.UnlockClientAccount(clientAccount.ClientAccountId));

                Assert.True(result);
            }
            public void the_clientaccount_will_be_unlocked_and_no_longer_retrievable()
            {
                StateManager.ResetStateManager();

                var clientAccount = new LockedClientAccount { ClientAccountId = 123, ClientName = "Test" };

                StateManager.LockClientAccount(clientAccount);

                Assert.NotNull(StateManager.GetClientAccount(clientAccount.ClientAccountId));

                Assert.True(StateManager.UnlockClientAccount(clientAccount.ClientAccountId));

                Assert.Null(StateManager.GetClientAccount(clientAccount.ClientAccountId));
            }
            public void the_method_called_should_be_retrievable_from_the_clientaccount_object()
            {
                StateManager.ResetStateManager();

                var methodName = MethodBase.GetCurrentMethod().Name;
                Console.WriteLine("Thread ID: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);

                var clientAccount = new LockedClientAccount { ClientAccountId = 123, ClientName = "Test", MethodCalled = methodName };

                StateManager.LockClientAccount(clientAccount);

                Assert.Equal(methodName, StateManager.GetClientAccount(123).MethodCalled);
            }
            public void the_clientaccount_is_stored_and_retrievable()
            {
                StateManager.ResetStateManager();

                var clientAccount = new LockedClientAccount { ClientAccountId = 123, ClientName = "Test" };

                Assert.DoesNotThrow(() => StateManager.LockClientAccount(clientAccount));

                Assert.DoesNotThrow(() => StateManager.GetClientAccount(clientAccount.ClientAccountId));
            }
            public void can_return_that_clientaccount_after_it_has_been_stored()
            {
                StateManager.ResetStateManager();

                var clientAccount = new LockedClientAccount { ClientAccountId = 123, ClientName = "Test" };

                Assert.DoesNotThrow(() => StateManager.LockClientAccount(clientAccount));

                var result = StateManager.GetClientAccount(clientAccount.ClientAccountId);

                Assert.Equal(clientAccount.ClientAccountId, result.ClientAccountId);
                Assert.Equal(clientAccount.ClientName, result.ClientName);
            }
            public void an_exception_will_be_thrown()
            {
                StateManager.ResetStateManager();

                var lockedClientAccount = new LockedClientAccount { ClientAccountId = 123, ClientName = "Test" };

                Assert.DoesNotThrow(() => StateManager.LockClientAccount(lockedClientAccount));

                Assert.DoesNotThrow(() => StateManager.GetClientAccount(lockedClientAccount.ClientAccountId));

                var newLockClientAccount = new LockedClientAccount { ClientAccountId = 123, ClientName = "Test" };

                ArgumentException ex = null;

                ex = Assert.Throws<ArgumentException>(() => StateManager.LockClientAccount(newLockClientAccount));

                Assert.True(ex.Message.IndexOf(string.Format("ClientAccountID {0} is already locked", newLockClientAccount.ClientAccountId)) > -1);
            }