Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEF creates trouble for integration tests #392

Open
fallwest opened this issue Aug 30, 2016 · 1 comment
Open

MEF creates trouble for integration tests #392

fallwest opened this issue Aug 30, 2016 · 1 comment

Comments

@fallwest
Copy link

fallwest commented Aug 30, 2016

I have to fight with MEF on my sever run of unit / integration tests. I have got past not finding the Ado provider with the code sample below but then run up against "SimpleDataException:

Simple.Data.SimpleDataException: No System.Data.SqlClient Provider found.. at Simple.Data.MefHelper.Compose[T](String contractName)" 

Would rather have feature that allows me to circumvent MEF for testing.

        [ClassInitialize]
        public static void ClassInitialize(TestContext testContext)
        {
            //Hack to avoid strange error that only occurs on automatic test server.
            //Error message: Simple.Data.SimpleDataException: No Ado Provider found. at Simple.Data.MefHelper.Compose[T](String contractName)
            var adoAdapter = new AdoAdapter();
            adoAdapter.Setup(new
            {
                ConnectionString = "Data Source=(local);Initial Catalog=DB;Integrated Security=True;User Instance=False",
                ProviderName = "System.Data.SqlClient"
            });

            Database.UseMockAdapter(adoAdapter);
        }

I have, of course, added all nuget packages to the test project.

@fallwest
Copy link
Author

fallwest commented Aug 30, 2016

Update:

Got this to work with by adding the following class to my test project:

using System.ComponentModel.Composition;
using Simple.Data.Ado;
using Simple.Data.SqlServer;

namespace Blabla.AppServer.Integration.Tests
{
    /// <summary>
    /// Noe spesiell dritt som trengs fordi Simple.Data bruker reflection og MEF som gjør at enhetstester feiler bare på byggserver
    /// </summary>
    // ReSharper disable once RedundantExtendsListEntry

    [Export(typeof(IConnectionProvider))]
    [Export("System.Data.SqlClient", typeof(IConnectionProvider))]
    // ReSharper disable once RedundantExtendsListEntry
    public class ConnectionProvider : SqlConnectionProvider, IConnectionProvider
    {
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant