public void Test_ValidateParameter_PassesWhenObject() { var attribute = new FromParamsAttribute(BindingStyle.Object); var controllerModel = new Mock <ControllerModel>(typeof(JsonRpcTestController).GetTypeInfo(), new List <object>()).Object; var actionModel = new Mock <ActionModel>(typeof(JsonRpcTestController).GetMethod(nameof(JsonRpcTestController.VoidAction)), new List <object>()).Object; var model = new Mock <ParameterModel>(typeof(JsonRpcTestController).GetMethod(nameof(JsonRpcTestController.VoidAction)).GetParameters()[2], new List <object> { attribute }).Object; actionModel.Controller = controllerModel; model.Action = actionModel; var parameterConvention = testEnvironment.ServiceProvider.GetRequiredService <ParameterConvention>(); Action action = () => parameterConvention.ValidateParameter(model, BindingStyle.Object); action.Should().NotThrow(); }
public void Test_ValidateParameter_ThrowsOnUnknown() { var attribute = new FromParamsAttribute(BindingStyle.Array); var controllerModel = new Mock <ControllerModel>(typeof(JsonRpcTestController).GetTypeInfo(), new List <object>()).Object; var actionModel = new Mock <ActionModel>(typeof(JsonRpcTestController).GetMethod(nameof(JsonRpcTestController.VoidAction)), new List <object>()).Object; var model = new Mock <ParameterModel>(typeof(JsonRpcTestController).GetMethod(nameof(JsonRpcTestController.VoidAction)).GetParameters()[3], new List <object> { attribute }).Object; actionModel.Controller = controllerModel; model.Action = actionModel; var parameterConvention = testEnvironment.ServiceProvider.GetRequiredService <ParameterConvention>(); Action action = () => parameterConvention.ValidateParameter(model, (BindingStyle)(-1)); action.Should().Throw <ArgumentOutOfRangeException>(); }
public void Test_GetRpcParameterInfo_UsesAttributes(BindingStyle bindingStyle) { var attribute = new FromParamsAttribute(bindingStyle); var serializerType = typeof(SnakeCaseJsonRpcSerializer); var controllerModel = new Mock <ControllerModel>(typeof(JsonRpcTestController).GetTypeInfo(), new List <object>()).Object; var actionModel = new Mock <ActionModel>(typeof(JsonRpcTestController).GetMethod(nameof(JsonRpcTestController.VoidAction)), new List <object>()).Object; var model = new Mock <ParameterModel>(typeof(JsonRpcTestController).GetMethod(nameof(JsonRpcTestController.VoidAction)).GetParameters()[0], new List <object> { attribute }).Object; actionModel.Controller = controllerModel; model.Action = actionModel; var parameterConvention = testEnvironment.ServiceProvider.GetRequiredService <ParameterConvention>(); var result = parameterConvention.GetParameterMetadata(model, serializerType); result.BindingStyle.Should().Be(bindingStyle); }
public void Test_SetBinding_SetsWhenNull() { var attribute = new FromParamsAttribute(BindingStyle.Array); var controllerModel = new Mock <ControllerModel>(typeof(JsonRpcTestController).GetTypeInfo(), new List <object>()).Object; var actionModel = new Mock <ActionModel>(typeof(JsonRpcTestController).GetMethod(nameof(JsonRpcTestController.VoidAction)), new List <object>()).Object; var model = new Mock <ParameterModel>(typeof(JsonRpcTestController).GetMethod(nameof(JsonRpcTestController.VoidAction)).GetParameters()[2], new List <object> { attribute }).Object; actionModel.Controller = controllerModel; model.Action = actionModel; var parameterConvention = testEnvironment.ServiceProvider.GetRequiredService <ParameterConvention>(); model.BindingInfo.Should().BeNull(); parameterConvention.SetBinding(model); model.BindingInfo.Should().NotBeNull(); model.BindingInfo.BinderType.Should().Be <JsonRpcModelBinder>(); model.BindingInfo.BindingSource.Should().Be(BindingSource.Custom); }