This repository has been archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding option to configure services when exposing the ASP.NET 5 pipel…
…ine via OWIN #398
- Loading branch information
Showing
4 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
|
||
namespace Microsoft.AspNet.Owin | ||
{ | ||
using AppFunc = Func<IDictionary<string, object>, Task>; | ||
using CreateMiddleware = Func< | ||
Func<IDictionary<string, object>, Task>, | ||
Func<IDictionary<string, object>, Task> | ||
>; | ||
using AddMiddleware = Action<Func< | ||
Func<IDictionary<string, object>, Task>, | ||
Func<IDictionary<string, object>, Task> | ||
>>; | ||
|
||
public class OwinExtensionTests | ||
{ | ||
static AppFunc notFound = async env => env["owin.ResponseStatusCode"] = 404; | ||
|
||
[Fact] | ||
public void OwinConfigureServiceProviderAddsServices() | ||
{ | ||
IList<CreateMiddleware> list = new List<CreateMiddleware>(); | ||
AddMiddleware build = list.Add; | ||
IServiceProvider serviceProvider = null; | ||
FakeService fakeService = null; | ||
|
||
var builder = build.UseBuilder(applicationBuilder => | ||
{ | ||
serviceProvider = applicationBuilder.ApplicationServices; | ||
applicationBuilder.Run(async context => | ||
{ | ||
fakeService = context.ApplicationServices.GetService<FakeService>(); | ||
}); | ||
}, new ServiceCollection().AddSingleton(new FakeService()).BuildServiceProvider()); | ||
|
||
list.Reverse().Aggregate(notFound, (next, middleware) => middleware(next)).Invoke(new Dictionary<string, object>()); | ||
|
||
Assert.NotNull(fakeService); | ||
Assert.NotNull(serviceProvider?.GetService<FakeService>()); | ||
} | ||
|
||
[Fact] | ||
public void OwinDefaultNoServices() | ||
{ | ||
IList<CreateMiddleware> list = new List<CreateMiddleware>(); | ||
AddMiddleware build = list.Add; | ||
IServiceProvider serviceProvider = null; | ||
FakeService fakeService = null; | ||
|
||
var builder = build.UseBuilder(applicationBuilder => | ||
{ | ||
serviceProvider = applicationBuilder.ApplicationServices; | ||
applicationBuilder.Run(async context => | ||
{ | ||
fakeService = context.ApplicationServices.GetService<FakeService>(); | ||
}); | ||
}); | ||
|
||
list.Reverse().Aggregate(notFound, (next, middleware) => middleware(next)).Invoke(new Dictionary<string, object>()); | ||
|
||
Assert.Null(fakeService); | ||
Assert.Null(serviceProvider); | ||
} | ||
|
||
public class FakeService | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters