3

对于使用 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 也会通过。谁能给我一些线索为什么会这样?

4

1 回答 1

4

我遇到了同样的错误,在搜索时我发现了这个:http ://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/583c7839-22a4-460e-8665-3e5e3998a0d5

看起来这是一个已知的错误。

于 2012-02-04T02:51:18.480 回答