Exemplo n.º 1
0
    public async Task BindModel_ReturnsFailedResult_EvenIfSelectedBinderReturnsNull()
    {
        // Arrange
        var bindingContext = GetBindingContext(typeof(Person), binderType: typeof(NullModelBinder));

        var binder = new BinderTypeModelBinder(typeof(NullModelBinder));

        // Act
        await binder.BindModelAsync(bindingContext);

        // Assert
        Assert.False(bindingContext.Result.IsModelSet);
    }
Exemplo n.º 2
0
    public async Task BindModel_CallsBindAsync_OnProvidedModelBinder()
    {
        // Arrange
        var bindingContext = GetBindingContext(typeof(Person), binderType: typeof(NotNullModelBinder));

        var model           = new Person();
        var serviceProvider = new ServiceCollection()
                              .AddSingleton <IModelBinder, NullModelBinder>()
                              .BuildServiceProvider();

        bindingContext.HttpContext.RequestServices = serviceProvider;

        var binder = new BinderTypeModelBinder(typeof(NotNullModelBinder));

        // Act
        await binder.BindModelAsync(bindingContext);

        // Assert
        var person = (Person)bindingContext.Result.Model;

        Assert.Equal(model.Age, person.Age);
        Assert.Equal(model.Name, person.Name);
    }