I am trying to run some integration tests for the token management API. The API also requires the launch of the token API.
Thus, my integration test should run both IdentityServer4 Web / API and management APIs at the same time. When I create two instances TestServer
, it seems like they both end in the same BaseAddress
( http://localhost
).
private readonly TestServer _identityTestServer;
private readonly TestServer _mgmtTestServer;
private readonly AppMgmtConfig _config;
private readonly AdminClient _adminClient;
private const string _certificatePassword = "test";
public AdminClientTests() : base(nameof(AdminClientTests))
{
var connectionString = GetConnectionString();
var dbSettings = new DbSettings(connectionString);
Environment.SetEnvironmentVariable("IdentityServer4ConnString",
dbSettings.IdentityServerConnectionString);
Environment.SetEnvironmentVariable("CertificatePassword", _certificatePassword);
_identityTestServer = new TestServer(new WebHostBuilder()
.UseStartup<USBIdentityServer.Startup>()
.UseEnvironment("IntegrationTest"));
USBIdentityServer.Program.InitializeDatabase(_identityTestServer.Host);
_mgmtTestServer = new TestServer(new WebHostBuilder()
.UseStartup<IdentityServer4.Management.Startup>()
.UseEnvironment("IntegrationTest"));
_config = GetConfig();
_adminClient = new AdminClient(_config);
}
Note:
Things I've already tried:
- Add
.UseUrls("http://localhost:5001")
to check if TestServer will work on this port. - Add
serverName.BaseAddress = new Uri("http://localhost:5001");
to check if TestServer will work on this port.
None of them affect him.
source
share