public void WhenCombinationContainsNoContent_ShouldNotThrow() { _stubHttpContext.Expect(hc => hc.Response).Return(_stubResponse); _stubHttpContext.Expect(hc => hc.Request).Return(_stubRequest); _stubRequest.Expect(r => r.Headers).Return(new NameValueCollection { { HttpHeaders.AcceptEncoding, "" } }); _stubResponse.ContentEncoding = Encoding.UTF8; _stubResponse.ContentType = MimeTypes.TextCss; _stubResponse.AddHeader(HttpHeaders.ContentLength, "15"); _stubResponse.Expect(r => r.OutputStream).Return(new MemoryStream(8092)).Repeat.Twice(); _stubResponse.Expect(r => r.Cache).Return(_stubCache); var emptyCombination = new IncludeCombination(IncludeType.Css, new[] { "foo.css" }, "", DateTime.UtcNow, new CssTypeElement()); _stubCombiner.Expect(c => c.GetCombination("foo")).Return(emptyCombination); var result = new IncludeCombinationResult(_stubCombiner, "foo", DateTime.UtcNow); result.ExecuteResult(_controllerContext); }
public void WhenDebugIs1InQueryString_CookieShouldBeCreatedAndAddedToResponse_WithDebugCookie() { var data = new CookiesData { Cookies = new HttpCookieCollection { new HttpCookie("debug", "1") }, DebugCookieWasPresent = true }; _mockFilterContext.Expect(fc => fc.HttpContext).Return(_mockHttpContext); _mockRequest.Expect(r => r.QueryString).Return(new NameValueCollection { { "debug", "1" } }); _mockHttpContext.Expect(hc => hc.Response).Return(_mockResponse); _mockResponse.Expect(r => r.Cookies).Return(data.Cookies); _filter.OnActionExecuted(_mockFilterContext); var result = data.Cookies["debug"]; Assert.IsNotNull(result); Assert.AreEqual("1", result.Value); _mocks.VerifyAll(); }
public void Test_SubFunction_RedirectToPermaUrl() { WxeContextMock.SetCurrent(_wxeContext); Uri uri = new Uri("http://localhost/root.wxe"); HttpResponseBase 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(); HttpRequestBase requestMock = _mockRepository.StrictMock <HttpRequestBase>(); requestMock.Stub(stub => stub.Url).Return(uri).Repeat.Any(); _httpContextMock.Stub(stub => stub.Request).Return(requestMock).Repeat.Any(); using (_mockRepository.Ordered()) { using (_mockRepository.Unordered()) { _pageMock.Expect(mock => mock.GetPostBackCollection()).Return(_postBackCollection); _pageMock.Expect(mock => mock.SaveAllState()); _pageMock.Expect(mock => mock.WxeHandler).Return(_wxeHandler); } //Redirect to subfunction responseMock.Expect(mock => mock.Redirect("/session/sub.wxe?WxeFunctionToken=" + _wxeContext.FunctionToken)) .WhenCalled(invocation => Thread.CurrentThread.Abort()); //Show sub function _subFunction.Expect(mock => mock.Execute(_wxeContext)).WhenCalled(invocation => Thread.CurrentThread.Abort()); //Return from sub function _subFunction.Expect(mock => mock.Execute(_wxeContext)).Throw(new WxeExecuteNextStepException()); //Return from sub function responseMock.Expect(mock => mock.Redirect("/session/root.wxe?WxeFunctionToken=" + _wxeContext.FunctionToken)) .WhenCalled( invocation => { PrivateInvoke.SetNonPublicField(_functionState, "_postBackID", 100); _pageStep.SetPostBackCollection(new NameValueCollection()); Thread.CurrentThread.Abort(); }); _pageExecutorMock.Expect(mock => mock.ExecutePage(_wxeContext, "~/ThePage", true)).WhenCalled( invocation => { Assert.That(((IExecutionStateContext)_pageStep).ExecutionState, Is.SameAs(NullExecutionState.Null)); Assert.That(_pageStep.PostBackCollection[WxePageInfo.PostBackSequenceNumberID], Is.EqualTo("100")); Assert.That(_pageStep.PostBackCollection.AllKeys, Has.Member("Key")); Assert.That(_pageStep.ReturningFunction, Is.SameAs(_subFunction)); Assert.That(_pageStep.IsReturningPostBack, Is.True); }); } _mockRepository.ReplayAll(); WxePermaUrlOptions permaUrlOptions = new WxePermaUrlOptions(); try { //Redirect to subfunction WxeRepostOptions repostOptions = WxeRepostOptions.DoRepost(null); _pageStep.ExecuteFunction(new PreProcessingSubFunctionStateParameters(_pageMock, _subFunction, permaUrlOptions), repostOptions); Assert.Fail(); } catch (ThreadAbortException) { Thread.ResetAbort(); } try { //Show sub function _pageStep.Execute(); Assert.Fail(); } catch (ThreadAbortException) { Thread.ResetAbort(); } try { //Return from sub function _pageStep.Execute(); Assert.Fail(); } catch (WxeExecuteNextStepException) { } try { //Return from sub function _pageStep.Execute(); Assert.Fail(); } catch (ThreadAbortException) { Thread.ResetAbort(); } //Show current page _pageStep.Execute(); _mockRepository.VerifyAll(); }
public void Test_ReturnToCaller() { NameValueCollection callerUrlParameters = new NameValueCollection { { "CallerKey", "CallerValue" } }; using (_mockRepository.Ordered()) { using (_mockRepository.Unordered()) { _pageMock.Expect(mock => mock.GetPostBackCollection()).Return(_postBackCollection); _pageMock.Expect(mock => mock.SaveAllState()); _pageMock.Expect(mock => mock.WxeHandler).Return(_wxeHandler); } //Redirect to external subfunction _responseMock .Expect(mock => mock.Redirect(Arg <string> .Matches(arg => arg == "/session/sub.wxe?WxeFunctionToken=" + _subFunction.FunctionToken))) .WhenCalled(invocation => Thread.CurrentThread.Abort()); //Show external sub function _subFunction.Expect(mock => mock.Execute(_wxeContext)).WhenCalled( invocation => { PrivateInvoke.SetNonPublicField(_functionState, "_postBackID", 100); _pageStep.SetPostBackCollection(new NameValueCollection()); Thread.CurrentThread.Abort(); }); //Return from external sub function _subFunction.Expect(mock => mock.Execute(_wxeContext)).Throw(new WxeExecuteNextStepException()); _requestMock.Expect(mock => mock.HttpMethod).Return("GET"); _pageExecutorMock.Expect(mock => mock.ExecutePage(_wxeContext, "~/ThePage", true)).WhenCalled( invocation => { Assert.That(((IExecutionStateContext)_pageStep).ExecutionState, Is.SameAs(NullExecutionState.Null)); Assert.That(_pageStep.PostBackCollection[WxePageInfo.PostBackSequenceNumberID], Is.EqualTo("100")); Assert.That(_pageStep.PostBackCollection.AllKeys, Has.Member("Key")); Assert.That(_pageStep.ReturningFunction, Is.SameAs(_subFunction)); Assert.That(_pageStep.IsReturningPostBack, Is.True); }); } _mockRepository.ReplayAll(); WxePermaUrlOptions permaUrlOptions = new WxePermaUrlOptions(); try { //Redirect to external subfunction WxeReturnOptions returnOptions = new WxeReturnOptions(callerUrlParameters); _pageStep.ExecuteFunctionExternalByRedirect(new PreProcessingSubFunctionStateParameters(_pageMock, _subFunction, permaUrlOptions), returnOptions); Assert.Fail(); } catch (ThreadAbortException) { Thread.ResetAbort(); } try { //Show external sub function _subFunction.Execute(); Assert.Fail(); } catch (ThreadAbortException) { Thread.ResetAbort(); } try { //Return from external sub function _subFunction.Execute(); Assert.Fail(); } catch (WxeExecuteNextStepException) { } Assert.That(_subFunction.ReturnUrl, Is.EqualTo("/session/root.wxe?CallerKey=CallerValue&WxeFunctionToken=" + _rootFunction.FunctionToken)); //Show current page _pageStep.Execute(); _mockRepository.VerifyAll(); }
public void WhenNoCombinationExists_ResponseCodeShouldBe404() { _mockHttpContext.Expect(hc => hc.Response).Return(_mockResponse); _mockResponse.Expect(r => r.ContentEncoding = Encoding.UTF8); _mockResponse.Expect(r => r.StatusCode = (int)HttpStatusCode.NotFound); _stubCombiner.Expect(c => c.GetCombination("foo")).Return(null); var result = new IncludeCombinationResult(_stubCombiner, "foo", DateTime.UtcNow); result.ExecuteResult(_controllerContext); _mocks.VerifyAll(); }