我将映射测试更改为使用重载.VerifyTheMappings(TEntity first)
,突然我的测试就通过了。我以前没有使用过这种过载,而且由于我不确定它是如何工作的,所以我担心我会误报。
我很惊讶主要是因为我认为我没有使用自动映射,而且我什至还没有映射整个实体。所以现在我想知道:
这个测试通过是因为它应该通过,还是因为它没有真正测试任何东西?
更新:经过进一步调查,我发现只要映射 ID,一切正常。这是应该的吗?.VerifyTheMappings(TEntity first)
真正测试什么?
我的代码:
配置
Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.DefaultSchema("dbo")
.ConnectionString(ConfigurationManager.ConnectionStrings["Nitro_Empty"].ConnectionString))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>());
实体:
public class InspectionObject : IEntity<int>
{
public virtual int ID { get; set; }
public virtual Project Project { get; set; }
public virtual InspectionObjectType Type { get; set; }
public virtual User CreatedByUser { get; set; }
public virtual DateTime Created { get; set; }
public virtual DateTime LastUpdated { get; set; }
public virtual User LastUpdatedByUser { get; set; }
public virtual string Littera { get; set; }
public virtual string Owner { get; set; }
public virtual string Address { get; set; }
public virtual string Caretaker { get; set; }
public virtual string Remarks { get; set; }
public virtual float PlacementX { get; set; }
public virtual float PlacementY { get; set; }
public virtual float PlacementZ { get; set; }
}
地图:
public class InspectionObjectMap : ClassMap<InspectionObject>
{
public InspectionObjectMap()
{
Id(i => i.ID).Not.Nullable();
}
}
考试:
[Test]
public void IspectionObject_MappingsAreOK()
{
var dtenow = DateTime.Now;
dtenow = new DateTime(dtenow.Ticks - (dtenow.Ticks % TimeSpan.TicksPerSecond), dtenow.Kind);
var io = new InspectionObject
{
ID = 1,
Project = Data.Project,
Type = Data.InspectionObjectTypeVilla,
CreatedByUser = Data.Consultant,
Created = dtenow,
LastUpdatedByUser = Data.UserConsultant1,
LastUpdated = dtenow.AddHours(1),
Littera = "15",
Owner = "Fastighetsägare",
Address = "Adress",
Caretaker = "Fastighetsskötare",
Remarks = "Anteckningar",
PlacementX = 1F,
PlacementY = 2F,
PlacementZ = 3F
};
var session = IoC.Resolve<ISession>();
new PersistenceSpecification<InspectionObject>.VerifyTheMappings(io);
}
(是的,我的SetUp
和TearDown
例程中也有一些导出/删除模式,但这都是标准的。它只是有点太深地嵌套在围绕这个应用程序构建的测试框架中,我不想挖掘相关的部分,因为它是不做任何花哨的事情,只是在花哨的地方......)