Unit test inner class in ASP.NET Core

I want a unit test class with an internal security level in an ASP.NET Core project. I added the AssemblyInfo.cs file to the properties of the test project:

 using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: InternalsVisibleTo("xxx.xxx.xxxTests")] 

However, when I call this in my test:

 mockApplicationBuilder.Verify(y => y.UseMiddleware<HttpExceptionMiddleware>()); 

I'm still getting

HttpExceptionMiddleware unavailable due to protection level

Why is my AssemblyInfo attribute not working?

My setup is that I have a solution with two folders (src and tests), and these folders have an src project and a test project in the root folder, respectively. The AssemblyInfo.cs file is in my properties of my src project. Do I need to specify the full path to the test project in my assemblyInfo.cs attribute?

My test project also has AssemblyInfo.cs , although I believe it doesn't matter.

+6
source share
2 answers

Without waiting for my decision, I can only offer suggestions

  • Make sure your ASP project is referenced in your test project, which should be or you will have other problems, and most likely as a reference to the project.
  • Check the assembly name of the test project and that InternalsVisibleTo contains the fully qualified name of the assembly
  • Make sure that HttpExceptionMiddleware is actually marked as internal
  • Clean and check for cleanliness, then restore your solution.
+1
source

A possible answer is that the AssemblyInfo.cs file is automatically generated (so it overwrites or ignores yours). Very guess. See also:

Equivalent to AssemblyInfo in dotnet / csproj core

0
source

Source: https://habr.com/ru/post/1015317/


All Articles