Load Rest API referenced assemblies from a .net core Integration Test project doesn't include the referenced projects

  • Thread starter Thread starter izinova
  • Start date Start date
I

izinova

Guest
I created an integration test project that has a reference to a Rest API project built in .Net Core 3.1

On the startup of my Rest Api I do some reflection to load some classes coded on other assemblies I have(like plugins that I load dynamically), but I do some discovery with reflection. I am not specifying the path of the assemblies, I simply add them as a reference on my Rest Api project and load them on this way

var assemblies = Assembly.GetEntryAssembly()?.GetReferencedAssemblies().Select(Assembly.Load);

Now, when I am running my integration test project it doesn't work. My integration test project has a reference to my Rest API project and also I use the approach of the

IClassFixture


which runs the Startup of my Rest Api project before executing the Test, but the execution context(main thread) on this case is the Test Project. When the Startup of my Rest Api is executed from the Integration Test main thread, no referenced assemblies are loaded.

Main problem is that my test project didn't have the same references that my Rest Api project had, so I add them as well as part of the Integration Test Project.

it didn't work

Also, I tried to create dummy objects from defined on those assemblies and use them inside of my Integration Test Project. If you don't create a dummy object the compiler doesn't see that you are using any of the definitions/classes from one of those assemblies, and it doesn't include them on the list of ReferenceAssemblies. See the idea below

private void CreateDummiesObject()
{
//To make the discovery process happen on assemblies that are referenced but not used until the runtime
//Core project
TypeHelper th = null;
//Data
Repository<Summary> rep = null;
//Data.Web.Api1
WebApi1DbContext dbContext = null;
}


it didn't work

Any idea of how can I solve this issue?

I posted the question as well on stacknbsp;Stackoverflow link

Continue reading...
 
Back
Top