JonPSmith / EfCore.TestSupport

Tools for helping in unit testing applications that use Entity Framework Core
https://www.thereformedprogrammer.net/new-features-for-unit-testing-your-entity-framework-core-5-code/
Other
352 stars 53 forks source link

Did not find '\bin\' in the assembly path C:\Users\username\.nuget\packages\efcore.testsupport\... #21

Closed Selmirrrrr closed 5 years ago

Selmirrrrr commented 5 years ago

Hi,

Firstly thank you very much for this useful lib, it'll help us a lot.

I'm facing an issue when calling creating seed data with Assembly.GetCallingAssembly()).Location, when referencing the project from NuGet.org the Assembly.GetCallingAssembly()).Location points to C:\Users\username\.nuget\packages\efcore.testsupport\2.0.0\lib\netstandard2.0\TestSupport.dll and TestSupport was unable to find \bin\ part in it and threw an exception.

Everything works fine when I reference directly your project in my solution.

My setup

The issue is present with built-in Visual Studio's test runner and with dotnet test, didn't tested with others.

To Reproduce

  1. Create new MSTest project
  2. Reference a project with a valid EFCore DbContext
  3. Create an extract test method as described in Wiki (https://github.com/JonPSmith/EfCore.TestSupport/wiki/Seed-from-Production---Extract-stage)
  4. Run the test

Expected behavior

A seed JSON file is created in current test's folder

Current behavior

An exception is thrown.

System.Exception: Did not find '\bin\' in the assembly. Do you need to provide the callingAssembly parameter? Stack Trace: at TestSupport.Helpers.TestData.GetCallingAssemblyTopLevelDir(Assembly callingAssembly) at TestSupport.Helpers.TestData.GetTestDataDir(String alternateTestDir, Assembly callingAssembly) at TestSupport.SeedDatabase.SeedJsonHelpers.FormJsonFilePath(String fileSuffix) at TestSupport.SeedDatabase.SeedJsonHelpers.WriteJsonToJsonFile(String fileSuffix, String json) at Trianon.HR.Data.EFCore.Tests.FilterTests.ExampleExtract() in C:\ieu\development\HR.Data\tests\Trianon.HR.Data.EFCore.Tests\FilterTests.cs:line 29

I saw that issues #4 and #14 face the same issue that should have been fixed since then but it seems it's still here...

I'll send you a PR to try to provide a way to avoid this issue in the future.

JonPSmith commented 5 years ago

Hi @Selmirrrrr,

Yes, it looks like I didn't get that quite right. Thanks for pointing this out.

I'm away from my office at the moment but I will have a look at this when I get back next week.

Selmirrrrr commented 5 years ago

Hi @JonPSmith,

Thanks for you feedback, here's my PR to avoid this issue : #22

JonPSmith commented 5 years ago

Hi @Selmirrrrr,

I'm back from my travels and have fixed this issue. There is a new version, 2.0.1, of EfCore.TestSupport which contains this fix.

Thanks for pointing this out and providing a PR. I used your pull request, but improved it a bit. If you don't provide the calling assembly it defaults to Assembly.GetCallingAssembly(), which is how the other versions work too.

Selmirrrrr commented 5 years ago

Great, thank you very much 👍