Removed Logging related ILogValues types and cleaned up tests.

This commit is contained in:
Kiran Challa 2015-04-16 08:27:17 -07:00
parent 20daab2fb5
commit 65bd8c448a
35 changed files with 24 additions and 1482 deletions

View File

@ -12,7 +12,6 @@ using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc.ApplicationModels
@ -23,7 +22,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public class DefaultControllerModelBuilder : IControllerModelBuilder
{
private readonly IActionModelBuilder _actionModelBuilder;
private readonly ILogger _logger;
private readonly AuthorizationOptions _authorizationOptions;
/// <summary>
@ -31,12 +29,10 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// </summary>
/// <param name="actionModelBuilder">The <see cref="IActionModelBuilder"/> used to create actions.</param>
public DefaultControllerModelBuilder(
IActionModelBuilder actionModelBuilder,
ILoggerFactory loggerFactory,
IActionModelBuilder actionModelBuilder,
IOptions<AuthorizationOptions> authorizationOptions)
{
_actionModelBuilder = actionModelBuilder;
_logger = loggerFactory.CreateLogger<DefaultControllerModelBuilder>();
_authorizationOptions = authorizationOptions?.Options ?? new AuthorizationOptions();
}

View File

@ -4,9 +4,7 @@
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Logging;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc.Core
@ -17,19 +15,16 @@ namespace Microsoft.AspNet.Mvc.Core
private readonly IControllerTypeProvider _controllerTypeProvider;
private readonly IReadOnlyList<IFilter> _globalFilters;
private readonly IEnumerable<IApplicationModelConvention> _conventions;
private readonly ILogger _logger;
public ControllerActionDescriptorProvider([NotNull] IControllerTypeProvider controllerTypeProvider,
[NotNull] IControllerModelBuilder applicationModelBuilder,
[NotNull] IGlobalFilterProvider globalFilters,
[NotNull] IOptions<MvcOptions> optionsAccessor,
[NotNull] ILoggerFactory loggerFactory)
[NotNull] IOptions<MvcOptions> optionsAccessor)
{
_controllerTypeProvider = controllerTypeProvider;
_applicationModelBuilder = applicationModelBuilder;
_globalFilters = globalFilters.Filters;
_conventions = optionsAccessor.Options.Conventions;
_logger = loggerFactory.CreateLogger<ControllerActionDescriptorProvider>();
}
public int Order
@ -55,13 +50,6 @@ namespace Microsoft.AspNet.Mvc.Core
{
var applicationModel = BuildModel();
ApplicationModelConventions.ApplyConventions(applicationModel, _conventions);
if (_logger.IsEnabled(LogLevel.Verbose))
{
foreach (var controller in applicationModel.Controllers)
{
_logger.LogVerbose(new ControllerModelValues(controller));
}
}
return ControllerActionDescriptorBuilder.Build(applicationModel);
}

View File

@ -4,9 +4,7 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.AspNet.Mvc.Logging;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Core
{
@ -17,17 +15,15 @@ namespace Microsoft.AspNet.Mvc.Core
public class DefaultActionDescriptorsCollectionProvider : IActionDescriptorsCollectionProvider
{
private readonly IServiceProvider _serviceProvider;
private readonly ILogger _logger;
private ActionDescriptorsCollection _collection;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultActionDescriptorsCollectionProvider" /> class.
/// </summary>
/// <param name="serviceProvider">The application IServiceProvider.</param>
public DefaultActionDescriptorsCollectionProvider(IServiceProvider serviceProvider, ILoggerFactory factory)
public DefaultActionDescriptorsCollectionProvider(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
_logger = factory.CreateLogger<DefaultActionDescriptorsCollectionProvider>();
}
/// <summary>
@ -65,14 +61,6 @@ namespace Microsoft.AspNet.Mvc.Core
providers[i].OnProvidersExecuted(context);
}
if (_logger.IsEnabled(LogLevel.Verbose))
{
foreach (var actionDescriptor in context.Results)
{
_logger.LogVerbose(new ActionDescriptorValues(actionDescriptor));
}
}
return new ActionDescriptorsCollection(
new ReadOnlyCollection<ActionDescriptor>(context.Results), 0);
}

View File

@ -1,51 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of an <see cref="IActionConstraintMetadata"/>.
/// </summary>
public class ActionConstraintValues : ReflectionBasedLogValues
{
public ActionConstraintValues(IActionConstraintMetadata inner)
{
var constraint = inner as IActionConstraint;
if (constraint != null)
{
IsConstraint = true;
Order = constraint.Order;
}
if (inner is IActionConstraintFactory)
{
IsFactory = true;
}
ActionConstraintMetadataType = inner.GetType();
}
/// <summary>
/// The <see cref="Type"/> of this <see cref="IActionConstraintMetadata"/>.
/// </summary>
public Type ActionConstraintMetadataType { get; }
/// <summary>
/// The constraint order if this is an <see cref="IActionConstraint"/>. See
/// <see cref="IActionConstraint.Order"/>.
/// </summary>
public int Order { get; }
/// <summary>
/// Whether the action constraint is an <see cref="IActionConstraint"/>.
/// </summary>
public bool IsConstraint { get; }
/// <summary>
/// Whether the action constraint is an <see cref="IActionConstraintFactory"/>.
/// </summary>
public bool IsFactory { get; }
}
}

View File

