コード例 #1
0
        public async Task GetBatchAccountQuotasAsync_UsesCache()
        {
            var azureProxy  = GetMockAzureProxy();
            var batchQuotas = new AzureBatchAccountQuotas {
                ActiveJobAndJobScheduleQuota = 1, PoolQuota = 1, DedicatedCoreQuota = 5, LowPriorityCoreQuota = 10
            };

            azureProxy.Setup(a => a.GetBatchAccountQuotasAsync()).Returns(Task.FromResult(batchQuotas));
            var cachingAzureProxy = new CachingWithRetriesAzureProxy(azureProxy.Object, cache);

            var quotas1 = await cachingAzureProxy.GetBatchAccountQuotasAsync();

            var quotas2 = await cachingAzureProxy.GetBatchAccountQuotasAsync();

            azureProxy.Verify(mock => mock.GetBatchAccountQuotasAsync(), Times.Once());
            Assert.AreEqual(batchQuotas, quotas1);
            Assert.AreEqual(quotas1, quotas2);
        }
コード例 #2
0
        public async Task GetBatchAccountQuotasAsync_ThrowsException_DoesNotSetCache()
        {
            SystemClock.SleepAsync = (_, __) => Task.FromResult(true);
            SystemClock.Sleep      = (_, __) => { };
            var azureProxy        = GetMockAzureProxy();
            var cachingAzureProxy = new CachingWithRetriesAzureProxy(azureProxy.Object, cache);

            azureProxy.Setup(a => a.GetBatchAccountQuotasAsync()).Throws <Exception>();

            await Assert.ThrowsExceptionAsync <Exception>(async() => await cachingAzureProxy.GetBatchAccountQuotasAsync());

            azureProxy.Verify(mock => mock.GetBatchAccountQuotasAsync(), Times.Exactly(4));
        }