GlobalFilter

Namespace: FreeSql
We found 10 examples in language CSharp for this search. You will see 48 fragments of code.
        [Fact]
        public void GuardClauses()
        {
            // Arrange
            var context = new ControllerContext();
            var descriptor = new Mock<ActionDescriptor>().Object;
            var collection = new FilterProviderCollection();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => collection.GetFilters(null, descriptor),
                "controllerContext"
                );
            Assert.ThrowsArgumentNull(
                () => collection.GetFilters(context, null),
                "actionDescriptor"
                );
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsCaches()
        {
            // Arrange
            var providers = new IFilterProvider[] 
            {
                new Mock<IFilterProvider>(MockBehavior.Strict).Object, 
                new Mock<IFilterProvider>(MockBehavior.Strict).Object
            };
            var collection = new FilterProviderCollection(providers);

            // Act
            IFilterProvider[] combined1 = collection.CombinedItems;
            IFilterProvider[] combined2 = collection.CombinedItems;

            // Assert
            Assert.Equal(providers, combined1);
            Assert.Same(combined1, combined2);
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsClearResetsCache()
        {
            TestCacheReset((collection) => collection.Clear());
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsInsertResetsCache()
        {
            TestCacheReset((collection) => collection.Insert(0, new Mock<IFilterProvider>(MockBehavior.Strict).Object));
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsRemoveResetsCache()
        {
            TestCacheReset((collection) => collection.RemoveAt(0));
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsSetResetsCache()
        {
            TestCacheReset((collection) => collection[0] = new Mock<IFilterProvider>(MockBehavior.Strict).Object);
        }

        [Fact]
        public void ActionFilters_ReturnsEmptyArray_WhenFiltersIsEmpty()
        {
            // Arrange
            IEnumerable<FilterInfo> filters = CreateEmptyFilters();
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;
            
            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(0, actionFilters.Length);
        }

        [Fact]
        public void ActionFilters_ReturnsActionFilters()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(3, actionFilters.Length);
            Assert.Same(expectedGlobalFilter, actionFilters[0]);
            Assert.Same(expectedControllerFilter, actionFilters[1]);
            Assert.Same(expectedActionFilter, actionFilters[2]);
        }

        [Fact]
        public void ActionFilters_ReturnsAllActionFilters_WhenOverrideScopeIsGlobal()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            FilterInfo overrideFilter = new FilterInfo(CreateOverride(typeof(IActionFilter)), FilterScope.Global);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter, overrideFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(3, actionFilters.Length);
            Assert.Same(expectedGlobalFilter, actionFilters[0]);
            Assert.Same(expectedControllerFilter, actionFilters[1]);
            Assert.Same(expectedActionFilter, actionFilters[2]);
        }

        [Fact]
        public void ActionFilters_ReturnsControllerAndBelowActionFilters_WhenOverrideScopeIsController()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            FilterInfo overrideFilter = new FilterInfo(CreateOverride(typeof(IActionFilter)), FilterScope.Controller);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter, overrideFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(2, actionFilters.Length);
            Assert.Same(expectedControllerFilter, actionFilters[0]);
            Assert.Same(expectedActionFilter, actionFilters[1]);
        }

        [Fact]
        public void ActionFilters_ReturnsActionScopeActionFilters_WhenOverrideScopeIsAction()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            FilterInfo overrideFilter = new FilterInfo(CreateOverride(typeof(IActionFilter)), FilterScope.Action);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter, overrideFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(1, actionFilters.Length);
            Assert.Same(expectedActionFilter, actionFilters[0]);
        }

        [Fact]
        public void ActionFilters_ReturnsAllActionFilters_WhenOtherFilterIsOverriddenAtActionLevel()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            FilterInfo overrideFilter = new FilterInfo(CreateOverride(typeof(object)), FilterScope.Action);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter, overrideFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(3, actionFilters.Length);
            Assert.Same(expectedGlobalFilter, actionFilters[0]);
            Assert.Same(expectedControllerFilter, actionFilters[1]);
            Assert.Same(expectedActionFilter, actionFilters[2]);
        }

        [Fact]
        public void GuardClauses()
        {
            // Arrange
            var context = new ControllerContext();
            var descriptor = new Mock<ActionDescriptor>().Object;
            var collection = new FilterProviderCollection();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => collection.GetFilters(null, descriptor),
                "controllerContext"
                );
            Assert.ThrowsArgumentNull(
                () => collection.GetFilters(context, null),
                "actionDescriptor"
                );
        }

        [Fact]
        public void GetFiltersUsesRegisteredProviders()
        {
            // Arrange
            var context = new ControllerContext();
            var descriptor = new Mock<ActionDescriptor>().Object;
            var filter = new Filter(new Object(), FilterScope.Action, null);
            var provider = new Mock<IFilterProvider>(MockBehavior.Strict);
            var collection = new FilterProviderCollection(new[] { provider.Object });
            provider.Setup(p => p.GetFilters(context, descriptor)).Returns(new[] { filter });

            // Act
            IEnumerable<Filter> result = collection.GetFilters(context, descriptor);

            // Assert
            Assert.Same(filter, result.Single());
        }

        [Fact]
        public void GetFiltersDelegatesToResolver()
        {
            // Arrange
            var context = new ControllerContext();
            var descriptor = new Mock<ActionDescriptor>().Object;
            var filter = new Filter(new Object(), FilterScope.Action, null);
            var provider = new Mock<IFilterProvider>(MockBehavior.Strict);
            var resolver = new Resolver<IEnumerable<IFilterProvider>> { Current = new[] { provider.Object } };
            var collection = new FilterProviderCollection(resolver);

            provider.Setup(p => p.GetFilters(context, descriptor)).Returns(new[] { filter });

            // Act
            IEnumerable<Filter> result = collection.GetFilters(context, descriptor);

            // Assert
            Assert.Same(filter, result.Single());
        }

        [Fact]
        public void GetFiltersSortsFiltersByOrderFirstThenScope()
        {
            // Arrange
            var context = new ControllerContext();
            var descriptor = new Mock<ActionDescriptor>().Object;
            var actionFilter = new Filter(new Object(), FilterScope.Action, null);
            var controllerFilter = new Filter(new Object(), FilterScope.Controller, null);
            var globalFilter = new Filter(new Object(), FilterScope.Global, null);
            var earlyActionFilter = new Filter(new Object(), FilterScope.Action, -100);
            var lateGlobalFilter = new Filter(new Object(), FilterScope.Global, 100);
            var provider = new Mock<IFilterProvider>(MockBehavior.Strict);
            var collection = new FilterProviderCollection(new[] { provider.Object });
            provider.Setup(p => p.GetFilters(context, descriptor))
                .Returns(new[] { actionFilter, controllerFilter, globalFilter, earlyActionFilter, lateGlobalFilter });

            // Act
            Filter[] result = collection.GetFilters(context, descriptor).ToArray();

            // Assert
            Assert.Equal(5, result.Length);
            Assert.Same(earlyActionFilter, result[0]);
            Assert.Same(globalFilter, result[1]);
            Assert.Same(controllerFilter, result[2]);
            Assert.Same(actionFilter, result[3]);
            Assert.Same(lateGlobalFilter, result[4]);
        }

        [Fact]
        public void GetFiltersIncludesLastFilterOnlyWithAttributeUsageAllowMultipleFalse()
        { // DDB #222988
            // Arrange
            var context = new ControllerContext();
            var descriptor = new Mock<ActionDescriptor>().Object;
            var globalFilter = new Filter(new AllowMultipleFalseAttribute(), FilterScope.Global, null);
            var controllerFilter = new Filter(new AllowMultipleFalseAttribute(), FilterScope.Controller, null);
            var actionFilter = new Filter(new AllowMultipleFalseAttribute(), FilterScope.Action, null);
            var provider = new Mock<IFilterProvider>(MockBehavior.Strict);
            var collection = new FilterProviderCollection(new[] { provider.Object });
            provider.Setup(p => p.GetFilters(context, descriptor))
                .Returns(new[] { controllerFilter, actionFilter, globalFilter });

            // Act
            IEnumerable<Filter> result = collection.GetFilters(context, descriptor);

            // Assert
            Assert.Same(actionFilter, result.Single());
        }

        [Fact]
        public void GetFiltersIncludesAllFiltersWithAttributeUsageAllowMultipleTrue()
        { // DDB #222988
            // Arrange
            var context = new ControllerContext();
            var descriptor = new Mock<ActionDescriptor>().Object;
            var globalFilter = new Filter(new AllowMultipleTrueAttribute(), FilterScope.Global, null);
            var controllerFilter = new Filter(new AllowMultipleTrueAttribute(), FilterScope.Controller, null);
            var actionFilter = new Filter(new AllowMultipleTrueAttribute(), FilterScope.Action, null);
            var provider = new Mock<IFilterProvider>(MockBehavior.Strict);
            var collection = new FilterProviderCollection(new[] { provider.Object });
            provider.Setup(p => p.GetFilters(context, descriptor))
                .Returns(new[] { controllerFilter, actionFilter, globalFilter });

            // Act
            List<Filter> result = collection.GetFilters(context, descriptor).ToList();

            // Assert
            Assert.Same(globalFilter, result[0]);
            Assert.Same(controllerFilter, result[1]);
            Assert.Same(actionFilter, result[2]);
        }

        public static void Init(IServiceCollection services, IConfiguration configuration)
        {
            Configuration = configuration;
            services.Configure<Secret>(configuration.GetSection("Secret"));
            services.Configure<Connection>(configuration.GetSection("Connection"));
            services.Configure<CreateMember>(configuration.GetSection("CreateMember"));
            services.Configure<ModifyMember>(configuration.GetSection("ModifyMember"));
            services.Configure<GlobalFilter>(configuration.GetSection("GlobalFilter"));


            var provider = services.BuildServiceProvider();
            IWebHostEnvironment environment = provider.GetRequiredService<IWebHostEnvironment>();
            CurrentPath = Path.Combine(environment.ContentRootPath, "").ReplacePath();

            Secret = provider.GetRequiredService<IOptions<Secret>>().Value;

            //设置修改或删除时需要设置为默认用户信息的字段
            CreateMember = provider.GetRequiredService<IOptions<CreateMember>>().Value ?? new CreateMember();
            ModifyMember = provider.GetRequiredService<IOptions<ModifyMember>>().Value ?? new ModifyMember();

            GlobalFilter = provider.GetRequiredService<IOptions<GlobalFilter>>().Value ?? new GlobalFilter();

            GlobalFilter.Actions = GlobalFilter.Actions ?? new string[0];

            _connection = provider.GetRequiredService<IOptions<Connection>>().Value;

    

            ExpMinutes = (configuration["ExpMinutes"] ?? "120").GetInt();

            DBType.Name = _connection.DBType;
            if (string.IsNullOrEmpty(_connection.DbConnectionString))
                throw new System.Exception("未配置好数据库默认连接");

            try
            {
                _connection.DbConnectionString = _connection.DbConnectionString.DecryptDES(Secret.DB);
            }
            catch { }

            if (!string.IsNullOrEmpty(_connection.RedisConnectionString))
            {
                try
                {
                    _connection.RedisConnectionString = _connection.RedisConnectionString.DecryptDES(Secret.Redis);
                }
                catch { }
            }

        }
        // 多个节点name格式 :["key:key1"]
        public static string GetSettingString(string key)
        {
            return Configuration[key];
        }
        // 多个节点,通过.GetSection("key")["key1"]获取
        public static IConfigurationSection GetSection(string key)
        {
            return Configuration.GetSection(key);
        }

        public static void Init(IServiceCollection services, IConfiguration configuration)
        {
            Configuration = configuration;
            services.Configure<Secret>(configuration.GetSection("Secret"));
            services.Configure<Connection>(configuration.GetSection("Connection"));
            services.Configure<CreateMember>(configuration.GetSection("CreateMember"));
            services.Configure<ModifyMember>(configuration.GetSection("ModifyMember"));
            services.Configure<GlobalFilter>(configuration.GetSection("GlobalFilter"));


            var provider = services.BuildServiceProvider();
            IWebHostEnvironment environment = provider.GetRequiredService<IWebHostEnvironment>();
            CurrentPath = Path.Combine(environment.ContentRootPath, "").ReplacePath();

            Secret = provider.GetRequiredService<IOptions<Secret>>().Value;

            //设置修改或删除时需要设置为默认用户信息的字段
            CreateMember = provider.GetRequiredService<IOptions<CreateMember>>().Value ?? new CreateMember();
            ModifyMember = provider.GetRequiredService<IOptions<ModifyMember>>().Value ?? new ModifyMember();

            GlobalFilter = provider.GetRequiredService<IOptions<GlobalFilter>>().Value ?? new GlobalFilter();

            GlobalFilter.Actions = GlobalFilter.Actions ?? new string[0];

            _connection = provider.GetRequiredService<IOptions<Connection>>().Value;

    

            ExpMinutes = (configuration["ExpMinutes"] ?? "120").GetInt();

            DBType.Name = _connection.DBType;
            if (string.IsNullOrEmpty(_connection.DbConnectionString))
                throw new System.Exception("未配置好数据库默认连接");

            try
            {
                _connection.DbConnectionString = _connection.DbConnectionString.DecryptDES(Secret.DB);
            }
            catch { }

            if (!string.IsNullOrEmpty(_connection.RedisConnectionString))
            {
                try
                {
                    _connection.RedisConnectionString = _connection.RedisConnectionString.DecryptDES(Secret.Redis);
                }
                catch { }
            }

        }
        // 多个节点name格式 :["key:key1"]
        public static string GetSettingString(string key)
        {
            return Configuration[key];
        }
        // 多个节点,通过.GetSection("key")["key1"]获取
        public static IConfigurationSection GetSection(string key)
        {
            return Configuration.GetSection(key);
        }

        [Fact]
        public void GuardClauses()
        {
            // Arrange
            var context = new ControllerContext();
            var descriptor = new Mock<ActionDescriptor>().Object;
            var collection = new FilterProviderCollection();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => collection.GetFilters(null, descriptor),
                "controllerContext"
                );
            Assert.ThrowsArgumentNull(
                () => collection.GetFilters(context, null),
                "actionDescriptor"
                );
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsCaches()
        {
            // Arrange
            var providers = new IFilterProvider[] 
            {
                new Mock<IFilterProvider>(MockBehavior.Strict).Object, 
                new Mock<IFilterProvider>(MockBehavior.Strict).Object
            };
            var collection = new FilterProviderCollection(providers);

            // Act
            IFilterProvider[] combined1 = collection.CombinedItems;
            IFilterProvider[] combined2 = collection.CombinedItems;

            // Assert
            Assert.Equal(providers, combined1);
            Assert.Same(combined1, combined2);
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsClearResetsCache()
        {
            TestCacheReset((collection) => collection.Clear());
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsInsertResetsCache()
        {
            TestCacheReset((collection) => collection.Insert(0, new Mock<IFilterProvider>(MockBehavior.Strict).Object));
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsRemoveResetsCache()
        {
            TestCacheReset((collection) => collection.RemoveAt(0));
        }

        [Fact]
        public void FilterProviderCollectionCombinedItemsSetResetsCache()
        {
            TestCacheReset((collection) => collection[0] = new Mock<IFilterProvider>(MockBehavior.Strict).Object);
        }

        public static void Init(IServiceCollection services, IConfiguration configuration)
        {
            Configuration = configuration;
            services.Configure<Secret>(configuration.GetSection("Secret"));
            services.Configure<Connection>(configuration.GetSection("Connection"));
            services.Configure<CreateMember>(configuration.GetSection("CreateMember"));
            services.Configure<ModifyMember>(configuration.GetSection("ModifyMember"));
            services.Configure<GlobalFilter>(configuration.GetSection("GlobalFilter"));


            var provider = services.BuildServiceProvider();
            IWebHostEnvironment environment = provider.GetRequiredService<IWebHostEnvironment>();
            CurrentPath = Path.Combine(environment.ContentRootPath, "").ReplacePath();

            Secret = provider.GetRequiredService<IOptions<Secret>>().Value;

            //设置修改或删除时需要设置为默认用户信息的字段
            CreateMember = provider.GetRequiredService<IOptions<CreateMember>>().Value ?? new CreateMember();
            ModifyMember = provider.GetRequiredService<IOptions<ModifyMember>>().Value ?? new ModifyMember();

            GlobalFilter = provider.GetRequiredService<IOptions<GlobalFilter>>().Value ?? new GlobalFilter();

            GlobalFilter.Actions = GlobalFilter.Actions ?? new string[0];

            _connection = provider.GetRequiredService<IOptions<Connection>>().Value;

    

            ExpMinutes = (configuration["ExpMinutes"] ?? "120").GetInt();

            DBType.Name = _connection.DBType;
            if (string.IsNullOrEmpty(_connection.DbConnectionString))
                throw new System.Exception("未配置好数据库默认连接");

            try
            {
                _connection.DbConnectionString = _connection.DbConnectionString.DecryptDES(Secret.DB);
            }
            catch { }

            if (!string.IsNullOrEmpty(_connection.RedisConnectionString))
            {
                try
                {
                    _connection.RedisConnectionString = _connection.RedisConnectionString.DecryptDES(Secret.Redis);
                }
                catch { }
            }

        }
        // 多个节点name格式 :["key:key1"]
        public static string GetSettingString(string key)
        {
            return Configuration[key];
        }
        // 多个节点,通过.GetSection("key")["key1"]获取
        public static IConfigurationSection GetSection(string key)
        {
            return Configuration.GetSection(key);
        }

        public static void Init(IServiceCollection services, IConfiguration configuration)
        {
            Configuration = configuration;
            services.Configure<Secret>(configuration.GetSection("Secret"));
            services.Configure<Connection>(configuration.GetSection("Connection"));
            services.Configure<CreateMember>(configuration.GetSection("CreateMember"));
            services.Configure<ModifyMember>(configuration.GetSection("ModifyMember"));
            services.Configure<GlobalFilter>(configuration.GetSection("GlobalFilter"));


            var provider = services.BuildServiceProvider();
            IWebHostEnvironment environment = provider.GetRequiredService<IWebHostEnvironment>();
            CurrentPath = Path.Combine(environment.ContentRootPath, "").ReplacePath();

            Secret = provider.GetRequiredService<IOptions<Secret>>().Value;

            //设置修改或删除时需要设置为默认用户信息的字段
            CreateMember = provider.GetRequiredService<IOptions<CreateMember>>().Value ?? new CreateMember();
            ModifyMember = provider.GetRequiredService<IOptions<ModifyMember>>().Value ?? new ModifyMember();

            GlobalFilter = provider.GetRequiredService<IOptions<GlobalFilter>>().Value ?? new GlobalFilter();

            GlobalFilter.Actions = GlobalFilter.Actions ?? new string[0];

            _connection = provider.GetRequiredService<IOptions<Connection>>().Value;

    

            ExpMinutes = (configuration["ExpMinutes"] ?? "120").GetInt();

            DBType.Name = _connection.DBType;
            if (string.IsNullOrEmpty(_connection.DbConnectionString))
                throw new System.Exception("未配置好数据库默认连接");

            try
            {
                _connection.DbConnectionString = _connection.DbConnectionString.DecryptDES(Secret.DB);
            }
            catch { }

            if (!string.IsNullOrEmpty(_connection.RedisConnectionString))
            {
                try
                {
                    _connection.RedisConnectionString = _connection.RedisConnectionString.DecryptDES(Secret.Redis);
                }
                catch { }
            }

        }
        // 多个节点name格式 :["key:key1"]
        public static string GetSettingString(string key)
        {
            return Configuration[key];
        }
        // 多个节点,通过.GetSection("key")["key1"]获取
        public static IConfigurationSection GetSection(string key)
        {
            return Configuration.GetSection(key);
        }

        [Fact]
        public void ActionFilters_ReturnsEmptyArray_WhenFiltersIsEmpty()
        {
            // Arrange
            IEnumerable<FilterInfo> filters = CreateEmptyFilters();
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;
            
            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(0, actionFilters.Length);
        }

        [Fact]
        public void ActionFilters_ReturnsActionFilters()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(3, actionFilters.Length);
            Assert.Same(expectedGlobalFilter, actionFilters[0]);
            Assert.Same(expectedControllerFilter, actionFilters[1]);
            Assert.Same(expectedActionFilter, actionFilters[2]);
        }

        [Fact]
        public void ActionFilters_ReturnsAllActionFilters_WhenOverrideScopeIsGlobal()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            FilterInfo overrideFilter = new FilterInfo(CreateOverride(typeof(IActionFilter)), FilterScope.Global);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter, overrideFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(3, actionFilters.Length);
            Assert.Same(expectedGlobalFilter, actionFilters[0]);
            Assert.Same(expectedControllerFilter, actionFilters[1]);
            Assert.Same(expectedActionFilter, actionFilters[2]);
        }

        [Fact]
        public void ActionFilters_ReturnsControllerAndBelowActionFilters_WhenOverrideScopeIsController()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            FilterInfo overrideFilter = new FilterInfo(CreateOverride(typeof(IActionFilter)), FilterScope.Controller);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter, overrideFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(2, actionFilters.Length);
            Assert.Same(expectedControllerFilter, actionFilters[0]);
            Assert.Same(expectedActionFilter, actionFilters[1]);
        }

        [Fact]
        public void ActionFilters_ReturnsActionScopeActionFilters_WhenOverrideScopeIsAction()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            FilterInfo overrideFilter = new FilterInfo(CreateOverride(typeof(IActionFilter)), FilterScope.Action);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter, overrideFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(1, actionFilters.Length);
            Assert.Same(expectedActionFilter, actionFilters[0]);
        }

        [Fact]
        public void ActionFilters_ReturnsAllActionFilters_WhenOtherFilterIsOverriddenAtActionLevel()
        {
            // Arrange
            IActionFilter expectedGlobalFilter = CreateDummyActionFilter();
            FilterInfo globalFilter = new FilterInfo(expectedGlobalFilter, FilterScope.Global);
            IActionFilter expectedControllerFilter = CreateDummyActionFilter();
            FilterInfo controllerFilter = new FilterInfo(expectedControllerFilter, FilterScope.Controller);
            IActionFilter expectedActionFilter = CreateDummyActionFilter();
            FilterInfo actionFilter = new FilterInfo(expectedActionFilter, FilterScope.Action);
            FilterInfo overrideFilter = new FilterInfo(CreateOverride(typeof(object)), FilterScope.Action);
            IEnumerable<FilterInfo> filters = new FilterInfo[] { globalFilter, controllerFilter, actionFilter, overrideFilter };
            FilterGrouping product = CreateProductUnderTest(filters);

            // Act
            IActionFilter[] actionFilters = product.ActionFilters;

            // Assert
            Assert.NotNull(actionFilters);
            Assert.Equal(3, actionFilters.Length);
            Assert.Same(expectedGlobalFilter, actionFilters[0]);
            Assert.Same(expectedControllerFilter, actionFilters[1]);
            Assert.Same(expectedActionFilter, actionFilters[2]);
        }


        [Fact]
        public void GetFilters_ReturnsNull_WhenJobIsNull()
        {
            var collection = new JobFilterProviderCollection();
            var filters = collection.GetFilters(null);

            Assert.Empty(filters);
        }

        [Fact]
        public void GetFiltersUsesRegisteredProviders()
        {
            // Arrange
            var filter = new JobFilter(new Object(), JobFilterScope.Method, null);
            var provider = new Mock<IJobFilterProvider>(MockBehavior.Strict);
            var collection = new JobFilterProviderCollection(provider.Object);
            provider.Setup(p => p.GetFilters(_job)).Returns(new[] { filter });

            // Act
            IEnumerable<JobFilter> result = collection.GetFilters(_job);

            // Assert
            Assert.Same(filter, result.Single());
        }

        [Fact]
        public void GetFiltersSortsFiltersByOrderFirstThenScope()
        {
            // Arrange
            var actionFilter = new JobFilter(new Object(), JobFilterScope.Method, null);
            var controllerFilter = new JobFilter(new Object(), JobFilterScope.Type, null);
            var globalFilter = new JobFilter(new Object(), JobFilterScope.Global, null);
            var earlyActionFilter = new JobFilter(new Object(), JobFilterScope.Method, -100);
            var lateGlobalFilter = new JobFilter(new Object(), JobFilterScope.Global, 100);
            var provider = new Mock<IJobFilterProvider>(MockBehavior.Strict);
            var collection = new JobFilterProviderCollection(provider.Object);
            provider.Setup(p => p.GetFilters(_job))
                .Returns(new[] { actionFilter, controllerFilter, globalFilter, earlyActionFilter, lateGlobalFilter });

            // Act
            JobFilter[] result = collection.GetFilters(_job).ToArray();

            // Assert
            Assert.Equal(5, result.Length);
            Assert.Same(earlyActionFilter, result[0]);
            Assert.Same(globalFilter, result[1]);
            Assert.Same(controllerFilter, result[2]);
            Assert.Same(actionFilter, result[3]);
            Assert.Same(lateGlobalFilter, result[4]);
        }

        [Fact]
        public void GetFiltersIncludesLastFilterOnlyWithAttributeUsageAllowMultipleFalse()
        {
            // Arrange
            var globalFilter = new JobFilter(new AllowMultipleFalseAttribute(), JobFilterScope.Global, null);
            var controllerFilter = new JobFilter(new AllowMultipleFalseAttribute(), JobFilterScope.Type, null);
            var actionFilter = new JobFilter(new AllowMultipleFalseAttribute(), JobFilterScope.Method, null);
            var provider = new Mock<IJobFilterProvider>(MockBehavior.Strict);
            var collection = new JobFilterProviderCollection(provider.Object);
            provider.Setup(p => p.GetFilters(_job))
                .Returns(new[] { controllerFilter, actionFilter, globalFilter });

            // Act
            IEnumerable<JobFilter> result = collection.GetFilters(_job);

            // Assert
            Assert.Same(actionFilter, result.Single());
        }

        [Fact]
        public void GetFiltersIncludesAllFiltersWithAttributeUsageAllowMultipleTrue()
        {
            // Arrange
            var globalFilter = new JobFilter(new AllowMultipleTrueAttribute(), JobFilterScope.Global, null);
            var controllerFilter = new JobFilter(new AllowMultipleTrueAttribute(), JobFilterScope.Type, null);
            var actionFilter = new JobFilter(new AllowMultipleTrueAttribute(), JobFilterScope.Method, null);
            var provider = new Mock<IJobFilterProvider>(MockBehavior.Strict);
            var collection = new JobFilterProviderCollection(provider.Object);
            provider.Setup(p => p.GetFilters(_job))
                .Returns(new[] { controllerFilter, actionFilter, globalFilter });

            // Act
            List<JobFilter> result = collection.GetFilters(_job).ToList();

            // Assert
            Assert.Same(globalFilter, result[0]);
            Assert.Same(controllerFilter, result[1]);
            Assert.Same(actionFilter, result[2]);
        }

        [Fact]
        public void GetFiltersIncludesLastFilterOnlyWithCustomFilterAllowMultipleFalse()
        {
            // Arrange
            var globalFilter = new JobFilter(new AllowMultipleCustomFilter(false), JobFilterScope.Global, null);
            var controllerFilter = new JobFilter(new AllowMultipleCustomFilter(false), JobFilterScope.Type, null);
            var actionFilter = new JobFilter(new AllowMultipleCustomFilter(false), JobFilterScope.Method, null);
            var provider = new Mock<IJobFilterProvider>(MockBehavior.Strict);
            var collection = new JobFilterProviderCollection(provider.Object);
            provider.Setup(p => p.GetFilters(_job))
                .Returns(new[] { controllerFilter, actionFilter, globalFilter });

            // Act
            IEnumerable<JobFilter> result = collection.GetFilters(_job);

            // Assert
            Assert.Same(actionFilter, result.Single());
        }

FreeSql.Internal.GlobalFilter : Object

Constructors :

public GlobalFilter()

Methods :

public GlobalFilter Apply(String name = , Expression<Func<TEntity, Boolean>> where = )
public GlobalFilter ApplyIf(String name = , Func<Boolean> condition = , Expression<Func<TEntity, Boolean>> where = )
public GlobalFilter ApplyOnly(String name = , Expression<Func<TEntity, Boolean>> where = )
public GlobalFilter ApplyOnlyIf(String name = , Func<Boolean> condition = , Expression<Func<TEntity, Boolean>> where = )
public Void Remove(String name = )
public List<Item> GetFilters()
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()