@ -1,121 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of the state of an <see cref="ActionDescriptor"/> or
/// <see cref="ControllerActionDescriptor"/>. Logged during action discovery.
/// </summary>
public class ActionDescriptorValues : ReflectionBasedLogValues
{
public ActionDescriptorValues([NotNull] ActionDescriptor inner)
{
Name = inner.Name;
DisplayName = inner.DisplayName;
Parameters = inner.Parameters.Select(p => new ParameterDescriptorValues(p)).ToList();
BoundProperties = inner.BoundProperties.Select(p => new ParameterDescriptorValues(p)).ToList();
FilterDescriptors = inner.FilterDescriptors.Select(f => new FilterDescriptorValues(f)).ToList();
RouteConstraints = inner.RouteConstraints.Select(r => new RouteDataActionConstraintValues(r)).ToList();
AttributeRouteInfo = new AttributeRouteInfoValues(inner.AttributeRouteInfo);
RouteValueDefaults = inner.RouteValueDefaults.ToDictionary(i => i.Key, i => i.Value.ToString());
ActionConstraints = inner.ActionConstraints?.Select(a => new ActionConstraintValues(a))?.ToList();
HttpMethods =
inner.ActionConstraints?.OfType<HttpMethodConstraint>().SelectMany(c => c.HttpMethods).ToList();
Properties = inner.Properties.ToDictionary(i => i.Key.ToString(), i => i.Value.GetType());
var controllerActionDescriptor = inner as ControllerActionDescriptor;
if (controllerActionDescriptor != null)
{
MethodInfo = controllerActionDescriptor.MethodInfo;
ControllerName = controllerActionDescriptor.ControllerName;
ControllerTypeInfo = controllerActionDescriptor.ControllerTypeInfo;
}
}
/// <summary>
/// The name of the action. See <see cref="ActionDescriptor.Name"/>.
/// </summary>
public string Name { get; }
/// <summary>
/// A friendly name for the action. See <see cref="ActionDescriptor.DisplayName"/>.
/// </summary>
public string DisplayName { get; }
/// <summary>
/// The parameters of the action as <see cref="ParameterDescriptorValues"/>.
/// See <see cref="ActionDescriptor.Parameters"/>.
/// </summary>
public IList<ParameterDescriptorValues> Parameters { get; }
/// <summary>
/// The parameters of the action as <see cref="ParameterDescriptorValues"/>.
/// See <see cref="ActionDescriptor.BoundProperties"/>.
/// </summary>
public IList<ParameterDescriptorValues> BoundProperties { get; }
/// <summary>
/// The filters of the action as <see cref="FilterDescriptorValues"/>.
/// See <see cref="ActionDescriptor.FilterDescriptors"/>.
/// </summary>
public IList<FilterDescriptorValues> FilterDescriptors { get; }
/// <summary>
/// The route constraints of the action as <see cref="RouteDataActionConstraintValues"/>.
/// See <see cref="ActionDescriptor.RouteConstraints"/>
/// </summary>
public IList<RouteDataActionConstraintValues> RouteConstraints { get; }
/// <summary>
/// The attribute route info of the action as <see cref="AttributeRouteInfoValues"/>.
/// See <see cref="ActionDescriptor.AttributeRouteInfo"/>.
/// </summary>
public AttributeRouteInfoValues AttributeRouteInfo { get; }
/// <summary>
/// See <see cref="ActionDescriptor.RouteValueDefaults"/>.
/// </summary>
public IDictionary<string, string> RouteValueDefaults { get; }
/// <summary>
/// The action constraints of the action as <see cref="ActionConstraintValues"/>.
/// See <see cref="ActionDescriptor.ActionConstraints"/>.
/// </summary>
public IList<ActionConstraintValues> ActionConstraints { get; }
/// <summary>
/// The http methods this action supports.
/// </summary>
public IList<string> HttpMethods { get; }
/// <summary>
/// See <see cref="ActionDescriptor.Properties"/>.
/// </summary>
public IDictionary<string, Type> Properties { get; }
/// <summary>
/// The method info of the action if this is a <see cref="ControllerActionDescriptor"/>.
/// See <see cref="ControllerActionDescriptor.MethodInfo"/>.
/// </summary>
public MethodInfo MethodInfo { get; }
/// <summary>
/// The name of the action's controller if this is a <see cref="ControllerActionDescriptor"/>.
/// See <see cref="ControllerActionDescriptor.ControllerName"/>.
/// </summary>
public string ControllerName { get; }
/// <summary>
/// The type info of the action's controller if this is a <see cref="ControllerActionDescriptor"/>.
/// See <see cref="ControllerActionDescriptor.ControllerTypeInfo"/>.
/// </summary>
public TypeInfo ControllerTypeInfo { get; }
}
}

View File

@ -1,95 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Represents the state of an <see cref="ActionModel"/>.
/// Logged as a substructure of <see cref="ControllerModelValues"/>
/// </summary>
public class ActionModelValues : ReflectionBasedLogValues
{
// note: omit the controller as this structure is nested inside the ControllerModelValues it belongs to
public ActionModelValues(ActionModel inner)
{
if (inner != null)
{
ActionName = inner.ActionName;
ActionMethod = inner.ActionMethod;
ApiExplorer = new ApiExplorerModelValues(inner.ApiExplorer);
Parameters = inner.Parameters.Select(p => new ParameterModelValues(p)).ToList();
RouteConstraints = inner.RouteConstraints.Select(
r => new RouteConstraintProviderValues(r)).ToList();
Filters = inner.Filters.Select(f => new FilterValues(f)).ToList();
if (inner.AttributeRouteModel != null)
{
AttributeRouteModel = new AttributeRouteModelValues(inner.AttributeRouteModel);
}
HttpMethods = inner.HttpMethods;
ActionConstraints = inner.ActionConstraints?.Select(a => new ActionConstraintValues(a))?.ToList();
Properties = new Dictionary<object, object>(inner.Properties);
}
}
/// <summary>
/// The name of the action. See <see cref="ActionModel.ActionName"/>.
/// </summary>
public string ActionName { get; }
/// <summary>
/// The method info of the action. See <see cref="ActionModel.ActionMethod"/>.
/// </summary>
public MethodInfo ActionMethod { get; }
/// <summary>
/// See <see cref="ActionModel.ApiExplorer"/>.
/// </summary>
public ApiExplorerModelValues ApiExplorer { get; }
/// <summary>
/// The parameters of the action as <see cref="ParameterModelValues"/>.
/// See <see cref="ActionModel.Parameters"/>.
/// </summary>
public IList<ParameterModelValues> Parameters { get; }
/// <summary>
/// The filters of the action as <see cref="FilterValues"/>.
/// See <see cref="ActionModel.Filters"/>.
/// </summary>
public IList<FilterValues> Filters { get; }
/// <summary>
/// The route constraints on the controller as <see cref="RouteConstraintProviderValues"/>.
/// See <see cref="ControllerModel.RouteConstraints"/>.
/// </summary>
public IList<RouteConstraintProviderValues> RouteConstraints { get; set; }
/// <summary>
/// The attribute route model of the action as <see cref="AttributeRouteModelValues"/>.
/// See <see cref="ActionModel.AttributeRouteModel"/>.
/// </summary>
public AttributeRouteModelValues AttributeRouteModel { get; }
/// <summary>
/// The http methods this action supports. See <see cref="ActionModel.HttpMethods"/>.
/// </summary>
public IList<string> HttpMethods { get; }
/// <summary>
/// The action constraints of the action as <see cref="ActionConstraintValues"/>.
/// See <see cref="ActionModel.ActionConstraints"/>.
/// </summary>
public IList<ActionConstraintValues> ActionConstraints { get; }
/// <summary>
/// Gets the set of properties associated with the action <see cref="ActionModel.Properties"/>.
/// </summary>
public IDictionary<object, object> Properties { get; }
}
}

