Issue with ordered visual studio test

Jan 5, 2015 at 2:25 PM
Edited Jan 5, 2015 at 2:31 PM
Hi all,
we are trying to use your lib within an ordered visual studio test. The exception looks like :

Test method XXX threw exception:
System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Result1 StackTrace:
bei System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName)
bei System.Data.Entity.Internal.AppConfig.<.ctor>b__2(ProviderElement e)
bei System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
bei System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
bei System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source)
bei System.Data.Entity.Internal.AppConfig.<.ctor>b__1()
bei System.Lazy1.CreateValue()
bei System.Lazy
1.LazyInitValue()
bei System.Lazy1.get_Value()
bei System.Data.Entity.Internal.AppConfig.get_DbProviderServices()
bei System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.RegisterDbProviderServices()
bei System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetServiceFactory(Type type, String name)
bei System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple
2 t)
bei System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
bei System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetService(Type type, Object key)
bei System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
bei System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext()
bei System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable
1 source, Func2 predicate)
bei System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
bei System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver
2.GetService(Type type, Object key)
bei System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver)
bei System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
bei System.Data.Entity.DbContext..ctor(DbConnection existingConnection, Boolean contextOwnsConnection)


This error occur if we try to instantiate a Dbcontext (connection, false) from an ordered test.
In case of usual unit tests everything works llike a charm ! )


Is there any chance we could get it to work? We could also try to find a workarund by using some repetative logic that inserts something into db, then updates it, but what is "the best practice" for testing insert/update / update if we use Effort ?

Regards,
Boris
Coordinator
Jan 5, 2015 at 9:49 PM
Hello,

Would you allow me to take a look on the entityFramework section of your configuration file?

As for the data loaders, you should probably give data loaders a try.

Cheers,
Tamas
Jan 6, 2015 at 8:03 AM
Edited Jan 6, 2015 at 8:22 AM
Hi Tamas,

as I said, usual unit tests run like a charm, we have this issue only with ordered tests.

Here is the App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <connectionStrings>
    <add name="TestDb" providerName="System.Data.SqlClient" connectionString="Data Source=localSqlServer;Initial Catalog=TestDb;Persist Security Info=True;User ID=TestUser;Password=TestUser;MultipleActiveResultSets=True" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
I think the issue is that on ordered test not all dll's are put by visual Studio into testResults subfolder.

By adding:
    [TestClass]
    [DeploymentItem("EntityFramework.SqlServer.dll")]
    [DeploymentItem("System.Data.dll")]
    public class XXXFixture
we managed to run successfully
        [AssemblyInitialize]
        public static void SetUp(TestContext testContext)
        {
            Connection = Effort.DbConnectionFactory.CreateTransient();
        }
but later on inserting some entries other dll's were not found. I guess that by adding all needed dll's via [DeploymentItem("XXX.dll")] into our test we would overcome that problem

Beside that what does speak against using the same connection as static field within a test and instantiating Dbcontext with Context = new SpecificContext(Connection, false) again and again in order to test complicated db logic (e.g. insert , then update, then update, then delete)? The approach with dataLoaders seems to be a little cumbersome. Do we have overseen something ? Any ideas why using dataLoaders would be beneficial?

By the way, thanks a lot for your lib, it's a really good tool which we will use in our tests that will be executed during tfs check-in.

Regards,
Boris