public async Task MemoryCache_SetAndGetToken() { MemoryTokenCacheManager tokenManger = new MemoryTokenCacheManager("1"); TokenCache tc = new TokenCache(); await tokenManger.SetToken(tc); var tc2 = await tokenManger.GetToken(); Assert.Equal(tc, tc2); await tokenManger.RemoveToken(); tc2 = await tokenManger.GetToken(); Assert.Null(tc2); }
public void MemoryCache_Test() { IServiceCollection sc = new ServiceCollection() .AddLogging() .AddHttpClient(); var sp = sc.BuildServiceProvider(); ClientCertificateInfo ci = new ClientCertificateInfo() { ClientID = "1", AuthUrl = "1", ClientSecret = "1" }; MockTokenProcessor processor = new MockTokenProcessor(); SetTokenProcessor setter = SetTokenProcessor.Bearer; CheckResponseProcessor checker = CheckResponseProcessor.NormalChecker; MemoryTokenCacheManager cacheManager = new MemoryTokenCacheManager(ci.ClientID); ClientCertificateManager ccm = new ClientCertificateManager( ci, processor, setter, checker, cacheManager, sp.GetRequiredService <ILogger <ClientCertificateManager> >(), sp.GetRequiredService <IHttpClientFactory>()); List <Task> taskList = new List <Task>(); for (int i = 0; i < 10; i++) { taskList.Add(Task.Run(async() => { await ccm.GetAccessToken(); })); } Task.WaitAll(taskList.ToArray()); Assert.Equal(1, processor.exeCount); }