View File

@ -1,33 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of an <see cref="ApiExplorerModel"/>.
/// </summary>
public class ApiExplorerModelValues : ReflectionBasedLogValues
{
public ApiExplorerModelValues(ApiExplorerModel inner)
{
if (inner != null)
{
IsVisible = inner.IsVisible;
GroupName = inner.GroupName;
}
}
/// <summary>
/// See <see cref="ApiExplorerModel.IsVisible"/>.
/// </summary>
public bool? IsVisible { get; }
/// <summary>
/// See <see cref="ApiExplorerModel.GroupName"/>.
/// </summary>
public string GroupName { get; }
}
}

View File

@ -1,37 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of the state of a <see cref="AttributeRouteInfo"/>. Logged as a substructure of
/// <see cref="ActionDescriptorValues"/>.
/// </summary>
public class AttributeRouteInfoValues : ReflectionBasedLogValues
{
public AttributeRouteInfoValues(AttributeRouteInfo inner)
{
Template = inner?.Template;
Order = inner?.Order;
Name = inner?.Name;
}
/// <summary>
/// The route template. See <see cref="AttributeRouteInfo.Template"/>.
/// </summary>
public string Template { get; }
/// <summary>
/// The order of the route. See <see cref="AttributeRouteInfo.Order"/>.
/// </summary>
public int? Order { get; }
/// <summary>
/// The name of the route. See <see cref="AttributeRouteInfo.Name"/>.
/// </summary>
public string Name { get; }
}
}

View File

@ -1,46 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of the state of a <see cref="AttributeRouteModel"/>. Logged as a substructure of
/// <see cref="ControllerModelValues"/>.
/// </summary>
public class AttributeRouteModelValues : ReflectionBasedLogValues
{
public AttributeRouteModelValues(AttributeRouteModel inner)
{
if (inner != null)
{
Template = inner.Template;
Order = inner.Order;
Name = inner.Name;
IsAbsoluteTemplate = inner.IsAbsoluteTemplate;
}
}
/// <summary>
/// The template of the route. See <see cref="AttributeRouteModel.Template"/>.
/// </summary>
public string Template { get; }
/// <summary>
/// The order of the route. See <see cref="AttributeRouteModel.Order"/>.
/// </summary>
public int? Order { get; }
/// <summary>
/// The name of the route. See <see cref="AttributeRouteModel.Name"/>.
/// </summary>
public string Name { get; }
/// <summary>
/// Whether or not the template is absolute. See <see cref="AttributeRouteModel.IsAbsoluteTemplate"/>.
/// </summary>
public bool IsAbsoluteTemplate { get; }
}
}

View File

@ -1,98 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of the state of a <see cref="ControllerModel"/>. Logged during controller discovery.
/// </summary>
public class ControllerModelValues : ReflectionBasedLogValues
{
public ControllerModelValues(ControllerModel inner)
{
if (inner != null)
{
ControllerName = inner.ControllerName;
ControllerType = inner.ControllerType.AsType();
ApiExplorer = new ApiExplorerModelValues(inner.ApiExplorer);
Actions = inner.Actions.Select(a => new ActionModelValues(a)).ToList();
Attributes = inner.Attributes.Select(a => a.GetType()).ToList();
ControllerProperties = inner.ControllerProperties.Select(p => new PropertyModelValues(p)).ToList();
Filters = inner.Filters.Select(f => new FilterValues(f)).ToList();
ActionConstraints = inner.ActionConstraints?.Select(a => new ActionConstraintValues(a))?.ToList();
RouteConstraints = inner.RouteConstraints.Select(
r => new RouteConstraintProviderValues(r)).ToList();
AttributeRoutes = inner.AttributeRoutes.Select(
a => new AttributeRouteModelValues(a)).ToList();
Properties = new Dictionary<object, object>(inner.Properties);
}
}
/// <summary>
/// The name of the controller. See <see cref="ControllerModel.ControllerName"/>.
/// </summary>
public string ControllerName { get; }
/// <summary>
/// The <see cref="Type"/> of the controller. See <see cref="ControllerModel.ControllerType"/>.
/// </summary>
public Type ControllerType { get; }
/// <summary>
/// The <see cref="Type"/> of the controller. See <see cref="ControllerModel.ControllerType"/>.
/// </summary>
public IList<PropertyModelValues> ControllerProperties { get; }
/// <summary>
/// See <see cref="ControllerModel.ApiExplorer"/>.
/// </summary>
public ApiExplorerModelValues ApiExplorer { get; }
/// <summary>
/// The actions of the controller as <see cref="ActionModelValues"/>.
/// See <see cref="ControllerModel.Actions"/>.
/// </summary>
public IList<ActionModelValues> Actions { get; }
/// <summary>
/// The <see cref="Type"/>s of the controller's attributes.
/// See <see cref="ControllerModel.Attributes"/>.
/// </summary>
public IList<Type> Attributes { get; }
/// <summary>
/// The filters on the controller as <see cref="FilterValues"/>.
/// See <see cref="ControllerModel.Filters"/>.
/// </summary>
public IList<FilterValues> Filters { get; }
/// <summary>
/// The action constraints on the controller as <see cref="ActionConstraintValues"/>.
/// See <see cref="ControllerModel.ActionConstraints"/>.
/// </summary>
public IList<ActionConstraintValues> ActionConstraints { get; }
/// <summary>
/// The route constraints on the controller as <see cref="RouteConstraintProviderValues"/>.
/// See <see cref="ControllerModel.RouteConstraints"/>.
/// </summary>
public IList<RouteConstraintProviderValues> RouteConstraints { get; set; }
/// <summary>
/// The attribute routes on the controller as <see cref="AttributeRouteModelValues"/>.
/// See <see cref="ControllerModel.AttributeRoutes"/>.
/// </summary>
public IList<AttributeRouteModelValues> AttributeRoutes { get; set; }
/// <summary>
/// Gets the set of properties associated with the controller <see cref="ControllerModel.Properties"/>.
/// </summary>
public IDictionary<object, object> Properties { get; }
}
}

