Example #1
0
        public void Add_WithTypeName_RegistersTypesAndDerivedType_ToBeExcluded(Type type)
        {
            // Arrange
            var options = new MvcOptions();

            options.ValidationExcludeFilters.Add(type.FullName);
            var optionsAccessor = new Mock <IOptions <MvcOptions> >();

            optionsAccessor.SetupGet(o => o.Options)
            .Returns(options);
            var typeActivatorCache = new Mock <ITypeActivatorCache>();
            var service            = Mock.Of <ITestService>();
            var serviceProvider    = new Mock <IServiceProvider>();

            serviceProvider.Setup(p => p.GetService(typeof(ITestService)))
            .Returns(service);
            var provider = new DefaultValidationExcludeFiltersProvider(optionsAccessor.Object,
                                                                       typeActivatorCache.Object,
                                                                       serviceProvider.Object);

            // Act
            var filters = provider.ExcludeFilters;

            // Assert
            Assert.Equal(1, filters.Count);
            Assert.True(filters[0].IsTypeExcluded(type));
        }
        public void Add_WithTypeName_RegisterDerivedType_BaseAndUnrealatedTypesAreNotExcluded(Type type)
        {
            // Arrange
            var options = new MvcOptions();

            options.ValidationExcludeFilters.Add(typeof(DerivedType).FullName);
            var optionsAccessor = new Mock <IOptions <MvcOptions> >();

            optionsAccessor.SetupGet(o => o.Options)
            .Returns(options);
            var activator       = new TypeActivator();
            var serviceProvider = new Mock <IServiceProvider>();
            var provider        = new DefaultValidationExcludeFiltersProvider(optionsAccessor.Object,
                                                                              activator,
                                                                              serviceProvider.Object);

            // Act
            var filters = provider.ExcludeFilters;

            // Assert
            Assert.Equal(1, filters.Count);
            Assert.False(filters[0].IsTypeExcluded(type));
        }