Update per comment

This commit is contained in:
ianhong 2014-11-17 15:30:55 -08:00
parent 7b58d569eb
commit 59b7352e8e
2 changed files with 18 additions and 46 deletions

View File

@ -9,8 +9,8 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
{
public class ParameterModel
{
public ParameterModel(ParameterInfo parameterInfo,
IReadOnlyList<object> attributes)
public ParameterModel([NotNull] ParameterInfo parameterInfo,
[NotNull] IReadOnlyList<object> attributes)
{
ParameterInfo = parameterInfo;

View File

@ -1137,32 +1137,31 @@ namespace Microsoft.AspNet.Mvc.Test
var options = new MockMvcOptionsAccessor();
options.Options.ApplicationModelConventions.Add(applicationConvention.Object);
var provider = GetProvider(typeof(ConventionsController).GetTypeInfo(), options);
var applicationModel = new ApplicationModel();
var model = provider.BuildModel();
var controller = new ControllerModel(typeof(ConventionsController).GetTypeInfo(),
new List<object>() { controllerConvention.Object });
controller.Application = applicationModel;
applicationModel.Controllers.Add(controller);
var controller = model.Controllers.Single();
model.Controllers.Remove(controller);
controller = BuildControllerModel(controller, controllerConvention.Object);
model.Controllers.Add(controller);
var methodInfo = typeof(ConventionsController).GetMethod("Create");
var actionModel = new ActionModel(methodInfo, new List<object>() { actionConvention.Object });
actionModel.Controller = controller;
controller.Actions.Add(actionModel);
var action = controller.Actions.Single();
controller.Actions.Remove(action);
action = BuildActionModel(action, actionConvention.Object);
controller.Actions.Add(action);
var parameter = action.Parameters.Single();
action.Parameters.Remove(parameter);
parameter = BuildParameterModel(parameter, parameterConvention.Object);
action.Parameters.Add(parameter);
var parameterInfo = actionModel.ActionMethod.GetParameters().Single();
var parameterModel = new ParameterModel(parameterInfo,
new List<object>() { parameterConvention.Object });
parameterModel.Action = actionModel;
actionModel.Parameters.Add(parameterModel);
// Act
ApplicationModelConventions.ApplyConventions(model, options.Options.ApplicationModelConventions);
ApplicationModelConventions.ApplyConventions(applicationModel, options.Options.ApplicationModelConventions);
// Assert
Assert.Equal(4, sequence);
}
[Fact]
public void BuildModel_SplitsConstraintsBasedOnRoute()
{
@ -1306,33 +1305,6 @@ namespace Microsoft.AspNet.Mvc.Test
Assert.Single(action.ActionConstraints, a => a is ConstraintAttribute);
}
private ActionModel BuildActionModel(ActionModel action, IActionModelConvention actionConvention)
{
var t = new ActionModel(action.ActionMethod,
new List<object>(action.Attributes) { actionConvention });
t.Parameters.AddRange(action.Parameters);
return t;
}
private ParameterModel BuildParameterModel(ParameterModel parameter, IParameterModelConvention parameterConvention)
{
var t = new ParameterModel(parameter.ParameterInfo,
new List<object>(parameter.Attributes) { parameterConvention });
t.Action = parameter.Action;
return t;
}
private ControllerModel BuildControllerModel(ControllerModel controller, IControllerModelConvention controllerConvention)
{
var t = new ControllerModel(controller.ControllerType,
new List<object>(controller.Attributes) { controllerConvention });
t.Actions.AddRange(controller.Actions);
return t;
}
private ControllerActionDescriptorProvider GetProvider(
TypeInfo controllerTypeInfo,
IEnumerable<IFilter> filters = null)