vendredi 9 février 2018

Setting cookies to httpClient of Asp.Net Core TestServer

I,m testing ASP.NET Core app with TestServer, and there are controllers that require cookie auth. I've created test server instance like this:

_testServer = new TestServer(new WebHostBuilder()
            .UseEnvironment(CustomEnvironments.Test)
            .UseContentRoot(currentDirectory)                
            .UseStartup<Web.Startup>()
            .UseUrls("http://localhost/"));

ApiClient = _testServer.CreateClient();

and now I have to add auth cookie, but it is ignored by server. If the client could be created directly I could pass HttpClientHandler to constractor and set UseCookies to false, and it works, but I can't access the handler when I get client from test server. Is there a way to add auth cookies to test client?

Aucun commentaire:

Enregistrer un commentaire