用 NUnit 和 FluentAssertion 运行一个简单的测试我有这个失败的消息:
Expected object to be
Gedi.Domain.Object.Entity.Persona
{
Annullato = False
Descrizione = "Persona1"
Id = 1
}, but found
Gedi.Domain.Object.Entity.Persona
{
Annullato = False
Descrizione = "Persona1"
Id = 1
}.
但我没有看到差异。这可能是失败的原因?
这是测试方法
public void CanSaveAndLoadDocumento()
{
//Arrange
Documento documentoTarget = new Documento();
Documento documentoActual;
documentoTarget.Id = fixture.Create<int>();
// Act
using (IUnitOfWork uow = new UnitOfWork())
{
uow.Start();
documentoTarget.Persona = uow.ServiceRepositoryFor<Persona>().GetById(1);
uow.DocumentoRepository.Create(documentoTarget);
uow.Commit();
uow.CloseConnection();
uow.Start();
documentoActual = uow.DocumentoRepository.GetById(documentoTarget.Id);
uow.CloseConnection();
}
//Assert
documentoActual.Persona.Should().Be(documentoTarget.Persona);
}
ID = 1 的角色是我直接在数据库中手写的
这是我与 NHibernate 一起使用的基础存储库
public abstract class RepositoryBase<TEntity, TKey> : IDisposable
where TEntity : class, IKeyedEntity<TKey>
where TKey : struct
{
protected ISession _session;
public RepositoryBase(ISession session)
{
_session = session;
}
public void Create(TEntity entity)
{
_session.SaveOrUpdate(entity);
}
public TEntity GetById(TKey id)
{
return _session.Get<TEntity>(id);
}
}
public class DocumentoRepository : RepositoryBase<Documento, int>
{
public DocumentoRepository(ISession session)
: base(session)
{
}
}