View File

@ -1,38 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of the state of a <see cref="FilterDescriptor"/>. Logged as a substructure of
/// <see cref="ActionDescriptorValues"/>.
/// </summary>
public class FilterDescriptorValues : ReflectionBasedLogValues
{
public FilterDescriptorValues([NotNull] FilterDescriptor inner)
{
Filter = new FilterValues(inner.Filter);
Order = inner.Order;
Scope = inner.Scope;
}
/// <summary>
/// The <see cref="IFilter"/> instance of the filter descriptor as <see cref="FilterValues"/>.
/// See <see cref="FilterDescriptor.Filter"/>.
/// </summary>
public FilterValues Filter { get; }
/// <summary>
/// The filter order. See <see cref="FilterDescriptor.Order"/>.
/// </summary>
public int Order { get; }
/// <summary>
/// The filter scope. See <see cref="FilterDescriptor.Scope"/>.
/// </summary>
public int Scope { get; }
}
}

View File

@ -1,64 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of an <see cref="IFilter"/>. Logged as a component of
/// <see cref="FilterDescriptorValues"/>, and as a substructure of <see cref="ControllerModelValues"/>
/// and <see cref="ActionModelValues"/>.
/// </summary>
public class FilterValues : ReflectionBasedLogValues
{
public FilterValues(IFilter inner)
{
FilterMetadataType = inner.GetType();
if (inner is IFilterFactory)
{
IsFactory = true;
if (inner is ServiceFilterAttribute)
{
FilterType = ((ServiceFilterAttribute)inner).ServiceType;
}
else if (inner is TypeFilterAttribute)
{
FilterType = ((TypeFilterAttribute)inner).ImplementationType;
}
}
if (FilterType != null)
{
FilterInterfaces = FilterType.GetInterfaces().ToList();
}
else
{
FilterInterfaces = FilterMetadataType.GetInterfaces().ToList();
}
}
/// <summary>
/// Whether or not the instance of <see cref="IFilter"/> is an <see cref="IFilterFactory"/>.
/// </summary>
public bool IsFactory { get; }
/// <summary>
/// The metadata type of the <see cref="IFilter"/>.
/// </summary>
public Type FilterMetadataType { get; }
/// <summary>
/// The inner <see cref="Type"/> of the <see cref="IFilter"/> if it is a <see cref="ServiceFilterAttribute"/>
/// or <see cref="TypeFilterAttribute"/>.
/// </summary>
public Type FilterType { get; }
/// <summary>
/// A list of interfaces the <see cref="IFilter"/> implements.
/// </summary>
public IList<Type> FilterInterfaces { get; }
}
}

View File

@ -1,32 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of a <see cref="ParameterDescriptor"/>. Logged as a substructure of
/// <see cref="ActionDescriptorValues"/>.
/// </summary>
public class ParameterDescriptorValues : ReflectionBasedLogValues
{
public ParameterDescriptorValues([NotNull] ParameterDescriptor inner)
{
ParameterName = inner.Name;
ParameterType = inner.ParameterType;
}
/// <summary>
/// The name of the parameter. See <see cref="ParameterDescriptor.Name"/>.
/// </summary>
public string ParameterName { get; }
/// <summary>
/// The <see cref="Type"/> of the parameter. See <see cref="ParameterDescriptor.ParameterType"/>.
/// </summary>
public Type ParameterType { get; }
}
}

View File

@ -1,34 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of a <see cref="ParameterModel"/>. Logged as a substructure of
/// <see cref="ActionModelValues"/>, this contains the name, type, and
/// binder metadata of the parameter.
/// </summary>
public class ParameterModelValues : ReflectionBasedLogValues
{
public ParameterModelValues([NotNull] ParameterModel inner)
{
ParameterName = inner.ParameterName;
ParameterType = inner.ParameterInfo.ParameterType;
}
/// <summary>
/// The name of the parameter. See <see cref="ParameterModel.ParameterName"/>.
/// </summary>
public string ParameterName { get; }
/// <summary>
/// The <see cref="Type"/> of the parameter.
/// </summary>
public Type ParameterType { get; }
}
}

View File

@ -1,34 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of a <see cref="PropertyModelValues"/>. Logged as a substructure of
/// <see cref="ControllerModelValues"/>, this contains the name, type, and
/// binder metadata of the property.
/// </summary>
public class PropertyModelValues : ReflectionBasedLogValues
{
public PropertyModelValues([NotNull] PropertyModel inner)
{
PropertyName = inner.PropertyName;
PropertyType = inner.PropertyInfo.PropertyType;
}
/// <summary>
/// The name of the property. See <see cref="PropertyModel.PropertyName"/>.
/// </summary>
public string PropertyName { get; }
/// <summary>
/// The <see cref="Type"/> of the property.
/// </summary>
public Type PropertyType { get; }
}
}

View File

@ -1,43 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of a <see cref="IRouteConstraintProvider"/>. Logged as a substructure of
/// <see cref="ControllerModelValues"/>
/// </summary>
public class RouteConstraintProviderValues : ReflectionBasedLogValues
{
public RouteConstraintProviderValues([NotNull] IRouteConstraintProvider inner)
{
RouteKey = inner.RouteKey;
RouteValue = inner.RouteValue;
RouteKeyHandling = inner.RouteKeyHandling;
BlockNonAttributedActions = inner.BlockNonAttributedActions;
}
/// <summary>
/// The route value key. See <see cref="IRouteConstraintProvider.RouteKey"/>.
/// </summary>
public string RouteKey { get; }
/// <summary>
/// The expected route value. See <see cref="IRouteConstraintProvider.RouteValue"/>.
/// </summary>
public string RouteValue { get; }
/// <summary>
/// The <see cref="RouteKeyHandling"/>. See <see cref="IRouteConstraintProvider.RouteKeyHandling"/>.
/// </summary>
public RouteKeyHandling RouteKeyHandling { get; }
/// <summary>
/// See <see cref="IRouteConstraintProvider.BlockNonAttributedActions"/>.
/// </summary>
public bool BlockNonAttributedActions { get; }
}
}

