Fortunately, xUnit and the WebApplicationFactory class don't need to directly reference the global namespace, top level statement Program.cs Program class. We can often use any class from the project being tested that is sufficiently exposed to the test project. The type param description of TEntryPoint in WebApplicationFactory<TEntryPoint> states "A type in the entry point assembly of the application. Typically the Startup or Program classes can be used."
If you look at the source code for the WebApplicationFactory class, you will see that it uses reflection to find the app entry point. There are lots of references in the WebApplicationFactory class code to typeof(TEntryPoint).Assembly. It's basically saying "I just need a class type that belongs to an assembly with an entry point." It could be a page model, middleware, MVC controller, or just a dummy class. Doesn't need to be partial. A public class is usable in more scenarios than an internal class though, if you have trouble with internal.
Assuming all these classes are in the project being tested, we can just as well reference the project via possible code options like these:
MyTests : IClassFixture<WebApplicationFactory<WebProjectNamespace.MyMiddlewareClass>>
MyTests : IClassFixture<WebApplicationFactory<WebProjectNamespace.MyPageModelClass>>
MyTests : IClassFixture<WebApplicationFactory<WebProjectNamespace.MyHelloWorldController>>
Referencing the project's Program class is a better indicator that you're referencing the project startup than referencing a random controller or page class name, but it's not strictly necessary.
Another solution is to use Project/Assembly aliases to differentiate the two, like so:
In your test project csproj file:
<ProjectReference Include="..\WebProject1\WebProject1.csproj" Aliases="global,WebProject1Assembly" />
<ProjectReference Include="..\WebProject2\WebProject2.csproj" Aliases="global,WebProject2Assembly" />
In your test CS file:
extern alias WebProject1Assembly;
extern alias WebProject2Assembly;
...
MyTests1 : IClassFixture<WebApplicationFactory<WebProject1Assembly::Program>>
...
MyTests2 : IClassFixture<WebApplicationFactory<WebProject2Assembly::Program>>
Note that referencing Program often necessitates that Program be public in order to avoid "Inconsistent accessibility" errors. If you are using a top level statements file in the project being tested, you can make Program public by adding this at the bottom of the file:
public partial class Program{}