Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit f2d3458

Browse files
author
Praburaj
committed
Adding a test for mutable feature collection
1 parent fde3b0d commit f2d3458

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using Microsoft.AspNet.Hosting.Builder;
6+
using Microsoft.AspNet.Owin;
7+
using Xunit;
8+
9+
namespace Microsoft.AspNet.Hosting.Tests
10+
{
11+
public class HttpContextFactoryFacts
12+
{
13+
[Fact]
14+
public void Mutable_FeatureCollection_Wrapped_For_OwinFeatureCollection()
15+
{
16+
var env = new Dictionary<string, object>();
17+
var contextFactory = new HttpContextFactory();
18+
var context = contextFactory.CreateHttpContext(new OwinFeatureCollection(env));
19+
20+
// Setting a feature will throw if the above feature collection is not wrapped in a mutable feature collection.
21+
context.SetFeature<ICustomFeature>(new CustomFeature(100));
22+
Assert.Equal(100, context.GetFeature<ICustomFeature>().Value);
23+
}
24+
25+
private interface ICustomFeature
26+
{
27+
int Value { get; }
28+
}
29+
30+
private class CustomFeature : ICustomFeature
31+
{
32+
private readonly int _value;
33+
public CustomFeature(int value)
34+
{
35+
_value = value;
36+
}
37+
38+
public int Value
39+
{
40+
get { return _value; }
41+
}
42+
}
43+
}
44+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"dependencies": {
33
"Microsoft.AspNet.Hosting": "1.0.0-*",
4+
"Microsoft.AspNet.Owin": "1.0.0-*",
45
"Microsoft.AspNet.RequestContainer": "1.0.0-*",
56
"xunit.runner.kre": "1.0.0-*"
67
},
78
"frameworks": {
8-
"aspnet50": { }
9+
"aspnet50": {}
910
},
1011
"commands": {
1112
"test": "xunit.runner.kre"
1213
},
1314
"webroot": "testroot"
14-
}
15+
}

0 commit comments

Comments
 (0)