Exemple #1
0
    public void Create_ForSupportedType_ReturnsBinder()
    {
        // Arrange
        var provider = new ComplexObjectModelBinderProvider();

        var context = new TestModelBinderProviderContext(typeof(Person));

        context.OnCreatingBinder(m =>
        {
            if (m.ModelType == typeof(int) || m.ModelType == typeof(string))
            {
                return(Mock.Of <IModelBinder>());
            }
            else
            {
                Assert.False(true, "Not the right model type");
                return(null);
            }
        });

        // Act
        var result = provider.GetBinder(context);

        // Assert
        Assert.IsType <ComplexObjectModelBinder>(result);
    }
Exemple #2
0
    public void Create_ForNonComplexType_ReturnsNull(Type modelType)
    {
        // Arrange
        var provider = new ComplexObjectModelBinderProvider();

        var context = new TestModelBinderProviderContext(modelType);

        // Act
        var result = provider.GetBinder(context);

        // Assert
        Assert.Null(result);
    }
 public BodyAndRouteModelBinderProvider(BodyModelBinderProvider bodyModelBinderProvider,
                                        ComplexObjectModelBinderProvider complexTypeModelBinderProvider)
 {
     _bodyModelBinderProvider        = bodyModelBinderProvider ?? throw new ArgumentNullException(nameof(bodyModelBinderProvider));
     _complexTypeModelBinderProvider = complexTypeModelBinderProvider ?? throw new ArgumentNullException(nameof(complexTypeModelBinderProvider));
 }