View File

@ -1,37 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
/// <summary>
/// Logging representation of the state of a <see cref="RouteDataActionConstraint"/>. Logged as a substructure of
/// <see cref="ActionDescriptorValues"/>.
/// </summary>
public class RouteDataActionConstraintValues : ReflectionBasedLogValues
{
public RouteDataActionConstraintValues([NotNull] RouteDataActionConstraint inner)
{
RouteKey = inner.RouteKey;
RouteValue = inner.RouteValue;
KeyHandling = inner.KeyHandling;
}
/// <summary>
/// The route key. See <see cref="RouteDataActionConstraint.RouteKey"/>.
/// </summary>
public string RouteKey { get; }
/// <summary>
/// The route value. See <see cref="RouteDataActionConstraint.RouteValue"/>.
/// </summary>
public string RouteValue { get; }
/// <summary>
/// The <see cref="RouteKeyHandling"/>. See <see cref="RouteDataActionConstraint.KeyHandling"/>.
/// </summary>
public RouteKeyHandling KeyHandling { get; }
}
}

View File

@ -1,85 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class ActionConstraintValuesTest
{
[Fact]
public void IActionConstraintMetadata_InitializesCorrectValues()
{
// Arrange
var constraint = new TestConstraintMetadata();
// Act
var constraintValues = new ActionConstraintValues(constraint);
// Assert
Assert.False(constraintValues.IsConstraint);
Assert.False(constraintValues.IsFactory);
Assert.Equal(0, constraintValues.Order);
Assert.Equal(typeof(TestConstraintMetadata), constraintValues.ActionConstraintMetadataType);
}
[Fact]
public void IActionConstraint_InitializesCorrectValues()
{
// Arrange
var constraint = new TestConstraint();
// Act
var constraintValues = new ActionConstraintValues(constraint);
// Assert
Assert.True(constraintValues.IsConstraint);
Assert.False(constraintValues.IsFactory);
Assert.Equal(23, constraintValues.Order);
Assert.Equal(typeof(TestConstraint), constraintValues.ActionConstraintMetadataType);
}
[Fact]
public void IActionConstraintFactory_InitializesCorrectValues()
{
// Arrange
var constraint = new TestFactory();
// Act
var constraintValues = new ActionConstraintValues(constraint);
// Assert
Assert.False(constraintValues.IsConstraint);
Assert.True(constraintValues.IsFactory);
Assert.Equal(0, constraintValues.Order);
Assert.Equal(typeof(TestFactory), constraintValues.ActionConstraintMetadataType);
}
private class TestConstraintMetadata : IActionConstraintMetadata
{
}
private class TestConstraint : IActionConstraint
{
public int Order
{
get { return 23; }
}
public bool Accept(ActionConstraintContext context)
{
return false;
}
}
private class TestFactory : IActionConstraintFactory
{
public IActionConstraint CreateInstance(IServiceProvider services)
{
return new TestConstraint();
}
}
}
}

View File

@ -1,24 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.ApplicationModels;
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class ActionModelValuesTest
{
[Fact]
public void ActionModelValues_IncludesAllProperties()
{
// Arrange
var exclude = new[] { "Controller", "Attributes", "IsActionNameMatchRequired" };
// Assert
PropertiesAssert.PropertiesAreTheSame(
typeof(ActionModel),
typeof(ActionModelValues),
exclude);
}
}
}

View File

@ -1,20 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.ApplicationModels;
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class ApiExplorerModelValuesTest
{
[Fact]
public void ApiExplorerModelValues_IncludesAllProperties()
{
// Assert
PropertiesAssert.PropertiesAreTheSame(
typeof(ApiExplorerModel),
typeof(ApiExplorerModelValues));
}
}
}

View File

