0

So I have this really simple test:

[TestMethod]
public void CheckAllParametersExist()
{
    try
    {
        new ParametersService().Get();
        Assert.IsTrue(true);
    }
    catch(Exception ex)
    {
        Assert.Fail(ex.Message);
    }
}

ParametersService().Get() runs through a parameters class finding all the properties and tries to populate them with values from a database. Occasionally when we release the website we might forget to publish some values, so I wanted a unit test in Bamboo to identify any parameters we may have missed.

To the crux of my problem: In Visual Studio 2017 the unit test passes fine. With MSTest is fails with:

Assert.Fail failed. The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.

Looking this particular error up it looks like I've got the wrong or mixed versions of EntityFramework. Having tried to fix this myself I have removed Entity framework from the Tests project nuget and app.config, then under the solution I consolidated the EntityFramework nuget and included Tests project again, still the same error. App.config shows version 6.0.0.0, nuget has installed 6.2.0

I am stuck, if anyone can suggest any solutions or identify any reasons why I might be seeing this problem I would be greatful.

Fyi: I am running MSTest with /testcontainer:tests.dll in the Tests project bin output debug folder.

Tod
  • 2,070
  • 21
  • 27
  • Can you make a simplified version of your `ParametersService().Get()` and post here? – Ignas Feb 16 '18 at 20:12
  • Time to [manually review the `.csproj` and `.config` files](https://stackoverflow.com/a/35991676) to ensure your dependency versioning is consistent throughout the solution (particularly Entity Framework). – NightOwl888 Feb 17 '18 at 08:44
  • Good suggestion, however all the references are correct in the csproj files. All the EntityFramework ones are 6.0.0.0 – Tod Feb 19 '18 at 16:25

1 Answers1

0

So it turns out the problem was with the App.Config. The problem is that we have some sections of the configuration loaded from external files. In this case connection strings. In VS it loads the config file for connections strings just fine. In MSTest it copies the DLLs to another folder but doesn't include the folders/config files.

Also MSTest has now been retired, as of VS2013 we should be using VsTest.console, however Bamboo hasn't caught up with that yet.

Tod
  • 2,070
  • 21
  • 27