Пример #1
0
        public void EnsureCacheLifetime()
        {
            var keyVaultHelper = new KeyVaultHelper(ConfigurationManager.AppSettings["ApplicationId"],
                                                    ConfigurationManager.AppSettings["ApplicationCertificate"]);
            var kv = new KeyVaultCache(keyVaultHelper, 4);

            var sw1      = Stopwatch.StartNew();
            var uncached = kv.GetSecret(_secret1, true).GetAwaiter().GetResult();

            sw1.Stop();

            var sw2    = Stopwatch.StartNew();
            var cached = kv.GetSecret(_secret1).GetAwaiter().GetResult();

            sw2.Stop();

            Thread.Sleep(5000);

            var sw3     = Stopwatch.StartNew();
            var refetch = kv.GetSecret(_secret1).GetAwaiter().GetResult();

            sw3.Stop();

            Trace.WriteLine($"Uncached: {sw1.ElapsedMilliseconds}, cached: {sw2.ElapsedMilliseconds}, refetch: {sw3.ElapsedMilliseconds} ms");

            Assert.AreEqual(uncached, cached);
            Assert.AreEqual(refetch, cached);
            Assert.IsTrue(sw1.ElapsedMilliseconds > 100);
            Assert.IsTrue(sw2.ElapsedMilliseconds < 10);
            Assert.IsTrue(sw3.ElapsedMilliseconds > 100);
        }
Пример #2
0
        /// <inheritdoc />
        public KvTests()
        {
            var keyVaultHelper = new KeyVaultHelper(ConfigurationManager.AppSettings["ApplicationId"],
                                                    ConfigurationManager.AppSettings["ApplicationCertificate"]);

            _kv      = new KeyVaultCache(keyVaultHelper);
            _secret1 = ConfigurationManager.AppSettings["Secret1"];
        }