mardi 1 mars 2016

.NET: Correctly implement DataSourceAttribute for local .mdf file

I am trying to create some data-driven unit tests in my C# solution. My data is in a file TestData.mdf. On my test method, I'm using the DataSourceAttribute to specify where to pull the data for testing. The test data should be coming from a table String_CanParseBooleanData in the TestData.mdf database file.

I have tried using all the constructors for DataSourceAttribute, with numerous different connection strings and provider invariant names, and cannot get past connection errors on the test.

The test method is just a skeleton so far, so I don't think it is the cause of any issue:

[TestMethod]
public void String_CanParseBoolean() {
    Assert.Inconclusive();
}

If I add a connection to my MDF file in the Server Explorer window, it lists the provider as

.NET Framework Data Provider for SQL Server

This does not look anything like the values for provider name invariant I've seen in code examples or Microsoft documentation. Those provider names are System.Data.SqlClient or System.Data.SqlServerCe.4.0, and if I use this for the provider element of the connection string, I will get an error that says that provider is not registered locally. If I use that for the provider argument of the attribute, I get an error saying it cannot find the provider.

What provider do I need to use an MDF file in VS2013?

Aucun commentaire:

Enregistrer un commentaire