public void ExecuteSubFunction_WithoutPermaUrl_DoNotReturnToCaller_GoesToRedirectingToSubFunction ()
    {
      IExecutionState executionState = CreateExecutionState (WxePermaUrlOptions.Null, WxeReturnOptions.Null);

      ExecutionStateContextMock.Expect (mock => mock.SetExecutionState (Arg<RedirectingToSubFunctionState>.Is.NotNull))
          .WhenCalled (
          invocation =>
          {
            var nextState = CheckExecutionState ((RedirectingToSubFunctionState) invocation.Arguments[0]);
            Assert.That (nextState.Parameters.SubFunction.ReturnUrl, Is.EqualTo ("DefaultReturn.html"));
            Assert.That (
                nextState.Parameters.DestinationUrl,
                Is.EqualTo ("/session/sub.wxe?WxeFunctionToken=" + SubFunction.FunctionToken));
          });

      MockRepository.ReplayAll ();

      executionState.ExecuteSubFunction (WxeContext);

      MockRepository.VerifyAll ();
    }
    public void ExecuteSubFunction_WithPermaUrl_ReturnToCaller_GoesToRedirectingToSubFunction ()
    {
      IExecutionState executionState = CreateExecutionState (new WxePermaUrlOptions(), new WxeReturnOptions());
      ExecutionStateContextMock.Stub (stub => stub.CurrentFunction).Return (RootFunction).Repeat.Any();

      ExecutionStateContextMock.Expect (mock => mock.SetExecutionState (Arg<RedirectingToSubFunctionState>.Is.NotNull))
          .WhenCalled (
          invocation =>
          {
            var nextState = CheckExecutionState ((RedirectingToSubFunctionState) invocation.Arguments[0]);
            Assert.That (nextState.Parameters.SubFunction.ReturnUrl, Is.EqualTo ("/session/root.wxe?WxeFunctionToken=" + WxeContext.FunctionToken));
            Assert.That (
                nextState.Parameters.DestinationUrl,
                Is.EqualTo ("/session/sub.wxe?Parameter1=OtherValue&WxeFunctionToken=" + SubFunction.FunctionToken));
          });

      MockRepository.ReplayAll();

      executionState.ExecuteSubFunction (WxeContext);

      MockRepository.VerifyAll();
    }
    public void ExecuteSubFunction_WithPermaUrl_WithCustumUrlParamters_DoNotReturnToCaller_GoesToRedirectingToSubFunction ()
    {
      WxePermaUrlOptions permaUrlOptions = new WxePermaUrlOptions (false, new NameValueCollection { { "Key", "NewValue" } });
      IExecutionState executionState = CreateExecutionState (permaUrlOptions, WxeReturnOptions.Null);

      ExecutionStateContextMock.Expect (mock => mock.SetExecutionState (Arg<RedirectingToSubFunctionState>.Is.NotNull))
          .WhenCalled (
          invocation =>
          {
            var nextState = CheckExecutionState ((RedirectingToSubFunctionState) invocation.Arguments[0]);
            Assert.That (nextState.Parameters.SubFunction.ReturnUrl, Is.EqualTo ("DefaultReturn.html"));
            Assert.That (
                nextState.Parameters.DestinationUrl,
                Is.EqualTo ("/session/sub.wxe?Key=NewValue&WxeFunctionToken=" + SubFunction.FunctionToken));
          });

      MockRepository.ReplayAll();

      executionState.ExecuteSubFunction (WxeContext);

      MockRepository.VerifyAll();
    }
        public void ExecuteSubFunction_WithPermaUrl_GoesToExecutingSubFunction()
        {
            WxePermaUrlOptions permaUrlOptions = new WxePermaUrlOptions();
            IExecutionState    executionState  = CreateExecutionState(permaUrlOptions);

            ExecutionStateContextMock.Expect(mock => mock.SetExecutionState(Arg <RedirectingToSubFunctionState> .Is.NotNull))
            .WhenCalled(
                invocation =>
            {
                var nextState = CheckExecutionState((RedirectingToSubFunctionState)invocation.Arguments[0]);
                Assert.That(
                    nextState.Parameters.DestinationUrl,
                    Is.EqualTo("/session/sub.wxe?Parameter1=OtherValue&WxeFunctionToken=" + WxeContext.FunctionToken));
                Assert.That(nextState.Parameters.ResumeUrl, Is.EqualTo("/session/root.wxe?WxeFunctionToken=" + WxeContext.FunctionToken));
            });

            MockRepository.ReplayAll();

            executionState.ExecuteSubFunction(WxeContext);

            MockRepository.VerifyAll();
        }