public void HasParameter_Returns_BooleanAsExpected() { // Arrange ActionModel action = _methodInfo.BuildActionModel(); // Act & Assert Assert.False(action.HasParameter <int>("key")); Assert.True(action.HasParameter <int>("id")); Assert.False(action.HasParameter <string>("id")); }
public void AddSelector_AddsCors_ForActionsWithCorsAttribute(Type controllerType, string actionName, bool expectedCorsSetting) { // Arrange IEdmModel model = new Mock <IEdmModel>().Object; MethodInfo methodInfo = controllerType.GetMethod(actionName); ActionModel action = methodInfo.BuildActionModel(); action.Controller = ControllerModelHelpers.BuildControllerModel(controllerType); // Act action.AddSelector("Get", string.Empty, model, new ODataPathTemplate(CountSegmentTemplate.Instance)); // Assert SelectorModel newSelector = action.Selectors.FirstOrDefault(); Assert.NotNull(newSelector); HttpMethodMetadata httpMethodMetadata = newSelector.EndpointMetadata.OfType <HttpMethodMetadata>().FirstOrDefault(); Assert.NotNull(httpMethodMetadata); Assert.Equal(httpMethodMetadata.AcceptCorsPreflight, expectedCorsSetting); }
public void AddSelector_ThrowsArgumentNull_ForInputParameter() { // Arrange & Act & Assert ActionModel action = null; ExceptionAssert.ThrowsArgumentNull(() => action.AddSelector(null, null, null, null), "action"); // Arrange & Act & Assert MethodInfo methodInfo = typeof(TestController).GetMethod("Get"); action = methodInfo.BuildActionModel(); ExceptionAssert.ThrowsArgumentNullOrEmpty(() => action.AddSelector(null, null, null, null), "httpMethods"); // Arrange & Act & Assert string httpMethods = "get"; ExceptionAssert.ThrowsArgumentNull(() => action.AddSelector(httpMethods, null, null, null), "model"); // Arrange & Act & Assert IEdmModel model = new Mock <IEdmModel>().Object; ExceptionAssert.ThrowsArgumentNull(() => action.AddSelector(httpMethods, null, model, null), "path"); }