Esempio n. 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 void Initialize_WithVariableReference()
        {
            WxeFunction function = new TestFunction();
            WxePageStep step     = new WxePageStep(new WxeVariableReference("ThePage"));

            function.Add(step);
            function.Variables["ThePage"] = "page.aspx";

            Assert.That(step.Page, Is.EqualTo("~/page.aspx"));
        }
        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());
        }
Esempio n. 4
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);
        }
        protected UserControlExecutor(WxeStep parentStep, WxeUserControl userControl, WxeFunction subFunction, Control sender, bool usesEventTarget)
        {
            ArgumentUtility.CheckNotNull("parentStep", parentStep);
            ArgumentUtility.CheckNotNull("userControl", userControl);
            ArgumentUtility.CheckNotNull("subFunction", subFunction);
            ArgumentUtility.CheckNotNull("sender", sender);
            if (userControl.WxePage == null)
            {
                throw new ArgumentException("Execution of user controls that are no longer part of the control hierarchy is not supported.", "userControl");
            }

            _backedUpUserControlState = userControl.SaveAllState();
            _backedUpUserControl      = userControl.AppRelativeVirtualPath;
            _userControlID            = userControl.UniqueID;
            _function = subFunction;

            _function.SetParentStep(parentStep);
            if (parentStep is WxeUserControlStep)
            {
                _pageStep = ((WxeUserControlStep)parentStep).PageStep;
            }
            else
            {
                _pageStep = ((WxePageStep)parentStep);
            }

            if (userControl.WxePage.IsPostBack)
            {
                _postBackCollection   = userControl.WxePage.GetPostBackCollection().Clone();
                _backedUpPostBackData = new NameValueCollection();

                if (usesEventTarget)
                {
                    //TODO: Update PreProcessingSubFunctionState with this check as well.
                    if (sender.UniqueID.Contains(":"))
                    {
                        throw new InvalidOperationException("Executing WxeUserControls are only supported on pages not rendered in XhtmlConformanceMode.Legacy.");
                    }

                    //TODO: Is this check really necessary?
                    if (_postBackCollection[ControlHelper.PostEventSourceID] != sender.UniqueID)
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      "The 'sender' does not match the value in {0}. Please pass the control that orignated the postback.",
                                      ControlHelper.PostEventSourceID),
                                  "sender");
                    }

                    _backedUpPostBackData.Add(ControlHelper.PostEventSourceID, _postBackCollection[ControlHelper.PostEventSourceID]);
                    _backedUpPostBackData.Add(ControlHelper.PostEventArgumentID, _postBackCollection[ControlHelper.PostEventArgumentID]);
                    _postBackCollection.Remove(ControlHelper.PostEventSourceID);
                    _postBackCollection.Remove(ControlHelper.PostEventArgumentID);
                }
                else
                {
                    throw new InvalidOperationException(
                              "The WxeUserControl does not support controls that do not use __EventTarget for signaling a postback event.");
                    //TODO: Check if controls that do not use __EventTarget can be supported
                    // _backedUpPostBackData.Add (sender.UniqueID, _postBackCollection[sender.UniqueID]);
                    // _postBackCollection.Remove (sender.UniqueID);
                }

                string uniqueIDPrefix = _userControlID + userControl.Page.IdSeparator;
                foreach (var key in _postBackCollection.AllKeys.Where(s => s.StartsWith(uniqueIDPrefix)))
                {
                    _backedUpPostBackData.Add(key, _postBackCollection[key]);
                    _postBackCollection.Remove(key);
                }
            }
        }
 public UserControlExecutor(WxePageStep parentStep, WxeUserControl userControl, WxeFunction subFunction, Control sender, bool usesEventTarget)
     : this((WxeStep)parentStep, userControl, subFunction, sender, usesEventTarget)
 {
 }
        public void Initialize_WithPath()
        {
            WxePageStep step = new WxePageStep("page.aspx");

            Assert.That(step.Page, Is.EqualTo("~/page.aspx"));
        }