Exemplo n.º 1
0
        public void StorageAccount_GetPropertiesThrows_InvalidCredentials()
        {
            var validator = new DefaultStorageCredentialsValidator();

            var storageMock     = new Mock <IStorageAccount>(MockBehavior.Strict);
            var blobClientMock  = new Mock <IStorageBlobClient>();
            var queueClientMock = new Mock <IStorageQueueClient>();
            var queueMock       = new Mock <IStorageQueue>();

            storageMock.Setup(s => s.Credentials)
            .Returns(new StorageCredentials("name", string.Empty));

            storageMock.Setup(s => s.CreateBlobClient(null))
            .Returns(blobClientMock.Object)
            .Verifiable();

            storageMock.Setup(s => s.SdkObject)
            .Returns(new CloudStorageAccount(new StorageCredentials("name", string.Empty), false));

            blobClientMock.Setup(b => b.GetServicePropertiesAsync(It.IsAny <CancellationToken>()))
            .Throws(new StorageException(""));

            var exception = Assert.Throws <InvalidOperationException>(() => validator.ValidateCredentialsAsync(storageMock.Object, It.IsAny <CancellationToken>()).GetAwaiter().GetResult());

            Assert.Equal("Invalid storage account 'name'. Please make sure your credentials are correct.", exception.Message);
            storageMock.Verify();
        }
