Это фабричный класс веб-приложения.
Программный класс, который он использует в расширении, является внутренним из проекта API. (Выполнено с помощью InternalsVisibleTo )
Код: Выделить всё
internal class DozerWebApplicationFactory : WebApplicationFactory
{
//Omitted not useful
}
Код: Выделить всё
public class QuotesControllerTests
{
private readonly DozerWebApplicationFactory _application;
private readonly HttpClient _httpClient;
public QuotesControllerTests()
{
// Arrange/Setup
_application = new DozerWebApplicationFactory();
_httpClient = _application.CreateClient();
}
}
Код: Выделить всё
public class QuotesControllerTests : IClassFixture
{
private readonly DozerWebApplicationFactory _application;
private readonly HttpClient _httpClient;
public QuotesControllerTests(DozerWebApplicationFactory application)
{
// It doesn't work because this constructor is public (tests need to be public) but the Factory is internal due to program being internal as stated above.
_application = application;
_httpClient = _application.CreateClient();
}
}
Код: Выделить всё
CS0051 Inconsistent accessibility: parameter type 'DozerWebApplicationFactory' is less accessible than method 'QuotesControllerTests.QuotesControllerTests(DozerWebApplicationFactory)'Подробнее здесь: https://stackoverflow.com/questions/791 ... ation-test
Мобильная версия