Example #1
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();
            }
        }
Example #2
0
        public void Test()
        {
            DataFilter.IsEnabled <ISoftDelete>().ShouldBeFalse();
            var filterContext = new FakeFilterContext();

            DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(true)).ShouldBeTrue();
            DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(false)).ShouldBeTrue();
            using (DataFilter.Enable <ISoftDelete>())
            {
                DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(true)).ShouldBeFalse();
                DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(false)).ShouldBeTrue();
                using (DataFilter.Disable <ISoftDelete>())
                {
                    DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(true)).ShouldBeTrue();
                    DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(false)).ShouldBeTrue();
                }
                DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(true)).ShouldBeFalse();
                DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(false)).ShouldBeTrue();
            }
            DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(true)).ShouldBeTrue();
            DataFilterDescriptor.BuildFilterExpression <SoftDeleteEntity>(DataFilter, filterContext).Compile()(new SoftDeleteEntity(false)).ShouldBeTrue();
        }