Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with Owin delegate #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Simple.Web.Tests/OwinSupport/OwinHelpersTests.cs
Original file line number Diff line number Diff line change
@@ -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<IDictionary<string, object>, System.Threading.Tasks.Task>;

public class OwinHelpersTests
{
[Fact]
public void UseSimpleWebUseCompatibleDelegate()
{
var mockAppBuilder = new MockAppBuilder();

mockAppBuilder.UseSimpleWeb();

Assert.IsAssignableFrom<Func<AppFunc, AppFunc>>(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<string, object> Properties { get; private set; }
}

}
}
5 changes: 5 additions & 0 deletions src/Simple.Web.Tests/Simple.Web.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -57,6 +61,7 @@
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="MediaTypeHandling\MediaTypeHandlerExTests.cs" />
<Compile Include="OwinSupport\OwinHelpersTests.cs" />
<Compile Include="PublicFolderTests.cs" />
<Compile Include="UriFromTypeTests.cs" />
<Compile Include="UriTemplateAttributeTests.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Simple.Web.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Owin" version="1.0" targetFramework="net40" />
<package id="xunit" version="1.9.1" targetFramework="net40" />
</packages>
6 changes: 3 additions & 3 deletions src/Simple.Web/OwinSupport/OwinHelpers.cs
Original file line number Diff line number Diff line change
@@ -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.Collections.Generic.IDictionary<string, object>, System.Threading.Tasks.Task>;

public static class OwinHelpers
{
public static void UseSimpleWeb(this IAppBuilder app)
{
app.Use(new Func<IDictionary<string,object>, Func<IDictionary<string,object>, Task>, Task>(Application.Run));
app.Use(new Func<AppFunc, AppFunc>(nextAppFunc => (AppFunc) (context => Application.Run(context, nextAppFunc))));
}
}
}
2 changes: 1 addition & 1 deletion src/Simple.Web/OwinSupport/OwinStartupBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected Action<IAppBuilder> Builder

protected OwinStartupBase()
{
this._builder = builder => builder.Use(new Func<IDictionary<string,object>, Func<IDictionary<string,object>, Task>, Task>(Application.Run));
this._builder = builder => builder.UseSimpleWeb();
}

protected OwinStartupBase(Action<IAppBuilder> builder)
Expand Down