在 R# 中运行单元测试时出现以下错误,但测试在 Visual Studio MSTest 中按预期通过,任何涉及实体框架的东西都会发生这种情况,其他测试工作没有问题,我认为这是因为dll 未部署,但确保所有 dll 都标记为 deploy local = true,还确保关闭分析,因为我读到这可能会导致 R# 出现问题,异常很奇怪,真的找不到关于为什么会发生这种情况的任何押韵或原因。代码执行也没有问题,所以它真的告诉我 R# 或我的配置有问题。不幸的是,我在 R# 中尝试了 MSTest 屏幕中的所有内容,但没有成功,即使使用“使用 MSTests.exe 运行测试(不推荐)”,但所有测试仍然失败,但仅当他们处理实体框架时。否则他们将毫无问题地工作。这发生在其他同事的系统中,所以它不仅仅是我的系统。
测试方法 Calamos.Ccs.Research.Repository.Test.DatabaseContext.EntityFrameworkContexts.ResearchContext
Test.TestFactorPeriod 抛出异常:System.InvalidOperationException:类型“Calamos.Ccs.Research.Business.Oltp.Geographic.Exchange”的属性“CountryId”上的 ForeignKeyAttribute 无效。在依赖类型“Calamos.Ccs.Research.Business.Oltp.Geographic.Exchange”上找不到导航属性“国家/地区”。Name 值应该是有效的导航属性名称。在 System.Data.Entity.ModelConfiguration.Conventions.ForeignKeyPrimitivePropertyAttributeConvention.ForeignKeyAttributeConventionImpl.ApplyNavigationProperty(PropertyInfo propertyInfo, ModelConfiguration modelConfiguration, ForeignKeyAttribute foreignKeyAttribute) 在 System.Data.Entity.ModelConfiguration.Conventions.ForeignKeyPrimitivePropertyAttributeConvention.ForeignKeyAttributeConventionImpl.Apply(PropertyInfo propertyInfo,3.System.Data.Entity.ModelConfiguration.Conventions.IConfigurationConvention<TMemberInfo,TConfiguration>.Apply(TMemberInfo memberInfo, Func
1 配置)在 System.Data.Entity.ModelConfiguration.Conventions.ForeignKeyPrimitivePropertyAttributeConvention.System.Data.Entity.ModelConfiguration.Conventions.IConfigurationConvention.Apply(PropertyInfo memberInfo, Func 1 configuration)
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ApplyPropertyConfiguration(PropertyInfo propertyInfo, ModelConfiguration modelConfiguration)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapStructuralElements(Type type, ICollection
1 annotations, Action 1structureTypeConfiguration 2 propertyMappingAction, Boolean mapDeclaredPropertiesOnly, Func
) 在 System.Data.Entity.ModelConfiguration。 Mappers.TypeMapper.MapEntityType(Type type) 在 System.Data.Entity.ModelConfiguration.Mappers.NavigationPropertyMapper.Map(PropertyInfo propertyInfo, EdmEntityType entityType, Func 1 entityTypeConfiguration, Type sourceType)
at System.Data.Entity.ModelConfiguration.Mappers.PropertyMapper.Map(PropertyInfo propertyInfo, EdmEntityType entityType, Func
1 entityTypeConfiguration, Type sourceType) 在 System.Data.Entity.ModelConfiguration.Mappers.TypeMapper。 <>c_ DisplayClass12.b _e(PropertyMapper m,PropertyInfo p)在 System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapStructuralElements(类型类型,ICollection1 annotations, Action
2 propertyMappingAction, Boolean mapDeclaredPropertiesOnly, Func 1 structuralTypeConfiguration)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type)
at System.Data.Entity.ModelConfiguration.Mappers.NavigationPropertyMapper.Map(PropertyInfo propertyInfo, EdmEntityType entityType, Func
1 entityTypeConfiguration, Type sourceType) 在 System.Data.Entity.ModelConfiguration.Mappers.PropertyMapper.Map(PropertyInfo propertyInfo, EdmEntityType entityType, Func 1 entityTypeConfiguration, Type sourceType)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.<>c__DisplayClass12.<MapEntityType>b__e(PropertyMapper m, PropertyInfo p)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapStructuralElements(Type type, ICollection
1 annotations, Action 1structureTypeConfiguration 2 propertyMappingAction, Boolean mapDeclaredPropertiesOnly, Func
) 在 System.Data.Entity.ModelConfiguration .Mappers.TypeMapper.MapEntityType(Type type) 在 System.Data.Entity.ModelConfiguration.Mappers.NavigationPropertyMapper.Map(PropertyInfo propertyInfo, EdmEntityType entityType, Func 1 entityTypeConfiguration, Type sourceType)
at System.Data.Entity.ModelConfiguration.Mappers.PropertyMapper.Map(PropertyInfo propertyInfo, EdmEntityType entityType, Func
1 entityTypeConfiguration, Type sourceType) 在 System.Data.Entity.ModelConfiguration.Mappers.TypeMapper .<>c_ DisplayClass12.bSystem.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapStructuralElements(类型类型,ICollection 1 annotations, Action
2 propertyMappingAction,布尔 mapDeclaredPropertiesOnly,Func 1 structuralTypeConfiguration)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type)
at System.Data.Entity.DbModelBuilder.<>c__DisplayClass7.<MapTypes>b__1(Type type)
at System.Linq.Enumerable.WhereListIterator
1.MoveNext() 在 System.Data.Entity.ModelConfiguration.Utilities 处的 _e(PropertyMapper m,PropertyInfo p)。 IEnumerableExtensions.Each(IEnumerable 1 ts, Action
1 action) at System.Data.Entity.DbModelBuilder.MapTypes(EdmModel model) at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) at System.Data.Entity.DbModelBuilder.Build( DbConnection providerConnection) 在 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) 在 System.Data.Entity.Internal.RetryLazy 2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet
1.Initialize() 在 System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery
1.System.Linq.IQueryable.get_Provider() 在 System.Linq.Queryable.FirstOrDefault(IQueryable 1 source, Expression
1 谓词) 在 Calamos.Ccs.Research.Repository.Test.DatabaseContext.EntityFrameworkContexts.ResearchContextTest.TestFactorPeriod() 在 ResearchContextTest.cs: 行290