@ -22,9 +22,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public void BuildControllerModel_DerivedFromControllerClass_HasFilter()
{
// Arrange
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var typeInfo = typeof(StoreController).GetTypeInfo();
// Act
@ -39,9 +37,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public void BuildControllerModel_AuthorizeAttributeAddsAuthorizeFilter()
{
// Arrange
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var typeInfo = typeof(AccountController).GetTypeInfo();
// Act
@ -61,8 +57,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
mockOptions.SetupGet(o => o.Options)
.Returns(corsOptions);
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
authorizationOptions: null);
authorizationOptions: null);
var typeInfo = typeof(CorsController).GetTypeInfo();
// Act
@ -76,9 +71,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public void BuildControllerModel_AddsControllerProperties()
{
// Arrange
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var typeInfo = typeof(ModelBinderController).GetTypeInfo();
// Act
@ -103,7 +96,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
mockOptions.SetupGet(o => o.Options)
.Returns(corsOptions);
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
authorizationOptions: null);
var typeInfo = typeof(DisableCorsController).GetTypeInfo();
@ -120,9 +112,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public void BuildControllerModel_ClassWithoutFilterInterfaces_HasNoControllerFilter()
{
// Arrange
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var typeInfo = typeof(NoFiltersController).GetTypeInfo();
// Act
@ -137,9 +127,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public void BuildControllerModel_ClassWithFilterInterfaces_HasFilter()
{
// Arrange
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var typeInfo = typeof(SomeFiltersController).GetTypeInfo();
// Act
@ -154,9 +142,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public void BuildControllerModel_ClassWithFilterInterfaces_UnsupportedType()
{
// Arrange
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var builder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var typeInfo = typeof(UnsupportedFiltersController).GetTypeInfo();
// Act

View File

@ -1,24 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.ApplicationModels;
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class AttributeRouteInfoValuesTest
{
[Fact]
public void AttributeRouteModelValues_IncludesAllProperties()
{
// Arrange
var exclude = new[] { "Attribute" };
// Assert
PropertiesAssert.PropertiesAreTheSame(
typeof(AttributeRouteModel),
typeof(AttributeRouteModelValues),
exclude);
}
}
}

View File

@ -1,20 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.Routing;
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class AttributeRouteModelValuesTest
{
[Fact]
public void AttributeRouteInfoValues_IncludesAllProperties()
{
// Assert
PropertiesAssert.PropertiesAreTheSame(
typeof(AttributeRouteInfo),
typeof(AttributeRouteInfoValues));
}
}
}

View File

@ -1365,16 +1365,13 @@ namespace Microsoft.AspNet.Mvc.Test
IEnumerable<IFilter> filters = null)
{
var controllerTypeProvider = new FixedSetControllerTypeProvider(new[] { controllerTypeInfo });
var controllerModelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var controllerModelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var provider = new ControllerActionDescriptorProvider(
controllerTypeProvider,
controllerModelBuilder,
new TestGlobalFilterProvider(filters),
new MockMvcOptionsAccessor(),
new NullLoggerFactory());
new MockMvcOptionsAccessor());
return provider;
}
@ -1383,16 +1380,13 @@ namespace Microsoft.AspNet.Mvc.Test
params TypeInfo[] controllerTypeInfo)
{
var controllerTypeProvider = new FixedSetControllerTypeProvider(controllerTypeInfo);
var controllerModelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var controllerModelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var provider = new ControllerActionDescriptorProvider(
controllerTypeProvider,
controllerModelBuilder,
new TestGlobalFilterProvider(),
new MockMvcOptionsAccessor(),
new NullLoggerFactory());
new MockMvcOptionsAccessor());
return provider;
}
@ -1402,9 +1396,7 @@ namespace Microsoft.AspNet.Mvc.Test
IApplicationModelConvention convention)
{
var controllerTypeProvider = new FixedSetControllerTypeProvider(new[] { type });
var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var options = new MockMvcOptionsAccessor();
options.Options.Conventions.Add(convention);
@ -1413,23 +1405,19 @@ namespace Microsoft.AspNet.Mvc.Test
controllerTypeProvider,
modelBuilder,
new TestGlobalFilterProvider(),
options,
new NullLoggerFactory());
options);
}
private IEnumerable<ActionDescriptor> GetDescriptors(params TypeInfo[] controllerTypeInfos)
{
var controllerTypeProvider = new FixedSetControllerTypeProvider(controllerTypeInfos);
var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var provider = new ControllerActionDescriptorProvider(
controllerTypeProvider,
modelBuilder,
new TestGlobalFilterProvider(),
new MockMvcOptionsAccessor(),
new NullLoggerFactory());
new MockMvcOptionsAccessor());
return provider.GetDescriptors();
}

View File

@ -1,24 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.ApplicationModels;
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class ControllerModelValuesTest
{
[Fact]
public void ControllerModelValues_IncludesAllProperties()
{
// Arrange
var exclude = new[] { "Application" };
// Assert
PropertiesAssert.PropertiesAreTheSame(
typeof(ControllerModel),
typeof(ControllerModelValues),
exclude);
}
}
}

View File

@ -1,161 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Reflection;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Logging;
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class DefaultActionDescriptorCollectionProviderLoggingTest
{
[Fact]
public void ControllerDiscovery()
{
// Arrange
var sink = new TestSink();
var loggerFactory = new TestLoggerFactory(sink);
// Act
var provider = GetProvider(
loggerFactory,
typeof(SimpleController).GetTypeInfo(),
typeof(BasicController).GetTypeInfo());
provider.GetDescriptors();
// Assert
// 2 controllers
Assert.Equal(2, sink.Writes.Count);
var controllerModelValues = Assert.IsType<ControllerModelValues>(sink.Writes[0].State);
Assert.NotNull(controllerModelValues);
Assert.Equal("Simple", controllerModelValues.ControllerName);
Assert.Equal(typeof(SimpleController), controllerModelValues.ControllerType);
Assert.Single(controllerModelValues.Actions);
Assert.Empty(controllerModelValues.AttributeRoutes);
Assert.Empty(controllerModelValues.RouteConstraints);
Assert.Empty(controllerModelValues.Attributes);
Assert.Empty(controllerModelValues.Filters);
controllerModelValues = Assert.IsType<ControllerModelValues>(sink.Writes[1].State);
Assert.NotNull(controllerModelValues);
Assert.Equal("Basic", controllerModelValues.ControllerName);
Assert.Equal(typeof(BasicController), controllerModelValues.ControllerType);
Assert.Equal(2, controllerModelValues.Actions.Count);
Assert.Equal("GET", controllerModelValues.Actions[0].HttpMethods.FirstOrDefault());
Assert.Equal("POST", controllerModelValues.Actions[1].HttpMethods.FirstOrDefault());
Assert.Empty(controllerModelValues.AttributeRoutes);
Assert.Empty(controllerModelValues.RouteConstraints);
Assert.NotEmpty(controllerModelValues.Attributes);
Assert.Single(controllerModelValues.Filters);
}
[Fact]
public void ActionDiscovery()
{
// Arrange
var sink = new TestSink();
var loggerFactory = new TestLoggerFactory(sink);
// Act
CreateActionDescriptors(loggerFactory,
typeof(SimpleController).GetTypeInfo(),
typeof(BasicController).GetTypeInfo());
// Assert
// 2 controllers, 3 actions
Assert.Equal(5, sink.Writes.Count);
Assert.IsType<ControllerModelValues>(sink.Writes[0].State);
Assert.IsType<ControllerModelValues>(sink.Writes[1].State);
var actionDescriptorValues = Assert.IsType<ActionDescriptorValues>(sink.Writes[2].State);
Assert.NotNull(actionDescriptorValues);
Assert.Equal("EmptyAction", actionDescriptorValues.Name);
Assert.Equal("Simple", actionDescriptorValues.ControllerName);
Assert.Equal(typeof(SimpleController), actionDescriptorValues.ControllerTypeInfo);
Assert.Null(actionDescriptorValues.AttributeRouteInfo.Name);
Assert.Null(actionDescriptorValues.ActionConstraints);
Assert.Empty(actionDescriptorValues.FilterDescriptors);
Assert.Empty(actionDescriptorValues.Parameters);
actionDescriptorValues = Assert.IsType<ActionDescriptorValues>(sink.Writes[3].State);
Assert.NotNull(actionDescriptorValues);
Assert.Equal("Basic", actionDescriptorValues.Name);
Assert.Equal("Basic", actionDescriptorValues.ControllerName);
Assert.Equal(typeof(BasicController), actionDescriptorValues.ControllerTypeInfo);
Assert.Null(actionDescriptorValues.AttributeRouteInfo.Name);
Assert.NotEmpty(actionDescriptorValues.ActionConstraints);
Assert.Equal(2, actionDescriptorValues.FilterDescriptors.Count);
Assert.Empty(actionDescriptorValues.Parameters);
actionDescriptorValues = Assert.IsType<ActionDescriptorValues>(sink.Writes[4].State);
Assert.NotNull(actionDescriptorValues);
Assert.Equal("Basic", actionDescriptorValues.Name);
Assert.Equal("Basic", actionDescriptorValues.ControllerName);
Assert.Equal(typeof(BasicController), actionDescriptorValues.ControllerTypeInfo);
Assert.Null(actionDescriptorValues.AttributeRouteInfo.Name);
Assert.NotEmpty(actionDescriptorValues.ActionConstraints);
Assert.Single(actionDescriptorValues.FilterDescriptors);
Assert.Single(actionDescriptorValues.RouteConstraints);
Assert.Single(actionDescriptorValues.Parameters);
}
private void CreateActionDescriptors(ILoggerFactory loggerFactory, params TypeInfo[] controllerTypeInfo)
{
var actionDescriptorProvider = GetProvider(loggerFactory, controllerTypeInfo);
// service container does not work quite like our built in Depenency Injection container.
var serviceContainer = new ServiceContainer();
var list = new List<IActionDescriptorProvider>()
{
actionDescriptorProvider,
};
serviceContainer.AddService(typeof(IEnumerable<IActionDescriptorProvider>), list);
var actionCollectionDescriptorProvider = new DefaultActionDescriptorsCollectionProvider(serviceContainer, loggerFactory);
var descriptors = actionCollectionDescriptorProvider.ActionDescriptors;
}
private ControllerActionDescriptorProvider GetProvider(
ILoggerFactory loggerFactory, params TypeInfo[] controllerTypeInfo)
{
var controllerTypeProvider = new FixedSetControllerTypeProvider(controllerTypeInfo);
var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
loggerFactory,
null);
var provider = new ControllerActionDescriptorProvider(
controllerTypeProvider,
modelBuilder,
new TestGlobalFilterProvider(),
new MockMvcOptionsAccessor(),
loggerFactory);
return provider;
}
private class SimpleController
{
public void EmptyAction() { }
}
[Authorize]
private class BasicController
{
[HttpGet]
[AllowAnonymous]
public void Basic() { }
[HttpPost]
[Route("/Basic")]
public void Basic(int id) { }
}
}
}

