Пример #1
0
        public async Task TokenTests_GetTokenWaitAndRefresh()
        {
            MicrosoftAppCredentials credentials = new MicrosoftAppCredentials("a40e1db0-b7a2-4e6e-af0e-b4987f73228f", "sbF0902^}tyvpvEDXTMX9^|");
            var result = await credentials.GetTokenAsync();

            Assert.IsNotNull(result);
            credentials.ClearTokenCache();
            var result2 = await credentials.GetTokenAsync();

            Assert.AreNotEqual(result.ExpiresOn, result2.ExpiresOn);
            Assert.AreNotEqual(result.AccessToken, result2.AccessToken);
        }
Пример #2
0
        public async Task TokenTests_RefreshTestLoad()
        {
            MicrosoftAppCredentials credentials = new MicrosoftAppCredentials("a40e1db0-b7a2-4e6e-af0e-b4987f73228f", "sbF0902^}tyvpvEDXTMX9^|");

            List <Task <AuthenticationResult> > tasks = new List <Task <AuthenticationResult> >();

            for (int i = 0; i < 1000; i++)
            {
                tasks.Add(credentials.GetTokenAsync());
            }

            foreach (var item in tasks)
            {
                Assert.IsFalse(item.IsFaulted);
                Assert.IsFalse(item.IsCanceled);
                AuthenticationResult result = await item;

                Assert.IsTrue(result.ExpiresOn > DateTimeOffset.UtcNow);
            }

            tasks.Clear();
            for (int i = 0; i < 1000; i++)
            {
                if (i % 100 == 50)
                {
                    credentials.ClearTokenCache();
                }

                tasks.Add(credentials.GetTokenAsync());
            }

            HashSet <AuthenticationResult> results = new HashSet <AuthenticationResult>(new AuthenticationResultEqualityComparer());

            for (int i = 0; i < 1000; i++)
            {
                Assert.IsFalse(tasks[i].IsFaulted);
                Assert.IsFalse(tasks[i].IsCanceled);
                AuthenticationResult result = await tasks[i];

                Assert.IsTrue(result.ExpiresOn > DateTimeOffset.UtcNow);
            }
        }