I upgraded one of our projects to EF6 this week and spent yesterday trying to get unit testing working again to no avail. I downloaded the latest build (Effort.1.0.0-beta5-140316) and updated the effort dll in the project to the one targeting EF6. Specifically,
I can get it running with no data loaded, but when I try to load data from our unit testing database I keep getting this error:
Assembly Initialization method UnitTests.Tests.TestingSetup.SetUp threw exception. Effort.Exceptions.EffortException: Effort.Exceptions.EffortException: Unhandled exception while trying to initialize the content of 'Table<____RefactorLog>' table ---> System.NullReferenceException: Object reference not set to an instance of an object.. Aborting test execution.
Note, it doesn't seem to be a problem with that particular table, it's just the first one it tries to load data for. When I deleted it from the model and tried again it just went to the next one in alphabetical order and threw the same error.
Here's my current initialization code:
IDataLoader wrappedDataLoader = new EntityDataLoader("metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string='Server=server;Database=database;User ID=userid;Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;multipleactiveresultsets=True;App=EntityFramework'");
var loader = new CachingDataLoader(wrappedDataLoader, false);
EntityConnection connection = Effort.EntityConnectionFactory.CreateTransient("metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string='Server=server;Database=database;User ID=userid;Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;multipleactiveresultsets=True;App=EntityFramework'", loader);
EntityFrameworkUnitOfWorkFactory.SetObjectContext(() => new DataEntities(connection));
If I don't specify the loader when creating the EntityConnection it works, but of course most of the tests fail at that point. I also was able to load data from CSV files, but this is a poor solution for multiple reasons. (Harder to maintain, could never get
working on our build server, etc.)
For what it's worth, I also added the following to my app.config file:
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameter value="v11.0" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="EffortProvider" type="Effort.Provider.EffortProviderServices, Effort" />
type="Effort.Provider.EffortProviderFactory, Effort" />
I'm stumped at this point. Before moving to EF6 I was using the ObjectContextFactory and it was fine, but that's not really an option anymore without reworking a lot of code in our repository framework.
Any ideas at this point would be great. I did download the source and tried to run against that so I could see the specific error being thrown instead of the generic one throw by Effort, but I couldn't get it to run against the source at all.