对于使用 SQL CE4 的数据库,我正在尝试使用 xunit 和 TestDriven.Net 进行测试。这是实体定义:
public class Product
{
private readonly ICollection<Inventory> inventories = new List<Inventory>();
private int id;
public virtual int Id { get; set; }
//public virtual string ProductName { get; set; }
public virtual ICollection<Inventory> Inventories
{
get { return inventories; }
}
}
public class ProductConfiguration : EntityTypeConfiguration<Product>
{
public ProductConfiguration()
{
HasKey(p => p.Id); //Id column of the product is an Identity column
Property(p => p.Id);
}
}
这是测试方法:
[Fact]
public void WhenProductAddedItShouldPersist()
{
var product= ObjectMother.Single<Product>();
productRepository.Add(product);
unitOfWork.Commit();
Assert.NotNull(productRepository.One(product.Id));
}
XUnit 通过该方法,而 TestDriven 失败并显示消息 - 'System.NotSupportedException : Default values not supported'。
令人惊讶的是 - 如果我向实体添加另一个属性(例如 ProductName),TestDriven 也会通过。谁能给我一些线索为什么会这样?