Exemplo n.º 2
0
        public void StorageAccount_QueueCheckThrows_BlobOnly_WhenCatchingNameResolutionFailure()
        {
            var validator = new DefaultStorageCredentialsValidator();

            var storageMock     = new Mock <IStorageAccount>(MockBehavior.Strict);
            var blobClientMock  = new Mock <IStorageBlobClient>();
            var queueClientMock = new Mock <IStorageQueueClient>();
            var queueMock       = new Mock <IStorageQueue>();

            storageMock.Setup(s => s.Credentials)
            .Returns(new StorageCredentials());

            storageMock.Setup(s => s.CreateBlobClient(null))
            .Returns(blobClientMock.Object)
            .Verifiable();

            blobClientMock.Setup(b => b.GetServicePropertiesAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync((ServiceProperties)null);

            storageMock.Setup(s => s.CreateQueueClient(null))
            .Returns(queueClientMock.Object)
            .Verifiable();

            queueClientMock.Setup(q => q.GetQueueReference(It.IsAny <string>()))
            .Returns(queueMock.Object);

            queueMock.Setup(q => q.ExistsAsync(It.IsAny <CancellationToken>()))
            .Throws(new StorageException("", new WebException("Remote name could not be resolved", WebExceptionStatus.NameResolutionFailure)));

            storageMock.SetupSet(s => s.Type = StorageAccountType.BlobOnly);

            validator.ValidateCredentialsAsync(storageMock.Object, It.IsAny <CancellationToken>()).GetAwaiter().GetResult();

            storageMock.Verify();
        }
Exemplo n.º 3
0
        public void StorageAccount_IsDevStoreAccount_StorageEmulatorRunning(string connectionString)
        {
            var validator = new DefaultStorageCredentialsValidator();

            var storageMock     = new Mock <IStorageAccount>(MockBehavior.Strict);
            var blobClientMock  = new Mock <IStorageBlobClient>();
            var queueClientMock = new Mock <IStorageQueueClient>();
            var queueMock       = new Mock <IStorageQueue>();

            storageMock.Setup(s => s.Credentials)
            .Returns(new StorageCredentials("name", string.Empty));

            storageMock.Setup(s => s.CreateBlobClient(null))
            .Returns(blobClientMock.Object)
            .Verifiable();

            storageMock.Setup(s => s.SdkObject)
            .Returns(() => CloudStorageAccount.Parse(connectionString));

            blobClientMock.Setup(b => b.GetServicePropertiesAsync(It.IsAny <CancellationToken>()))
            .Throws(new StorageException(""));

            var exception = Assert.Throws <InvalidOperationException>(() => validator.ValidateCredentialsAsync(storageMock.Object, It.IsAny <CancellationToken>()).GetAwaiter().GetResult());

            Assert.Equal(Constants.CheckAzureStorageEmulatorMessage, exception.Message);
            storageMock.Verify();
        }
Exemplo n.º 4
0
        public void StorageAccount_QueueCheckThrowsUnexpectedStorage()
        {
            var validator = new DefaultStorageCredentialsValidator();

            var storageMock     = new Mock <IStorageAccount>(MockBehavior.Strict);
            var blobClientMock  = new Mock <IStorageBlobClient>();
            var queueClientMock = new Mock <IStorageQueueClient>();
            var queueMock       = new Mock <IStorageQueue>();

            storageMock.Setup(s => s.Credentials)
            .Returns(new StorageCredentials());

            storageMock.Setup(s => s.CreateBlobClient(null))
            .Returns(blobClientMock.Object)
            .Verifiable();

            blobClientMock.Setup(b => b.GetServicePropertiesAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync((ServiceProperties)null);

            storageMock.Setup(s => s.CreateQueueClient(null))
            .Returns(queueClientMock.Object)
            .Verifiable();

            queueClientMock.Setup(q => q.GetQueueReference(It.IsAny <string>()))
            .Returns(queueMock.Object);

            queueMock.Setup(q => q.ExistsAsync(It.IsAny <CancellationToken>()))
            .Throws(new StorageException("some other storage exception", null));

            var storageException = Assert.Throws <StorageException>(() => validator.ValidateCredentialsAsync(storageMock.Object, It.IsAny <CancellationToken>()).GetAwaiter().GetResult());

            Assert.Equal("some other storage exception", storageException.Message);
            storageMock.Verify();
        }
Exemplo n.º 5
0
        public void PrimaryStorageAccount_QueueCheckThrows()
        {
            var validator = new DefaultStorageCredentialsValidator();

            var storageMock     = new Mock <IStorageAccount>(MockBehavior.Strict);
            var blobClientMock  = new Mock <IStorageBlobClient>();
            var queueClientMock = new Mock <IStorageQueueClient>();
            var queueMock       = new Mock <IStorageQueue>();

            storageMock.Setup(s => s.Credentials)
            .Returns(new StorageCredentials());

            storageMock.Setup(s => s.CreateBlobClient(null))
            .Returns(blobClientMock.Object)
            .Verifiable();

            blobClientMock.Setup(b => b.GetServicePropertiesAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(null);

            storageMock.Setup(s => s.CreateQueueClient(null))
            .Returns(queueClientMock.Object)
            .Verifiable();

            queueClientMock.Setup(q => q.GetQueueReference(It.IsAny <string>()))
            .Returns(queueMock.Object);

            queueMock.Setup(q => q.ExistsAsync(It.IsAny <CancellationToken>()))
            .Throws(new StorageException("", new WebException("Remote name could not be resolved", WebExceptionStatus.NameResolutionFailure)));

            ExceptionAssert.ThrowsInvalidOperation(() => validator.ValidateCredentialsAsync(storageMock.Object, true, It.IsAny <CancellationToken>())
                                                   .GetAwaiter().GetResult(), "Invalid storage account ''. Primary storage accounts must be general purpose accounts and not restricted blob storage accounts."
                                                   );

            storageMock.Verify();
        }
Exemplo n.º 6
0
        public void PrimaryStorageAccount_AlreadySet_SkipVerification()
        {
            var validator = new DefaultStorageCredentialsValidator();

            var storageMock = new Mock <IStorageAccount>(MockBehavior.Strict);

            storageMock.Setup(s => s.Credentials)
            .Returns((StorageCredentials)null);

            validator.ValidateCredentialsAsync(storageMock.Object, true, It.IsAny <CancellationToken>()).GetAwaiter().GetResult();

            storageMock.Verify();
        }
Exemplo n.º 7
0
        public void SecondaryStorageAccount_NoQueueCheck()
        {
            var validator = new DefaultStorageCredentialsValidator();

            var storageMock    = new Mock <IStorageAccount>(MockBehavior.Strict);
            var blobClientMock = new Mock <IStorageBlobClient>();

            storageMock.Setup(s => s.Credentials)
            .Returns(new StorageCredentials());

            storageMock.Setup(s => s.CreateBlobClient(null))
            .Returns(blobClientMock.Object)
            .Verifiable();

            blobClientMock.Setup(b => b.GetServicePropertiesAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(null);

            validator.ValidateCredentialsAsync(storageMock.Object, false, It.IsAny <CancellationToken>()).GetAwaiter().GetResult();

            storageMock.Verify();
        }