diff --git a/AspNetAbstractions.sln b/AspNetAbstractions.sln index 2e07b4f2cb..82b860829b 100644 --- a/AspNetAbstractions.sln +++ b/AspNetAbstractions.sln @@ -7,14 +7,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Abstractio EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.FeatureModel", "src\Microsoft.AspNet.FeatureModel\Microsoft.AspNet.FeatureModel.csproj", "{A780873E-09F9-4E44-AE06-AF00C4E88E1E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.HttpEnvironment", "src\Microsoft.AspNet.HttpEnvironment\Microsoft.AspNet.HttpEnvironment.csproj", "{46D69EC9-7096-49D8-A184-A9BB5B2419A1}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.HttpFeature", "src\Microsoft.AspNet.HttpFeature\Microsoft.AspNet.HttpFeature.csproj", "{42309978-0661-41D8-8654-39453265C5F9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.PipelineCore", "src\Microsoft.AspNet.PipelineCore\Microsoft.AspNet.PipelineCore.csproj", "{A4D3E280-8838-4614-9B99-4874C3CBDF82}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.PipelineCore.Tests", "src\Microsoft.AspNet.PipelineCore.Tests\Microsoft.AspNet.PipelineCore.Tests.csproj", "{86942914-0334-4352-87ED-B971281C74E2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.FeatureModel.Tests", "test\Microsoft.AspNet.FeatureModel.Tests\Microsoft.AspNet.FeatureModel.Tests.csproj", "{8C671AE3-1188-499F-A2A2-3A0B117B33CE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,10 +29,6 @@ Global {A780873E-09F9-4E44-AE06-AF00C4E88E1E}.Debug|Any CPU.Build.0 = Debug|Any CPU {A780873E-09F9-4E44-AE06-AF00C4E88E1E}.Release|Any CPU.ActiveCfg = Release|Any CPU {A780873E-09F9-4E44-AE06-AF00C4E88E1E}.Release|Any CPU.Build.0 = Release|Any CPU - {46D69EC9-7096-49D8-A184-A9BB5B2419A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {46D69EC9-7096-49D8-A184-A9BB5B2419A1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {46D69EC9-7096-49D8-A184-A9BB5B2419A1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {46D69EC9-7096-49D8-A184-A9BB5B2419A1}.Release|Any CPU.Build.0 = Release|Any CPU {42309978-0661-41D8-8654-39453265C5F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {42309978-0661-41D8-8654-39453265C5F9}.Debug|Any CPU.Build.0 = Debug|Any CPU {42309978-0661-41D8-8654-39453265C5F9}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -45,6 +41,10 @@ Global {86942914-0334-4352-87ED-B971281C74E2}.Debug|Any CPU.Build.0 = Debug|Any CPU {86942914-0334-4352-87ED-B971281C74E2}.Release|Any CPU.ActiveCfg = Release|Any CPU {86942914-0334-4352-87ED-B971281C74E2}.Release|Any CPU.Build.0 = Release|Any CPU + {8C671AE3-1188-499F-A2A2-3A0B117B33CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C671AE3-1188-499F-A2A2-3A0B117B33CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C671AE3-1188-499F-A2A2-3A0B117B33CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C671AE3-1188-499F-A2A2-3A0B117B33CE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Microsoft.AspNet.Abstractions/HttpContext.cs b/src/Microsoft.AspNet.Abstractions/HttpContext.cs new file mode 100644 index 0000000000..241c1d17e2 --- /dev/null +++ b/src/Microsoft.AspNet.Abstractions/HttpContext.cs @@ -0,0 +1,28 @@ +using System; + +namespace Microsoft.AspNet.Abstractions +{ + public abstract class HttpContext : IDisposable + { + // TODO - review IOwinContext for properties + + public abstract HttpRequest Request { get; } + public abstract HttpResponse Response { get; } + + public abstract void Dispose(); + + public abstract object GetInterface(Type type); + + public abstract void SetInterface(Type type, object instance); + + public virtual T GetInterface() + { + return (T)GetInterface(typeof(T)); + } + + public virtual void SetInterface(T instance) + { + SetInterface(typeof(T), instance); + } + } +} diff --git a/src/Microsoft.AspNet.Abstractions/HttpContextBase.cs b/src/Microsoft.AspNet.Abstractions/HttpContextBase.cs deleted file mode 100644 index e1ceb30048..0000000000 --- a/src/Microsoft.AspNet.Abstractions/HttpContextBase.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Microsoft.AspNet.Abstractions -{ - public abstract class HttpContextBase - { - // TODO - review IOwinContext for properties - - public abstract HttpRequestBase Request { get; } - public abstract HttpResponseBase Response { get; } - } -} diff --git a/src/Microsoft.AspNet.Abstractions/HttpRequestBase.cs b/src/Microsoft.AspNet.Abstractions/HttpRequest.cs similarity index 80% rename from src/Microsoft.AspNet.Abstractions/HttpRequestBase.cs rename to src/Microsoft.AspNet.Abstractions/HttpRequest.cs index face559bdb..7277195cc7 100644 --- a/src/Microsoft.AspNet.Abstractions/HttpRequestBase.cs +++ b/src/Microsoft.AspNet.Abstractions/HttpRequest.cs @@ -3,11 +3,11 @@ using System.IO; namespace Microsoft.AspNet.Abstractions { - public abstract class HttpRequestBase + public abstract class HttpRequest { // TODO - review IOwinRequest for properties - public abstract HttpContextBase HttpContext { get; } + public abstract HttpContext HttpContext { get; } public abstract Uri Uri { get; } public abstract PathString PathBase { get; set; } diff --git a/src/Microsoft.AspNet.Abstractions/HttpResponseBase.cs b/src/Microsoft.AspNet.Abstractions/HttpResponse.cs similarity index 69% rename from src/Microsoft.AspNet.Abstractions/HttpResponseBase.cs rename to src/Microsoft.AspNet.Abstractions/HttpResponse.cs index 518ea0355c..caf5dcb09e 100644 --- a/src/Microsoft.AspNet.Abstractions/HttpResponseBase.cs +++ b/src/Microsoft.AspNet.Abstractions/HttpResponse.cs @@ -2,11 +2,11 @@ namespace Microsoft.AspNet.Abstractions { - public abstract class HttpResponseBase + public abstract class HttpResponse { // TODO - review IOwinResponse for completeness - public abstract HttpContextBase HttpContext { get; } + public abstract HttpContext HttpContext { get; } public abstract int StatusCode { get; set; } public abstract Stream Body { get; set; } } diff --git a/src/Microsoft.AspNet.Abstractions/IBuilder.cs b/src/Microsoft.AspNet.Abstractions/IBuilder.cs index 9016434cc3..c82f759739 100644 --- a/src/Microsoft.AspNet.Abstractions/IBuilder.cs +++ b/src/Microsoft.AspNet.Abstractions/IBuilder.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Abstractions IBuilder New(); RequestDelegate Build(); - object GetFeature(Type type); - void SetFeature(Type type, object feature); + object GetItem(Type type); + void SetItem(Type type, object feature); } } diff --git a/src/Microsoft.AspNet.Abstractions/Microsoft.AspNet.Abstractions.csproj b/src/Microsoft.AspNet.Abstractions/Microsoft.AspNet.Abstractions.csproj index 4f5b7f0b33..56b8af40c3 100644 --- a/src/Microsoft.AspNet.Abstractions/Microsoft.AspNet.Abstractions.csproj +++ b/src/Microsoft.AspNet.Abstractions/Microsoft.AspNet.Abstractions.csproj @@ -36,9 +36,9 @@ - - - + + + diff --git a/src/Microsoft.AspNet.Abstractions/RequestDelegate.cs b/src/Microsoft.AspNet.Abstractions/RequestDelegate.cs index 98b48bcf94..235b430713 100644 --- a/src/Microsoft.AspNet.Abstractions/RequestDelegate.cs +++ b/src/Microsoft.AspNet.Abstractions/RequestDelegate.cs @@ -2,5 +2,5 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Abstractions { - public delegate Task RequestDelegate(HttpContextBase context); + public delegate Task RequestDelegate(HttpContext context); } \ No newline at end of file diff --git a/src/Microsoft.AspNet.FeatureModel/FeatureContainer.cs b/src/Microsoft.AspNet.FeatureModel/FeatureContainer.cs deleted file mode 100644 index 1b7949658a..0000000000 --- a/src/Microsoft.AspNet.FeatureModel/FeatureContainer.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using Microsoft.AspNet.FeatureModel.Implementation; - -namespace Microsoft.AspNet.FeatureModel -{ - public class FeatureContainer : IFeatureContainer - { - private readonly IFeatureContainer _defaultFeatures; - private readonly IDictionary _featureByFeatureType = new Dictionary(); - private readonly IDictionary _featureTypeByName = new Dictionary(); - private readonly object _containerSync = new Object(); - private int _containerRevision; - - public FeatureContainer() - { - } - - public FeatureContainer(IFeatureContainer defaultFeatures) - { - _defaultFeatures = defaultFeatures; - } - - public virtual object GetFeature(Type type) - { - object feature; - if (_featureByFeatureType.TryGetValue(type, out feature)) - { - return feature; - } - - Type actualType; - if (_featureTypeByName.TryGetValue(type.FullName, out actualType)) - { - if (_featureByFeatureType.TryGetValue(actualType, out feature)) - { - return Converter.Convert(type, actualType, feature); - } - } - - return _defaultFeatures != null ? _defaultFeatures.GetFeature(type) : null; - } - - public virtual object GetDefaultFeature(Type type) - { - return null; - } - - public virtual void SetFeature(Type type, object feature) - { - lock (_containerSync) - { - Type priorFeatureType; - if (_featureTypeByName.TryGetValue(type.FullName, out priorFeatureType)) - { - if (priorFeatureType == type) - { - _featureByFeatureType[type] = feature; - } - else - { - _featureTypeByName[type.FullName] = type; - _featureByFeatureType.Remove(priorFeatureType); - _featureByFeatureType.Add(type, feature); - } - } - else - { - _featureTypeByName.Add(type.FullName, type); - _featureByFeatureType.Add(type, feature); - } - Interlocked.Increment(ref _containerRevision); - } - } - - public virtual int Revision - { - get { return _containerRevision; } - } - - public void Dispose() - { - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.FeatureModel/IFeatureContainer.cs b/src/Microsoft.AspNet.FeatureModel/IFeatureContainer.cs deleted file mode 100644 index 52529983d0..0000000000 --- a/src/Microsoft.AspNet.FeatureModel/IFeatureContainer.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Microsoft.AspNet.FeatureModel -{ - public interface IFeatureContainer : IDisposable - { - object GetFeature(Type type); - void SetFeature(Type type, object feature); - //IEnumerable GetFeatureTypes(); - int Revision { get; } - } -} diff --git a/src/Microsoft.AspNet.FeatureModel/IInterfaceDictionary.cs b/src/Microsoft.AspNet.FeatureModel/IInterfaceDictionary.cs new file mode 100644 index 0000000000..18d07e7937 --- /dev/null +++ b/src/Microsoft.AspNet.FeatureModel/IInterfaceDictionary.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNet.FeatureModel +{ + public interface IInterfaceDictionary : IDictionary, IDisposable + { + int Revision { get; } + } +} diff --git a/src/Microsoft.AspNet.FeatureModel/Implementation/Converter.cs b/src/Microsoft.AspNet.FeatureModel/Implementation/Converter.cs index 7f080ab884..918d9f2b8f 100644 --- a/src/Microsoft.AspNet.FeatureModel/Implementation/Converter.cs +++ b/src/Microsoft.AspNet.FeatureModel/Implementation/Converter.cs @@ -352,7 +352,7 @@ namespace Microsoft.AspNet.FeatureModel.Implementation static Type CreateWrapperType(Type targetType, Type sourceType, VerificationSucceededResult result) { Dictionary mappings = result.methodMappings; - Type baseType = Assembly.GetExecutingAssembly().GetType("InterfaceMapper.BaseType`1").MakeGenericType(sourceType); + Type baseType = typeof(BaseType<>).MakeGenericType(sourceType); TypeBuilder tb = modb.DefineType("ProxyType" + counter++ + " wrapping:" + sourceType.Name + " to look like:" + targetType.Name, TypeAttributes.Class, baseType, new Type[] { targetType }); ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { sourceType }); ILGenerator il = cb.GetILGenerator(); diff --git a/src/Microsoft.AspNet.FeatureModel/InterfaceDictionary.cs b/src/Microsoft.AspNet.FeatureModel/InterfaceDictionary.cs new file mode 100644 index 0000000000..2181f686f8 --- /dev/null +++ b/src/Microsoft.AspNet.FeatureModel/InterfaceDictionary.cs @@ -0,0 +1,188 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading; +using Microsoft.AspNet.FeatureModel.Implementation; + +namespace Microsoft.AspNet.FeatureModel +{ + public class InterfaceDictionary : IInterfaceDictionary + { + private readonly IInterfaceDictionary _defaults; + private readonly IDictionary _featureByFeatureType = new Dictionary(); + private readonly IDictionary _featureTypeByName = new Dictionary(); + private readonly object _containerSync = new Object(); + private int _containerRevision; + + public InterfaceDictionary() + { + } + + public InterfaceDictionary(IInterfaceDictionary defaults) + { + _defaults = defaults; + } + + public object GetInterface() + { + return GetInterface(null); + } + + public object GetInterface(Type type) + { + if (type == null) throw new ArgumentNullException("type"); + object feature; + if (_featureByFeatureType.TryGetValue(type, out feature)) + { + return feature; + } + + Type actualType; + if (_featureTypeByName.TryGetValue(type.FullName, out actualType)) + { + if (_featureByFeatureType.TryGetValue(actualType, out feature)) + { + if (type.IsInstanceOfType(feature)) + { + return feature; + } + return Converter.Convert(type, actualType, feature); + } + } + + if (_defaults != null && _defaults.TryGetValue(type, out feature)) + { + return feature; + } + return null; + } + + void SetInterface(Type type, object feature) + { + if (type == null) throw new ArgumentNullException("type"); + if (feature == null) throw new ArgumentNullException("feature"); + + lock (_containerSync) + { + Type priorFeatureType; + if (_featureTypeByName.TryGetValue(type.FullName, out priorFeatureType)) + { + if (priorFeatureType == type) + { + _featureByFeatureType[type] = feature; + } + else + { + _featureTypeByName[type.FullName] = type; + _featureByFeatureType.Remove(priorFeatureType); + _featureByFeatureType.Add(type, feature); + } + } + else + { + _featureTypeByName.Add(type.FullName, type); + _featureByFeatureType.Add(type, feature); + } + Interlocked.Increment(ref _containerRevision); + } + } + + public virtual int Revision + { + get { return _containerRevision; } + } + + public void Dispose() + { + } + + public IEnumerator> GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + SetInterface(item.Key, item.Value); + } + + public void Clear() + { + throw new NotImplementedException(); + } + + public bool Contains(KeyValuePair item) + { + object value; + return TryGetValue(item.Key, out value) && Equals(item.Value, value); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + throw new NotImplementedException(); + } + + public bool Remove(KeyValuePair item) + { + return Contains(item) && Remove(item.Key); + } + + public int Count + { + get { throw new NotImplementedException(); } + } + + public bool IsReadOnly + { + get { return false; } + } + + public bool ContainsKey(Type key) + { + if (key == null) throw new ArgumentNullException("key"); + return GetInterface(key) != null; + } + + public void Add(Type key, object value) + { + if (key == null) throw new ArgumentNullException("key"); + if (value == null) throw new ArgumentNullException("value"); + if (ContainsKey(key)) + { + throw new ArgumentException(); + } + SetInterface(key, value); + } + + public bool Remove(Type key) + { + throw new NotImplementedException(); + } + + public bool TryGetValue(Type key, out object value) + { + throw new NotImplementedException(); + } + + public object this[Type key] + { + get { return GetInterface(key); } + set { SetInterface(key, value); } + } + + public ICollection Keys + { + get { throw new NotImplementedException(); } + } + + public ICollection Values + { + get { throw new NotImplementedException(); } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.FeatureModel/InterfaceObject.cs b/src/Microsoft.AspNet.FeatureModel/InterfaceObject.cs new file mode 100644 index 0000000000..6f81904e03 --- /dev/null +++ b/src/Microsoft.AspNet.FeatureModel/InterfaceObject.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using Microsoft.AspNet.FeatureModel.Implementation; + +namespace Microsoft.AspNet.FeatureModel +{ + public class InterfaceObject : IInterfaceDictionary + { + private readonly object _instance; + + public InterfaceObject(object instance) + { + _instance = instance; + } + + public void Dispose() + { + var disposable = _instance as IDisposable; + if (disposable != null) + { + disposable.Dispose(); + } + } + + public object GetInterface(Type type) + { + if (type.IsInstanceOfType(_instance)) + { + return _instance; + } + foreach (var interfaceType in _instance.GetType().GetInterfaces()) + { + if (interfaceType.FullName == type.FullName) + { + return Converter.Convert(interfaceType, type, _instance); + } + } + return null; + } + + public void SetInterface(Type type, object feature) + { + throw new NotImplementedException(); + } + + public int Revision + { + get { return 0; } + } + + public IEnumerator> GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + throw new NotImplementedException(); + } + + public void Clear() + { + throw new NotImplementedException(); + } + + public bool Contains(KeyValuePair item) + { + throw new NotImplementedException(); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + throw new NotImplementedException(); + } + + public bool Remove(KeyValuePair item) + { + throw new NotImplementedException(); + } + + public int Count + { + get { throw new NotImplementedException(); } + } + + public bool IsReadOnly + { + get { throw new NotImplementedException(); } + } + + public bool ContainsKey(Type key) + { + throw new NotImplementedException(); + } + + public void Add(Type key, object value) + { + throw new NotImplementedException(); + } + + public bool Remove(Type key) + { + throw new NotImplementedException(); + } + + public bool TryGetValue(Type key, out object value) + { + throw new NotImplementedException(); + } + + public object this[Type key] + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + + public ICollection Keys + { + get { throw new NotImplementedException(); } + } + + public ICollection Values + { + get { throw new NotImplementedException(); } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.FeatureModel/Microsoft.AspNet.FeatureModel.csproj b/src/Microsoft.AspNet.FeatureModel/Microsoft.AspNet.FeatureModel.csproj index a3db9ed3d3..5109def60a 100644 --- a/src/Microsoft.AspNet.FeatureModel/Microsoft.AspNet.FeatureModel.csproj +++ b/src/Microsoft.AspNet.FeatureModel/Microsoft.AspNet.FeatureModel.csproj @@ -34,10 +34,10 @@ - - + + - + diff --git a/src/Microsoft.AspNet.FeatureModel/ObjectFeatureContainer.cs b/src/Microsoft.AspNet.FeatureModel/ObjectFeatureContainer.cs deleted file mode 100644 index 48bcb98b75..0000000000 --- a/src/Microsoft.AspNet.FeatureModel/ObjectFeatureContainer.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using Microsoft.AspNet.FeatureModel.Implementation; - -namespace Microsoft.AspNet.FeatureModel -{ - public class ObjectFeatureContainer : IFeatureContainer - { - private readonly object _instance; - - public ObjectFeatureContainer(object instance) - { - _instance = instance; - } - - public void Dispose() - { - var disposable = _instance as IDisposable; - if (disposable != null) - { - disposable.Dispose(); - } - } - - public object GetFeature(Type type) - { - if (type.IsInstanceOfType(_instance)) - { - return _instance; - } - foreach (var interfaceType in _instance.GetType().GetInterfaces()) - { - if (interfaceType.FullName == type.FullName) - { - return Converter.Convert(interfaceType, type, _instance); - } - } - return null; - } - - public void SetFeature(Type type, object feature) - { - throw new NotImplementedException(); - } - - public int Revision - { - get { return 0; } - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.HttpEnvironment/HttpEnvironmentBase.cs b/src/Microsoft.AspNet.HttpEnvironment/HttpEnvironment.cs similarity index 54% rename from src/Microsoft.AspNet.HttpEnvironment/HttpEnvironmentBase.cs rename to src/Microsoft.AspNet.HttpEnvironment/HttpEnvironment.cs index 4d1036d835..5836b621e9 100644 --- a/src/Microsoft.AspNet.HttpEnvironment/HttpEnvironmentBase.cs +++ b/src/Microsoft.AspNet.HttpEnvironment/HttpEnvironment.cs @@ -2,7 +2,7 @@ namespace Microsoft.AspNet.HttpEnvironment { - public abstract class HttpEnvironmentBase : FeatureContainer, IHttpEnvironment + public abstract class HttpEnvironment : InterfaceDictionary, IHttpEnvironment { } } diff --git a/src/Microsoft.AspNet.HttpEnvironment/HttpEnvironmentExtensions.cs b/src/Microsoft.AspNet.HttpEnvironment/HttpEnvironmentExtensions.cs deleted file mode 100644 index ab296451d5..0000000000 --- a/src/Microsoft.AspNet.HttpEnvironment/HttpEnvironmentExtensions.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Microsoft.AspNet.HttpEnvironment -{ - public static class HttpEnvironmentExtensions - { - public static TFeature GetFeature(this IHttpEnvironment environment) where TFeature : class - { - return (TFeature)environment.GetFeature(typeof(TFeature)); - } - } -} diff --git a/src/Microsoft.AspNet.HttpEnvironment/IHttpEnvironment.cs b/src/Microsoft.AspNet.HttpEnvironment/IHttpEnvironment.cs index ab0bb92bc9..8c4b99eda5 100644 --- a/src/Microsoft.AspNet.HttpEnvironment/IHttpEnvironment.cs +++ b/src/Microsoft.AspNet.HttpEnvironment/IHttpEnvironment.cs @@ -2,7 +2,7 @@ namespace Microsoft.AspNet.HttpEnvironment { - public interface IHttpEnvironment : IFeatureContainer + public interface IHttpEnvironment : IInterfaceDictionary { } } diff --git a/src/Microsoft.AspNet.HttpEnvironment/Microsoft.AspNet.HttpEnvironment.csproj b/src/Microsoft.AspNet.HttpEnvironment/Microsoft.AspNet.HttpEnvironment.csproj index b1db630e6e..048afaa76f 100644 --- a/src/Microsoft.AspNet.HttpEnvironment/Microsoft.AspNet.HttpEnvironment.csproj +++ b/src/Microsoft.AspNet.HttpEnvironment/Microsoft.AspNet.HttpEnvironment.csproj @@ -34,8 +34,7 @@ - - + diff --git a/src/Microsoft.AspNet.HttpFeature/IHttpApplicationInformation.cs b/src/Microsoft.AspNet.HttpFeature/IHttpApplicationInformation.cs index 497bff550b..37dea109ab 100644 --- a/src/Microsoft.AspNet.HttpFeature/IHttpApplicationInformation.cs +++ b/src/Microsoft.AspNet.HttpFeature/IHttpApplicationInformation.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Security.Claims; using System.Threading; -namespace Microsoft.AspNet.Interfaces +namespace Microsoft.AspNet.HttpFeature { public interface IHttpApplicationInformation { diff --git a/src/Microsoft.AspNet.HttpFeature/IHttpBuffering.cs b/src/Microsoft.AspNet.HttpFeature/IHttpBuffering.cs index 2936208463..e13fde6988 100644 --- a/src/Microsoft.AspNet.HttpFeature/IHttpBuffering.cs +++ b/src/Microsoft.AspNet.HttpFeature/IHttpBuffering.cs @@ -1,4 +1,4 @@ -namespace Microsoft.AspNet.Interfaces +namespace Microsoft.AspNet.HttpFeature { public interface IHttpBuffering { diff --git a/src/Microsoft.AspNet.HttpFeature/IHttpConnection.cs b/src/Microsoft.AspNet.HttpFeature/IHttpConnection.cs index a375e3358b..d659efd69c 100644 --- a/src/Microsoft.AspNet.HttpFeature/IHttpConnection.cs +++ b/src/Microsoft.AspNet.HttpFeature/IHttpConnection.cs @@ -1,6 +1,6 @@ using System.Net; -namespace Microsoft.AspNet.Interfaces +namespace Microsoft.AspNet.HttpFeature { public interface IHttpConnection { diff --git a/src/Microsoft.AspNet.HttpFeature/IHttpRequest.cs b/src/Microsoft.AspNet.HttpFeature/IHttpRequestInformation.cs similarity index 83% rename from src/Microsoft.AspNet.HttpFeature/IHttpRequest.cs rename to src/Microsoft.AspNet.HttpFeature/IHttpRequestInformation.cs index f125863ee2..424c06f940 100644 --- a/src/Microsoft.AspNet.HttpFeature/IHttpRequest.cs +++ b/src/Microsoft.AspNet.HttpFeature/IHttpRequestInformation.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.IO; -namespace Microsoft.AspNet.Interfaces +namespace Microsoft.AspNet.HttpFeature { - public interface IHttpRequest + public interface IHttpRequestInformation { string Protocol { get; set; } string Scheme { get; set; } diff --git a/src/Microsoft.AspNet.HttpFeature/IHttpResponse.cs b/src/Microsoft.AspNet.HttpFeature/IHttpResponseInformation.cs similarity index 79% rename from src/Microsoft.AspNet.HttpFeature/IHttpResponse.cs rename to src/Microsoft.AspNet.HttpFeature/IHttpResponseInformation.cs index 85921559eb..ce0185c88e 100644 --- a/src/Microsoft.AspNet.HttpFeature/IHttpResponse.cs +++ b/src/Microsoft.AspNet.HttpFeature/IHttpResponseInformation.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.IO; -namespace Microsoft.AspNet.Interfaces +namespace Microsoft.AspNet.HttpFeature { - public interface IHttpResponse + public interface IHttpResponseInformation { int StatusCode { get; set; } string ReasonPhrase { get; set; } diff --git a/src/Microsoft.AspNet.HttpFeature/IHttpSendFile.cs b/src/Microsoft.AspNet.HttpFeature/IHttpSendFile.cs index 5d10d36c32..f64ea29264 100644 --- a/src/Microsoft.AspNet.HttpFeature/IHttpSendFile.cs +++ b/src/Microsoft.AspNet.HttpFeature/IHttpSendFile.cs @@ -1,7 +1,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNet.Interfaces +namespace Microsoft.AspNet.HttpFeature { public interface IHttpSendFile { diff --git a/src/Microsoft.AspNet.HttpFeature/IHttpTransportLayerSecurity.cs b/src/Microsoft.AspNet.HttpFeature/IHttpTransportLayerSecurity.cs index 0d4555284e..596462e28c 100644 --- a/src/Microsoft.AspNet.HttpFeature/IHttpTransportLayerSecurity.cs +++ b/src/Microsoft.AspNet.HttpFeature/IHttpTransportLayerSecurity.cs @@ -1,7 +1,7 @@ using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; -namespace Microsoft.AspNet.Interfaces +namespace Microsoft.AspNet.HttpFeature { public interface IHttpTransportLayerSecurity { diff --git a/src/Microsoft.AspNet.HttpFeature/IHttpWebSocketAccept.cs b/src/Microsoft.AspNet.HttpFeature/IHttpWebSocketAccept.cs index f5dbfb8c21..ad0374c7f9 100644 --- a/src/Microsoft.AspNet.HttpFeature/IHttpWebSocketAccept.cs +++ b/src/Microsoft.AspNet.HttpFeature/IHttpWebSocketAccept.cs @@ -1,7 +1,7 @@ using System.Net.WebSockets; using System.Threading.Tasks; -namespace Microsoft.AspNet.Interfaces +namespace Microsoft.AspNet.HttpFeature { public interface IHttpWebSocketAccept { diff --git a/src/Microsoft.AspNet.HttpFeature/Microsoft.AspNet.HttpFeature.csproj b/src/Microsoft.AspNet.HttpFeature/Microsoft.AspNet.HttpFeature.csproj index f881a5f0c9..7b6ab541d0 100644 --- a/src/Microsoft.AspNet.HttpFeature/Microsoft.AspNet.HttpFeature.csproj +++ b/src/Microsoft.AspNet.HttpFeature/Microsoft.AspNet.HttpFeature.csproj @@ -46,8 +46,8 @@ - - + + diff --git a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationChallenge.cs b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationChallenge.cs index cb336ef6c6..4f8324d45e 100644 --- a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationChallenge.cs +++ b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationChallenge.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Microsoft.AspNet.Interfaces +namespace Microsoft.AspNet.HttpFeature.Security { public interface IAuthenticationChallenge { diff --git a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationDescription.cs b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationDescription.cs index 590addffc4..f7cca258f5 100644 --- a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationDescription.cs +++ b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationDescription.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Microsoft.AspNet.Interfaces.Security +namespace Microsoft.AspNet.HttpFeature.Security { public interface IAuthenticationDescription { diff --git a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationResult.cs b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationResult.cs index 93c9e9a08d..b047bae8bd 100644 --- a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationResult.cs +++ b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationResult.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Security.Claims; +using Microsoft.AspNet.HttpFeature.Security; +// ReSharper disable once CheckNamespace namespace Microsoft.AspNet.Interfaces.Security { public interface IAuthenticationResult diff --git a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationSignIn.cs b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationSignIn.cs index 663f19a9a3..6033b173c5 100644 --- a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationSignIn.cs +++ b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationSignIn.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Security.Claims; -namespace Microsoft.AspNet.Interfaces.Security +namespace Microsoft.AspNet.HttpFeature.Security { public interface IAuthenticationSignIn { diff --git a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationSignOut.cs b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationSignOut.cs index 763bcaed7f..bab55a23e1 100644 --- a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationSignOut.cs +++ b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationSignOut.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Microsoft.AspNet.Interfaces.Security +namespace Microsoft.AspNet.HttpFeature.Security { public interface IAuthenticationSignOut { diff --git a/src/Microsoft.AspNet.HttpFeature/Security/IHttpAuthentication.cs b/src/Microsoft.AspNet.HttpFeature/Security/IHttpAuthentication.cs index ed955970ac..477df94a12 100644 --- a/src/Microsoft.AspNet.HttpFeature/Security/IHttpAuthentication.cs +++ b/src/Microsoft.AspNet.HttpFeature/Security/IHttpAuthentication.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; using System.Security.Principal; using System.Threading.Tasks; +using Microsoft.AspNet.Interfaces.Security; -namespace Microsoft.AspNet.Interfaces.Security +namespace Microsoft.AspNet.HttpFeature.Security { public interface IHttpAuthentication { diff --git a/src/Microsoft.AspNet.PipelineCore.Tests/BuilderTests.cs b/src/Microsoft.AspNet.PipelineCore.Tests/BuilderTests.cs index d4f89b64c4..c38e8bbd9a 100644 --- a/src/Microsoft.AspNet.PipelineCore.Tests/BuilderTests.cs +++ b/src/Microsoft.AspNet.PipelineCore.Tests/BuilderTests.cs @@ -12,8 +12,8 @@ namespace Microsoft.AspNet.PipelineCore.Tests var builder = new Builder(); var app = builder.Build(); - var mockHttpContext = new Moq.Mock(); - var mockHttpResponse = new Moq.Mock(); + var mockHttpContext = new Moq.Mock(); + var mockHttpResponse = new Moq.Mock(); mockHttpContext.SetupGet(x => x.Response).Returns(mockHttpResponse.Object); mockHttpResponse.SetupProperty(x => x.StatusCode); diff --git a/src/Microsoft.AspNet.PipelineCore/Builder.cs b/src/Microsoft.AspNet.PipelineCore/Builder.cs index 1e350b305d..26068cf03e 100644 --- a/src/Microsoft.AspNet.PipelineCore/Builder.cs +++ b/src/Microsoft.AspNet.PipelineCore/Builder.cs @@ -4,45 +4,52 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.HttpEnvironment; -using Microsoft.AspNet.Interfaces; -using Microsoft.AspNet.PipelineCore.Owin; namespace Microsoft.AspNet.PipelineCore { public class Builder : IBuilder { - private readonly IFeatureContainer _features; + private readonly IInterfaceDictionary _interfaces; + private readonly IDictionary _properties; private readonly IList _components = new List(); public Builder() { - _features = new FeatureModel.FeatureContainer(); + _interfaces = new InterfaceDictionary(); + _properties = new Dictionary(); } - public Builder(IFeatureContainer features) + public Builder(IInterfaceDictionary interfaces, IDictionary properties) { - _features = features; + _interfaces = interfaces; + _properties = properties; } public void Dispose() { - _features.Dispose(); + _interfaces.Dispose(); } - public virtual object GetFeature(Type type) + public virtual object GetItem(Type key) { - return _features.GetFeature(type); + object value; + return _interfaces.TryGetValue(key, out value); } - public virtual void SetFeature(Type type, object feature) + public virtual void SetItem(Type key, object value) { - _features.SetFeature(type, feature); + _interfaces[key] = value; } - public virtual int Revision + public virtual object GetItem(string key) { - get { return _features.Revision; } + object value; + return _properties.TryGetValue(key, out value); + } + + public virtual void SetItem(string key, object value) + { + _properties[key] = value; } public IBuilder Use(object middleware, params object[] args) @@ -65,7 +72,7 @@ namespace Microsoft.AspNet.PipelineCore public IBuilder New() { - return new Builder(_features); + return new Builder(_interfaces, _properties); } public RequestDelegate Build() diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs new file mode 100644 index 0000000000..bbd69ef0f8 --- /dev/null +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs @@ -0,0 +1,42 @@ +using System; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.FeatureModel; + +namespace Microsoft.AspNet.PipelineCore +{ + public class DefaultHttpContext : HttpContext + { + private readonly IInterfaceDictionary _environment; + private readonly HttpRequest _request; + private readonly HttpResponse _response; + + public DefaultHttpContext(IInterfaceDictionary environment) + { + _environment = environment; + _request = new DefaultHttpRequest(this); + _response = new DefaultHttpResponse(this); + } + + public override HttpRequest Request { get { return _request; } } + public override HttpResponse Response { get { return _response; } } + + public int Revision { get { return _environment.Revision; } } + + public override void Dispose() + { + // REVIEW: is this necessary? is the environment "owned" by the context? + _environment.Dispose(); + } + + public override object GetInterface(Type type) + { + object value; + return _environment.TryGetValue(type, out value) ? value : null; + } + + public override void SetInterface(Type type, object instance) + { + _environment[type] = instance; + } + } +} diff --git a/src/Microsoft.AspNet.PipelineCore/HttpRequest.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpRequest.cs similarity index 77% rename from src/Microsoft.AspNet.PipelineCore/HttpRequest.cs rename to src/Microsoft.AspNet.PipelineCore/DefaultHttpRequest.cs index 2a7385d81a..73860a9f32 100644 --- a/src/Microsoft.AspNet.PipelineCore/HttpRequest.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpRequest.cs @@ -1,31 +1,31 @@ using System; using System.IO; using Microsoft.AspNet.Abstractions; -using Microsoft.AspNet.HttpEnvironment; +using Microsoft.AspNet.HttpFeature; using Microsoft.AspNet.Interfaces; namespace Microsoft.AspNet.PipelineCore { - public class HttpRequest : HttpRequestBase + public class DefaultHttpRequest : HttpRequest { - private readonly HttpContext _context; + private readonly DefaultHttpContext _context; private int _revision; - private IHttpRequest _request; + private IHttpRequestInformation _request; private IHttpConnection _connection; - public HttpRequest(HttpContext context) + public DefaultHttpRequest(DefaultHttpContext context) { _context = context; } - private IHttpRequest IHttpRequest + private IHttpRequestInformation IHttpRequest { - get { return EnsureCurrent(_request) ?? (_request = _context.GetFeature()); } + get { return EnsureCurrent(_request) ?? (_request = _context.GetInterface()); } } private IHttpConnection IHttpConnection { - get { return EnsureCurrent(_connection) ?? (_connection = _context.GetFeature()); } + get { return EnsureCurrent(_connection) ?? (_connection = _context.GetInterface()); } } private T EnsureCurrent(T feature) where T : class @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.PipelineCore return null; } - public override HttpContextBase HttpContext { get { return _context; } } + public override HttpContext HttpContext { get { return _context; } } public override Uri Uri { diff --git a/src/Microsoft.AspNet.PipelineCore/HttpResponse.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs similarity index 61% rename from src/Microsoft.AspNet.PipelineCore/HttpResponse.cs rename to src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs index bb467e8691..27ed56f4e5 100644 --- a/src/Microsoft.AspNet.PipelineCore/HttpResponse.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs @@ -1,24 +1,24 @@ using System.IO; using Microsoft.AspNet.Abstractions; -using Microsoft.AspNet.HttpEnvironment; -using Microsoft.AspNet.Interfaces; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.HttpFeature.Security; namespace Microsoft.AspNet.PipelineCore { - public class HttpResponse : HttpResponseBase + public class DefaultHttpResponse : HttpResponse { - private readonly HttpContext _context; - private IHttpResponse _response; + private readonly DefaultHttpContext _context; + private IHttpResponseInformation _response; private int _revision; - public HttpResponse(HttpContext context) + public DefaultHttpResponse(DefaultHttpContext context) { _context = context; } - private IHttpResponse IHttpResponse + private IHttpResponseInformation IHttpResponse { - get { return EnsureCurrent(_response) ?? (_response = _context.GetFeature()); } + get { return EnsureCurrent(_response) ?? (_response = _context.GetInterface()); } } private T EnsureCurrent(T feature) where T : class @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.PipelineCore return null; } - public override HttpContextBase HttpContext { get { return _context; } } + public override HttpContext HttpContext { get { return _context; } } public override int StatusCode { diff --git a/src/Microsoft.AspNet.PipelineCore/HttpContext.cs b/src/Microsoft.AspNet.PipelineCore/HttpContext.cs deleted file mode 100644 index a75c522b56..0000000000 --- a/src/Microsoft.AspNet.PipelineCore/HttpContext.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using Microsoft.AspNet.Abstractions; -using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.HttpEnvironment; - -namespace Microsoft.AspNet.PipelineCore -{ - public class HttpContext : HttpContextBase, IHttpEnvironment - { - private readonly IFeatureContainer _features; - private readonly HttpRequestBase _request; - private readonly HttpResponseBase _response; - - public HttpContext(IHttpEnvironment environment) - { - _features = environment; - _request = new HttpRequest(this); - _response = new HttpResponse(this); - } - - public override HttpRequestBase Request { get { return _request; } } - public override HttpResponseBase Response { get { return _response; } } - - public void Dispose() - { - _features.Dispose(); - } - - public object GetFeature(Type type) - { - return _features.GetFeature(type); - } - - public void SetFeature(Type type, object feature) - { - _features.SetFeature(type, feature); - } - - public int Revision - { - get { return _features.Revision; } - } - } -} diff --git a/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.csproj b/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.csproj index 1cd72c4c66..27cd7e01f4 100644 --- a/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.csproj +++ b/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.csproj @@ -36,9 +36,9 @@ - - - + + + @@ -52,10 +52,6 @@ {4e1520b1-01f4-481b-96a2-24067eaa52fa} Microsoft.AspNet.Abstractions - - {46D69EC9-7096-49D8-A184-A9BB5B2419A1} - Microsoft.AspNet.HttpEnvironment - {42309978-0661-41d8-8654-39453265c5f9} Microsoft.AspNet.HttpFeature diff --git a/src/Microsoft.AspNet.PipelineCore/Owin/OwinHttpEnvironment.cs b/src/Microsoft.AspNet.PipelineCore/Owin/OwinHttpEnvironment.cs index 8f8a948434..124f49e471 100644 --- a/src/Microsoft.AspNet.PipelineCore/Owin/OwinHttpEnvironment.cs +++ b/src/Microsoft.AspNet.PipelineCore/Owin/OwinHttpEnvironment.cs @@ -6,13 +6,13 @@ using System.Net; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.HttpEnvironment; +using Microsoft.AspNet.HttpFeature; using Microsoft.AspNet.Interfaces; namespace Microsoft.AspNet.PipelineCore.Owin { public class OwinHttpEnvironment : - IHttpRequest, IHttpResponse, IHttpConnection, IHttpSendFile, IHttpTransportLayerSecurity + IHttpRequestInformation, IHttpResponseInformation, IHttpConnection, IHttpSendFile, IHttpTransportLayerSecurity { public IDictionary Environment { get; set; } @@ -36,84 +36,84 @@ namespace Microsoft.AspNet.PipelineCore.Owin Environment[key] = value; } - string IHttpRequest.Protocol + string IHttpRequestInformation.Protocol { get { return Prop("owin.RequestProtocol"); } set { Prop("owin.RequestProtocol", value); } } - Uri IHttpRequest.Uri + Uri IHttpRequestInformation.Uri { get { throw new NotImplementedException(); } } - string IHttpRequest.Scheme + string IHttpRequestInformation.Scheme { get { return Prop("owin.RequestScheme"); } set { Prop("owin.RequestScheme", value); } } - string IHttpRequest.Method + string IHttpRequestInformation.Method { get { return Prop("owin.RequestMethod"); } set { Prop("owin.RequestMethod", value); } } - string IHttpRequest.PathBase + string IHttpRequestInformation.PathBase { get { return Prop("owin.RequestPathBase"); } set { Prop("owin.RequestPathBase", value); } } - string IHttpRequest.Path + string IHttpRequestInformation.Path { get { return Prop("owin.RequestPath"); } set { Prop("owin.RequestPath", value); } } - string IHttpRequest.QueryString + string IHttpRequestInformation.QueryString { get { return Prop("owin.RequestQueryString"); } set { Prop("owin.RequestQueryString", value); } } - IDictionary IHttpRequest.Headers + IDictionary IHttpRequestInformation.Headers { get { return Prop>("owin.RequestHeaders"); } set { Prop("owin.RequestHeaders", value); } } - Stream IHttpRequest.Body + Stream IHttpRequestInformation.Body { get { return Prop("owin.RequestBody"); } set { Prop("owin.RequestBody", value); } } - int IHttpResponse.StatusCode + int IHttpResponseInformation.StatusCode { get { return Prop("owin.ResponseStatusCode"); } set { Prop("owin.ResponseStatusCode", value); } } - string IHttpResponse.ReasonPhrase + string IHttpResponseInformation.ReasonPhrase { get { return Prop("owin.ResponseReasonPhrase"); } set { Prop("owin.ResponseReasonPhrase", value); } } - IDictionary IHttpResponse.Headers + IDictionary IHttpResponseInformation.Headers { get { return Prop>("owin.ResponseHeaders"); } set { Prop("owin.ResponseHeaders", value); } } - Stream IHttpResponse.Body + Stream IHttpResponseInformation.Body { get { return Prop("owin.ResponseBody"); } set { Prop("owin.ResponseBody", value); } } - void IHttpResponse.OnSendingHeaders(Action callback, object state) + void IHttpResponseInformation.OnSendingHeaders(Action callback, object state) { // TODO: } diff --git a/test/Microsoft.AspNet.FeatureModel.Tests/Class1.cs b/test/Microsoft.AspNet.FeatureModel.Tests/Class1.cs new file mode 100644 index 0000000000..7527e07ffc --- /dev/null +++ b/test/Microsoft.AspNet.FeatureModel.Tests/Class1.cs @@ -0,0 +1,63 @@ +using System; +using Shouldly; +using Xunit; + +namespace Microsoft.AspNet.FeatureModel.Tests +{ + public interface IThing + { + string Hello(); + } + + public class Thing : IThing + { + public string Hello() + { + return "World"; + } + } + + public class InterfaceDictionaryTests + { + [Fact] + public void AddedInterfaceIsReturned() + { + var interfaces = new InterfaceDictionary(); + var thing = new Thing(); + + interfaces.Add(typeof(IThing), thing); + + interfaces[typeof(IThing)].ShouldBe(thing); + + object thing2; + interfaces.TryGetValue(typeof(IThing), out thing2).ShouldBe(true); + thing2.ShouldBe(thing); + } + + [Fact] + public void IndexerAlsoAddsItems() + { + var interfaces = new InterfaceDictionary(); + var thing = new Thing(); + + interfaces[typeof(IThing)] = thing; + + interfaces[typeof(IThing)].ShouldBe(thing); + + object thing2; + interfaces.TryGetValue(typeof(IThing), out thing2).ShouldBe(true); + thing2.ShouldBe(thing); + } + + [Fact] + public void SecondCallToAddThrowsException() + { + var interfaces = new InterfaceDictionary(); + var thing = new Thing(); + + interfaces.Add(typeof(IThing), thing); + + Should.Throw(() => interfaces.Add(typeof(IThing), thing)); + } + } +} diff --git a/test/Microsoft.AspNet.FeatureModel.Tests/Microsoft.AspNet.FeatureModel.Tests.csproj b/test/Microsoft.AspNet.FeatureModel.Tests/Microsoft.AspNet.FeatureModel.Tests.csproj new file mode 100644 index 0000000000..98d1189ee4 --- /dev/null +++ b/test/Microsoft.AspNet.FeatureModel.Tests/Microsoft.AspNet.FeatureModel.Tests.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {8C671AE3-1188-499F-A2A2-3A0B117B33CE} + Library + Properties + Microsoft.AspNet.FeatureModel.Tests + Microsoft.AspNet.FeatureModel.Tests + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\Shouldly.1.1.1.1\lib\35\Shouldly.dll + + + + + ..\..\packages\xunit.1.9.2\lib\net20\xunit.dll + + + + + + + + + + + + {A780873E-09F9-4E44-AE06-AF00C4E88E1E} + Microsoft.AspNet.FeatureModel + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.FeatureModel.Tests/Properties/AssemblyInfo.cs b/test/Microsoft.AspNet.FeatureModel.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..da65ff9698 --- /dev/null +++ b/test/Microsoft.AspNet.FeatureModel.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft.AspNet.FeatureModel.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Microsoft.AspNet.FeatureModel.Tests")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a780740b-8831-40e0-a084-489d738dfef5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/Microsoft.AspNet.FeatureModel.Tests/packages.config b/test/Microsoft.AspNet.FeatureModel.Tests/packages.config new file mode 100644 index 0000000000..5500407987 --- /dev/null +++ b/test/Microsoft.AspNet.FeatureModel.Tests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file