View File

@ -13,7 +13,6 @@ using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Logging;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.Internal;
@ -645,7 +644,7 @@ namespace Microsoft.AspNet.Mvc
serviceContainer.AddService(typeof(IEnumerable<IActionDescriptorProvider>), list);
var actionCollectionDescriptorProvider = new DefaultActionDescriptorsCollectionProvider(serviceContainer, new NullLoggerFactory());
var actionCollectionDescriptorProvider = new DefaultActionDescriptorsCollectionProvider(serviceContainer);
var decisionTreeProvider = new ActionSelectorDecisionTreeProvider(actionCollectionDescriptorProvider);
var actionConstraintProviders = new IActionConstraintProvider[] {
@ -669,16 +668,13 @@ namespace Microsoft.AspNet.Mvc
.ToList();
var controllerTypeProvider = new FixedSetControllerTypeProvider(controllerTypes);
var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
NullLoggerFactory.Instance,
null);
var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
return new ControllerActionDescriptorProvider(
controllerTypeProvider,
modelBuilder,
new TestGlobalFilterProvider(),
new MockMvcOptionsAccessor(),
new NullLoggerFactory());
new MockMvcOptionsAccessor());
}
private static HttpContext GetHttpContext(string httpMethod)

View File

@ -1,20 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.Logging;
using Xunit;
namespace Microsoft.AspNet.Mvc.Test.Logging
{
public class FilterDescriptorValuesTest
{
[Fact]
public void FilterDescriptorValues_IncludesAllProperties()
{
// Assert
PropertiesAssert.PropertiesAreTheSame(
typeof(FilterDescriptor),
typeof(FilterDescriptorValues));
}
}
}

View File

@ -1,99 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class FilterValuesTest
{
[Fact]
public void IFilter_InitializesCorrectValues()
{
// Arrange
var filter = new TestFilter();
// Act
var filterValues = new FilterValues(filter);
// Assert
Assert.False(filterValues.IsFactory);
Assert.Null(filterValues.FilterType);
Assert.Equal(typeof(TestFilter), filterValues.FilterMetadataType);
Assert.Equal(
new List<Type>() { typeof(IFilter), typeof(IExceptionFilter) },
filterValues.FilterInterfaces);
}
[Fact]
public void IFilterFactory_InitializesCorrectValues()
{
// Arrange
var filter = new TestFactory();
// Act
var filterValues = new FilterValues(filter);
// Assert
Assert.True(filterValues.IsFactory);
Assert.Null(filterValues.FilterType);
Assert.Equal(typeof(TestFactory), filterValues.FilterMetadataType);
Assert.Equal(
new List<Type>() { typeof(IFilterFactory), typeof(IFilter) },
filterValues.FilterInterfaces);
}
[Fact]
public void ServiceFilterAttribute_InitializesCorrectValues()
{
// Arrange
var filter = new ServiceFilterAttribute(typeof(TestFilter));
// Act
var filterValues = new FilterValues(filter);
// Assert
Assert.True(filterValues.IsFactory);
Assert.Equal(typeof(TestFilter), filterValues.FilterType);
Assert.Equal(typeof(ServiceFilterAttribute), filterValues.FilterMetadataType);
Assert.Equal(
new List<Type>() { typeof(IFilter), typeof(IExceptionFilter) },
filterValues.FilterInterfaces);
}
[Fact]
public void TypeFilterAttribute_InitializesCorrectValues()
{
// Arrange
var filter = new TypeFilterAttribute(typeof(TestFilter));
// Act
var filterValues = new FilterValues(filter);
// Assert
Assert.True(filterValues.IsFactory);
Assert.Equal(typeof(TestFilter), filterValues.FilterType);
Assert.Equal(typeof(TypeFilterAttribute), filterValues.FilterMetadataType);
Assert.Equal(
new List<Type>() { typeof(IFilter), typeof(IExceptionFilter) },
filterValues.FilterInterfaces);
}
private class TestFilter : IFilter, IExceptionFilter
{
public void OnException(ExceptionContext context)
{
}
}
private class TestFactory : IFilterFactory
{
public IFilter CreateInstance(IServiceProvider serviceProvider)
{
return new TestFilter();
}
}
}
}

