在ASP.NET Boilerplate中使用测试框架“工作量”的问题

时间:2018-09-20 00:02:00

标签: entity-framework aspnetboilerplate asp.net-boilerplate effort

在ABP项目中使用Effort的测试遇到问题。

据我了解,我的问题出在EntityFramework.DynamicFilters上,GitHub上有一个issue在谈论这个问题。但是似乎确实有一种对我有效的解决方法。

运行测试时,所有使用DynamicFilters的操作均不起作用。 (其他测试确实可以正常工作。)

是否有解决此问题的方法?如果是,我需要安装哪个版本?

我想在测试中继续使用DynamicFilters,因为这是我的业务逻辑的一部分。

我正在使用以下版本:

  • ABP 3.8.2(ASP.NET MVC 5.x模板)
  • 工作量1.3.9(也已通过 1.3.0和1.3.3)
  • NMemory 2.0.3(也已通过1.1.2测试)

非常感谢您的帮助!


这是错误日志:

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.

这些是我正在使用的过滤器:

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>());

0 个答案:

没有答案