public void GetBlobBaseClientForUriWithId_ShouldReturnValidClient_WhenCalledAsExpected() { // Arrange var clientRequestId = "{\"somehappykey\" : \"somehappyvalue\"}"; var expectedScheme = "https"; var expectedAccount = "gridwichasset00sasb"; var expectedEndpointSuffix = "core.windows.net"; var expectedContainer = "container1"; var expectedBlob = "path1/blob1.mp4"; Uri uri1 = new Uri($"{expectedScheme}://{expectedAccount}.blob.{expectedEndpointSuffix}/{expectedContainer}/{expectedBlob}"); // Ensure we don't pick up a cached object: _blobBaseClientCache.Remove(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1)); // Act var ctx = new StorageClientProviderContext(clientRequestId, false, string.Empty); var newClientSleeve = _blobBaseClientProvider.GetBlobClientSleeveForUri(uri1, ctx); var newClient = newClientSleeve.Client; // Assert newClient.AccountName.ShouldBe(expectedAccount); newClient.BlobContainerName.ShouldBe(expectedContainer); newClient.Name.ShouldBe(expectedBlob); newClient.Uri.ShouldBe(uri1); newClient.ShouldBeOfType <BlobBaseClient>(); }
public BlobBaseClientProviderTests() { _settingsProvider = Mock.Of <ISettingsProvider>(); _logger = Mock.Of <IObjectLogger <BlobBaseClientProvider> >(); _identity = Mock.Of <TokenCredential>(); _blobBaseClientCache = new CachingService(); _blobBaseClientProvider = new BlobBaseClientProvider(_settingsProvider, _blobBaseClientCache, _logger, _identity); }
public void GetBlobBaseClientForUri_ShouldThrow_WhenUnknownStorageAccount() { // Arrange Uri uri1 = new Uri("https://gridwichasset00sasbblob.core.windows.net/container1/blob1.mp4"); // Ensure we don't pick up a cached object: _blobBaseClientCache.Remove(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1)); // Act & Assert Assert.Throws <ArgumentException>(() => _blobBaseClientProvider.GetBlobClientSleeveForUri(uri1, StorageClientProviderContext.None)); Mock.Get(_logger).Verify(x => x.LogExceptionObject(LogEventIds.BlobBaseClientProviderUriMissingAccountName, It.IsAny <UriFormatException>(), It.IsAny <object>()), Times.Once, "An exception should be logged when the storage account is unknown."); }
public void GetBlobBaseClientForUri_ShouldReturnExistingClient_WhenAlreadyInDictionary() { // Arrange Uri uri1 = new Uri("https://gridwichasset00sasb.blob.core.windows.net/container1/blob1.mp4"); // Ensure we don't pick up a cached object: _blobBaseClientCache.Remove(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1)); var blobBaseClient = Mock.Of <BlobBaseClient>(); var context = StorageClientProviderContext.None; var sleeve = MockSleeve(blobBaseClient, context); _blobBaseClientCache.Add(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1, context), sleeve); // Act var result = _blobBaseClientProvider.GetBlobClientSleeveForUri(uri1, context); // Assert result.Client.ShouldBe(blobBaseClient); }
public void GetBlobBaseClientForUriWithId_ShouldReturnExistingClient_WhenAlreadyInDictionary() { // Arrange var context1 = new StorageClientProviderContext("{\"somehappykey\" : \"somehappyvalue\"}", false, string.Empty); Uri uri1 = new Uri("https://gridwichasset00sasb.blob.core.windows.net/container1/blob1.mp4"); // Ensure we don't pick up a cached object: _blobBaseClientCache.Remove(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1, context1)); var blobSleeve = MockSleeve(Mock.Of <BlobBaseClient>(), context1); _blobBaseClientCache.Add(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1, context1), blobSleeve); // Act var result = _blobBaseClientProvider.GetBlobClientSleeveForUri(uri1, context1); // Assert result.Client.ShouldBe(blobSleeve.Client); result.Context.ShouldBe(blobSleeve.Context); }
public void GetBlobBaseClientForUri_ShouldReturnNewClient_WhenNotInDictionary() { // Arrange var context = new StorageClientProviderContext("{ \"something\" : \"good\" }", false, string.Empty); var expectedScheme = "https"; var expectedAccount = "gridwichasset00sasb"; var expectedEndpointSuffix = "core.windows.net"; var expectedContainer = "container1"; var expectedBlob = "path1/blob1.mp4"; Uri uri1 = new Uri($"{expectedScheme}://{expectedAccount}.{expectedEndpointSuffix}/{expectedContainer}/{expectedBlob}"); Uri uri2 = new Uri("https://gridwichasset00sasb.blob.core.windows.net/container2/blob2.mp4"); // Ensure we don't pick up a cached object: _blobBaseClientCache.Remove(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1, context)); _blobBaseClientCache.Remove(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri2, context)); var blobBaseClient = Mock.Of <BlobBaseClient>(); var sleeve = MockSleeve(blobBaseClient, context); _blobBaseClientCache.Add(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1, context), sleeve); // Act var existingClientSleeve = _blobBaseClientProvider.GetBlobClientSleeveForUri(uri1, context); var existingClient = existingClientSleeve.Client; var newClientSleeve = _blobBaseClientProvider.GetBlobClientSleeveForUri(uri2, context); var newClient = newClientSleeve.Client; // Assert // So existing should match original and new shouldn't. existingClientSleeve.ShouldNotBe(newClientSleeve); existingClientSleeve.ShouldBe(sleeve); newClient.ShouldBeOfType <BlobBaseClient>(); newClient.ShouldNotBeSameAs(sleeve.Client); existingClient.ShouldBe(sleeve.Client); newClient.ShouldNotBe(existingClient); }
public void GetBlobBaseClientForUriWithId_ShouldReturnNewClient_WhenNotInDictionary() { // Arrange var context1 = new StorageClientProviderContext("{\"somehappykey\" : \"somehappyvalue\"}", false, string.Empty); var context2 = new StorageClientProviderContext("{\"anotherhappykey\" : \"anotherhappyvalue\"}", false, string.Empty); var expectedScheme = "https"; var expectedAccount = "gridwichasset00sasb"; var expectedEndpointSuffix = "core.windows.net"; var expectedContainer = "container1"; var expectedBlob = "path1/blob1.mp4"; Uri uri1 = new Uri($"{expectedScheme}://{expectedAccount}.{expectedEndpointSuffix}/{expectedContainer}/{expectedBlob}"); Uri uri2 = new Uri("https://gridwichasset00sasb.blob.core.windows.net/container2/blob2.mp4"); // Ensure we don't pick up a cached object: _blobBaseClientCache.Remove(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1, context1)); _blobBaseClientCache.Remove(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri2, context2)); var blobBaseClient = Mock.Of <BlobBaseClient>(); var sleeve1 = MockSleeve(blobBaseClient, context1); _blobBaseClientCache.Add(BlobBaseClientProvider.GetCacheKeyForBlobBaseClient(uri1, context1), sleeve1); // Act var existingClientSleeve = _blobBaseClientProvider.GetBlobClientSleeveForUri(uri1, context1); var existingClient = existingClientSleeve.Client; var newClientSleeve = _blobBaseClientProvider.GetBlobClientSleeveForUri(uri2, context2); var newClient = newClientSleeve.Client; // Assert existingClient.ShouldBeSameAs(blobBaseClient); newClient.ShouldNotBeSameAs(blobBaseClient); existingClientSleeve.Context.ShouldBeEquivalentTo(context1); newClientSleeve.Context.ShouldBeEquivalentTo(context2); }