I am currently using xUnit 2 in combination with WebApplicationFactory for integration testing. This works well and I am able to run tests on an Umbraco site in-memory.
When I upgrade to xUnit v3 however, the same tests throw errors. I’m able to compile and run, but I get a runtime error when starting the website:
System.IO.FileNotFoundException : Could not load file or assembly 'Mono.Cecil, [...] The system cannot find the file specified.
Stack Trace:
----- Inner Stack Trace -----
RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
Assembly.Load(AssemblyName assemblyRef)
ReferenceResolver.ResolveAssemblies()
FindAssembliesWithReferencesTo.Find()
DefaultUmbracoAssemblyProvider.get_Assemblies()
TypeFinder.GetAllAssemblies()
TypeFinder.GetFilteredAssemblies(IEnumerable`1 excludeFromResults, String[] exclusionFilter)
TypeFinder.get_AssembliesToScan()
TypeLoader.get_AssembliesToScan()
...
I found this similar looking issue on GitHub:
opened 12:29PM - 24 Jul 23 UTC
closed 06:08PM - 30 Nov 23 UTC
community/pr
type/feature
area/backend
affected/v10
affected/v11
affected/v12
community/hackathon
### Which Umbraco version are you using? (Please write the *exact* version, exam… ple: 10.1.0)
umbraco 11.4.2
### Bug summary
I'm getting the following error when running an integration test using where I'm using JetBrains Rider 2023.1.4 I'm getting the following exception
```
OneTimeSetUp: System.IO.FileNotFoundException : Could not load file or assembly 'ReSharperTestRunner, Version=2.11.1.99, Culture=neutral, PublicKeyToken=5c492ec4f3eccde3'. The system cannot find the file specified.
-----
System.IO.FileNotFoundException : Could not load file or assembly 'ReSharperTestRunner, Version=2.11.1.99, Culture=neutral, PublicKeyToken=5c492ec4f3eccde3'. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Umbraco.Cms.Core.Composing.ReferenceResolver.ResolveAssemblies()
at Umbraco.Cms.Core.Composing.FindAssembliesWithReferencesTo.Find()
at Umbraco.Cms.Core.Composing.DefaultUmbracoAssemblyProvider.get_Assemblies()
at Umbraco.Cms.Core.Composing.TypeFinder.GetAllAssemblies()
at Umbraco.Cms.Core.Composing.TypeFinder.GetFilteredAssemblies(IEnumerable`1 excludeFromResults, String[] exclusionFilter)
at Umbraco.Cms.Core.Composing.TypeFinder.get_AssembliesToScan()
at Umbraco.Cms.Core.Composing.TypeLoader.get_AssembliesToScan()
at Umbraco.Cms.Core.Composing.TypeLoader.<>c__DisplayClass21_0`1.<GetTypes>b__0()
at Umbraco.Cms.Core.Composing.TypeLoader.GetTypesInternalLocked(Type baseType, Type attributeType, Func`1 finder, String action, Boolean cache)
at Umbraco.Cms.Core.Composing.TypeLoader.GetTypesInternal(Type baseType, Type attributeType, Func`1 finder, String action, Boolean cache)
at Umbraco.Cms.Core.Composing.TypeLoader.GetTypes[T](Boolean cache, IEnumerable`1 specificAssemblies)
at Umbraco.Cms.Core.DependencyInjection.UmbracoBuilderExtensions.AddAllCoreCollectionBuilders(IUmbracoBuilder builder)
at Umbraco.Cms.Core.DependencyInjection.UmbracoBuilder.AddCoreServices()
at Umbraco.Cms.Core.DependencyInjection.UmbracoBuilder..ctor(IServiceCollection services, IConfiguration config, TypeLoader typeLoader, ILoggerFactory loggerFactory, IProfiler profiler, AppCaches appCaches, IHostingEnvironment hostingEnvironment)
at Umbraco.Extensions.UmbracoBuilderExtensions.AddUmbraco(IServiceCollection services, IWebHostEnvironment webHostEnvironment, IConfiguration config)
at umb.web.Startup.ConfigureServices(IServiceCollection services) in C:\git\umbraco-upgrade-project\src\umb.web\Startup.cs:line 37
at Store.Core.Tests.TestIntegrationServiceProvider..ctor() in C:\git\umbraco-upgrade-project\tests\Store.Core.Tests\TestIntegrationServiceProvider.cs:line 36
at Store.Core.Tests.ProductServiceTests..ctor()
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
```
Rider is trying to use 'ReSharperTestRunner' and the TypeFinder class is not filtering the DLL out(only the 32 bit version) see. Would it possible to remove the 32 from KnownAssemblyExclusionFilter to exclude any ReSharperTestRunner dlls?
[TypeFinder.cs:37](https://github.com/umbraco/Umbraco-CMS/blob/1527b2577e7273157cfede70444c65f838a87225/src/Umbraco.Core/Composing/TypeFinder.cs#L37)
Don't know it is because of I'm using a new version of Rider and resharper or it the configuration of my test project.
### Specifics
Running the test is not possible from Rider and resharper - It's possible using the CLI and running "dotnet test" or using Visual studios built in test explorer.
### Steps to reproduce
Create a new test project that reference an umbraco project, the running the test that uses the startup file in the umbraco project - something like this:
```
var services = new ServiceCollection();
var root = @"C:\git\umbraco-upgrade-project\src\umb.web";
IWebHostEnvironment testWebHostEnvironment = new TestWebHostEnvironment
{
ApplicationName = "umb.web",
ContentRootPath = root,
EnvironmentName = "Development",
WebRootPath = @"C:\path\umb.web\wwwroot\",
ContentRootFileProvider = new PhysicalFileProvider(root),
WebRootFileProvider = new CompositeFileProvider()
};
IConfiguration config = new ConfigurationBuilder()
// .SetBasePath(root)
.AddJsonFile("appsettings.json")
// root + Path.DirectorySeparatorChar +
.Build();
services.AddSingleton(config);
services.AddSingleton(testWebHostEnvironment);
var startup = new Startup(testWebHostEnvironment, config);
startup.ConfigureServices(services);
ServiceProvider = services
.BuildServiceProvider();
var productService = ServiceProvider.GetService<IProductService>();
```
### Expected result / actual result
Should be possible to run from Rider and resharper
But the resolution here was to update Umbraco’s assembly whitelist, which hardly seems like a durable solution.
Has anyone been able to make this work and is willing to share?