我遇到了一个非常奇怪的问题。我有几个工作的Fitnesse测试,它们在数据库中插入数据,然后测试我的完整MVC应用程序堆栈。
当我尝试将2个Component属性映射添加到我的实体映射时,我收到一条错误消息“无法找到汇编'FluentNHibernate ......',这看起来有点神秘。
所有这一切都是通过Fitnesse运行的,所以这可能是Fitnesse如何加载依赖关系的问题......我不知道确切知道。我唯一知道的是这个代码运行正常,直到我添加2“组件”映射。最重要的是,当这些代码通过普通的Web应用程序运行时,这些映射运行正常(所以我知道“Component”映射和SessionFactory类在Tests项目之外工作)。
有没有人有任何想法,为什么我会收到我收到的错误消息?如果我需要发布任何其他代码,请告诉我。非常感谢任何帮助!
DLL版本:
这是我的实体:
// namespace Reporting.Domain
public class Holdings
{
public virtual int HoldingsId { get; set; }
public virtual DateTime AsOfDate { get; set; }
public virtual string Portfolio { get; set; }
// need to add these next 2 properties!
public virtual Balances PriorPeriod { get; set; }
public virtual Balances CurrentPeriod { get; set; }
}
我的映射文件:
// namespace Reporting.Infrastructure
public sealed class HoldingsMap : ClassMap<Holdings>
{
public HoldingsMap()
{
Id(x => x.HoldingsId).GeneratedBy.Identity();
Map(x => x.AsOfDate).Not.Nullable();
Map(x => x.Portfolio).Not.Nullable();
// adding these lines eventually leads to the error
Component(x=> x.PriorPeriod).ColumnPrefix("Prior");
Component(x=> x.CurrentPeriod).ColumnPrefix("Current");
}
}
我的SessionFactory(调用BuildSessionFactory时发生错误):
// namespace Reporting.Infrastructure
public class SessionFactory
{
public ISessionFactory CreateSession(Action<Configuration> configurationFunction)
{
return CreateConfiguration().ExposeConfiguration(c => {}).BuildSessionFactory();
}
private FluentConfiguration CreateConfiguration()
{
var connectionString = "...";
var msSqlConfiguration = MsSqlConfiguration.MsSql2008.ConnectionString(connectionString);
var database = Fluently.Configure().Database(msSqlConfiguration);
return database.Mappings(m => m.FluentMappings.AddFromAssemblyOf<SessionFactory>().Conventions.Add(ForeignKey.EndsWith("Id")));
}
}
我得到了这个堆栈跟踪:
__EXCEPTION__:System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> System.Runtime.Serialization.SerializationException: Unable to find assembly 'FluentNHibernate, Version=1.3.0.733, Culture=neutral, PublicKeyToken=8aa435e3cb308880'.
at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage)
at FluentNHibernate.Utils.Extensions.DeepClone[T](T obj)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at FluentNHibernate.Visitors.ComponentReferenceResolutionVisitor.ProcessComponent(ReferenceComponentMapping mapping)
at FluentNHibernate.MappingModel.ClassBased.ReferenceComponentMapping.AcceptVisitor(IMappingModelVisitor visitor)
at FluentNHibernate.MappingModel.MappedMembers.AcceptVisitor(IMappingModelVisitor visitor)
at FluentNHibernate.MappingModel.ClassBased.ClassMappingBase.AcceptVisitor(IMappingModelVisitor visitor)
at FluentNHibernate.MappingModel.HibernateMapping.AcceptVisitor(IMappingModelVisitor visitor)
at FluentNHibernate.Utils.CollectionExtensions.Each[T](IEnumerable`1 enumerable, Action`1 each)
at FluentNHibernate.PersistenceModel.ApplyVisitors(IEnumerable`1 mappings)
at FluentNHibernate.PersistenceModel.BuildMappings()
at FluentNHibernate.PersistenceModel.Configure(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at Reporting.Infrastructure.SessionFactory.CreateSession() in Reporting.Infrastructure\SessionFactory.cs:line 32
at Reporting.FitnesseTests.Database.Setup() in Reporting.FitnesseTests\Database.cs:line 23
--- End of inner exception stack trace ---
at fitSharp.Machine.Model.TypedValue.ThrowExceptionIfNotValid()
at fitSharp.Slim.Operators.ExecuteCall.ExecuteOperation(Tree`1 parameters)
at fitSharp.Slim.Operators.InvokeInstructionBase.Invoke(TypedValue instance, MemberName memberName, Tree`1 parameters)
FWIW,这就是我在Fitnesse Tests项目中使用会话工厂的方式:
// namespace Reporting.FitnesseTests
public class Database
{
public static ISession Session { get; private set; }
public static void Setup()
{
Session = new SessionFactory().CreateSession().OpenSession();
}
}
我的Fitnesse Classpath是:
!path ..\Reporting.FitnesseTests\bin\Debug\Reporting.FitnesseTests.dll
答案 0 :(得分:3)
尝试将测试所需的DLL放在与fitsharp Runner.exe相同的文件夹中。我遇到的一个问题是app.config中定义的.NET运行时依赖关系是从执行进程的目录中解析出来的,在这种情况下,可能是fitsharp所在的目录。显然有一种方法可以使用fitharp套件配置文件来改变这种行为,但我无法使其成功运行(http://fitsharp.github.com/FitSharp/SuiteConfigurationFile.html)。