I'm having a problems in my tests using Effort in an ABP project.
As far as I understand, my problem is with the EntityFramework.DynamicFilters and there's a issue in GitHub talking about this. But there does seem to be a work-around that works for me.
When I run my tests all the operations that use DynamicFilters do not work. (Other Tests do work as expected.)
Is there is a solution for this problem? If so, which version(s) do I need to install?
I'd like to keep using DynamicFilters in my tests because is part of my business logic.
I'm using the following versions:
- ABP 3.8.2 (template ASP.NET MVC 5.x)
- Effort 1.3.9 (also tested with 1.3.0 and 1.3.3)
- NMemory 2.0.3 (also tested with 1.1.2)
Thanks a lot for any help!
This is the error log:
Result StackTrace: in EntityFramework.DynamicFilters.DynamicFilterExtensions.SetParameterList(IEnumerable paramValueCollection, DbParameter param, DbCommand command, DbContext context) in EntityFramework.DynamicFilters.DynamicFilterExtensions.SetSqlParameters(DbContext context, DbCommand command) in EntityFramework.DynamicFilters.DynamicFilterCommandInterceptor.SetDynamicFilterParameterValues(DbCommand command, DbContext context) in EntityFramework.DynamicFilters.DynamicFilterCommandInterceptor.ReaderExecuting(DbCommand command, DbCommandInterceptionContext`1 interceptionContext) in System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.b__d(IDbCommandInterceptor i, DbCommand t, DbCommandInterceptionContext`1 c) in System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) in System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) in System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) in System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) in System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) in System.Data.Entity.Core.Objects.ObjectQuery`1.c__DisplayClass7.b__6() in System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) in System.Data.Entity.Core.Objects.ObjectQuery`1.c__DisplayClass7.b__5() in System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation) in System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) in System.Data.Entity.Core.Objects.ObjectQuery`1..GetEnumerator>b__0() in System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() in System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) in System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.b__1[TResult](IEnumerable`1 sequence) in System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot) in System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression) in System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression) in System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate) in Abp.Domain.Repositories.AbpRepositoryBase`2.FirstOrDefault(TPrimaryKey id) en D:\Github\aspnetboilerplate\src\Abp\Domain\Repositories\AbpRepositoryBase.cs:línea 107 in Castle.Proxies.KpiRepositoryProxy.FirstOrDefault_callback(Int32 id) in Castle.Proxies.Invocations.AbpRepositoryBase`2_FirstOrDefault.InvokeMethodOnTarget() in Castle.DynamicProxy.AbstractInvocation.Proceed() in Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) en D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:línea 67 in Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) en D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:línea 59 in Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) en D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:línea 49 in Castle.DynamicProxy.AbstractInvocation.Proceed() in Castle.Proxies.KpiRepositoryProxy.FirstOrDefault(Int32 id) in Abp.Domain.Repositories.AbpRepositoryBase`2.Get(TPrimaryKey id) en D:\Github\aspnetboilerplate\src\Abp\Domain\Repositories\AbpRepositoryBase.cs:línea 75 in Castle.Proxies.KpiRepositoryProxy.Get_callback(Int32 id) in Castle.Proxies.Invocations.AbpRepositoryBase`2_Get.InvokeMethodOnTarget() in Castle.DynamicProxy.AbstractInvocation.Proceed() in Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) en D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:línea 67 in Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) en D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:línea 59 in Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) en D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:línea 49 in Castle.DynamicProxy.AbstractInvocation.Proceed() in Castle.Proxies.KpiRepositoryProxy.Get(Int32 id) in MyCompany.Student.Services.KpiOwnerAppService.UpdateRootKpi(UpdateRootKpiInput input) en C:\Users\gzanoletti\source\repos\MyCompany\Student\Services\KpiOwnerAppService.cs:línea 261 in Castle.Proxies.KpiOwnerAppServiceProxy.UpdateRootKpi_callback(UpdateRootKpiInput input) in Castle.Proxies.Invocations.IKpiOwnerAppService_UpdateRootKpi.InvokeMethodOnTarget() in Castle.DynamicProxy.AbstractInvocation.Proceed() in Abp.Authorization.AuthorizationInterceptor.Intercept(IInvocation invocation) en D:\Github\aspnetboilerplate\src\Abp\Authorization\AuthorizationInterceptor.cs:línea 20 in Castle.DynamicProxy.AbstractInvocation.Proceed() in Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) en D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:línea 67 in Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) en D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:línea 59 in Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) en D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:línea 49 in Castle.DynamicProxy.AbstractInvocation.Proceed() in Abp.Auditing.AuditingInterceptor.PerformSyncAuditing(IInvocation invocation, AuditInfo auditInfo) en D:\Github\aspnetboilerplate\src\Abp\Auditing\AuditingInterceptor.cs:línea 56 in Abp.Auditing.AuditingInterceptor.Intercept(IInvocation invocation) en D:\Github\aspnetboilerplate\src\Abp\Auditing\AuditingInterceptor.cs:línea 41 in Castle.DynamicProxy.AbstractInvocation.Proceed() in Abp.Runtime.Validation.Interception.ValidationInterceptor.Intercept(IInvocation invocation) en D:\Github\aspnetboilerplate\src\Abp\Runtime\Validation\Interception\ValidationInterceptor.cs:línea 33 in Castle.DynamicProxy.AbstractInvocation.Proceed() in Castle.Proxies.KpiOwnerAppServiceProxy.UpdateRootKpi(UpdateRootKpiInput input) in MyCompany.Student.KpiOwnerAppService_Test.Update_Kpi_Trend_Test() en C:\Users\gzanoletti\source\repos\MyCompany\Tests\MyCompany.Tests\Student\KpiOwnerAppService_Test.cs:línea 71 Result Message: System.NullReferenceException : Object reference not set to an instance of an object.
These are the filters I'm using:
modelBuilder.Filter(GlobalDataFilters.OwnerFilter, (IOwner obj, int ownerId) => (obj.OwnerId == ownerId), 0);
modelBuilder.Filter(GlobalDataFilters.ListOfOwnerFilter, (IOwner obj, List<int> ownerIds) => ownerIds.Contains(obj.OwnerId), new List<int>());
modelBuilder.Filter(
GlobalDataFilters.DateRangeFilter,
(IDateRange obj, DateTime startDate, DateTime endDate) => (startDate <= obj.EndDate && endDate >= obj.StartDate),
new DateTime(Clock.Now.Year, 1, 1), new DateTime(Clock.Now.Year, 12, 31));
modelBuilder.Filter(GlobalDataFilters.OwnersFilter, (IOwners obj, List<int> ownerIds) => obj.Owners.Any(o => ownerIds.Contains(o.Id)), new List<int>());
modelBuilder.Filter(GlobalDataFilters.ListOfProvidersFilter, (IProvider obj, List<int> providerIds) => obj.ProviderId.HasValue && providerIds.Contains(obj.ProviderId.Value), new List<int>());
modelBuilder.Filter(
GlobalDataFilters.HasCreationTimeFilter,
(IHasCreationTime obj, DateTime startDate, DateTime endDate) => (startDate <= obj.CreationTime && obj.CreationTime <= endDate),
new DateTime(Clock.Now.Year, 1, 1),
new DateTime(Clock.Now.Year, 12, 31),
dynamicFilterConfig => dynamicFilterConfig.SelectEntityTypeCondition(type => typeof(MyClass1).IsAssignableFrom(type)));
modelBuilder.Filter(GlobalDataFilters.LeaderFilter, (ILeader obj, int leaderId) => (obj.LeaderId == leaderId), 0);
modelBuilder.Filter(GlobalDataFilters.ListOfLeadersFilter, (ILeader obj, List<int> leaderIds) => leaderIds.Contains(obj.LeaderId), new List<int>());