View File

@ -172,7 +172,7 @@ namespace Microsoft.AspNet.Routing.Tests
context.Setup(o => o.RequestServices
.GetService(typeof(IActionDescriptorsCollectionProvider)))
.Returns(new DefaultActionDescriptorsCollectionProvider(context.Object.RequestServices, new NullLoggerFactory()));
.Returns(new DefaultActionDescriptorsCollectionProvider(context.Object.RequestServices));
return context.Object;
}

View File

@ -1,23 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class RouteConstraintProviderValuesTest
{
[Fact]
public void RouteConstraintProviderValues_IncludesAllProperties()
{
// Arrange
var exclude = new[] { "TypeId" };
// Assert
PropertiesAssert.PropertiesAreTheSame(
typeof(RouteConstraintAttribute),
typeof(RouteConstraintProviderValues),
exclude);
}
}
}

View File

@ -1,19 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Xunit;
namespace Microsoft.AspNet.Mvc.Logging
{
public class RouteDataActionConstraintValuesTest
{
[Fact]
public void RouteDataActionConstraintValues_IncludesAllProperties()
{
// Assert
PropertiesAssert.PropertiesAreTheSame(
typeof(RouteDataActionConstraint),
typeof(RouteDataActionConstraintValues));
}
}
}

View File

@ -1,113 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if DNX451 // Since Json.net serialization fails in CoreCLR
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using LoggingWebSite;
using LoggingWebSite.Controllers;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Logging;
using Microsoft.Framework.DependencyInjection;
using Newtonsoft.Json;
using Xunit;
namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class LoggingStartupTest
{
private const string SiteName = nameof(LoggingWebSite);
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _configureServices = new Startup().ConfigureServices;
[Fact]
public async Task AssemblyValues_LoggedAtStartup()
{
// Arrange and Act
var logs = await GetLogsByDataTypeAsync<AssemblyValues>();
// Assert
Assert.NotEmpty(logs);
foreach (var log in logs)
{
dynamic assembly = log.State;
Assert.NotNull(assembly);
Assert.Equal(
"LoggingWebSite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
assembly.AssemblyName.ToString());
}
}
[Fact]
public async Task ControllerModelValues_LoggedAtStartup()
{
// Arrange and Act
var logs = await GetLogsByDataTypeAsync<ControllerModelValues>();
// Assert
Assert.Single(logs);
dynamic controller = logs.First().State;
Assert.Equal("Home", controller.ControllerName.ToString());
Assert.Equal(typeof(HomeController).AssemblyQualifiedName, controller.ControllerType.ToString());
Assert.Equal("Index", controller.Actions[0].ActionName.ToString());
Assert.Empty(controller.ApiExplorer.IsVisible);
Assert.Empty(controller.ApiExplorer.GroupName.ToString());
Assert.Empty(controller.Attributes);
Assert.Empty(controller.ActionConstraints);
Assert.Empty(controller.RouteConstraints);
Assert.Empty(controller.AttributeRoutes);
var filter = Assert.Single(controller.Filters);
Assert.Equal(typeof(ControllerActionFilter).AssemblyQualifiedName, (string)filter.FilterMetadataType);
}
[Fact]
public async Task ActionDescriptorValues_LoggedAtStartup()
{
// Arrange and Act
var logs = await GetLogsByDataTypeAsync<ActionDescriptorValues>();
// Assert
Assert.Single(logs);
dynamic action = logs.First().State;
Assert.Equal("Index", action.Name.ToString());
Assert.Empty(action.Parameters);
Assert.Equal("action", action.RouteConstraints[0].RouteKey.ToString());
Assert.Equal("controller", action.RouteConstraints[1].RouteKey.ToString());
Assert.Empty(action.RouteValueDefaults);
Assert.Empty(action.ActionConstraints.ToString());
Assert.Empty(action.HttpMethods.ToString());
Assert.Empty(action.Properties);
Assert.Equal("Home", action.ControllerName.ToString());
var filter = Assert.Single(action.FilterDescriptors).Filter;
Assert.Equal(typeof(ControllerActionFilter).AssemblyQualifiedName, (string)filter.FilterMetadataType);
}
private async Task<IEnumerable<LogInfoDto>> GetLogsByDataTypeAsync<T>()
{
var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
var client = server.CreateClient();
var requestTraceId = Guid.NewGuid().ToString();
var response = await client.GetAsync(string.Format(
"http://localhost/home/index?{0}={1}",
LoggingExtensions.RequestTraceIdQueryKey,
requestTraceId));
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
response = await client.GetAsync("http://localhost/logs");
var body = await response.Content.ReadAsStringAsync();
var activityDtos = JsonConvert.DeserializeObject<List<ActivityContextDto>>(body);
return activityDtos.GetLogsByDataType<T>();
}
}
}
#endif

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
#if !DNXCORE50
using Moq;
#endif

View File

@ -12,7 +12,6 @@ using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.WebApiCompatShim;
using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit;
@ -373,9 +372,7 @@ namespace System.Web.Http
var assemblyProvider = new FixedSetAssemblyProvider();
assemblyProvider.CandidateAssemblies.Add(GetType().GetTypeInfo().Assembly);
var controllerTypeProvider = new NamespaceFilteredControllerTypeProvider(assemblyProvider);
var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null),
new LoggerFactory(),
null);
var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);
var filterProvider = new Mock<IGlobalFilterProvider>();
filterProvider
@ -396,8 +393,7 @@ namespace System.Web.Http
controllerTypeProvider,
modelBuilder,
filterProvider.Object,
optionsAccessor.Object,
new LoggerFactory());
optionsAccessor.Object);
return provider;
}