Example #1
0
        public void Test_FailAfterExceptionAndFailInListener()
        {
            TestFunction2 function = new TestFunction2();

            function.SetExecutionListener(_executionListenerMock);

            WxeStep   step1         = MockRepository.GenerateMock <WxeStep> ();
            Exception stepException = new Exception("StepException");

            step1.Expect(mock => mock.Execute(_context)).Throw(stepException);
            function.Add(step1);

            Exception listenerException = new Exception("ListenerException");

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionFail(_context, stepException)).Throw(listenerException);
            }
            _mockRepository.ReplayAll();

            try
            {
                function.Execute(_context);
                Assert.Fail();
            }
            catch (WxeFatalExecutionException actualException)
            {
                Assert.That(actualException.InnerException, Is.SameAs(stepException));
                Assert.That(actualException.OuterException, Is.SameAs(listenerException));
            }

            _mockRepository.VerifyAll();
        }
        protected override void OnPreRender(EventArgs e)
        {
            //  A call to the ResourceDispatcher to get have the automatic resources dispatched
            ResourceDispatcher.Dispatch(this, ResourceManagerUtility.GetResourceManager(this));

            base.OnPreRender(e);

            HtmlHeadAppender.Current.RegisterPageStylesheetLink();

            var key = GetType().FullName + "_Global";

            if (!HtmlHeadAppender.Current.IsRegistered(key))
            {
                HtmlHeadAppender.Current.RegisterStylesheetLink(key, "Html/global.css");
            }


            LiteralControl stack = new LiteralControl();

            StringBuilder sb = new StringBuilder();

            sb.Append("<br /><div>");
            sb.Append("<b>Stack:</b><br />");
            for (WxeStep step = CurrentPageStep; step != null; step = step.ParentStep)
            {
                sb.AppendFormat("{0}<br />", step.ToString());
            }
            sb.Append("</div>");
            stack.Text = sb.ToString();

            WxeControls.Add(stack);
        }
Example #3
0
        public void Test_ThreadAbort_WithFatalException()
        {
            TestFunction2 function = new TestFunction2();

            function.SetExecutionListener(_executionListenerMock);

            WxeStep step1 = MockRepository.GenerateMock <WxeStep> ();

            step1.Expect(mock => mock.Execute(_context)).WhenCalled(invocation => Thread.CurrentThread.Abort());
            function.Add(step1);

            var fatalExecutionException = new WxeFatalExecutionException(new Exception("Pause exception"), null);

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionPause(_context)).Throw(fatalExecutionException);
            }
            _mockRepository.ReplayAll();

            try
            {
                function.Execute(_context);
                Assert.Fail();
            }
            catch (WxeFatalExecutionException actualException)
            {
                Assert.That(actualException, Is.SameAs(fatalExecutionException));
                Thread.ResetAbort();
            }
        }
Example #4
0
        public void CreateTransactionStrategy_WithParentTransaction()
        {
            ITransactionMode transactionMode = new CreateChildIfParentTransactionMode(true, new TestTransactionFactory());

            WxeFunction parentFunction = new TestFunction2(new CreateRootTransactionMode(true, new TestTransactionFactory()));
            WxeFunction childFunction  = new TestFunction2(transactionMode);

            parentFunction.Add(childFunction);

            WxeStep stepMock = MockRepository.GenerateMock <WxeStep>();

            childFunction.Add(stepMock);

            WxeContextFactory wxeContextFactory = new WxeContextFactory();
            WxeContext        context           = wxeContextFactory.CreateContext(new TestFunction());

            stepMock.Expect(mock => mock.Execute(context)).WhenCalled(
                invocation =>
            {
                TransactionStrategyBase strategy = ((TestFunction2)childFunction).TransactionStrategy;
                Assert.That(strategy, Is.InstanceOf(typeof(ChildTransactionStrategy)));
                Assert.That(((ChildTransactionStrategy)strategy).AutoCommit, Is.True);
                Assert.That(strategy.OuterTransactionStrategy, Is.SameAs(((TestFunction2)parentFunction).TransactionStrategy));
            });

            parentFunction.Execute(context);
        }
