public void Add()
        {
            var functionStateManager = new WxeFunctionStateManager(_session);

            functionStateManager.Add(_functionState);

            Assert.That(_session[GetSessionKeyForFunctionState()], Is.SameAs(_functionState));
        }
        public void IsExpired_DelaysForOneMinute()
        {
            WxeFunctionState        functionState        = new WxeFunctionState(new TestFunction(), 1, true);
            WxeFunctionStateManager functionStateManager = new WxeFunctionStateManager(_session);

            functionStateManager.Add(functionState);
            Assert.That(functionStateManager.IsExpired(functionState.FunctionToken), Is.False);
            Thread.Sleep(61000);
            Assert.That(functionStateManager.IsExpired(functionState.FunctionToken), Is.True);
        }
        public void Touch()
        {
            WxeFunctionStateManager functionStateManager = new WxeFunctionStateManager(_session);

            functionStateManager.Add(_functionState);
            DateTime lastAccess = functionStateManager.GetLastAccess(_functionState.FunctionToken);

            Thread.Sleep(1000);
            functionStateManager.Touch(_functionState.FunctionToken);
            Assert.Greater(functionStateManager.GetLastAccess(_functionState.FunctionToken), lastAccess);
        }
        public void CleanupExpired_DelaysForOneMinute()
        {
            WxeFunctionState        functionStateExpired    = new WxeFunctionState(new TestFunction(), 1, true);
            WxeFunctionState        functionStateNotExpired = new WxeFunctionState(new TestFunction(), 10, true);
            WxeFunctionStateManager functionStateManager    = new WxeFunctionStateManager(_session);

            functionStateManager.Add(functionStateExpired);
            functionStateManager.Add(functionStateNotExpired);

            var resultBeforeExpiration = functionStateManager.CleanUpExpired();

            Assert.That(resultBeforeExpiration, Is.EqualTo(2));

            Thread.Sleep(61000);

            Assert.That(functionStateManager.IsExpired(functionStateExpired.FunctionToken), Is.True);
            Assert.That(functionStateManager.IsExpired(functionStateNotExpired.FunctionToken), Is.False);

            var resultAfterExpiration = functionStateManager.CleanUpExpired();

            Assert.That(resultAfterExpiration, Is.EqualTo(1));
            Assert.That(functionStateManager.IsExpired(functionStateNotExpired.FunctionToken), Is.False);
            Assert.That(_session[GetSessionKeyForFunctionState(functionStateExpired.FunctionToken)], Is.Null);
        }