I am trying to build some unit tests for a few web service calls in my project. I am using Entity Framework 6.1.3 in my project to retrieve the data at the service layer (with a code-first approach). I did some research on how to Mock a DatabaseContext object and I found out that Effort can do this.
I followed the documentation when implementing Effort in my unit tests but when I try to seed data to my entities I get a "System.InvalidOperationException: 'Sequence contains no matching element'" exception. I am not entirely sure why this is happening. Any help will be much appreciated. Thanks!
Here is how the code looks like....
//THE CALLER -- Doing what Effort suggests to do.
var dbConnection = DbConnectionFactory.CreateTransient();
FakeDbContext = new FakeDbContext(dbConnection);
DatabaseSeed.AddTestData(FakeDbContext);
Here is where I seed data to the entities...
public static void AddTestData(IFakeDbContext context)
{
//**************** IT CRASHES HERE *********************
context.FakeEntity1.AddOrUpdate(new FakeEntity1
{
Name1 = "TestingName1",
LastName1 = "TestingLastName1"
});
context.SaveChanges();
}
Here is my Entity Model...
[Table("rpt.FakeEntity1")]
public partial class FakeEntity1 : IFakeEntity1
{
[Key]
[Column(Order = 0)]
[StringLength(20)]
public string Name1 { get; set; }
[Key]
[Column(Order = 1)]
[StringLength(20)]
public string LastName1 { get; set; }
}
Here is my DatabaseContext...
public partial class FakeDbContext: IFakeDbContext
{
public FakeDbContext(DbConnection dbConnection)
: base(dbConnection, true)
{
//Effort requires this.
}
}
public interface IFakeDbContext :IDisposable
{
DbSet<FakeEntity1> FakeEntity1 {get; set;}
}
I also have another class FakeDbContext.Base that overrides OnModelCreating.
Here is the Stack Trace:
The stack trace shows that the exception is thrown when the data provider is looking for a "store type from name". This indicates that you're using a data type that Effort doesn't support. This is confirmed by an issue in the Effort project.