Beispiel #1
0
        public void BindModelAsync_ThrowsArgument_ModelBindingContextMustHaveRequest()
        {
            // Arrange
            ODataQueryParameterBindingAttribute.ODataQueryParameterBinding binding = new ODataQueryParameterBindingAttribute.ODataQueryParameterBinding();
            Mock <HttpContext> httpContext = new Mock <HttpContext>();

            httpContext.Setup(c => c.Request).Returns((HttpRequest)null);

            Mock <ModelBindingContext> context = new Mock <ModelBindingContext>();

            context.Setup(c => c.HttpContext).Returns(httpContext.Object);

            // Act & Assert
            ExceptionAssert.ThrowsArgument(
                () => binding.BindModelAsync(context.Object),
                "bindingContext",
                "The model binding context requires an attached request in order to model binding.");
        }
Beispiel #2
0
        public void BindModelAsync_ThrowsArgument_ActionContextMustHaveDescriptor()
        {
            // Arrange
            ODataQueryParameterBindingAttribute.ODataQueryParameterBinding binding = new ODataQueryParameterBindingAttribute.ODataQueryParameterBinding();

            Mock <ModelBindingContext> context = new Mock <ModelBindingContext>();

            context.Setup(c => c.HttpContext).Returns(new DefaultHttpContext());

            ActionContext actionContext = new ActionContext
            {
                ActionDescriptor = null
            };

            context.Setup(c => c.ActionContext).Returns(actionContext);

            // Act & Assert
            ExceptionAssert.ThrowsArgument(
                () => binding.BindModelAsync(context.Object),
                "actionContext",
                "The HttpActionContext.ActionDescriptor is null.");
        }
Beispiel #3
0
 public void BindModelAsync_ThrowsArgumentNull_BindingContext()
 {
     // Arrange & Act & Assert
     ODataQueryParameterBindingAttribute.ODataQueryParameterBinding binding = new ODataQueryParameterBindingAttribute.ODataQueryParameterBinding();
     ExceptionAssert.ThrowsArgumentNull(() => binding.BindModelAsync(null), "bindingContext");
 }