3

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.NotSupportedException : 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?

1
  • Maybe this not an answer for your question but there is another approach to TDD your work, without using EF or even DB using Dev Magic Fake devmagicfake.codeplex.com Commented Sep 6, 2011 at 11:25

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.