File: ModelBinding\ValueProviderFactoryExtensionsTest.cs
Web Access
Project: src\src\Mvc\Mvc.Core\test\Microsoft.AspNetCore.Mvc.Core.Test.csproj (Microsoft.AspNetCore.Mvc.Core.Test)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
namespace Microsoft.AspNetCore.Mvc.ModelBinding;
 
public class ValueProviderFactoryExtensionsTest
{
    [Fact]
    public void RemoveType_RemovesAllOfType()
    {
        // Arrange
        var list = new List<IValueProviderFactory>
            {
                new FooValueProviderFactory(),
                new BarValueProviderFactory(),
                new FooValueProviderFactory()
            };
 
        // Act
        list.RemoveType(typeof(FooValueProviderFactory));
 
        // Assert
        var factory = Assert.Single(list);
        Assert.IsType<BarValueProviderFactory>(factory);
    }
 
    [Fact]
    public void GenericRemoveType_RemovesAllOfType()
    {
        // Arrange
        var list = new List<IValueProviderFactory>
            {
                new FooValueProviderFactory(),
                new BarValueProviderFactory(),
                new FooValueProviderFactory()
            };
 
        // Act
        list.RemoveType<FooValueProviderFactory>();
 
        // Assert
        var factory = Assert.Single(list);
        Assert.IsType<BarValueProviderFactory>(factory);
    }
 
    private class FooValueProviderFactory : IValueProviderFactory
    {
        public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
        {
            throw new NotImplementedException();
        }
    }
 
    private class BarValueProviderFactory : IValueProviderFactory
    {
        public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
        {
            throw new NotImplementedException();
        }
    }
}