public void HttpMethodConstraintsAppliedCorrectly() { foreach (var @case in new[] { new { Verb = "GET", callback = _classifyRequestTypeQuery, existingConstraints = new string[0] }, new { Verb = "POST", callback = _classifyRequestTypeCommand, existingConstraints = new string[0] }, new { Verb = "GET", callback = _classifyRequestTypeQuery, existingConstraints = new [] { "DELETE" } }, new { Verb = "POST", callback = _classifyRequestTypeCommand, existingConstraints = new [] { "DELETE" } }, new { Verb = "DELETE", callback = _classifyRequestTypeCommandDelete, existingConstraints = new [] { "DELETE" } }, }) { var controllerModel = GetControllerModel(@case.existingConstraints); var convention = new ExtendedConvention(null, null, @case.callback); convention.Apply(controllerModel); Assert.AreEqual(1, controllerModel.Actions.Count); var actionModel = controllerModel.Actions.Single(); Assert.AreEqual(1, actionModel.Selectors.Count); var selector = actionModel.Selectors.Single(); Assert.AreEqual(1, selector.ActionConstraints.Count(c => c.GetType() == typeof(HttpMethodActionConstraint))); var actionConstraint = (HttpMethodActionConstraint)selector.ActionConstraints.Single(c => c.GetType() == typeof(HttpMethodActionConstraint)); Assert.AreEqual(1, actionConstraint.HttpMethods.Count(m => m == @case.Verb)); foreach (var httpConstraint in @case.existingConstraints) { Assert.AreEqual(1, actionConstraint.HttpMethods.Count(m => m == httpConstraint)); } } }
public void ActionNameSetCorrectly() { foreach (var @case in new[] { new { callback = (Func <Type, MethodInfo, string>)null, Name = "Index" }, new { callback = _provideActionName, Name = "IndexIndex" } }) { var controllerModel = GetControllerModel(); var convention = new ExtendedConvention(null, @case.callback, null); convention.Apply(controllerModel); Assert.AreEqual(@case.Name, controllerModel.Actions.First().ActionName); } }
public void ControllerNameSetCorrectly() { foreach (var @case in new[] { new { callback = (Func <Type, string>)null, Name = "GetTestDataRequest" }, new { callback = _provideControllerName, Name = "GetTestData" } }) { var controllerModel = GetControllerModel(); var convention = new ExtendedConvention(@case.callback, null, null); convention.Apply(controllerModel); Assert.AreEqual(@case.Name, controllerModel.ControllerName); } }