From c6601cb3183b73e82550dc57463520b3147b7d90 Mon Sep 17 00:00:00 2001 From: Michael Whelan Date: Sun, 17 May 2015 17:42:49 +0100 Subject: [PATCH 1/6] Initial implementation of WithMvcPipelineTo --- .../TestStack.FluentMVCTesting.Tests.csproj | 1 + TestStack.FluentMVCTesting.Tests/app.config | 11 ++++++ .../ControllerExtensions.cs | 37 ++++++++++++++++++- .../TestStack.FluentMVCTesting.csproj | 6 ++- TestStack.FluentMvcTesting/app.config | 11 ++++++ TestStack.FluentMvcTesting/packages.config | 1 + 6 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 TestStack.FluentMVCTesting.Tests/app.config create mode 100644 TestStack.FluentMvcTesting/app.config diff --git a/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj b/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj index 5129022..73b5bf7 100644 --- a/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj +++ b/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj @@ -108,6 +108,7 @@ + diff --git a/TestStack.FluentMVCTesting.Tests/app.config b/TestStack.FluentMVCTesting.Tests/app.config new file mode 100644 index 0000000..451c829 --- /dev/null +++ b/TestStack.FluentMVCTesting.Tests/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/TestStack.FluentMvcTesting/ControllerExtensions.cs b/TestStack.FluentMvcTesting/ControllerExtensions.cs index 4c377c8..eb54fe0 100644 --- a/TestStack.FluentMvcTesting/ControllerExtensions.cs +++ b/TestStack.FluentMvcTesting/ControllerExtensions.cs @@ -3,11 +3,14 @@ using System.Threading.Tasks; using System.Web.Mvc; +#if NET45 +using Xania.AspNet.Simulator; +#endif + namespace TestStack.FluentMVCTesting { public static class ControllerExtensions { - public static T WithModelErrors(this T controller) where T : Controller { controller.ModelState.AddModelError("Key", "Value"); @@ -18,11 +21,19 @@ public static ControllerResultTest WithCallTo(this T controller, where T : Controller where TAction : ActionResult { +#if NET45 + var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(object)), actionCall.Parameters); + var action = controller.Action(expression); + var result = action.Execute(); + + return new ControllerResultTest(controller, action.ActionDescriptor.ActionName, result.ActionResult); +#else var actionName = ((MethodCallExpression)actionCall.Body).Method.Name; var actionResult = actionCall.Compile().Invoke(controller); return new ControllerResultTest(controller, actionName, actionResult); +#endif } public static ControllerResultTest WithCallTo(this T controller, Expression>> actionCall) @@ -36,6 +47,30 @@ public static ControllerResultTest WithCallTo(this T controller, return new ControllerResultTest(controller, actionName, actionResult); } +#if NET45 + public static ControllerResultTest WithMvcPipelineTo(this T controller, Expression> actionCall) + where T : Controller + where TAction : ActionResult + { + var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof (object)), actionCall.Parameters); + var action = controller.Action(expression); + var result = action.Execute(); + + return new ControllerResultTest(controller, action.ActionDescriptor.ActionName, result.ActionResult); + } + + public static ControllerResultTest WithMvcPipelineTo(this T controller, Expression>> actionCall) + where T : Controller + where TAction : ActionResult + { + var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(object)), actionCall.Parameters); + var action = controller.Action(expression); + var result = action.Execute(); + + return new ControllerResultTest(controller, action.ActionDescriptor.ActionName, result.ActionResult); + } +#endif + public static ControllerResultTest WithCallToChild(this T controller, Expression> actionCall) where T : Controller where TAction : ActionResult diff --git a/TestStack.FluentMvcTesting/TestStack.FluentMVCTesting.csproj b/TestStack.FluentMvcTesting/TestStack.FluentMVCTesting.csproj index b9925ec..7ca4a4b 100644 --- a/TestStack.FluentMvcTesting/TestStack.FluentMVCTesting.csproj +++ b/TestStack.FluentMvcTesting/TestStack.FluentMVCTesting.csproj @@ -20,7 +20,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;NET45 prompt 4 false @@ -74,6 +74,9 @@ + + ..\packages\Xania.AspNet.Simulator.1.2.11\lib\net45\Xania.AspNet.Simulator.dll + @@ -95,6 +98,7 @@ + diff --git a/TestStack.FluentMvcTesting/app.config b/TestStack.FluentMvcTesting/app.config new file mode 100644 index 0000000..451c829 --- /dev/null +++ b/TestStack.FluentMvcTesting/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/TestStack.FluentMvcTesting/packages.config b/TestStack.FluentMvcTesting/packages.config index fbce3fe..79d6758 100644 --- a/TestStack.FluentMvcTesting/packages.config +++ b/TestStack.FluentMvcTesting/packages.config @@ -5,4 +5,5 @@ + \ No newline at end of file From 432ff3f64fafada6a3d61b5294c6780793dac6df Mon Sep 17 00:00:00 2001 From: Michael Whelan Date: Mon, 18 May 2015 12:59:58 +0100 Subject: [PATCH 2/6] Temporarily disabled mvcpipeline in WithCallTo --- TestStack.FluentMvcTesting/ControllerExtensions.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/TestStack.FluentMvcTesting/ControllerExtensions.cs b/TestStack.FluentMvcTesting/ControllerExtensions.cs index eb54fe0..e891232 100644 --- a/TestStack.FluentMvcTesting/ControllerExtensions.cs +++ b/TestStack.FluentMvcTesting/ControllerExtensions.cs @@ -21,19 +21,19 @@ public static ControllerResultTest WithCallTo(this T controller, where T : Controller where TAction : ActionResult { -#if NET45 - var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(object)), actionCall.Parameters); - var action = controller.Action(expression); - var result = action.Execute(); +//#if NET45 +// var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(object)), actionCall.Parameters); +// var action = controller.Action(expression); +// var result = action.Execute(); - return new ControllerResultTest(controller, action.ActionDescriptor.ActionName, result.ActionResult); -#else +// return new ControllerResultTest(controller, action.ActionDescriptor.ActionName, result.ActionResult); +//#else var actionName = ((MethodCallExpression)actionCall.Body).Method.Name; var actionResult = actionCall.Compile().Invoke(controller); return new ControllerResultTest(controller, actionName, actionResult); -#endif +//#endif } public static ControllerResultTest WithCallTo(this T controller, Expression>> actionCall) From 968dd11cf18d898628193f48cc910ed5d143a030 Mon Sep 17 00:00:00 2001 From: Michael Whelan Date: Mon, 18 May 2015 13:55:52 +0100 Subject: [PATCH 3/6] Re-enabled pipeline in WithCallTo All FluentMvc.Tests passing but sample tests failing with type constraint error VerificationException --- .../ControllerExtensions.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/TestStack.FluentMvcTesting/ControllerExtensions.cs b/TestStack.FluentMvcTesting/ControllerExtensions.cs index e891232..2f32dcd 100644 --- a/TestStack.FluentMvcTesting/ControllerExtensions.cs +++ b/TestStack.FluentMvcTesting/ControllerExtensions.cs @@ -21,19 +21,19 @@ public static ControllerResultTest WithCallTo(this T controller, where T : Controller where TAction : ActionResult { -//#if NET45 -// var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(object)), actionCall.Parameters); -// var action = controller.Action(expression); -// var result = action.Execute(); +#if NET45 + var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(object)), actionCall.Parameters); + var action = controller.Action(expression); + var result = action.Execute(); -// return new ControllerResultTest(controller, action.ActionDescriptor.ActionName, result.ActionResult); -//#else + return new ControllerResultTest(controller, action.ActionDescriptor.ActionName, result.ActionResult); +#else var actionName = ((MethodCallExpression)actionCall.Body).Method.Name; var actionResult = actionCall.Compile().Invoke(controller); return new ControllerResultTest(controller, actionName, actionResult); -//#endif +#endif } public static ControllerResultTest WithCallTo(this T controller, Expression>> actionCall) @@ -63,7 +63,7 @@ public static ControllerResultTest WithMvcPipelineTo(this T contr where T : Controller where TAction : ActionResult { - var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(object)), actionCall.Parameters); + var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(Task)), actionCall.Parameters); var action = controller.Action(expression); var result = action.Execute(); From eda51c09aacb2739cd77e1300a48a3233fa69e84 Mon Sep 17 00:00:00 2001 From: Michael Whelan Date: Tue, 19 May 2015 08:03:05 +0100 Subject: [PATCH 4/6] Added Xania.AspNet.Simulator as Assembly --- ...Stack.FluentMVCTesting.Sample.Tests.csproj | 36 +-- .../packages.config | 6 +- .../TestStack.FluentMVCTesting.Sample.csproj | 36 +-- .../Web.config | 2 +- .../packages.config | 6 +- Settings.StyleCop | 5 + .../TestStack.FluentMVCTesting.Tests.csproj | 36 +-- TestStack.FluentMVCTesting.Tests/app.config | 2 +- .../packages.config | 6 +- TestStack.FluentMVCTesting.sln | 8 +- .../ControllerExtensions.cs | 5 +- .../TestStack.FluentMVCTesting.csproj | 45 ++-- TestStack.FluentMvcTesting/app.config | 2 +- TestStack.FluentMvcTesting/packages.config | 7 +- Xania.AspNet.Simulator/ActionContext.cs | 10 + .../ActionRequestExtensions.cs | 43 ++++ .../ActionRequestWrapper.cs | 114 +++++++++ .../ActionRouterPathProvider.cs | 12 + Xania.AspNet.Simulator/AspNetUtility.cs | 62 +++++ Xania.AspNet.Simulator/ControllerAction.cs | 107 +++++++++ .../ControllerActionResult.cs | 47 ++++ .../DirectControllerAction.cs | 99 ++++++++ .../HttpContextSimulator.cs | 58 +++++ .../HttpListenerRequestWrapper.cs | 69 ++++++ .../HttpListenerResponseWrapper.cs | 107 +++++++++ .../HttpServerExtensions.cs | 24 ++ Xania.AspNet.Simulator/HttpServerSimulator.cs | 85 +++++++ Xania.AspNet.Simulator/IControllerAction.cs | 21 ++ .../LinqActionDescriptor.cs | 49 ++++ .../Properties/AssemblyInfo.cs | 36 +++ Xania.AspNet.Simulator/Router.cs | 65 ++++++ Xania.AspNet.Simulator/RouterAction.cs | 94 ++++++++ Xania.AspNet.Simulator/RouterExtensions.cs | 26 +++ Xania.AspNet.Simulator/SimpleHttpRequest.cs | 12 + Xania.AspNet.Simulator/SimpleSessionState.cs | 31 +++ .../SimulatorActionInvoker.cs | 117 ++++++++++ Xania.AspNet.Simulator/SimulatorExtensions.cs | 219 ++++++++++++++++++ .../Xania.AspNet.Simulator.csproj | 110 +++++++++ Xania.AspNet.Simulator/app.config | 11 + Xania.AspNet.Simulator/packages.config | 8 + 40 files changed, 1744 insertions(+), 94 deletions(-) create mode 100644 Settings.StyleCop create mode 100644 Xania.AspNet.Simulator/ActionContext.cs create mode 100644 Xania.AspNet.Simulator/ActionRequestExtensions.cs create mode 100644 Xania.AspNet.Simulator/ActionRequestWrapper.cs create mode 100644 Xania.AspNet.Simulator/ActionRouterPathProvider.cs create mode 100644 Xania.AspNet.Simulator/AspNetUtility.cs create mode 100644 Xania.AspNet.Simulator/ControllerAction.cs create mode 100644 Xania.AspNet.Simulator/ControllerActionResult.cs create mode 100644 Xania.AspNet.Simulator/DirectControllerAction.cs create mode 100644 Xania.AspNet.Simulator/HttpContextSimulator.cs create mode 100644 Xania.AspNet.Simulator/HttpListenerRequestWrapper.cs create mode 100644 Xania.AspNet.Simulator/HttpListenerResponseWrapper.cs create mode 100644 Xania.AspNet.Simulator/HttpServerExtensions.cs create mode 100644 Xania.AspNet.Simulator/HttpServerSimulator.cs create mode 100644 Xania.AspNet.Simulator/IControllerAction.cs create mode 100644 Xania.AspNet.Simulator/LinqActionDescriptor.cs create mode 100644 Xania.AspNet.Simulator/Properties/AssemblyInfo.cs create mode 100644 Xania.AspNet.Simulator/Router.cs create mode 100644 Xania.AspNet.Simulator/RouterAction.cs create mode 100644 Xania.AspNet.Simulator/RouterExtensions.cs create mode 100644 Xania.AspNet.Simulator/SimpleHttpRequest.cs create mode 100644 Xania.AspNet.Simulator/SimpleSessionState.cs create mode 100644 Xania.AspNet.Simulator/SimulatorActionInvoker.cs create mode 100644 Xania.AspNet.Simulator/SimulatorExtensions.cs create mode 100644 Xania.AspNet.Simulator/Xania.AspNet.Simulator.csproj create mode 100644 Xania.AspNet.Simulator/app.config create mode 100644 Xania.AspNet.Simulator/packages.config diff --git a/Samples/TestStack.FluentMVCTesting.Sample.Tests/TestStack.FluentMVCTesting.Sample.Tests.csproj b/Samples/TestStack.FluentMVCTesting.Sample.Tests/TestStack.FluentMVCTesting.Sample.Tests.csproj index 3f1a983..858864c 100644 --- a/Samples/TestStack.FluentMVCTesting.Sample.Tests/TestStack.FluentMVCTesting.Sample.Tests.csproj +++ b/Samples/TestStack.FluentMVCTesting.Sample.Tests/TestStack.FluentMVCTesting.Sample.Tests.csproj @@ -49,29 +49,29 @@ - - ..\..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.Helpers.dll - True + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - - ..\..\packages\Microsoft.AspNet.Mvc.5.2.2\lib\net45\System.Web.Mvc.dll - True + + False + ..\..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - - ..\..\packages\Microsoft.AspNet.Razor.3.2.2\lib\net45\System.Web.Razor.dll - True + + False + ..\..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll - - ..\..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.dll - True + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll - - ..\..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Deployment.dll - True + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll - - ..\..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Razor.dll - True + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll diff --git a/Samples/TestStack.FluentMVCTesting.Sample.Tests/packages.config b/Samples/TestStack.FluentMVCTesting.Sample.Tests/packages.config index 9757012..756879d 100644 --- a/Samples/TestStack.FluentMVCTesting.Sample.Tests/packages.config +++ b/Samples/TestStack.FluentMVCTesting.Sample.Tests/packages.config @@ -1,8 +1,8 @@  - - - + + + diff --git a/Samples/TestStack.FluentMVCTesting.Sample/TestStack.FluentMVCTesting.Sample.csproj b/Samples/TestStack.FluentMVCTesting.Sample/TestStack.FluentMVCTesting.Sample.csproj index 525a4b7..9d208d7 100644 --- a/Samples/TestStack.FluentMVCTesting.Sample/TestStack.FluentMVCTesting.Sample.csproj +++ b/Samples/TestStack.FluentMVCTesting.Sample/TestStack.FluentMVCTesting.Sample.csproj @@ -53,29 +53,29 @@ - - ..\..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.Helpers.dll - True + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - - ..\..\packages\Microsoft.AspNet.Mvc.5.2.2\lib\net45\System.Web.Mvc.dll - True + + False + ..\..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - - ..\..\packages\Microsoft.AspNet.Razor.3.2.2\lib\net45\System.Web.Razor.dll - True + + False + ..\..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll - - ..\..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.dll - True + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll - - ..\..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Deployment.dll - True + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll - - ..\..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Razor.dll - True + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll diff --git a/Samples/TestStack.FluentMVCTesting.Sample/Web.config b/Samples/TestStack.FluentMVCTesting.Sample/Web.config index 5766172..73d58b9 100644 --- a/Samples/TestStack.FluentMVCTesting.Sample/Web.config +++ b/Samples/TestStack.FluentMVCTesting.Sample/Web.config @@ -47,7 +47,7 @@ - + diff --git a/Samples/TestStack.FluentMVCTesting.Sample/packages.config b/Samples/TestStack.FluentMVCTesting.Sample/packages.config index 96d2cec..df7e914 100644 --- a/Samples/TestStack.FluentMVCTesting.Sample/packages.config +++ b/Samples/TestStack.FluentMVCTesting.Sample/packages.config @@ -8,10 +8,10 @@ - - + + - + diff --git a/Settings.StyleCop b/Settings.StyleCop new file mode 100644 index 0000000..b8dcb05 --- /dev/null +++ b/Settings.StyleCop @@ -0,0 +1,5 @@ + + + False + + \ No newline at end of file diff --git a/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj b/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj index 73b5bf7..c2d8ab9 100644 --- a/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj +++ b/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj @@ -50,29 +50,29 @@ - - ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.Helpers.dll - True + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - - ..\packages\Microsoft.AspNet.Mvc.5.2.2\lib\net45\System.Web.Mvc.dll - True + + False + ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - - ..\packages\Microsoft.AspNet.Razor.3.2.2\lib\net45\System.Web.Razor.dll - True + + False + ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll - - ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.dll - True + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll - - ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Deployment.dll - True + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll - - ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Razor.dll - True + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll diff --git a/TestStack.FluentMVCTesting.Tests/app.config b/TestStack.FluentMVCTesting.Tests/app.config index 451c829..d7256aa 100644 --- a/TestStack.FluentMVCTesting.Tests/app.config +++ b/TestStack.FluentMVCTesting.Tests/app.config @@ -4,7 +4,7 @@ - + diff --git a/TestStack.FluentMVCTesting.Tests/packages.config b/TestStack.FluentMVCTesting.Tests/packages.config index 9757012..756879d 100644 --- a/TestStack.FluentMVCTesting.Tests/packages.config +++ b/TestStack.FluentMVCTesting.Tests/packages.config @@ -1,8 +1,8 @@  - - - + + + diff --git a/TestStack.FluentMVCTesting.sln b/TestStack.FluentMVCTesting.sln index e772e1f..9f158f0 100644 --- a/TestStack.FluentMVCTesting.sln +++ b/TestStack.FluentMVCTesting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30501.0 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestStack.FluentMVCTesting", "TestStack.FluentMVCTesting\TestStack.FluentMVCTesting.csproj", "{152CA00F-18D3-4CF5-8CA0-2C5B70CBEA19}" EndProject @@ -30,6 +30,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestStack.FluentMVCTesting. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestStack.FluentMVCTesting.Sample", "Samples\TestStack.FluentMVCTesting.Sample\TestStack.FluentMVCTesting.Sample.csproj", "{FD292B9E-1493-428F-8AF6-F7CF9CF463C5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xania.AspNet.Simulator", "Xania.AspNet.Simulator\Xania.AspNet.Simulator.csproj", "{04B8C6C8-D531-468D-B07B-C2EBF9BF13E8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -68,6 +70,10 @@ Global {FD292B9E-1493-428F-8AF6-F7CF9CF463C5}.Debug|Any CPU.Build.0 = Debug|Any CPU {FD292B9E-1493-428F-8AF6-F7CF9CF463C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {FD292B9E-1493-428F-8AF6-F7CF9CF463C5}.Release|Any CPU.Build.0 = Release|Any CPU + {04B8C6C8-D531-468D-B07B-C2EBF9BF13E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {04B8C6C8-D531-468D-B07B-C2EBF9BF13E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {04B8C6C8-D531-468D-B07B-C2EBF9BF13E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {04B8C6C8-D531-468D-B07B-C2EBF9BF13E8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TestStack.FluentMvcTesting/ControllerExtensions.cs b/TestStack.FluentMvcTesting/ControllerExtensions.cs index 2f32dcd..e931e76 100644 --- a/TestStack.FluentMvcTesting/ControllerExtensions.cs +++ b/TestStack.FluentMvcTesting/ControllerExtensions.cs @@ -22,18 +22,19 @@ public static ControllerResultTest WithCallTo(this T controller, where TAction : ActionResult { #if NET45 - var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(object)), actionCall.Parameters); + var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof (object)), actionCall.Parameters); var action = controller.Action(expression); var result = action.Execute(); return new ControllerResultTest(controller, action.ActionDescriptor.ActionName, result.ActionResult); + #else var actionName = ((MethodCallExpression)actionCall.Body).Method.Name; var actionResult = actionCall.Compile().Invoke(controller); return new ControllerResultTest(controller, actionName, actionResult); -#endif +#endif } public static ControllerResultTest WithCallTo(this T controller, Expression>> actionCall) diff --git a/TestStack.FluentMvcTesting/TestStack.FluentMVCTesting.csproj b/TestStack.FluentMvcTesting/TestStack.FluentMVCTesting.csproj index 7ca4a4b..69d81ed 100644 --- a/TestStack.FluentMvcTesting/TestStack.FluentMVCTesting.csproj +++ b/TestStack.FluentMvcTesting/TestStack.FluentMVCTesting.csproj @@ -45,38 +45,35 @@ - - ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.Helpers.dll - True + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - - ..\packages\Microsoft.AspNet.Mvc.5.2.2\lib\net45\System.Web.Mvc.dll - True + + False + ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - - ..\packages\Microsoft.AspNet.Razor.3.2.2\lib\net45\System.Web.Razor.dll - True + + False + ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll - - ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.dll - True + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll - - ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Deployment.dll - True + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll - - ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Razor.dll - True + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll - - ..\packages\Xania.AspNet.Simulator.1.2.11\lib\net45\Xania.AspNet.Simulator.dll - @@ -105,6 +102,12 @@ + + + {04b8c6c8-d531-468d-b07b-c2ebf9bf13e8} + Xania.AspNet.Simulator + + + \ No newline at end of file diff --git a/Xania.AspNet.Simulator/app.config b/Xania.AspNet.Simulator/app.config new file mode 100644 index 0000000..e2e0187 --- /dev/null +++ b/Xania.AspNet.Simulator/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Xania.AspNet.Simulator/packages.config b/Xania.AspNet.Simulator/packages.config new file mode 100644 index 0000000..60d6113 --- /dev/null +++ b/Xania.AspNet.Simulator/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file From 31a211aa6938b84fa6c53a8f603af846ee2b577e Mon Sep 17 00:00:00 2001 From: Michael Whelan Date: Tue, 19 May 2015 15:47:22 +0100 Subject: [PATCH 5/6] Got MvcPipeline working --- .../MvcPipeline/WithMvcPipelineShould.cs | 36 +++++++++++++++++++ .../TestStack.FluentMVCTesting.Tests.csproj | 3 +- .../ControllerExtensions.cs | 16 ++------- 3 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 TestStack.FluentMVCTesting.Tests/MvcPipeline/WithMvcPipelineShould.cs diff --git a/TestStack.FluentMVCTesting.Tests/MvcPipeline/WithMvcPipelineShould.cs b/TestStack.FluentMVCTesting.Tests/MvcPipeline/WithMvcPipelineShould.cs new file mode 100644 index 0000000..5074b3f --- /dev/null +++ b/TestStack.FluentMVCTesting.Tests/MvcPipeline/WithMvcPipelineShould.cs @@ -0,0 +1,36 @@ +namespace TestStack.FluentMVCTesting.Tests.MvcPipeline +{ + using NUnit.Framework; + using TestStack.FluentMVCTesting.Tests.TestControllers; + +#if NET45 + [TestFixture] + class WithMvcPipelineShould + { + [Test] + public void Call_action() + { + var controller = new ControllerExtensionsController(); + controller.WithMvcPipelineTo(c => c.SomeAction()); + Assert.That(controller.SomeActionCalled); + } + + [Test] + public void Work_correctly_for_valid_check() + { + new AsyncController() + .WithMvcPipelineTo(c => c.AsyncViewAction()) + .ShouldRenderDefaultView(); + } + + [Test] + public void Work_correctly_for_invalid_check() + { + var controller = new AsyncController(); + Assert.Throws( + () => controller.WithMvcPipelineTo(c => c.AsyncViewAction()).ShouldGiveHttpStatus() + ); + } + } +#endif +} diff --git a/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj b/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj index c2d8ab9..53f307d 100644 --- a/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj +++ b/TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj @@ -20,7 +20,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;NET45 prompt 4 false @@ -89,6 +89,7 @@ + diff --git a/TestStack.FluentMvcTesting/ControllerExtensions.cs b/TestStack.FluentMvcTesting/ControllerExtensions.cs index e931e76..bdf4aeb 100644 --- a/TestStack.FluentMvcTesting/ControllerExtensions.cs +++ b/TestStack.FluentMvcTesting/ControllerExtensions.cs @@ -17,24 +17,14 @@ public static T WithModelErrors(this T controller) where T : Controller return controller; } - public static ControllerResultTest WithCallTo(this T controller, Expression> actionCall) - where T : Controller + public static ControllerResultTest WithCallTo(this T controller, Expression> actionCall) where T : Controller where TAction : ActionResult { -#if NET45 - var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof (object)), actionCall.Parameters); - var action = controller.Action(expression); - var result = action.Execute(); - - return new ControllerResultTest(controller, action.ActionDescriptor.ActionName, result.ActionResult); - -#else var actionName = ((MethodCallExpression)actionCall.Body).Method.Name; var actionResult = actionCall.Compile().Invoke(controller); return new ControllerResultTest(controller, actionName, actionResult); -#endif } public static ControllerResultTest WithCallTo(this T controller, Expression>> actionCall) @@ -53,7 +43,7 @@ public static ControllerResultTest WithMvcPipelineTo(this T contr where T : Controller where TAction : ActionResult { - var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof (object)), actionCall.Parameters); + var expression = Expression.Lambda>(actionCall.Body, actionCall.Parameters); var action = controller.Action(expression); var result = action.Execute(); @@ -64,7 +54,7 @@ public static ControllerResultTest WithMvcPipelineTo(this T contr where T : Controller where TAction : ActionResult { - var expression = Expression.Lambda>(Expression.Convert(actionCall.Body, typeof(Task)), actionCall.Parameters); + var expression = Expression.Lambda>(actionCall.Body, actionCall.Parameters); var action = controller.Action(expression); var result = action.Execute(); From 93f72354c6452e1d3f618798726d5c1390522e80 Mon Sep 17 00:00:00 2001 From: Michael Whelan Date: Wed, 20 May 2015 15:06:08 +0100 Subject: [PATCH 6/6] Added test to verify that filters run using WithMvcPipelineTo --- .../MvcPipeline/WithMvcPipelineShould.cs | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/TestStack.FluentMVCTesting.Tests/MvcPipeline/WithMvcPipelineShould.cs b/TestStack.FluentMVCTesting.Tests/MvcPipeline/WithMvcPipelineShould.cs index 5074b3f..025f354 100644 --- a/TestStack.FluentMVCTesting.Tests/MvcPipeline/WithMvcPipelineShould.cs +++ b/TestStack.FluentMVCTesting.Tests/MvcPipeline/WithMvcPipelineShould.cs @@ -1,8 +1,9 @@ +using System.Web.Mvc; +using NUnit.Framework; +using TestStack.FluentMVCTesting.Tests.TestControllers; + namespace TestStack.FluentMVCTesting.Tests.MvcPipeline { - using NUnit.Framework; - using TestStack.FluentMVCTesting.Tests.TestControllers; - #if NET45 [TestFixture] class WithMvcPipelineShould @@ -16,20 +17,36 @@ public void Call_action() } [Test] - public void Work_correctly_for_valid_check() + public void Can_exercise_filters() { - new AsyncController() - .WithMvcPipelineTo(c => c.AsyncViewAction()) - .ShouldRenderDefaultView(); + GlobalFilters.Filters.Add(new LoggingFilter()); + var controller = new ControllerExtensionsController(); + + controller.WithMvcPipelineTo(c => c.SomeAction()); + + Assert.That(LoggingFilter.OnActionExecutingRan); + Assert.That(LoggingFilter.OnActionExecutedRan); } - [Test] - public void Work_correctly_for_invalid_check() + private class LoggingFilter : ActionFilterAttribute, IActionFilter { - var controller = new AsyncController(); - Assert.Throws( - () => controller.WithMvcPipelineTo(c => c.AsyncViewAction()).ShouldGiveHttpStatus() - ); + public static bool OnActionExecutingRan; + public static bool OnActionExecutedRan; + + public LoggingFilter() + { + OnActionExecutingRan = false; + OnActionExecutedRan = false; + } + public override void OnActionExecuting(ActionExecutingContext filterContext) + { + OnActionExecutingRan = true; + } + + public override void OnActionExecuted(ActionExecutedContext filterContext) + { + OnActionExecutedRan = true; + } } } #endif