From 5950258d4d062690a880dbaadbc7d7f1fa01de9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Truds=C3=B8=20Mahon?= Date: Tue, 24 Dec 2013 08:39:08 +0100 Subject: [PATCH] Fixed issue with Owin delegate - Changed OwinStartupBase to use OwinHelpers extension method --- .../OwinSupport/OwinHelpersTests.cs | 48 +++++++++++++++++++ src/Simple.Web.Tests/Simple.Web.Tests.csproj | 5 ++ src/Simple.Web.Tests/packages.config | 1 + src/Simple.Web/OwinSupport/OwinHelpers.cs | 6 +-- src/Simple.Web/OwinSupport/OwinStartupBase.cs | 2 +- 5 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/Simple.Web.Tests/OwinSupport/OwinHelpersTests.cs diff --git a/src/Simple.Web.Tests/OwinSupport/OwinHelpersTests.cs b/src/Simple.Web.Tests/OwinSupport/OwinHelpersTests.cs new file mode 100644 index 0000000..bdd7c3f --- /dev/null +++ b/src/Simple.Web.Tests/OwinSupport/OwinHelpersTests.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; + +namespace Simple.Web.Tests.OwinSupport +{ + using System; + using Owin; + using Web.OwinSupport; + using Xunit; + + using AppFunc = System.Func, System.Threading.Tasks.Task>; + + public class OwinHelpersTests + { + [Fact] + public void UseSimpleWebUseCompatibleDelegate() + { + var mockAppBuilder = new MockAppBuilder(); + + mockAppBuilder.UseSimpleWeb(); + + Assert.IsAssignableFrom>(mockAppBuilder.AssignedMiddleWare); + } + + private class MockAppBuilder : IAppBuilder + { + public IAppBuilder Use(object middleware, params object[] args) + { + AssignedMiddleWare = middleware; + return this; + } + + public object AssignedMiddleWare { get; private set; } + + public object Build(Type returnType) + { + throw new NotImplementedException(); + } + + public IAppBuilder New() + { + throw new NotImplementedException(); + } + + public IDictionary Properties { get; private set; } + } + + } +} \ No newline at end of file diff --git a/src/Simple.Web.Tests/Simple.Web.Tests.csproj b/src/Simple.Web.Tests/Simple.Web.Tests.csproj index b662832..bbe75bd 100644 --- a/src/Simple.Web.Tests/Simple.Web.Tests.csproj +++ b/src/Simple.Web.Tests/Simple.Web.Tests.csproj @@ -33,6 +33,10 @@ 4 + + False + ..\packages\Owin.1.0\lib\net40\Owin.dll + @@ -57,6 +61,7 @@ Properties\CommonAssemblyInfo.cs + diff --git a/src/Simple.Web.Tests/packages.config b/src/Simple.Web.Tests/packages.config index 88520d5..37f4dbf 100644 --- a/src/Simple.Web.Tests/packages.config +++ b/src/Simple.Web.Tests/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/src/Simple.Web/OwinSupport/OwinHelpers.cs b/src/Simple.Web/OwinSupport/OwinHelpers.cs index 45bab0b..c706df2 100644 --- a/src/Simple.Web/OwinSupport/OwinHelpers.cs +++ b/src/Simple.Web/OwinSupport/OwinHelpers.cs @@ -1,15 +1,15 @@ namespace Simple.Web.OwinSupport { using System; - using System.Collections.Generic; - using System.Threading.Tasks; using Owin; + using AppFunc = System.Func, System.Threading.Tasks.Task>; + public static class OwinHelpers { public static void UseSimpleWeb(this IAppBuilder app) { - app.Use(new Func, Func, Task>, Task>(Application.Run)); + app.Use(new Func(nextAppFunc => (AppFunc) (context => Application.Run(context, nextAppFunc)))); } } } \ No newline at end of file diff --git a/src/Simple.Web/OwinSupport/OwinStartupBase.cs b/src/Simple.Web/OwinSupport/OwinStartupBase.cs index 98457c5..97365b8 100644 --- a/src/Simple.Web/OwinSupport/OwinStartupBase.cs +++ b/src/Simple.Web/OwinSupport/OwinStartupBase.cs @@ -21,7 +21,7 @@ protected Action Builder protected OwinStartupBase() { - this._builder = builder => builder.Use(new Func, Func, Task>, Task>(Application.Run)); + this._builder = builder => builder.UseSimpleWeb(); } protected OwinStartupBase(Action builder)