简体   繁体   English

为计算值的实体框架6努力进行单元测试

[英]unit testing with effort for entity framework 6 with computed values

Using effort EF6 with code first does not populate computed values. 使用EF6首先使用代码不会填充计算值。 I have a datetime field (FechaCreacion) that is computed. 我有一个计算的日期时间字段(FechaCreacion)。 How can I emulate it in Effort, so It is populated with DateTime.Now after savingChanges() ? 我怎样才能在Effort中模拟它,所以在saveChanges()之后用DateTime.Now填充它?

This post Using Effort (EF Testing Tool) with Computed Column is DB First instead of Code First as my example, but seems unanswered too. 这篇文章使用Effort(EF测试工具)和计算列是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);
}

This value is computed in SQLServer as GetDate() 此值在SQLServer中计算为GetDate()

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

In sql server works well, but when using Effort in unit testing, the field gets empty date value. 在sql server中运行良好,但在单元测试中使用Effort时,该字段获取空日期值。

在此输入图像描述

This would seem like an issue with Effort. 这似乎是Effort的一个问题。 I have opened an issue on their github site: https://github.com/tamasflamich/effort/issues/62 我在他们的github网站上打开了一个问题: https//github.com/tamasflamich/effort/issues/62

This issue is fixed with the latest update. 此问题已通过最新更新修复。

You have to set the global EntityFrameworkEffortManager.UseDefaultForNotNullable flag as true. 您必须将全局EntityFrameworkEffortManager.UseDefaultForNotNullable标志设置为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM