/// <summary>
        ///
        /// </summary>
        /// <typeparam name="TFilter"></typeparam>
        /// <param name="options"></param>
        /// <param name="descriptAction"></param>
        /// <returns></returns>
        public static DataFilterOptions Configure <TFilter>(this DataFilterOptions options, Action <DataFilterDescriptor <TFilter> > descriptAction) where TFilter : class
        {
            var descriptor = options.Filter <TFilter>();

            descriptAction(descriptor);
            return(options);
        }
Beispiel #2
0
        public void CtorEnable()
        {
            var mock    = new Moq.Mock <IServiceProvider>();
            var options = new DataFilterOptions();

            options.Configure <ISoftDelete>(d => d.Expression(t => t.IsDeleted == false));
            var descriptor = options.Filter <ISoftDelete>();

            mock.Setup(s => s.GetService(Moq.It.IsAny <Type>())).Returns(new DataFilter <ISoftDelete>(new OptionsWrapper <DataFilterOptions>(options)));
            var filter        = new DataFilter(mock.Object);
            var filterContext = new FakeFilterContext();

            descriptor.BuildFilterExpression <SoftDeleteEntity>(filter, filterContext).Compile()(new SoftDeleteEntity(true)).ShouldBeFalse();
            descriptor.BuildFilterExpression <SoftDeleteEntity>(filter, filterContext).Compile()(new SoftDeleteEntity(false)).ShouldBeTrue();
            using (filter.Disable <ISoftDelete>())
            {
                descriptor.BuildFilterExpression <SoftDeleteEntity>(filter, filterContext).Compile()(new SoftDeleteEntity(true)).ShouldBeTrue();
                descriptor.BuildFilterExpression <SoftDeleteEntity>(filter, filterContext).Compile()(new SoftDeleteEntity(false)).ShouldBeTrue();
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TFilter"></typeparam>
 /// <param name="options"></param>
 /// <returns></returns>
 public static DataFilterDescriptor <TFilter> Filter <TFilter>(this DataFilterOptions options) where TFilter : class
 {
     return(options.Descriptors.GetOrAdd(typeof(TFilter), t => new DataFilterDescriptor <TFilter>()) as DataFilterDescriptor <TFilter>);
 }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TFilter"></typeparam>
 /// <param name="options"></param>
 /// <returns></returns>
 internal static IDataFilterDescriptor <TFilter> Filter <TFilter>(this DataFilterOptions options) where TFilter : class => options.Descriptors.GetOrAdd(typeof(TFilter), t => new DataFilterDescriptor <TFilter>()) as DataFilterDescriptor <TFilter>;