Example #5
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            StringBuilder sb = new StringBuilder();

            sb.Append("<b>Stack:</b><br />");
            for (WxeStep step = CurrentPageStep; step != null; step = step.ParentStep)
            {
                sb.AppendFormat("{0}<br />", step.ToString());
            }
            Stack.Text = sb.ToString();
        }
        public override void SetUp()
        {
            base.SetUp();

            _parentStep = new WxePageStep("page.aspx");
            ExecutionStateContextMock.Stub(stub => stub.CurrentStep).Return(_parentStep).Repeat.Any();

            _pageMock = MockRepository.StrictMock <IWxePage>();

            PostBackCollection.Add("Key", "Value");
            PostBackCollection.Add(c_senderUniqueID, "Value");
            PostBackCollection.Add(ControlHelper.PostEventSourceID, "TheEventSource");
            PostBackCollection.Add(ControlHelper.PostEventArgumentID, "TheEventArgument");
        }
Example #7
0
        public void Test_ReEntryAfterThreadAbort()
        {
            TestFunction2 function = new TestFunction2();

            function.SetExecutionListener(_executionListenerMock);

            WxeStep step1 = MockRepository.GenerateMock <WxeStep> ();

            step1.Expect(mock => mock.Execute(_context)).WhenCalled(invocation => Thread.CurrentThread.Abort()).Repeat.Once();
            function.Add(step1);

            WxeStep step2 = MockRepository.GenerateMock <WxeStep>();

            step2.Expect(mock => mock.Execute(_context));
            function.Add(step2);

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionPause(_context));
            }
            _mockRepository.ReplayAll();

            try
            {
                function.Execute(_context);
                Assert.Fail();
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
            }

            _mockRepository.VerifyAll();
            _mockRepository.BackToRecordAll();

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionStop(_context));
            }
            _mockRepository.ReplayAll();

            function.Execute(_context);

            _mockRepository.VerifyAll();
        }
Example #8
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            for (WxeStep step = CurrentPageStep; step != null; step = step.ParentStep)
            {
                sb.AppendFormat("{0}<br>", step.ToString());
            }
            StackLabel.Text = sb.ToString();

            Var1Label.Text          = Function.Var1;
            Var2Label.Text          = Function.Var2;
            IsPostBackCheck.Checked = IsPostBack;

            if (!IsPostBack)
            {
                Calendar1.SelectedDate = DateTime.Now.Date;
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //var control = Page.LoadControl ("FirstControl.ascx");
            //control.ID = "FirstControl";
            //FirstControlPlaceHoder.Controls.Add (control);

            ViewStateValue++;
            ViewStateLabel.Text = ViewStateValue.ToString();

            ControlStateValue++;
            ControlStateLabel.Text = ControlStateValue.ToString();

            StringBuilder stringBuilder = new StringBuilder();

            for (WxeStep step = CurrentPageStep; step != null; step = step.ParentStep)
            {
                stringBuilder.AppendFormat("{0}<br>", step);
            }
            StackLabel.Text = stringBuilder.ToString();

            if (!IsPostBack)
            {
                Assertion.IsNull(SubControlWithState.ValueInViewState);
                SubControlWithState.ValueInViewState = 1.ToString ();

                Assertion.IsNull(SubControlWithState.ValueInControlState);
                SubControlWithState.ValueInControlState = 1.ToString ();
            }
            else
            {
                Assertion.IsNotNull(SubControlWithState.ValueInViewState);
                SubControlWithState.ValueInViewState = (int.Parse(SubControlWithState.ValueInViewState) + 1).ToString();

                Assertion.IsNotNull(SubControlWithState.ValueInControlState);
                SubControlWithState.ValueInControlState = (int.Parse(SubControlWithState.ValueInControlState) + 1).ToString();
            }
        }
Example #10
0
 public static new T GetStepByType <T> (WxeStep step)
     where T : WxeStep
 {
     return(WxeStep.GetStepByType <T> (step));
 }
        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 void GetFunctionForStep()
        {
            WxeFunction function = WxeStep.GetFunction(_nestedLevel1FunctionStep);

            Assert.That(function, Is.SameAs(_nestedLevel1Function));
        }
        public void GetStepByTypeForNull()
        {
            WxeStep step = TestStep.GetStepByType <WxeStep> (null);

            Assert.That(step, Is.Null);
        }
        public void GetParentStepForStandAloneStep()
        {
            WxeStep parentStep = _standAloneStep.ParentStep;

            Assert.That(parentStep, Is.Null);
        }
        public void GetParentStepForStep()
        {
            WxeStep parentStep = _nestedLevel2FunctionStep.ParentStep;

            Assert.That(parentStep, Is.SameAs(_nestedLevel2Function));
        }