示例#1
0
        public void SetUp()
        {
            _mockRepository = new MockRepository();

            _rootFunction = new TestFunction();
            _subFunction  = _mockRepository.PartialMock <TestFunction>();

            _httpContextMock  = _mockRepository.DynamicMock <HttpContextBase>();
            _pageExecutorMock = _mockRepository.StrictMock <IWxePageExecutor>();
            _functionState    = new WxeFunctionState(_rootFunction, true);

            _pageStep = _mockRepository.PartialMock <WxePageStep> ("ThePage");
            _pageStep.SetPageExecutor(_pageExecutorMock);

            _pageMock           = _mockRepository.DynamicMock <IWxePage>();
            _postBackCollection = new NameValueCollection {
                { "Key", "Value" }
            };
            _wxeHandler = new WxeHandler();

            UrlMappingConfiguration.Current.Mappings.Add(new UrlMappingEntry(_rootFunction.GetType(), "~/root.wxe"));
            UrlMappingConfiguration.Current.Mappings.Add(new UrlMappingEntry(_subFunction.GetType(), "~/sub.wxe"));

            _functionStateManager = new WxeFunctionStateManager(new FakeHttpSessionStateBase());
            _wxeContext           = new WxeContext(_httpContextMock, _functionStateManager, _functionState, new NameValueCollection());
        }
        public WxeContext CreateContext(WxeFunction rootFunction)
        {
            HttpContextBase         httpContext          = MockRepository.GenerateStub <HttpContextBase> ();
            WxeFunctionStateManager functionStateManager = new WxeFunctionStateManager(MockRepository.GenerateStub <HttpSessionStateBase> ());
            WxeFunctionState        functionState        = new WxeFunctionState(rootFunction, false);
            NameValueCollection     queryString          = new NameValueCollection();

            return(new WxeContext(httpContext, functionStateManager, functionState, queryString));
        }
        public void GetItem()
        {
            _session.Add(GetSessionKeyForFunctionState(), _functionState);

            var functionStateManager = new WxeFunctionStateManager(_session);
            WxeFunctionState actual  = functionStateManager.GetItem(_functionState.FunctionToken);

            Assert.That(actual, 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 RetrieveMissingFunctionStateWithTypeFromMapping()
        {
            HttpContext context = HttpContextHelper.CreateHttpContext("GET", "Test.wxe", null);

            UrlMappingConfiguration.Current.Mappings.Add(new UrlMappingEntry(_functionType, "~/Test.wxe"));

            WxeFunctionState functionState = _wxeHandler.ResumeExistingFunctionState(context, c_functionTokenForMissingFunctionState);

            Assert.That(functionState, Is.Not.Null);
            Assert.That(functionState.Function.GetType(), Is.EqualTo(_functionType));
        }
        public void AbortExistingFunctionStateMissingFunction()
        {
            NameValueCollection queryString = new NameValueCollection();

            queryString.Set(WxeHandler.Parameters.WxeAction, WxeHandler.Actions.Abort);
            HttpContextHelper.SetQueryString(CurrentHttpContext, queryString);

            WxeFunctionState functionState =
                _wxeHandler.ResumeExistingFunctionState(CurrentHttpContext, c_functionTokenForFunctionStateWithMissingFunction);

            Assert.That(functionState, Is.Null);
            Assert.That(_functionStateWithMissingFunction.IsAborted, Is.True);
        }
        public void CreateNewFunctionStateState()
        {
            WxeFunctionState functionState = _wxeHandler.CreateNewFunctionState(CurrentHttpContext, _functionType);

            Assert.That(functionState, Is.Not.Null);
            Assert.That(functionState.FunctionToken, Is.Not.Null);
            Assert.That(functionState.Function, Is.Not.Null);
            Assert.That(functionState.Function.GetType(), Is.EqualTo(_functionType));
            Assert.That(functionState.Function.ReturnUrl, Is.EqualTo(TestFunction.ReturnUrlValue));

            WxeFunctionState expiredFunctionState = WxeFunctionStateManager.Current.GetItem(c_functionTokenForExpiredFunctionState);

            Assert.That(expiredFunctionState, Is.Null);
        }
        public void RetrieveMissingFunctionStateWithTypeFromQueryString()
        {
            HttpContext         context     = HttpContextHelper.CreateHttpContext("GET", "Test.wxe", null);
            NameValueCollection queryString = new NameValueCollection();

            queryString.Add(WxeHandler.Parameters.WxeFunctionType, _functionTypeName);
            HttpContextHelper.SetQueryString(context, queryString);

            Remotion.Web.ExecutionEngine.UrlMapping.UrlMappingConfiguration.SetCurrent(null);

            WxeFunctionState functionState = _wxeHandler.ResumeExistingFunctionState(context, c_functionTokenForMissingFunctionState);

            Assert.That(functionState, Is.Not.Null);
            Assert.That(functionState.Function.GetType(), Is.EqualTo(typeof(TestFunction)));
        }
        public void AbortExistingFunctionState()
        {
            NameValueCollection queryString = new NameValueCollection();

            queryString.Set(WxeHandler.Parameters.WxeAction, WxeHandler.Actions.Abort);
            HttpContextHelper.SetQueryString(CurrentHttpContext, queryString);

            WxeFunctionState functionState = _wxeHandler.ResumeExistingFunctionState(CurrentHttpContext, c_functionTokenForFunctionStateWithEnabledCleanUp);

            Assert.That(functionState, Is.Null);
            Assert.That(_functionStateWithEnabledCleanUp.IsAborted, Is.True);

            WxeFunctionState expiredFunctionState = WxeFunctionStateManager.Current.GetItem(c_functionTokenForExpiredFunctionState);

            Assert.That(expiredFunctionState, Is.Null);
        }
示例#10
0
        public void SetUp()
        {
            _mockRepository = new MockRepository();

            _rootFunction = new TestFunction();
            _subFunction  = _mockRepository.PartialMock <TestFunction>();

            _httpContextMock  = _mockRepository.DynamicMock <HttpContextBase>();
            _pageExecutorMock = _mockRepository.StrictMock <IWxePageExecutor>();
            _functionState    = new WxeFunctionState(_rootFunction, true);

            _pageStep = _mockRepository.PartialMock <WxePageStep> ("ThePage");
            _pageStep.SetPageExecutor(_pageExecutorMock);

            _functionStateManager = new WxeFunctionStateManager(new FakeHttpSessionStateBase());
            _wxeContext           = new WxeContext(_httpContextMock, _functionStateManager, _functionState, new NameValueCollection());
        }
        public void RetrieveExistingFunctionState()
        {
            DateTime timeBeforeRefresh = DateTime.Now;

            Thread.Sleep(20);

            WxeFunctionState functionState = _wxeHandler.ResumeExistingFunctionState(CurrentHttpContext, c_functionTokenForFunctionStateWithEnabledCleanUp);

            Assert.That(functionState, Is.SameAs(_functionStateWithEnabledCleanUp));
            Assert.That(WxeFunctionStateManager.Current.GetLastAccess(c_functionTokenForFunctionStateWithEnabledCleanUp) > timeBeforeRefresh, Is.True);
            Assert.That(functionState.IsAborted, Is.False);
            Assert.That(WxeFunctionStateManager.Current.IsExpired(c_functionTokenForFunctionStateWithEnabledCleanUp), Is.False);

            WxeFunctionState expiredFunctionState = WxeFunctionStateManager.Current.GetItem(c_functionTokenForExpiredFunctionState);

            Assert.That(expiredFunctionState, Is.Null);
        }
示例#12
0
        public void SetUp()
        {
            _mockRepository = new MockRepository();

            _rootFunction = new TestFunction();
            PrivateInvoke.InvokeNonPublicMethod(_rootFunction, "SetFunctionToken", "RootFunction");

            _subFunction = _mockRepository.PartialMock <TestFunction>();

            _httpContextMock  = _mockRepository.DynamicMock <HttpContextBase>();
            _pageExecutorMock = _mockRepository.StrictMock <IWxePageExecutor>();
            _functionState    = new WxeFunctionState(_rootFunction, true);

            _pageStep = _mockRepository.PartialMock <WxePageStep> ("ThePage");
            _pageStep.SetPageExecutor(_pageExecutorMock);
            _rootFunction.Add(_pageStep);

            _pageMock           = _mockRepository.DynamicMock <IWxePage>();
            _postBackCollection = new NameValueCollection {
                { "Key", "Value" }
            };
            _wxeHandler = new WxeHandler();

            UrlMappingConfiguration.Current.Mappings.Add(new UrlMappingEntry(_rootFunction.GetType(), "~/root.wxe"));
            UrlMappingConfiguration.Current.Mappings.Add(new UrlMappingEntry(_subFunction.GetType(), "~/sub.wxe"));

            _functionStateManager = new WxeFunctionStateManager(new FakeHttpSessionStateBase());

            Uri uri = new Uri("http://localhost/root.wxe");

            _responseMock = _mockRepository.StrictMock <HttpResponseBase>();
            _responseMock.Stub(stub => stub.ApplyAppPathModifier("~/sub.wxe")).Return("/session/sub.wxe").Repeat.Any();
            _responseMock.Stub(stub => stub.ApplyAppPathModifier("/session/sub.wxe")).Return("/session/sub.wxe").Repeat.Any();
            _responseMock.Stub(stub => stub.ApplyAppPathModifier("~/root.wxe")).Return("/session/root.wxe").Repeat.Any();
            _responseMock.Stub(stub => stub.ApplyAppPathModifier("/session/root.wxe")).Return("/session/root.wxe").Repeat.Any();
            _responseMock.Stub(stub => stub.ContentEncoding).Return(Encoding.Default).Repeat.Any();
            _httpContextMock.Stub(stub => stub.Response).Return(_responseMock).Repeat.Any();

            _requestMock = _mockRepository.StrictMock <HttpRequestBase>();
            _requestMock.Stub(stub => stub.Url).Return(uri).Repeat.Any();
            _httpContextMock.Stub(stub => stub.Request).Return(_requestMock).Repeat.Any();

            _wxeContext = new WxeContext(_httpContextMock, _functionStateManager, _functionState, new NameValueCollection());
            WxeContextMock.SetCurrent(_wxeContext);
        }
        public void RefreshExistingFunctionState()
        {
            NameValueCollection queryString = new NameValueCollection();

            queryString.Set(WxeHandler.Parameters.WxeAction, WxeHandler.Actions.Refresh);
            HttpContextHelper.SetQueryString(CurrentHttpContext, queryString);

            DateTime timeBeforeRefresh = DateTime.Now;

            Thread.Sleep(20);

            WxeFunctionState functionState = _wxeHandler.ResumeExistingFunctionState(CurrentHttpContext, c_functionTokenForFunctionStateWithEnabledCleanUp);

            Assert.That(functionState, Is.Null);
            Assert.That(WxeFunctionStateManager.Current.GetLastAccess(c_functionTokenForFunctionStateWithEnabledCleanUp) > timeBeforeRefresh, Is.True);
            Assert.That(_functionStateWithEnabledCleanUp.IsAborted, Is.False);
            Assert.That(WxeFunctionStateManager.Current.IsExpired(c_functionTokenForFunctionStateWithEnabledCleanUp), Is.False);
        }
        public void CreateNewFunctionStateStateWithReturnToSelf()
        {
            NameValueCollection queryString = new NameValueCollection();

            queryString.Set(WxeHandler.Parameters.WxeReturnToSelf, "True");
            HttpContextHelper.SetQueryString(CurrentHttpContext, queryString);

            WxeFunctionState functionState = _wxeHandler.CreateNewFunctionState(CurrentHttpContext, _functionType);

            Assert.That(functionState, Is.Not.Null);
            Assert.That(functionState.FunctionToken, Is.Not.Null);
            Assert.That(functionState.Function, Is.Not.Null);
            Assert.That(functionState.Function.GetType(), Is.EqualTo(_functionType));
            Assert.That(functionState.Function.ReturnUrl, Is.EqualTo(CurrentHttpContext.Request.RawUrl));

            WxeFunctionState expiredFunctionState = WxeFunctionStateManager.Current.GetItem(c_functionTokenForExpiredFunctionState);

            Assert.That(expiredFunctionState, Is.Null);
        }
示例#15
0
        public virtual void SetUp()
        {
            _mockRepository            = new MockRepository();
            _executionStateContextMock = MockRepository.StrictMock <IExecutionStateContext>();

            _rootFunction = new TestFunction("Value");
            _subFunction  = CreateSubFunction();

            _httpContextMock = MockRepository.DynamicMock <HttpContextBase>();
            _functionState   = new WxeFunctionState(_rootFunction, true);

            _responseMock = MockRepository.StrictMock <HttpResponseBase>();
            _httpContextMock.Stub(stub => stub.Response).Return(_responseMock).Repeat.Any();

            _requestMock = MockRepository.StrictMock <HttpRequestBase>();
            _httpContextMock.Stub(stub => stub.Request).Return(_requestMock).Repeat.Any();

            _postBackCollection = new NameValueCollection();

            _functionStateManager = new WxeFunctionStateManager(new FakeHttpSessionStateBase());
            _wxeContext           = new WxeContext(_httpContextMock, _functionStateManager, _functionState, new NameValueCollection());
        }
        public void CreateNewFunctionStateStateWithArgument()
        {
            string agrumentValue            = "True";
            NameValueCollection queryString = new NameValueCollection();

            queryString.Set(TestFunction.Parameter1Name, agrumentValue);
            HttpContextHelper.SetQueryString(CurrentHttpContext, queryString);

            WxeFunctionState functionState = _wxeHandler.CreateNewFunctionState(CurrentHttpContext, _functionType);

            Assert.That(functionState, Is.Not.Null);
            Assert.That(functionState.FunctionToken, Is.Not.Null);
            Assert.That(functionState.Function, Is.Not.Null);
            Assert.That(functionState.Function.GetType(), Is.EqualTo(_functionType));
            TestFunction testFunction = (TestFunction)functionState.Function;

            Assert.That(testFunction.Parameter1, Is.EqualTo(agrumentValue));

            WxeFunctionState expiredFunctionState = WxeFunctionStateManager.Current.GetItem(c_functionTokenForExpiredFunctionState);

            Assert.That(expiredFunctionState, Is.Null);
        }
        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);
        }
        public void SetUp()
        {
            _session = new FakeHttpSessionStateBase();

            _functionState = new WxeFunctionState(new TestFunction(), 1, true);
        }
 public new void CleanUpFunctionState(WxeFunctionState functionState)
 {
     base.CleanUpFunctionState(functionState);
 }
 public new void ExecuteFunctionState(HttpContext context, WxeFunctionState functionState, bool isNewFunction)
 {
     base.ExecuteFunctionState(context, functionState, isNewFunction);
 }
 public new void ProcessFunctionState(HttpContext context, WxeFunctionState functionState, bool isNewFunction)
 {
     base.ProcessFunctionState(context, functionState, isNewFunction);
 }