使用Entity Framework 6进行带有计算值的单元测试工作量

3
使用 EF6 的 Code First 无法填充计算值。我有一个日期时间字段 (FechaCreacion) 是计算的。如何在 Effort 中模拟它,以便在保存更改后用 DateTime.Now 填充它?这篇文章 Using Effort (EF Testing Tool) with Computed Column 是 DB First 而不是 Code First,但似乎也没有得到答案。
EffortConnection connection = (EffortConnection)DbConnectionFactory.CreateTransient();

using (var c = new ControlConfigContext(connection))
{
    c.Database.CreateIfNotExists();

    CambioRepositoryTestLoadData.Load(c);

    string direccionMac = "FFFF";
    var repo = new CambioRepository(c);
    var primerConcesionarioTerminal = repo.GetPrimerConcesionarioTerminal(direccionMac);


    Assert.AreEqual("terminal1", primerConcesionarioTerminal.Terminal);
}

这个值在SQLServer中是通过GetDate()计算得出的。

this.Property(t => t.FechaCreacion).HasColumnName("FechaCreacion").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);

在SQL Server中运行良好,但在使用Effort进行单元测试时,该字段会获得空日期值。

enter image description here

2个回答

0

0

最新的更新已经修复了这个问题。

您需要将全局EntityFrameworkEffortManager.UseDefaultForNotNullable标志设置为true。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接