I am trying both xunit and TestDriven.Net for testing, for database using SQL CE4. Here is the entity definition:
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);
}
}
And here is the test method:
[Fact]
public void WhenProductAddedItShouldPersist()
{
var product= ObjectMother.Single<Product>();
productRepository.Add(product);
unitOfWork.Commit();
Assert.NotNull(productRepository.One(product.Id));
}
XUnit passes the method while TestDriven fails with the message - 'System.NotSupportedExce开发者_JS百科ption : Default values not supported'.
Surprisingly- if I add another property to the entity (e.g. ProductName), TestDriven also pass. Could anyone give me some clue why this is happening?
I'm getting the same error and while searching I found this: http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/583c7839-22a4-460e-8665-3e5e3998a0d5
Looks like it's a known bug.
精彩评论