I am attempting to get a handle on Unit testing a very simple ASP.NET MVC test app I\'ve built using the Code First approach in the latest EF4 CTP. I\'m not very experience
You probably getting an error
AutoFixture was unable to create an instance from System.Data.Entity.DbSet`1[...], most likely because it has no public constructor, is an abstract or non-public type.
The DbSet has a protected constructor.
The approach usually taken to support testability create your own implementation of the Db Set
public class MyDbSet : IDbSet where T : class
{
Use this as
public class MyContext : DbContext
{
public virtual MyDbSet Prices { get; set; }
}
If you look at the below SO question, 2ns answer, you should be able to find the complete implementation of a custom DbSet.
Unit testing with EF4 "Code First" and Repository
Then the
var priceService = fixture.Create();
Should not throw an exception.