0

I have about 1600 test which passes and i've added one test with DeploymentItem and DataSource to get testcases from prepared XML. Test alone works, it even work in whole testclass but when I try to run all test all tests fails. We use EF and VS Test.

In every test there's the same error:

OTController_Test.TestInitialize Returned exception. System.InvalidOperationException: 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..

Test looks like this:

[DeploymentItem("C:\\Users\\mateusz.sobczyk\\Source\\Repos\\Aplixcom_InsertData\\Aplixcom_InsertData_Test\\XMLGenerator\\Tests\\test.xml")]
        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\test.xml", "XMLWrappedModel", DataAccessMethod.Sequential)]
        [TestMethod]
        public void testme()
        {
            string tmp = TestContext.DataRow["JsonModel"].ToString();
            string failinfo = TestContext.DataRow["FailInfo"].ToString();
            string TestCategory = TestContext.DataRow["TestCategory"].ToString();
            Group obj = System.Web.Helpers.Json.Decode<Group>(tmp);
            if (obj == null)
            {
                AssertAll.Execute(
                () => Assert.AreEqual(null, tmp),
                () => Assert.AreEqual("[ID:[FailedCreateFailInfo][Nazwa:[FailedCreateFailInfo]", failinfo),
                () => Assert.AreEqual("Testy Mocy", TestCategory)
                );
            }
            else
            {
                switch (obj.ID)
                {
                    case 2:
                        AssertAll.Execute(
                            () => Assert.AreEqual("a", obj.Nazwa),
                            () => Assert.AreEqual("[ID: 2][Nazwa: a]", failinfo),
                            () => Assert.AreEqual("Testy Mocy", TestCategory)
                            );
                        break;
                    case 3:
                        AssertAll.Execute(
                            () => Assert.AreEqual("b", obj.Nazwa),
                            () => Assert.AreEqual("[ID: 3][Nazwa: b]", failinfo),
                            () => Assert.AreEqual("Testy Mocy", TestCategory)
                            );

                        break;
                    case 4:
                        AssertAll.Execute(
                            () => Assert.AreEqual("b", obj.Nazwa),
                            () => Assert.AreEqual("[ID: 4][Nazwa: b]", failinfo),
                            () => Assert.AreEqual("Testy Mocy", TestCategory)
                            );
                        break;
                }
            }
        }

My web.config

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
    </providers>
  </entityFramework>

I have no clue how to fix this. I tried to refresh my references but it didn't helped. How do i make it work? Because from now on I wanted to use datasource in testing and I hope you will help me:)

Raz Luvaton
  • 3,166
  • 4
  • 21
  • 36
  • It is strange that the error only shows when running all tests. Do you have any configuration code in `TestInitialize` in this class that is different from other classes? Are you using static variables for your database context in the tests? Are you correctly disposing your database context in each test, or at least in each test class? Anyway, this error is usually caused by a missing `EntityFramework.SqlServer.dll` in your test project. [This post](https://stackoverflow.com/questions/14033193/entity-framework-provider-type-could-not-be-loaded) shows several ways to fix it. – Diana Jul 10 '17 at 17:31
  • Generally in 'TestInitialize' i am redirecting connectionstring to testserver and that's all. In testCleanup i am clearing my DB. TestClasses ran separately passes without any problem. I do have EntityFramework.sqlserwer.dll in my project and i tried to swap it and it didn't sucess. – Mateusz Sobczyk Jul 11 '17 at 07:43

0 Answers0