public void GetBatchActiveJobCount_ThrowsException_RetriesThreeTimes() { SystemClock.SleepAsync = (_, __) => Task.FromResult(true); SystemClock.Sleep = (_, __) => { }; var azureProxy = GetMockAzureProxy(); var cachingAzureProxy = new CachingWithRetriesAzureProxy(azureProxy.Object, cache); azureProxy.Setup(a => a.GetBatchActiveJobCount()).Throws <Exception>(); Assert.ThrowsException <Exception>(() => cachingAzureProxy.GetBatchActiveJobCount()); azureProxy.Verify(mock => mock.GetBatchActiveJobCount(), Times.Exactly(4)); }
public async Task GetVMSizesAndPricesAsync_UsesCache() { var azureProxy = GetMockAzureProxy(); var cachingAzureProxy = new CachingWithRetriesAzureProxy(azureProxy.Object, cache); var vmSizesAndPrices1 = await cachingAzureProxy.GetVmSizesAndPricesAsync(); var vmSizesAndPrices2 = await cachingAzureProxy.GetVmSizesAndPricesAsync(); azureProxy.Verify(mock => mock.GetVmSizesAndPricesAsync(), Times.Once()); Assert.AreEqual(vmSizesAndPrices1, vmSizesAndPrices2); Assert.AreEqual(4, vmSizesAndPrices1.Count); }
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)); }
public async Task GetStorageAccountInfoAsync_UsesCache() { var azureProxy = GetMockAzureProxy(); var storageAccountInfo = new StorageAccountInfo { Name = "defaultstorageaccount", Id = "Id", BlobEndpoint = "https://defaultstorageaccount/", SubscriptionId = "SubId" }; azureProxy.Setup(a => a.GetStorageAccountInfoAsync(It.IsAny <string>())).Returns(Task.FromResult(storageAccountInfo)); var cachingAzureProxy = new CachingWithRetriesAzureProxy(azureProxy.Object, cache); var info1 = await cachingAzureProxy.GetStorageAccountInfoAsync("defaultstorageaccount"); var info2 = await cachingAzureProxy.GetStorageAccountInfoAsync("defaultstorageaccount"); azureProxy.Verify(mock => mock.GetStorageAccountInfoAsync("defaultstorageaccount"), Times.Once()); Assert.AreEqual(storageAccountInfo, info1); Assert.AreEqual(info1, info2); }
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); }
public async Task GetContainerRegistryInfoAsync_UsesCache() { var azureProxy = GetMockAzureProxy(); var containerRegistryInfo = new ContainerRegistryInfo { RegistryServer = "registryServer1", Username = "******", Password = "******" }; azureProxy.Setup(a => a.GetContainerRegistryInfoAsync(It.IsAny <string>())).Returns(Task.FromResult(containerRegistryInfo)); var cachingAzureProxy = new CachingWithRetriesAzureProxy(azureProxy.Object, cache); var info1 = await cachingAzureProxy.GetContainerRegistryInfoAsync("registryServer1/imageName1:tag1"); var info2 = await cachingAzureProxy.GetContainerRegistryInfoAsync("registryServer1/imageName1:tag1"); azureProxy.Verify(mock => mock.GetContainerRegistryInfoAsync("registryServer1/imageName1:tag1"), Times.Once()); Assert.AreEqual(containerRegistryInfo, info1); Assert.AreEqual(info1, info2); }