API to retrieve wrapped services
This commit is contained in:
Родитель
e77aac8542
Коммит
2bc5d0fade
|
@ -1,47 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http.OData.Formatter;
|
||||
using Microsoft.Data.Edm;
|
||||
|
||||
namespace System.Web.Http
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal static class MediaTypeFormatterExtensions
|
||||
{
|
||||
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
|
||||
Justification = "Calling the formatter only to identify the ODataFormatter; exceptions can be ignored")]
|
||||
internal static bool IsODataFormatter(this MediaTypeFormatter formatter)
|
||||
{
|
||||
Contract.Assert(formatter != null);
|
||||
|
||||
ODataMediaTypeFormatter odataFormatter = formatter as ODataMediaTypeFormatter;
|
||||
|
||||
if (odataFormatter != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Detects ODataFormatters that are wrapped by tracing
|
||||
// Creates a dummy request message and sees if the formatter adds a model to the request properties
|
||||
// This is a workaround until tracing provides information about the wrapped inner formatter
|
||||
using (HttpRequestMessage request = new HttpRequestMessage())
|
||||
{
|
||||
try
|
||||
{
|
||||
formatter.GetPerRequestFormatterInstance(typeof(IEdmModel), request, mediaType: null);
|
||||
return request.Properties.ContainsKey(ODataMediaTypeFormatter.IsODataKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore exceptions - it isn't the OData formatter we're looking for
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,8 +32,6 @@ namespace System.Web.Http.OData.Formatter
|
|||
private const string ODataMaxServiceVersion = "MaxDataServiceVersion";
|
||||
private const string ODataServiceVersion = "DataServiceVersion";
|
||||
|
||||
internal const string IsODataKey = "MS_IsOData";
|
||||
|
||||
private readonly ODataDeserializerProvider _deserializerProvider;
|
||||
private readonly ODataVersion _version;
|
||||
|
||||
|
@ -161,13 +159,6 @@ namespace System.Web.Http.OData.Formatter
|
|||
}
|
||||
else
|
||||
{
|
||||
// Adds information to allow callers to identify the ODataMediaTypeFormatter through the tracing wrapper
|
||||
// This is a workaround until tracing provides information about the wrapped inner formatter
|
||||
if (type == typeof(IEdmModel))
|
||||
{
|
||||
request.Properties[IsODataKey] = true;
|
||||
}
|
||||
|
||||
ODataVersion version = GetResponseODataVersion(request);
|
||||
return new ODataMediaTypeFormatter(this, version, request);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Linq;
|
|||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.OData.Formatter;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.OData
|
||||
{
|
||||
|
@ -50,7 +51,7 @@ namespace System.Web.Http.OData
|
|||
|
||||
// If any OData formatters are registered globally, do nothing and use those instead
|
||||
MediaTypeFormatterCollection controllerFormatters = controllerSettings.Formatters;
|
||||
if (!controllerFormatters.Where(f => f != null && f.IsODataFormatter()).Any())
|
||||
if (!controllerFormatters.Where(f => f != null && Decorator.GetInner(f) is ODataMediaTypeFormatter).Any())
|
||||
{
|
||||
// Remove Xml and Json formatters to avoid media type conflicts
|
||||
controllerFormatters.RemoveRange(
|
||||
|
|
|
@ -80,7 +80,6 @@
|
|||
<Compile Include="OData\Routing\ODataRouteConstants.cs" />
|
||||
<Compile Include="OData\EntitySetController.cs" />
|
||||
<Compile Include="OData\NonValidatingParameterBindingAttribute.cs" />
|
||||
<Compile Include="MediaTypeFormatterExtensions.cs" />
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
<Compile Include="ODataHttpErrorExtensions.cs" />
|
||||
<Compile Include="ODataHttpConfigurationExtensions.cs" />
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
namespace System.Web.Http.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a method for retrieving the innermost object of an object that might be wrapped by an <see cref="IDecorator{T}"/>.
|
||||
/// </summary>
|
||||
public static class Decorator
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the innermost object which does not implement <see cref="IDecorator{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="outer">Object which needs to be unwrapped.</param>
|
||||
/// <returns>The innermost object of Type T which does not implement <see cref="IDecorator{T}"/>.</returns>
|
||||
public static T GetInner<T>(T outer)
|
||||
{
|
||||
T inner = outer;
|
||||
IDecorator<T> decorator = inner as IDecorator<T>;
|
||||
while (decorator != null)
|
||||
{
|
||||
inner = decorator.Inner;
|
||||
IDecorator<T> innerDecorator = inner as IDecorator<T>;
|
||||
if (decorator == innerDecorator)
|
||||
{
|
||||
break;
|
||||
}
|
||||
decorator = innerDecorator;
|
||||
}
|
||||
|
||||
return inner;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
namespace System.Web.Http.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a decorator that exposes the inner decorated object.
|
||||
/// </summary>
|
||||
public interface IDecorator<out T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the inner object.
|
||||
/// </summary>
|
||||
T Inner { get; }
|
||||
}
|
||||
}
|
|
@ -110,6 +110,8 @@
|
|||
<Compile Include="Routing\HttpRouteEntry.cs" />
|
||||
<Compile Include="Routing\IHttpRouteInfoProvider.cs" />
|
||||
<Compile Include="Routing\IInlineConstraintResolver.cs" />
|
||||
<Compile Include="Services\Decorator.cs" />
|
||||
<Compile Include="Services\IDecorator.cs" />
|
||||
<Compile Include="Tracing\TraceLevelHelper.cs" />
|
||||
<Compile Include="Tracing\TraceKindHelper.cs" />
|
||||
<Compile Include="Validation\IModelValidatorCache.cs" />
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Net.Http;
|
|||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
|
@ -13,7 +14,7 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
/// Tracer for <see cref="ActionFilterAttribute"/>.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "internal type needs to override, tracer are not sealed")]
|
||||
internal class ActionFilterAttributeTracer : ActionFilterAttribute
|
||||
internal class ActionFilterAttributeTracer : ActionFilterAttribute, IDecorator<ActionFilterAttribute>
|
||||
{
|
||||
private const string ActionExecutedMethodName = "ActionExecuted";
|
||||
private const string ActionExecutingMethodName = "ActionExecuting";
|
||||
|
@ -30,6 +31,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public ActionFilterAttribute Inner
|
||||
{
|
||||
get { return _innerFilter; }
|
||||
}
|
||||
|
||||
public override bool AllowMultiple
|
||||
{
|
||||
get
|
||||
|
|
|
@ -5,13 +5,14 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IActionFilter"/>.
|
||||
/// </summary>
|
||||
internal class ActionFilterTracer : FilterTracer, IActionFilter
|
||||
internal class ActionFilterTracer : FilterTracer, IActionFilter, IDecorator<IActionFilter>
|
||||
{
|
||||
private const string ExecuteActionFilterAsyncMethodName = "ExecuteActionFilterAsync";
|
||||
|
||||
|
@ -20,6 +21,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
{
|
||||
}
|
||||
|
||||
public new IActionFilter Inner
|
||||
{
|
||||
get { return InnerActionFilter; }
|
||||
}
|
||||
|
||||
private IActionFilter InnerActionFilter
|
||||
{
|
||||
get { return InnerFilter as IActionFilter; }
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
using System.Diagnostics.Contracts;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IActionValueBinder"/>
|
||||
/// </summary>
|
||||
internal class ActionValueBinderTracer : IActionValueBinder
|
||||
internal class ActionValueBinderTracer : IActionValueBinder, IDecorator<IActionValueBinder>
|
||||
{
|
||||
private readonly IActionValueBinder _innerBinder;
|
||||
private readonly ITraceWriter _traceWriter;
|
||||
|
@ -23,6 +24,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public IActionValueBinder Inner
|
||||
{
|
||||
get { return _innerBinder; }
|
||||
}
|
||||
|
||||
// Creates wrapping tracers for all HttpParameterBindings
|
||||
HttpActionBinding IActionValueBinder.GetBinding(HttpActionDescriptor actionDescriptor)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Diagnostics.Contracts;
|
|||
using System.Net.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
|
@ -12,7 +13,7 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
/// Tracer for <see cref="AuthorizationFilterAttribute"/>
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "internal type needs to override, tracer are not sealed")]
|
||||
internal class AuthorizationFilterAttributeTracer : AuthorizationFilterAttribute
|
||||
internal class AuthorizationFilterAttributeTracer : AuthorizationFilterAttribute, IDecorator<AuthorizationFilterAttribute>
|
||||
{
|
||||
private const string OnAuthorizationMethodName = "OnAuthorization";
|
||||
|
||||
|
@ -28,6 +29,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceStore = traceWriter;
|
||||
}
|
||||
|
||||
public AuthorizationFilterAttribute Inner
|
||||
{
|
||||
get { return _innerFilter; }
|
||||
}
|
||||
|
||||
public override bool AllowMultiple
|
||||
{
|
||||
get
|
||||
|
|
|
@ -5,13 +5,14 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IAuthorizationFilter"/>.
|
||||
/// </summary>
|
||||
internal class AuthorizationFilterTracer : FilterTracer, IAuthorizationFilter
|
||||
internal class AuthorizationFilterTracer : FilterTracer, IAuthorizationFilter, IDecorator<IAuthorizationFilter>
|
||||
{
|
||||
private const string ExecuteAuthorizationFilterAsyncMethodName = "ExecuteAuthorizationFilterAsync";
|
||||
|
||||
|
@ -20,6 +21,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
{
|
||||
}
|
||||
|
||||
public new IAuthorizationFilter Inner
|
||||
{
|
||||
get { return InnerAuthorizationFilter; }
|
||||
}
|
||||
|
||||
private IAuthorizationFilter InnerAuthorizationFilter
|
||||
{
|
||||
get { return InnerFilter as IAuthorizationFilter; }
|
||||
|
|
|
@ -6,18 +6,21 @@ using System.Net.Http;
|
|||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
internal class BufferedMediaTypeFormatterTracer : BufferedMediaTypeFormatter, IFormatterTracer
|
||||
internal class BufferedMediaTypeFormatterTracer : BufferedMediaTypeFormatter, IFormatterTracer, IDecorator<BufferedMediaTypeFormatter>
|
||||
{
|
||||
private const string OnReadFromStreamMethodName = "ReadFromStream";
|
||||
private const string OnWriteToStreamMethodName = "WriteToStream";
|
||||
|
||||
private readonly BufferedMediaTypeFormatter _inner;
|
||||
private MediaTypeFormatterTracer _innerTracer;
|
||||
|
||||
public BufferedMediaTypeFormatterTracer(BufferedMediaTypeFormatter innerFormatter, ITraceWriter traceWriter, HttpRequestMessage request)
|
||||
{
|
||||
_inner = innerFormatter;
|
||||
_innerTracer = new MediaTypeFormatterTracer(innerFormatter, traceWriter, request);
|
||||
|
||||
// copy non-overridable members from inner formatter
|
||||
|
@ -30,6 +33,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
get { return _innerTracer.Request; }
|
||||
}
|
||||
|
||||
public BufferedMediaTypeFormatter Inner
|
||||
{
|
||||
get { return _inner; }
|
||||
}
|
||||
|
||||
public MediaTypeFormatter InnerFormatter
|
||||
{
|
||||
get { return _innerTracer.InnerFormatter; }
|
||||
|
|
|
@ -5,13 +5,14 @@ using System.Diagnostics.Contracts;
|
|||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IContentNegotiator"/>.
|
||||
/// </summary>
|
||||
internal class ContentNegotiatorTracer : IContentNegotiator
|
||||
internal class ContentNegotiatorTracer : IContentNegotiator, IDecorator<IContentNegotiator>
|
||||
{
|
||||
private const string NegotiateMethodName = "Negotiate";
|
||||
|
||||
|
@ -27,6 +28,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public IContentNegotiator Inner
|
||||
{
|
||||
get { return _innerNegotiator; }
|
||||
}
|
||||
|
||||
public ContentNegotiationResult Negotiate(Type type, HttpRequestMessage request, IEnumerable<MediaTypeFormatter> formatters)
|
||||
{
|
||||
ContentNegotiationResult result = null;
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using System.Diagnostics.Contracts;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
|
@ -11,7 +12,7 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
/// Tracer for <see cref="ExceptionFilterAttribute"/>.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "internal type needs to override, tracer are not sealed")]
|
||||
internal class ExceptionFilterAttributeTracer : ExceptionFilterAttribute
|
||||
internal class ExceptionFilterAttributeTracer : ExceptionFilterAttribute, IDecorator<ExceptionFilterAttribute>
|
||||
{
|
||||
private const string OnExceptionMethodName = "OnException";
|
||||
|
||||
|
@ -27,6 +28,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceStore = traceWriter;
|
||||
}
|
||||
|
||||
public ExceptionFilterAttribute Inner
|
||||
{
|
||||
get { return _innerFilter; }
|
||||
}
|
||||
|
||||
public override bool AllowMultiple
|
||||
{
|
||||
get
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IExceptionFilter"/>.
|
||||
/// </summary>
|
||||
internal class ExceptionFilterTracer : FilterTracer, IExceptionFilter
|
||||
internal class ExceptionFilterTracer : FilterTracer, IExceptionFilter, IDecorator<IExceptionFilter>
|
||||
{
|
||||
private const string ExecuteExceptionFilterAsyncMethodName = "ExecuteExceptionFilterAsync";
|
||||
|
||||
|
@ -18,6 +19,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
{
|
||||
}
|
||||
|
||||
public new IExceptionFilter Inner
|
||||
{
|
||||
get { return InnerExceptionFilter; }
|
||||
}
|
||||
|
||||
public IExceptionFilter InnerExceptionFilter
|
||||
{
|
||||
get { return InnerFilter as IExceptionFilter; }
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class and helper for the creation of filter tracers.
|
||||
/// </summary>
|
||||
internal class FilterTracer : IFilter
|
||||
internal class FilterTracer : IFilter, IDecorator<IFilter>
|
||||
{
|
||||
public FilterTracer(IFilter innerFilter, ITraceWriter traceWriter)
|
||||
{
|
||||
|
@ -20,6 +21,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
TraceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public IFilter Inner
|
||||
{
|
||||
get { return InnerFilter; }
|
||||
}
|
||||
|
||||
public IFilter InnerFilter { get; set; }
|
||||
|
||||
public ITraceWriter TraceWriter { get; set; }
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Net.Http;
|
|||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
|
@ -13,11 +14,14 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
/// Tracer for <see cref="FormUrlEncodedMediaTypeFormatter"/>.
|
||||
/// It is required because users can select formatters by this type.
|
||||
/// </summary>
|
||||
internal class FormUrlEncodedMediaTypeFormatterTracer : FormUrlEncodedMediaTypeFormatter, IFormatterTracer
|
||||
internal class FormUrlEncodedMediaTypeFormatterTracer : FormUrlEncodedMediaTypeFormatter, IFormatterTracer, IDecorator<FormUrlEncodedMediaTypeFormatter>
|
||||
{
|
||||
private readonly FormUrlEncodedMediaTypeFormatter _inner;
|
||||
private MediaTypeFormatterTracer _innerTracer;
|
||||
|
||||
public FormUrlEncodedMediaTypeFormatterTracer(FormUrlEncodedMediaTypeFormatter innerFormatter, ITraceWriter traceWriter, HttpRequestMessage request)
|
||||
{
|
||||
_inner = innerFormatter;
|
||||
_innerTracer = new MediaTypeFormatterTracer(innerFormatter, traceWriter, request);
|
||||
|
||||
// copy non-overridable members from inner formatter
|
||||
|
@ -31,6 +35,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
get { return _innerTracer.Request; }
|
||||
}
|
||||
|
||||
public FormUrlEncodedMediaTypeFormatter Inner
|
||||
{
|
||||
get { return _inner; }
|
||||
}
|
||||
|
||||
public MediaTypeFormatter InnerFormatter
|
||||
{
|
||||
get { return _innerTracer.InnerFormatter; }
|
||||
|
|
|
@ -11,6 +11,7 @@ using System.Web.Http.Controllers;
|
|||
using System.Web.Http.Metadata;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
|
@ -18,12 +19,12 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
/// Tracer to wrap a <see cref="FormatterParameterBinding"/>.
|
||||
/// Its primary purpose is to intercept binding requests so that it can create tracers for the formatters.
|
||||
/// </summary>
|
||||
internal class FormatterParameterBindingTracer : FormatterParameterBinding
|
||||
internal class FormatterParameterBindingTracer : FormatterParameterBinding, IDecorator<FormatterParameterBinding>
|
||||
{
|
||||
private const string ExecuteBindingAsyncMethodName = "ExecuteBindingAsync";
|
||||
|
||||
private FormatterParameterBinding _innerBinding;
|
||||
private ITraceWriter _traceWriter;
|
||||
private readonly FormatterParameterBinding _innerBinding;
|
||||
private readonly ITraceWriter _traceWriter;
|
||||
|
||||
public FormatterParameterBindingTracer(FormatterParameterBinding innerBinding, ITraceWriter traceWriter) : base(innerBinding.Descriptor, innerBinding.Formatters, innerBinding.BodyModelValidator)
|
||||
{
|
||||
|
@ -34,6 +35,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public FormatterParameterBinding Inner
|
||||
{
|
||||
get { return _innerBinding; }
|
||||
}
|
||||
|
||||
public override string ErrorMessage
|
||||
{
|
||||
get { return _innerBinding.ErrorMessage; }
|
||||
|
|
|
@ -5,10 +5,11 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
internal class HttpActionBindingTracer : HttpActionBinding
|
||||
internal class HttpActionBindingTracer : HttpActionBinding, IDecorator<HttpActionBinding>
|
||||
{
|
||||
private const string ExecuteBindingAsyncMethodName = "ExecuteBindingAsync";
|
||||
|
||||
|
@ -36,6 +37,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
}
|
||||
}
|
||||
|
||||
public HttpActionBinding Inner
|
||||
{
|
||||
get { return _innerBinding; }
|
||||
}
|
||||
|
||||
public override Task ExecuteBindingAsync(Controllers.HttpActionContext actionContext, CancellationToken cancellationToken)
|
||||
{
|
||||
return _traceWriter.TraceBeginEndAsync(
|
||||
|
|
|
@ -11,13 +11,14 @@ using System.Threading.Tasks;
|
|||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="HttpActionDescriptor"/>.
|
||||
/// </summary>
|
||||
internal class HttpActionDescriptorTracer : HttpActionDescriptor
|
||||
internal class HttpActionDescriptorTracer : HttpActionDescriptor, IDecorator<HttpActionDescriptor>
|
||||
{
|
||||
private const string ExecuteMethodName = "ExecuteAsync";
|
||||
|
||||
|
@ -34,6 +35,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public HttpActionDescriptor Inner
|
||||
{
|
||||
get { return _innerDescriptor; }
|
||||
}
|
||||
|
||||
public override ConcurrentDictionary<object, object> Properties
|
||||
{
|
||||
get
|
||||
|
|
|
@ -6,13 +6,14 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IHttpActionInvoker"/>.
|
||||
/// </summary>
|
||||
internal class HttpActionInvokerTracer : IHttpActionInvoker
|
||||
internal class HttpActionInvokerTracer : IHttpActionInvoker, IDecorator<IHttpActionInvoker>
|
||||
{
|
||||
private const string InvokeActionAsyncMethodName = "InvokeActionAsync";
|
||||
|
||||
|
@ -28,6 +29,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public IHttpActionInvoker Inner
|
||||
{
|
||||
get { return _innerInvoker; }
|
||||
}
|
||||
|
||||
Task<HttpResponseMessage> IHttpActionInvoker.InvokeActionAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
|
||||
{
|
||||
if (actionContext == null)
|
||||
|
|
|
@ -4,13 +4,14 @@ using System.Diagnostics.Contracts;
|
|||
using System.Linq;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IHttpActionSelector"/>.
|
||||
/// </summary>
|
||||
internal class HttpActionSelectorTracer : IHttpActionSelector
|
||||
internal class HttpActionSelectorTracer : IHttpActionSelector, IDecorator<IHttpActionSelector>
|
||||
{
|
||||
private const string SelectActionMethodName = "SelectAction";
|
||||
|
||||
|
@ -26,6 +27,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public IHttpActionSelector Inner
|
||||
{
|
||||
get { return _innerSelector; }
|
||||
}
|
||||
|
||||
public ILookup<string, HttpActionDescriptor> GetActionMapping(HttpControllerDescriptor controllerDescriptor)
|
||||
{
|
||||
return _innerSelector.GetActionMapping(controllerDescriptor);
|
||||
|
|
|
@ -5,13 +5,14 @@ using System.Net.Http;
|
|||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Dispatcher;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IHttpControllerActivator"/>.
|
||||
/// </summary>
|
||||
internal class HttpControllerActivatorTracer : IHttpControllerActivator
|
||||
internal class HttpControllerActivatorTracer : IHttpControllerActivator, IDecorator<IHttpControllerActivator>
|
||||
{
|
||||
private const string CreateMethodName = "Create";
|
||||
|
||||
|
@ -27,6 +28,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public IHttpControllerActivator Inner
|
||||
{
|
||||
get { return _innerActivator; }
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "disposable controller is later released in ReleaseController")]
|
||||
IHttpController IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
|
||||
{
|
||||
|
|
|
@ -7,13 +7,14 @@ using System.Diagnostics.Contracts;
|
|||
using System.Net.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref=" HttpControllerDescriptor"/>
|
||||
/// </summary>
|
||||
internal class HttpControllerDescriptorTracer : HttpControllerDescriptor
|
||||
internal class HttpControllerDescriptorTracer : HttpControllerDescriptor, IDecorator<HttpControllerDescriptor>
|
||||
{
|
||||
private const string CreateControllerMethodName = "CreateController";
|
||||
|
||||
|
@ -28,7 +29,12 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
|
||||
_innerDescriptor = innerDescriptor;
|
||||
_traceWriter = traceWriter;
|
||||
}
|
||||
}
|
||||
|
||||
public HttpControllerDescriptor Inner
|
||||
{
|
||||
get { return _innerDescriptor; }
|
||||
}
|
||||
|
||||
public override ConcurrentDictionary<object, object> Properties
|
||||
{
|
||||
|
|
|
@ -6,13 +6,14 @@ using System.Net.Http;
|
|||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Dispatcher;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IHttpControllerSelector"/>.
|
||||
/// </summary>
|
||||
internal class HttpControllerSelectorTracer : IHttpControllerSelector
|
||||
internal class HttpControllerSelectorTracer : IHttpControllerSelector, IDecorator<IHttpControllerSelector>
|
||||
{
|
||||
private const string SelectControllerMethodName = "SelectController";
|
||||
|
||||
|
@ -28,6 +29,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public IHttpControllerSelector Inner
|
||||
{
|
||||
get { return _innerSelector; }
|
||||
}
|
||||
|
||||
HttpControllerDescriptor IHttpControllerSelector.SelectController(HttpRequestMessage request)
|
||||
{
|
||||
HttpControllerDescriptor controllerDescriptor = null;
|
||||
|
|
|
@ -7,13 +7,14 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Hosting;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer for <see cref="IHttpController"/>.
|
||||
/// </summary>
|
||||
internal class HttpControllerTracer : IHttpController, IDisposable
|
||||
internal class HttpControllerTracer : IHttpController, IDisposable, IDecorator<IHttpController>
|
||||
{
|
||||
private const string DisposeMethodName = "Dispose";
|
||||
private const string ExecuteAsyncMethodName = "ExecuteAsync";
|
||||
|
@ -32,6 +33,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public IHttpController Inner
|
||||
{
|
||||
get { return _innerController; }
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
IDisposable disposable = _innerController as IDisposable;
|
||||
|
|
|
@ -10,6 +10,7 @@ using System.Web.Http.Controllers;
|
|||
using System.Web.Http.Metadata;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
using System.Web.Http.ValueProviders;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
|
@ -18,7 +19,7 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
/// Tracer to wrap an <see cref="HttpParameterBinding"/>.
|
||||
/// Its primary purpose is to monitor <see cref="ExecuteBindingAsync"/>.
|
||||
/// </summary>
|
||||
internal class HttpParameterBindingTracer : HttpParameterBinding, IValueProviderParameterBinding
|
||||
internal class HttpParameterBindingTracer : HttpParameterBinding, IValueProviderParameterBinding, IDecorator<HttpParameterBinding>
|
||||
{
|
||||
private const string ExecuteBindingAsyncMethodName = "ExecuteBindingAsync";
|
||||
|
||||
|
@ -31,6 +32,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
TraceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public HttpParameterBinding Inner
|
||||
{
|
||||
get { return InnerBinding; }
|
||||
}
|
||||
|
||||
protected HttpParameterBinding InnerBinding { get; private set; }
|
||||
|
||||
protected ITraceWriter TraceWriter { get; private set; }
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Net.Http;
|
|||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
|
@ -13,11 +14,14 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
/// Tracer for <see cref="JsonMediaTypeFormatter"/>.
|
||||
/// It is required because users can select formatters by this type.
|
||||
/// </summary>
|
||||
internal class JsonMediaTypeFormatterTracer : JsonMediaTypeFormatter, IFormatterTracer
|
||||
internal class JsonMediaTypeFormatterTracer : JsonMediaTypeFormatter, IFormatterTracer, IDecorator<JsonMediaTypeFormatter>
|
||||
{
|
||||
private readonly JsonMediaTypeFormatter _inner;
|
||||
private MediaTypeFormatterTracer _innerTracer;
|
||||
|
||||
public JsonMediaTypeFormatterTracer(JsonMediaTypeFormatter innerFormatter, ITraceWriter traceWriter, HttpRequestMessage request)
|
||||
{
|
||||
_inner = innerFormatter;
|
||||
_innerTracer = new MediaTypeFormatterTracer(innerFormatter, traceWriter, request);
|
||||
|
||||
// copy values we cannot override
|
||||
|
@ -33,6 +37,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
get { return _innerTracer.Request; }
|
||||
}
|
||||
|
||||
public JsonMediaTypeFormatter Inner
|
||||
{
|
||||
get { return _inner; }
|
||||
}
|
||||
|
||||
public MediaTypeFormatter InnerFormatter
|
||||
{
|
||||
get { return _innerTracer.InnerFormatter; }
|
||||
|
|
|
@ -9,18 +9,21 @@ using System.Net.Http.Formatting;
|
|||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer to monitor <see cref="MediaTypeFormatter"/> instances.
|
||||
/// </summary>
|
||||
internal class MediaTypeFormatterTracer : MediaTypeFormatter, IFormatterTracer
|
||||
internal class MediaTypeFormatterTracer : MediaTypeFormatter, IFormatterTracer, IDecorator<MediaTypeFormatter>
|
||||
{
|
||||
private const string ReadFromStreamAsyncMethodName = "ReadFromStreamAsync";
|
||||
private const string WriteToStreamAsyncMethodName = "WriteToStreamAsync";
|
||||
private const string GetPerRequestFormatterInstanceMethodName = "GetPerRequestFormatterInstance";
|
||||
|
||||
private readonly MediaTypeFormatter _inner;
|
||||
|
||||
public MediaTypeFormatterTracer(MediaTypeFormatter innerFormatter, ITraceWriter traceWriter, HttpRequestMessage request)
|
||||
{
|
||||
Contract.Assert(innerFormatter != null);
|
||||
|
@ -29,11 +32,17 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
InnerFormatter = innerFormatter;
|
||||
TraceWriter = traceWriter;
|
||||
Request = request;
|
||||
_inner = innerFormatter;
|
||||
|
||||
// copy all non-overridable members from inner formatter
|
||||
CopyNonOverriableMembersFromInner(this);
|
||||
}
|
||||
|
||||
public MediaTypeFormatter Inner
|
||||
{
|
||||
get { return _inner; }
|
||||
}
|
||||
|
||||
public MediaTypeFormatter InnerFormatter { get; private set; }
|
||||
|
||||
public ITraceWriter TraceWriter { get; set; }
|
||||
|
|
|
@ -4,13 +4,14 @@ using System.Diagnostics.Contracts;
|
|||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracer to wrap a <see cref="DelegatingHandler"/>.
|
||||
/// </summary>
|
||||
internal class MessageHandlerTracer : DelegatingHandler
|
||||
internal class MessageHandlerTracer : DelegatingHandler, IDecorator<DelegatingHandler>
|
||||
{
|
||||
private const string SendAsyncMethodName = "SendAsync";
|
||||
|
||||
|
@ -26,6 +27,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
_traceWriter = traceWriter;
|
||||
}
|
||||
|
||||
public DelegatingHandler Inner
|
||||
{
|
||||
get { return _innerHandler; }
|
||||
}
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
return _traceWriter.TraceBeginEndAsync<HttpResponseMessage>(
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Net.Http;
|
|||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Services;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
|
@ -13,12 +14,14 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
/// Tracer for <see cref="XmlMediaTypeFormatter"/>.
|
||||
/// It is required because users can select formatters by this type.
|
||||
/// </summary>
|
||||
internal class XmlMediaTypeFormatterTracer : XmlMediaTypeFormatter, IFormatterTracer
|
||||
internal class XmlMediaTypeFormatterTracer : XmlMediaTypeFormatter, IFormatterTracer, IDecorator<XmlMediaTypeFormatter>
|
||||
{
|
||||
private readonly XmlMediaTypeFormatter _inner;
|
||||
private MediaTypeFormatterTracer _innerTracer;
|
||||
|
||||
public XmlMediaTypeFormatterTracer(XmlMediaTypeFormatter innerFormatter, ITraceWriter traceWriter, HttpRequestMessage request)
|
||||
{
|
||||
_inner = innerFormatter;
|
||||
_innerTracer = new MediaTypeFormatterTracer(innerFormatter, traceWriter, request);
|
||||
|
||||
// copy values we cannot override
|
||||
|
@ -33,6 +36,11 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
get { return _innerTracer.Request; }
|
||||
}
|
||||
|
||||
public XmlMediaTypeFormatter Inner
|
||||
{
|
||||
get { return _inner; }
|
||||
}
|
||||
|
||||
public MediaTypeFormatter InnerFormatter
|
||||
{
|
||||
get { return _innerTracer.InnerFormatter; }
|
||||
|
|
|
@ -11,6 +11,8 @@ using System.Web.Http.OData.Formatter;
|
|||
using System.Web.Http.OData.Query;
|
||||
using System.Web.Http.OData.Routing;
|
||||
using System.Web.Http.OData.TestCommon.Models;
|
||||
using System.Web.Http.Services;
|
||||
using System.Web.Http.Tracing;
|
||||
using Microsoft.Data.Edm;
|
||||
using Microsoft.Data.Edm.Library;
|
||||
using Microsoft.Data.OData;
|
||||
|
@ -46,7 +48,29 @@ namespace System.Web.Http.OData
|
|||
configuration.Formatters.Add(formatter2);
|
||||
|
||||
// Act
|
||||
IEnumerable<MediaTypeFormatter> result = configuration.Formatters.Where(f => f != null && f.IsODataFormatter());
|
||||
IEnumerable<MediaTypeFormatter> result = configuration.Formatters.Where(f => f != null && Decorator.GetInner(f) is ODataMediaTypeFormatter);
|
||||
|
||||
// Assert
|
||||
IEnumerable<MediaTypeFormatter> expectedFormatters = new MediaTypeFormatter[]
|
||||
{
|
||||
formatter1, formatter2
|
||||
};
|
||||
|
||||
Assert.True(expectedFormatters.SequenceEqual(result));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsODataFormatter_ReturnsTrue_For_Derived_ODataFormatters()
|
||||
{
|
||||
// Arrange
|
||||
HttpConfiguration configuration = new HttpConfiguration();
|
||||
ODataMediaTypeFormatter formatter1 = CreateODataFormatter();
|
||||
DerivedODataMediaTypeFormatter formatter2 = new DerivedODataMediaTypeFormatter(new ODataPayloadKind[0]);
|
||||
configuration.Formatters.Add(formatter1);
|
||||
configuration.Formatters.Add(formatter2);
|
||||
|
||||
// Act
|
||||
IEnumerable<MediaTypeFormatter> result = configuration.Formatters.Where(f => f != null && Decorator.GetInner(f) is ODataMediaTypeFormatter);
|
||||
|
||||
// Assert
|
||||
IEnumerable<MediaTypeFormatter> expectedFormatters = new MediaTypeFormatter[]
|
||||
|
@ -100,5 +124,13 @@ namespace System.Web.Http.OData
|
|||
{
|
||||
return new ODataMediaTypeFormatter(new ODataPayloadKind[0]);
|
||||
}
|
||||
|
||||
private class DerivedODataMediaTypeFormatter: ODataMediaTypeFormatter
|
||||
{
|
||||
public DerivedODataMediaTypeFormatter(IEnumerable<ODataPayloadKind> payloadKinds)
|
||||
: base(payloadKinds)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,163 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
namespace System.Web.Http.Services
|
||||
{
|
||||
public class DecoratorTests
|
||||
{
|
||||
[Fact]
|
||||
public void GetInner_Returns_Inner_Object_From_ObjectWrapper()
|
||||
{
|
||||
// Arrange
|
||||
DummyAggregatedClass dummyInnerObject = new DummyAggregatedClass();
|
||||
DummyObjectWrapper dummyObjectWrapper = new DummyObjectWrapper(dummyInnerObject);
|
||||
IBaseInterface dummyBase = dummyObjectWrapper as IBaseInterface;
|
||||
|
||||
// Act
|
||||
DummyAggregatedClass innerObject = Decorator.GetInner(dummyBase) as DummyAggregatedClass;
|
||||
|
||||
// Assert
|
||||
Assert.Same(dummyInnerObject, innerObject);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInner_Returns_InnerMost_Object_From_ObjectWrapper()
|
||||
{
|
||||
// Arrange
|
||||
DummyAggregatedClass dummyInnerObject = new DummyAggregatedClass();
|
||||
DummyObjectWrapper dummyObjectWrapper = new DummyObjectWrapper(dummyInnerObject);
|
||||
DummyDoubleLayerWrapper dummyDoubleLayerWrapper = new DummyDoubleLayerWrapper(dummyObjectWrapper);
|
||||
IBaseInterface dummyBase = dummyDoubleLayerWrapper as IBaseInterface;
|
||||
|
||||
// Act
|
||||
DummyAggregatedClass innerObject = Decorator.GetInner(dummyBase) as DummyAggregatedClass;
|
||||
|
||||
// Assert
|
||||
Assert.Same(dummyInnerObject, innerObject);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInner_Call_On_InnerObject_Returns_InnerObject()
|
||||
{
|
||||
// Arrange
|
||||
DummyAggregatedClass dummyInnerObject = new DummyAggregatedClass();
|
||||
IBaseInterface dummyBase = dummyInnerObject as IBaseInterface;
|
||||
|
||||
// Act
|
||||
DummyAggregatedClass innerObject = Decorator.GetInner(dummyBase) as DummyAggregatedClass;
|
||||
|
||||
// Assert
|
||||
Assert.Same(dummyInnerObject, innerObject);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInner_Call_On_Wrapper_Which_Does_Not_Contain_InnerObject_Returns_Wrapper()
|
||||
{
|
||||
// Arrange
|
||||
DummyWrapper dummyWrapper = new DummyWrapper();
|
||||
IBaseInterface dummyBase = dummyWrapper as IBaseInterface;
|
||||
|
||||
// Act
|
||||
DummyWrapper innerObject = Decorator.GetInner(dummyBase) as DummyWrapper;
|
||||
|
||||
// Assert
|
||||
Assert.Same(dummyWrapper, innerObject);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInner_Returns_Itself_From_AnyClass_Which_Does_Not_Implement_Base_Interface()
|
||||
{
|
||||
// Arrange
|
||||
Mock<object> dummyClass = new Mock<object>();
|
||||
|
||||
// Act
|
||||
object innerObject = Decorator.GetInner(dummyClass.Object);
|
||||
|
||||
// Assert
|
||||
Assert.Same(dummyClass.Object, innerObject);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInner_Returns_Null_When_Null_Is_Passed()
|
||||
{
|
||||
// Arrange
|
||||
object nullValue = null;
|
||||
|
||||
// Act
|
||||
object innerObject = Decorator.GetInner(nullValue);
|
||||
|
||||
// Assert
|
||||
Assert.Null(innerObject);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInner_Returns_Inner_Object_From_ObjectWrapper_Which_Wraps_Itself()
|
||||
{
|
||||
// Arrange
|
||||
DummyAggregatedClass dummyInnerObject = new DummyAggregatedClass();
|
||||
DummyBaseWrapper dummyBaseWrapper = new DummyBaseWrapper(dummyInnerObject);
|
||||
IBaseInterface dummyBase = dummyBaseWrapper as IBaseInterface;
|
||||
|
||||
// Act
|
||||
DummyBaseWrapper innerObject = Decorator.GetInner(dummyBase) as DummyBaseWrapper;
|
||||
|
||||
// Assert
|
||||
Assert.Same(dummyBaseWrapper, innerObject);
|
||||
}
|
||||
|
||||
private interface IBaseInterface { }
|
||||
|
||||
private class DummyAggregatedClass : IBaseInterface { }
|
||||
|
||||
private class DummyWrapper : IBaseInterface { }
|
||||
|
||||
private class DummyObjectWrapper : IBaseInterface, IDecorator<DummyAggregatedClass>
|
||||
{
|
||||
private readonly DummyAggregatedClass _inner;
|
||||
|
||||
public DummyObjectWrapper(DummyAggregatedClass innerObject)
|
||||
{
|
||||
_inner = innerObject;
|
||||
}
|
||||
|
||||
public DummyAggregatedClass Inner
|
||||
{
|
||||
get { return _inner; }
|
||||
}
|
||||
}
|
||||
|
||||
private class DummyDoubleLayerWrapper : IBaseInterface, IDecorator<DummyObjectWrapper>
|
||||
{
|
||||
private readonly DummyObjectWrapper _inner;
|
||||
|
||||
public DummyDoubleLayerWrapper(DummyObjectWrapper innerObject)
|
||||
{
|
||||
_inner = innerObject;
|
||||
}
|
||||
|
||||
public DummyObjectWrapper Inner
|
||||
{
|
||||
get { return _inner; }
|
||||
}
|
||||
}
|
||||
|
||||
private class DummyBaseWrapper : IBaseInterface, IDecorator<IBaseInterface>
|
||||
{
|
||||
private readonly IBaseInterface _inner;
|
||||
|
||||
public DummyBaseWrapper(IBaseInterface innerObject)
|
||||
{
|
||||
_inner = innerObject;
|
||||
}
|
||||
|
||||
public IBaseInterface Inner
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -141,6 +141,7 @@
|
|||
<Compile Include="Routing\UriPathExtensionMappingTests.cs" />
|
||||
<Compile Include="Routing\UrlHelperTest.cs" />
|
||||
<Compile Include="Services\ControllerServicesTests.cs" />
|
||||
<Compile Include="Services\DecoratorTests.cs" />
|
||||
<Compile Include="Services\DefaultServicesTests.cs" />
|
||||
<Compile Include="Services\ServicesExtensionsTests.cs" />
|
||||
<Compile Include="Tracing\TraceRecordTest.cs" />
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -204,5 +205,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, traceWriter.Traces[3].Exception);
|
||||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_ActionFilterAttributeTracer_Returns_ActionFilterAttribute()
|
||||
{
|
||||
// Arrange
|
||||
ActionFilterAttribute expectedInner = new Mock<ActionFilterAttribute>().Object;
|
||||
ActionFilterAttributeTracer productUnderTest = new ActionFilterAttributeTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
ActionFilterAttribute actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_ActionFilterAttributeTracer_Returns_ActionFilterAttribute()
|
||||
{
|
||||
// Arrange
|
||||
ActionFilterAttribute expectedInner = new Mock<ActionFilterAttribute>().Object;
|
||||
ActionFilterAttributeTracer productUnderTest = new ActionFilterAttributeTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
ActionFilterAttribute actualInner = Decorator.GetInner(productUnderTest as ActionFilterAttribute);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -79,5 +80,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_ActionFilterTracer_Returns_IActionFilter()
|
||||
{
|
||||
// Arrange
|
||||
IActionFilter expectedInner = new Mock<IActionFilter>().Object;
|
||||
ActionFilterTracer productUnderTest = new ActionFilterTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IActionFilter actualInner = productUnderTest.Inner as IActionFilter;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_Property_On_ActionFilterTracer_Returns_IActionFilter()
|
||||
{
|
||||
// Arrange
|
||||
IActionFilter expectedInner = new Mock<IActionFilter>().Object;
|
||||
ActionFilterTracer productUnderTest = new ActionFilterTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IActionFilter actualInner = Decorator.GetInner(productUnderTest as IActionFilter);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Net.Http;
|
|||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -96,6 +97,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
// Assert
|
||||
Assert.IsAssignableFrom<FormatterParameterBindingTracer>(actualBinding.ParameterBindings[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_ActionValueBinderTracer_Returns_IActionValueBinder()
|
||||
{
|
||||
// Arrange
|
||||
IActionValueBinder expectedInner = new Mock<IActionValueBinder>().Object;
|
||||
ActionValueBinderTracer productUnderTest = new ActionValueBinderTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IActionValueBinder actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_Property_On_ActionValueBinderTracer_Returns_IActionValueBinder()
|
||||
{
|
||||
// Arrange
|
||||
IActionValueBinder expectedInner = new Mock<IActionValueBinder>().Object;
|
||||
ActionValueBinderTracer productUnderTest = new ActionValueBinderTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IActionValueBinder actualInner = Decorator.GetInner(productUnderTest as IActionValueBinder);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -168,5 +169,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_AuthorizationFilterAttributeTracer_Returns_AuthorizationFilterAttribute()
|
||||
{
|
||||
// Arrange
|
||||
AuthorizationFilterAttribute expectedInner = new Mock<AuthorizationFilterAttribute>().Object;
|
||||
AuthorizationFilterAttributeTracer productUnderTest = new AuthorizationFilterAttributeTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
AuthorizationFilterAttribute actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_AuthorizationFilterAttributeTracer_Returns_AuthorizationFilterAttribute()
|
||||
{
|
||||
// Arrange
|
||||
AuthorizationFilterAttribute expectedInner = new Mock<AuthorizationFilterAttribute>().Object;
|
||||
AuthorizationFilterAttributeTracer productUnderTest = new AuthorizationFilterAttributeTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
AuthorizationFilterAttribute actualInner = Decorator.GetInner(productUnderTest as AuthorizationFilterAttribute);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -73,5 +74,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_AuthorizationFilterTracer_Returns_IAuthorizationFilter()
|
||||
{
|
||||
// Arrange
|
||||
IAuthorizationFilter expectedInner = new Mock<IAuthorizationFilter>().Object;
|
||||
AuthorizationFilterTracer productUnderTest = new AuthorizationFilterTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IAuthorizationFilter actualInner = productUnderTest.Inner as IAuthorizationFilter;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_AuthorizationFilterTracer_Returns_IAuthorizationFilter()
|
||||
{
|
||||
// Arrange
|
||||
IAuthorizationFilter expectedInner = new Mock<IAuthorizationFilter>().Object;
|
||||
AuthorizationFilterTracer productUnderTest = new AuthorizationFilterTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IAuthorizationFilter actualInner = Decorator.GetInner(productUnderTest as IAuthorizationFilter);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,14 @@
|
|||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
internal class BufferedMediaTypeFormatterTracerTest : MediaTypeFormatterTracerTestBase<BufferedMediaTypeFormatter, BufferedMediaTypeFormatterTracer>
|
||||
public class BufferedMediaTypeFormatterTracerTest
|
||||
{
|
||||
public override BufferedMediaTypeFormatterTracer CreateTracer(BufferedMediaTypeFormatter formatter, HttpRequestMessage request, ITraceWriter traceWriter)
|
||||
{
|
||||
return new BufferedMediaTypeFormatterTracer(formatter, traceWriter, request);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BufferSize_Uses_Inners()
|
||||
{
|
||||
|
@ -134,5 +130,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, thrown);
|
||||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_BufferedMediaTypeFormatterTracer_Returns_BufferedMediaTypeFormatter()
|
||||
{
|
||||
// Arrange
|
||||
BufferedMediaTypeFormatter expectedInner = new Mock<BufferedMediaTypeFormatter>().Object;
|
||||
BufferedMediaTypeFormatterTracer productUnderTest = new BufferedMediaTypeFormatterTracer(expectedInner, new TestTraceWriter(), new HttpRequestMessage());
|
||||
|
||||
// Act
|
||||
BufferedMediaTypeFormatter actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_BufferedMediaTypeFormatterTracer_Returns_BufferedMediaTypeFormatter()
|
||||
{
|
||||
// Arrange
|
||||
BufferedMediaTypeFormatter expectedInner = new Mock<BufferedMediaTypeFormatter>().Object;
|
||||
BufferedMediaTypeFormatterTracer productUnderTest = new BufferedMediaTypeFormatterTracer(expectedInner, new TestTraceWriter(), new HttpRequestMessage());
|
||||
|
||||
// Act
|
||||
BufferedMediaTypeFormatter actualInner = Decorator.GetInner(productUnderTest as BufferedMediaTypeFormatter);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -187,5 +188,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Equal<TraceRecord>(expectedTraces, _traceWriter.Traces, new TraceRecordComparer());
|
||||
Assert.Same(expectedException, _traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_ContentNegotiatiorTracer_Returns_IContentNegotiator()
|
||||
{
|
||||
// Arrange
|
||||
IContentNegotiator expectedInner = new Mock<IContentNegotiator>().Object;
|
||||
ContentNegotiatorTracer productUnderTest = new ContentNegotiatorTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IContentNegotiator actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_ContentNegotiatiorTracer_Returns_IContentNegotiator()
|
||||
{
|
||||
// Arrange
|
||||
IContentNegotiator expectedInner = new Mock<IContentNegotiator>().Object;
|
||||
ContentNegotiatorTracer productUnderTest = new ContentNegotiatorTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IContentNegotiator actualInner = Decorator.GetInner(productUnderTest as IContentNegotiator);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -170,5 +171,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_ExceptionFilterAttributeTracer_Returns_ExceptionFilterAttribute()
|
||||
{
|
||||
// Arrange
|
||||
ExceptionFilterAttribute expectedInner = new Mock<ExceptionFilterAttribute>().Object;
|
||||
ExceptionFilterAttributeTracer productUnderTest = new ExceptionFilterAttributeTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
ExceptionFilterAttribute actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_ExceptionFilterAttributeTracer_Returns_ExceptionFilterAttribute()
|
||||
{
|
||||
// Arrange
|
||||
ExceptionFilterAttribute expectedInner = new Mock<ExceptionFilterAttribute>().Object;
|
||||
ExceptionFilterAttributeTracer productUnderTest = new ExceptionFilterAttributeTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
ExceptionFilterAttribute actualInner = Decorator.GetInner(productUnderTest as ExceptionFilterAttribute);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Net.Http;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -67,5 +68,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_ExceptionFilterTracer_Returns_IExceptionFilter()
|
||||
{
|
||||
// Arrange
|
||||
IExceptionFilter expectedInner = new Mock<IExceptionFilter>().Object;
|
||||
ExceptionFilterTracer productUnderTest = new ExceptionFilterTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IExceptionFilter actualInner = productUnderTest.Inner as IExceptionFilter;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_ExceptionFilterTracer_Returns_IExceptionFilter()
|
||||
{
|
||||
// Arrange
|
||||
IExceptionFilter expectedInner = new Mock<IExceptionFilter>().Object;
|
||||
ExceptionFilterTracer productUnderTest = new ExceptionFilterTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IExceptionFilter actualInner = Decorator.GetInner(productUnderTest.Inner as IExceptionFilter);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -248,6 +249,34 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Equal(1, wrappedFilters.Where(f => f.Instance.GetType() == typeof(ExceptionFilterTracer)).Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_FilterTracer_Returns_IFilter()
|
||||
{
|
||||
// Arrange
|
||||
IFilter expectedInner = new Mock<IFilter>().Object;
|
||||
FilterTracer productUnderTest = new FilterTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IFilter actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_Property_On_FilterTracer_Returns_IFilter()
|
||||
{
|
||||
// Arrange
|
||||
IFilter expectedInner = new Mock<IFilter>().Object;
|
||||
FilterTracer productUnderTest = new FilterTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IFilter actualInner = Decorator.GetInner(productUnderTest as IFilter);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
// Test filter class that exposes all filter behaviors will cause separate filters for each
|
||||
class TestFilterAllBehaviors : IActionFilter, IExceptionFilter, IAuthorizationFilter
|
||||
{
|
||||
|
|
|
@ -2,17 +2,13 @@
|
|||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
internal class FormUrlEncodedMediaTypeFormatterTracerTest : ReadWriteMediaTypeFormatterTracerTestBase<FormUrlEncodedMediaTypeFormatter, FormUrlEncodedMediaTypeFormatterTracer>
|
||||
public class FormUrlEncodedMediaTypeFormatterTracerTest
|
||||
{
|
||||
public override FormUrlEncodedMediaTypeFormatterTracer CreateTracer(FormUrlEncodedMediaTypeFormatter formatter, HttpRequestMessage request, ITraceWriter traceWriter)
|
||||
{
|
||||
return new FormUrlEncodedMediaTypeFormatterTracer(formatter, traceWriter, request);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MaxDepth_Uses_Inners()
|
||||
{
|
||||
|
@ -38,5 +34,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
// Act & Assert
|
||||
Assert.Equal(innerFormatter.ReadBufferSize, tracer.ReadBufferSize);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_FormUrlEncodedMediaTypeFormatterTracer_Returns_FormUrlEncodedMediaTypeFormatter()
|
||||
{
|
||||
// Arrange
|
||||
FormUrlEncodedMediaTypeFormatter expectedInner = new FormUrlEncodedMediaTypeFormatter();
|
||||
FormUrlEncodedMediaTypeFormatterTracer productUnderTest = new FormUrlEncodedMediaTypeFormatterTracer(expectedInner, new TestTraceWriter(), new HttpRequestMessage());
|
||||
|
||||
// Act
|
||||
FormUrlEncodedMediaTypeFormatter actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_FormUrlEncodedMediaTypeFormatterTracer_Returns_FormUrlEncodedMediaTypeFormatter()
|
||||
{
|
||||
// Arrange
|
||||
FormUrlEncodedMediaTypeFormatter expectedInner = new FormUrlEncodedMediaTypeFormatter();
|
||||
FormUrlEncodedMediaTypeFormatterTracer productUnderTest = new FormUrlEncodedMediaTypeFormatterTracer(expectedInner, new TestTraceWriter(), new HttpRequestMessage());
|
||||
|
||||
// Act
|
||||
FormUrlEncodedMediaTypeFormatter actualInner = Decorator.GetInner(productUnderTest as FormUrlEncodedMediaTypeFormatter);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ using System.Web.Http.Controllers;
|
|||
using System.Web.Http.Metadata;
|
||||
using System.Web.Http.Metadata.Providers;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using System.Web.Http.Services;
|
||||
using System.Web.Http.Validation;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
@ -200,5 +201,36 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_FormatterParameterBindingTracer_Returns_FormatterParameterBinding()
|
||||
{
|
||||
// Arrange
|
||||
HttpParameterDescriptor httpParameterDescriptor = new Mock<HttpParameterDescriptor>().Object;
|
||||
MediaTypeFormatterCollection mediaTypeFormatterCollection = new MediaTypeFormatterCollection();
|
||||
FormatterParameterBinding expectedInner = new FormatterParameterBinding(httpParameterDescriptor, mediaTypeFormatterCollection, null);
|
||||
FormatterParameterBindingTracer productUnderTest = new FormatterParameterBindingTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
FormatterParameterBinding actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_FormatterParameterBindingTracer_Returns_FormatterParameterBinding()
|
||||
{
|
||||
// Arrange
|
||||
HttpParameterDescriptor httpParameterDescriptor = new Mock<HttpParameterDescriptor>().Object;
|
||||
MediaTypeFormatterCollection mediaTypeFormatterCollection = new MediaTypeFormatterCollection();
|
||||
FormatterParameterBinding expectedInner = new FormatterParameterBinding(httpParameterDescriptor, mediaTypeFormatterCollection, null);
|
||||
FormatterParameterBindingTracer productUnderTest = new FormatterParameterBindingTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
FormatterParameterBinding actualInner = Decorator.GetInner(productUnderTest as FormatterParameterBinding);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Net.Http;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -119,5 +120,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, thrown);
|
||||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_HttpActionBindingTracer_Returns_HttpActionBinding()
|
||||
{
|
||||
// Arrange
|
||||
HttpActionBinding expectedInner = new HttpActionBinding();
|
||||
HttpActionBindingTracer productUnderTest = new HttpActionBindingTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
HttpActionBinding actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_HttpActionBindingTracer_Returns_HttpActionBinding()
|
||||
{
|
||||
// Arrange
|
||||
HttpActionBinding expectedInner = new HttpActionBinding();
|
||||
HttpActionBindingTracer productUnderTest = new HttpActionBindingTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
HttpActionBinding actualInner = Decorator.GetInner(productUnderTest as HttpActionBinding);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -371,5 +372,35 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_HttpActionDescriptorTracer_Returns_HttpActionDescriptor()
|
||||
{
|
||||
// Arrange
|
||||
HttpActionDescriptor expectedInner = new Mock<HttpActionDescriptor>().Object;
|
||||
HttpControllerContext controllerContext = ContextUtil.CreateControllerContext();
|
||||
HttpActionDescriptorTracer productUnderTest = new HttpActionDescriptorTracer(controllerContext, expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
HttpActionDescriptor actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_HttpActionDescriptorTracer_Returns_HttpActionDescriptor()
|
||||
{
|
||||
// Arrange
|
||||
HttpActionDescriptor expectedInner = new Mock<HttpActionDescriptor>().Object;
|
||||
HttpControllerContext controllerContext = ContextUtil.CreateControllerContext();
|
||||
HttpActionDescriptorTracer productUnderTest = new HttpActionDescriptorTracer(controllerContext, expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
HttpActionDescriptor actualInner = Decorator.GetInner(productUnderTest as HttpActionDescriptor);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Net.Http;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -208,5 +209,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
Assert.Equal(expectedException, traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_HttpActionInvokerTracer_Returns_IHttpActionInvoker()
|
||||
{
|
||||
// Arrange
|
||||
IHttpActionInvoker expectedInner = new Mock<IHttpActionInvoker>().Object;
|
||||
HttpActionInvokerTracer productUnderTest = new HttpActionInvokerTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpActionInvoker actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_HttpActionInvokerTracer_Returns_IHttpActionInvoker()
|
||||
{
|
||||
// Arrange
|
||||
IHttpActionInvoker expectedInner = new Mock<IHttpActionInvoker>().Object;
|
||||
HttpActionInvokerTracer productUnderTest = new HttpActionInvokerTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpActionInvoker actualInner = Decorator.GetInner(productUnderTest as IHttpActionInvoker);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
using System.Collections.ObjectModel;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -77,5 +78,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, thrown);
|
||||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_HttpActionSelectorTracer_Returns_IHttpActionSelector()
|
||||
{
|
||||
// Arrange
|
||||
IHttpActionSelector expectedInner = new Mock<IHttpActionSelector>().Object;
|
||||
HttpActionSelectorTracer productUnderTest = new HttpActionSelectorTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpActionSelector actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_HttpActionSelectorTracer_Returns_IHttpActionSelector()
|
||||
{
|
||||
// Arrange
|
||||
IHttpActionSelector expectedInner = new Mock<IHttpActionSelector>().Object;
|
||||
HttpActionSelectorTracer productUnderTest = new HttpActionSelectorTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpActionSelector actualInner = Decorator.GetInner(productUnderTest as IHttpActionSelector);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
using System.Net.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Dispatcher;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -61,5 +62,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, thrown);
|
||||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_HttpControllerActivatorTracer_Returns_IHttpControllerActivator()
|
||||
{
|
||||
// Arrange
|
||||
IHttpControllerActivator expectedInner = new Mock<IHttpControllerActivator>().Object;
|
||||
HttpControllerActivatorTracer productUnderTest = new HttpControllerActivatorTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpControllerActivator actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_HttpControllerActivatorTracer_Returns_IHttpControllerActivator()
|
||||
{
|
||||
// Arrange
|
||||
IHttpControllerActivator expectedInner = new Mock<IHttpControllerActivator>().Object;
|
||||
HttpControllerActivatorTracer productUnderTest = new HttpControllerActivatorTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpControllerActivator actualInner = Decorator.GetInner(productUnderTest as IHttpControllerActivator);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -76,6 +77,34 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(_exception, traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_HttpControllerDescriptorTracer_Returns_HttpControllerDescriptor()
|
||||
{
|
||||
// Arrange
|
||||
HttpControllerDescriptor expectedInner = new Mock<HttpControllerDescriptor>().Object;
|
||||
HttpControllerDescriptorTracer productUnderTest = new HttpControllerDescriptorTracer(new HttpConfiguration(), "controller", typeof(ApiController), expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
HttpControllerDescriptor actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_HttpControllerDescriptorTracer_Returns_HttpControllerDescriptor()
|
||||
{
|
||||
// Arrange
|
||||
HttpControllerDescriptor expectedInner = new Mock<HttpControllerDescriptor>().Object;
|
||||
HttpControllerDescriptorTracer productUnderTest = new HttpControllerDescriptorTracer(new HttpConfiguration(), "controller", typeof(ApiController), expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
HttpControllerDescriptor actualInner = Decorator.GetInner(productUnderTest as HttpControllerDescriptor);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
private static HttpControllerDescriptorTracer GetHttpControllerDescriptorTracer(HttpControllerDescriptor controllerDescriptor, ITraceWriter traceWriter)
|
||||
{
|
||||
return new HttpControllerDescriptorTracer(
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
using System.Net.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Dispatcher;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -62,5 +63,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, thrown);
|
||||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_HttpControllerSelectorTracer_Returns_IHttpControllerSelector()
|
||||
{
|
||||
// Arrange
|
||||
IHttpControllerSelector expectedInner = new Mock<IHttpControllerSelector>().Object;
|
||||
HttpControllerSelectorTracer productUnderTest = new HttpControllerSelectorTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpControllerSelector actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_HttpControllerSelectorTracer_Returns_IHttpControllerSelector()
|
||||
{
|
||||
// Arrange
|
||||
IHttpControllerSelector expectedInner = new Mock<IHttpControllerSelector>().Object;
|
||||
HttpControllerSelectorTracer productUnderTest = new HttpControllerSelectorTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpControllerSelector actualInner = Decorator.GetInner(productUnderTest as IHttpControllerSelector);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Hosting;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
|
@ -188,5 +189,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
// Assert
|
||||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_HttpControllerTracer_Returns_IHttpController()
|
||||
{
|
||||
// Arrange
|
||||
IHttpController expectedInner = new Mock<IHttpController>().Object;
|
||||
HttpControllerTracer productUnderTest = new HttpControllerTracer(new HttpRequestMessage(), expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpController actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_HttpControllerTracer_Returns_IHttpController()
|
||||
{
|
||||
// Arrange
|
||||
IHttpController expectedInner = new Mock<IHttpController>().Object;
|
||||
HttpControllerTracer productUnderTest = new HttpControllerTracer(new HttpRequestMessage(), expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
IHttpController actualInner = Decorator.GetInner(productUnderTest as IHttpController);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.Web.Http.Controllers;
|
|||
using System.Web.Http.Metadata;
|
||||
using System.Web.Http.Metadata.Providers;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using System.Web.Http.Services;
|
||||
using System.Web.Http.ValueProviders;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
@ -210,5 +211,39 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(exception, traceWriter.Traces[1].Exception);
|
||||
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_HttpParameterBindingTracer_Returns_HttpParameterBinding()
|
||||
{
|
||||
// Arrange
|
||||
Mock<HttpParameterDescriptor> mockParamDescriptor = new Mock<HttpParameterDescriptor>() { CallBase = true };
|
||||
mockParamDescriptor.Setup(d => d.ParameterName).Returns("paramName");
|
||||
mockParamDescriptor.Setup(d => d.ParameterType).Returns(typeof(string));
|
||||
HttpParameterBinding expectedInner = new Mock<HttpParameterBinding>(mockParamDescriptor.Object).Object;
|
||||
HttpParameterBindingTracer productUnderTest = new HttpParameterBindingTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
HttpParameterBinding actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_HttpParameterBindingTracer_Returns_HttpParameterBinding()
|
||||
{
|
||||
// Arrange
|
||||
Mock<HttpParameterDescriptor> mockParamDescriptor = new Mock<HttpParameterDescriptor>() { CallBase = true };
|
||||
mockParamDescriptor.Setup(d => d.ParameterName).Returns("paramName");
|
||||
mockParamDescriptor.Setup(d => d.ParameterType).Returns(typeof(string));
|
||||
HttpParameterBinding expectedInner = new Mock<HttpParameterBinding>(mockParamDescriptor.Object).Object;
|
||||
HttpParameterBindingTracer productUnderTest = new HttpParameterBindingTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
HttpParameterBinding actualInner = Decorator.GetInner(productUnderTest as HttpParameterBinding);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,18 +2,14 @@
|
|||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
internal class JsonMediaTypeFormatterTracerTest : ReadWriteMediaTypeFormatterTracerTestBase<JsonMediaTypeFormatter, JsonMediaTypeFormatterTracer>
|
||||
public class JsonMediaTypeFormatterTracerTest
|
||||
{
|
||||
public override JsonMediaTypeFormatterTracer CreateTracer(JsonMediaTypeFormatter formatter, HttpRequestMessage request, ITraceWriter traceWriter)
|
||||
{
|
||||
return new JsonMediaTypeFormatterTracer(formatter, traceWriter, request);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseDataContractJsonSerializer_Uses_Inners()
|
||||
{
|
||||
|
@ -66,5 +62,32 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
Assert.Same(innerFormatter.SerializerSettings, tracer.SerializerSettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_JsonMediaTypeFormatterTracerTest_Returns_JsonMediaTypeFormatter()
|
||||
{
|
||||
// Arrange
|
||||
JsonMediaTypeFormatter expectedInner = new JsonMediaTypeFormatter();
|
||||
JsonMediaTypeFormatterTracer productUnderTest = new JsonMediaTypeFormatterTracer(expectedInner, new TestTraceWriter(), new HttpRequestMessage());
|
||||
|
||||
// Act
|
||||
JsonMediaTypeFormatter actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_JsonMediaTypeFormatterTracerTest_Returns_JsonMediaTypeFormatter()
|
||||
{
|
||||
// Arrange
|
||||
JsonMediaTypeFormatter expectedInner = new JsonMediaTypeFormatter();
|
||||
JsonMediaTypeFormatterTracer productUnderTest = new JsonMediaTypeFormatterTracer(expectedInner, new TestTraceWriter(), new HttpRequestMessage());
|
||||
|
||||
// Act
|
||||
JsonMediaTypeFormatter actualInner = Decorator.GetInner(productUnderTest as JsonMediaTypeFormatter);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,18 +2,14 @@
|
|||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
internal class MediaTypeFormatterTracerTest : ReadWriteMediaTypeFormatterTracerTestBase<MediaTypeFormatter, MediaTypeFormatterTracer>
|
||||
public class MediaTypeFormatterTracerTest
|
||||
{
|
||||
public override MediaTypeFormatterTracer CreateTracer(MediaTypeFormatter formatter, HttpRequestMessage request, ITraceWriter traceWriter)
|
||||
{
|
||||
return new MediaTypeFormatterTracer(formatter, traceWriter, request);
|
||||
}
|
||||
|
||||
public static TheoryDataSet<MediaTypeFormatter> AllKnownFormatters
|
||||
{
|
||||
get
|
||||
|
@ -42,5 +38,35 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
IFormatterTracer tracer = Assert.IsAssignableFrom<IFormatterTracer>(tracingFormatter);
|
||||
Assert.Same(formatter, tracer.InnerFormatter);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[PropertyData("AllKnownFormatters")]
|
||||
public void Inner_Property_On_All_MediaTypeFormatterTracers_Returns_Object_Of_Type_MediaTypeFormatter(MediaTypeFormatter formatter)
|
||||
{
|
||||
// Arrange
|
||||
HttpRequestMessage request = new HttpRequestMessage();
|
||||
MediaTypeFormatter formatterTracer = MediaTypeFormatterTracer.CreateTracer(formatter, new TestTraceWriter(), request);
|
||||
|
||||
// Act
|
||||
MediaTypeFormatter innerFormatter = (formatterTracer as IDecorator<MediaTypeFormatter>).Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(formatter, innerFormatter);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[PropertyData("AllKnownFormatters")]
|
||||
public void Decorator_GetInner_On_All_MediaTypeFormatterTracers_Returns_Object_Of_Type_MediaTypeFormatter(MediaTypeFormatter formatter)
|
||||
{
|
||||
// Arrange
|
||||
HttpRequestMessage request = new HttpRequestMessage();
|
||||
MediaTypeFormatter formatterTracer = MediaTypeFormatterTracer.CreateTracer(formatter, new TestTraceWriter(), request);
|
||||
|
||||
// Act
|
||||
MediaTypeFormatter innerFormatter = Decorator.GetInner(formatterTracer);
|
||||
|
||||
// Assert
|
||||
Assert.Same(formatter, innerFormatter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@ using System.Net.Http;
|
|||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
using Moq;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
|
@ -154,5 +156,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
return _callback(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_MessageHandlerTracer_Returns_DelegatingHandler()
|
||||
{
|
||||
// Arrange
|
||||
DelegatingHandler expectedInner = new Mock<DelegatingHandler>().Object;
|
||||
MessageHandlerTracer productUnderTest = new MessageHandlerTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
DelegatingHandler actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_MessageHandlerTracer_Returns_DelegatingHandler()
|
||||
{
|
||||
// Arrange
|
||||
DelegatingHandler expectedInner = new Mock<DelegatingHandler>().Object;
|
||||
MessageHandlerTracer productUnderTest = new MessageHandlerTracer(expectedInner, new TestTraceWriter());
|
||||
|
||||
// Act
|
||||
DelegatingHandler actualInner = Decorator.GetInner(productUnderTest as DelegatingHandler);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,13 @@
|
|||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Web.Http.Services;
|
||||
using Microsoft.TestCommon;
|
||||
|
||||
namespace System.Web.Http.Tracing.Tracers
|
||||
{
|
||||
internal class XmlMediaTypeFormatterTracerTest : ReadWriteMediaTypeFormatterTracerTestBase<XmlMediaTypeFormatter, XmlMediaTypeFormatterTracer>
|
||||
public class XmlMediaTypeFormatterTracerTest
|
||||
{
|
||||
public override XmlMediaTypeFormatterTracer CreateTracer(XmlMediaTypeFormatter formatter, HttpRequestMessage request, ITraceWriter traceWriter)
|
||||
{
|
||||
return new XmlMediaTypeFormatterTracer(formatter, traceWriter, request);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseXmlSerializer_Uses_Inners()
|
||||
{
|
||||
|
@ -51,5 +47,33 @@ namespace System.Web.Http.Tracing.Tracers
|
|||
// Act & Assert
|
||||
Assert.Equal(innerFormatter.Indent, tracer.Indent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inner_Property_On_XmlMediaTypeFormatterTracer_Returns_XmlMediaTypeFormatter()
|
||||
{
|
||||
// Arrange
|
||||
XmlMediaTypeFormatter expectedInner = new XmlMediaTypeFormatter();
|
||||
XmlMediaTypeFormatterTracer productUnderTest = new XmlMediaTypeFormatterTracer(expectedInner, new TestTraceWriter(), new HttpRequestMessage());
|
||||
|
||||
// Act
|
||||
XmlMediaTypeFormatter actualInner = productUnderTest.Inner;
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Decorator_GetInner_On_XmlMediaTypeFormatterTracer_Returns_XmlMediaTypeFormatter()
|
||||
{
|
||||
// Arrange
|
||||
XmlMediaTypeFormatter expectedInner = new XmlMediaTypeFormatter();
|
||||
XmlMediaTypeFormatterTracer productUnderTest = new XmlMediaTypeFormatterTracer(expectedInner, new TestTraceWriter(), new HttpRequestMessage());
|
||||
|
||||
// Act
|
||||
XmlMediaTypeFormatter actualInner = Decorator.GetInner(productUnderTest as XmlMediaTypeFormatter);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedInner, actualInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче