Пример #1
0
        internal DefaultStorageAccountProvider(IServiceProvider services, IConnectionStringProvider ambientConnectionStringProvider,
                                               IStorageAccountParser storageAccountParser, IStorageCredentialsValidator storageCredentialsValidator)
        {
            if (services == null)
            {
                throw new ArgumentNullException("services");
            }

            if (ambientConnectionStringProvider == null)
            {
                throw new ArgumentNullException("ambientConnectionStringProvider");
            }

            if (storageAccountParser == null)
            {
                throw new ArgumentNullException("storageAccountParser");
            }

            if (storageCredentialsValidator == null)
            {
                throw new ArgumentNullException("storageCredentialsValidator");
            }

            _services = services;
            _ambientConnectionStringProvider = ambientConnectionStringProvider;
            _storageCredentialsValidator     = storageCredentialsValidator;
            _storageAccountParser            = storageAccountParser;
        }
        internal DefaultStorageAccountProvider(IServiceProvider services, IConnectionStringProvider ambientConnectionStringProvider, 
            IStorageAccountParser storageAccountParser, IStorageCredentialsValidator storageCredentialsValidator)
        {
            if (services == null)
            {
                throw new ArgumentNullException("services");
            }

            if (ambientConnectionStringProvider == null)
            {
                throw new ArgumentNullException("ambientConnectionStringProvider");
            }

            if (storageAccountParser == null)
            {
                throw new ArgumentNullException("storageAccountParser");
            }

            if (storageCredentialsValidator == null)
            {
                throw new ArgumentNullException("storageCredentialsValidator");
            }

            _services = services;
            _ambientConnectionStringProvider = ambientConnectionStringProvider;
            _storageCredentialsValidator = storageCredentialsValidator;
            _storageAccountParser = storageAccountParser;
        }
 private static DefaultStorageAccountProvider CreateProductUnderTest(
     IConnectionStringProvider ambientConnectionStringProvider, IStorageAccountParser storageAccountParser,
     IStorageCredentialsValidator storageCredentialsValidator)
 {
     return(new DefaultStorageAccountProvider(ambientConnectionStringProvider, storageAccountParser,
                                              storageCredentialsValidator));
 }
Пример #4
0
        public void GetAccountAsync_WhenDashboardOverridden_ReturnsParsedAccount()
        {
            IConnectionStringProvider connectionStringProvider = CreateDummyConnectionStringProvider();
            string                        connectionString     = "valid-ignore";
            IStorageAccount               parsedAccount        = Mock.Of <IStorageAccount>();
            IServiceProvider              services             = CreateServices();
            IStorageAccountParser         parser    = CreateParser(services, ConnectionStringNames.Dashboard, connectionString, parsedAccount);
            IStorageCredentialsValidator  validator = CreateValidator(parsedAccount);
            DefaultStorageAccountProvider provider  = CreateProductUnderTest(services, connectionStringProvider, parser, validator);

            provider.DashboardConnectionString = connectionString;
            IStorageAccount actualAccount = provider.GetAccountAsync(
                ConnectionStringNames.Dashboard, CancellationToken.None).GetAwaiter().GetResult();

            Assert.Same(parsedAccount, actualAccount);
        }
        public async Task GetAccountAsync_WhenWebJobsDashboardAccountNotGeneral_Throws()
        {
            string connectionString = "valid-ignore";
            var    connStringMock   = new Mock <IConnectionStringProvider>();

            connStringMock.Setup(c => c.GetConnectionString(ConnectionStringNames.Dashboard)).Returns(connectionString);
            var connectionStringProvider = connStringMock.Object;
            var accountMock = new Mock <IStorageAccount>();

            accountMock.SetupGet(s => s.Type).Returns(StorageAccountType.Premium);
            accountMock.SetupGet(s => s.Credentials).Returns(new StorageCredentials("name", string.Empty));
            var parsedAccount = accountMock.Object;
            IServiceProvider              services  = CreateServices();
            IStorageAccountParser         parser    = CreateParser(services, ConnectionStringNames.Dashboard, connectionString, parsedAccount);
            IStorageCredentialsValidator  validator = CreateValidator(parsedAccount);
            DefaultStorageAccountProvider provider  = CreateProductUnderTest(services, connectionStringProvider, parser, validator);
            var exception = await Assert.ThrowsAsync <InvalidOperationException>(() => provider.GetDashboardAccountAsync(CancellationToken.None));

            Assert.Equal("Storage account 'name' is of unsupported type 'Premium'. Supported types are 'General Purpose'", exception.Message);
        }
Пример #6
0
        public void GetAccountAsync_WhenInvalidCredentials_PropagatesValidatorException(string connectionStringName)
        {
            string                              connectionString         = "invalid-ignore";
            IStorageAccount                     parsedAccount            = Mock.Of <IStorageAccount>();
            Exception                           expectedException        = new InvalidOperationException();
            IConnectionStringProvider           connectionStringProvider = CreateConnectionStringProvider(connectionStringName, connectionString);
            IServiceProvider                    services      = CreateServices();
            IStorageAccountParser               parser        = CreateParser(services, connectionStringName, connectionString, parsedAccount);
            Mock <IStorageCredentialsValidator> validatorMock = new Mock <IStorageCredentialsValidator>(
                MockBehavior.Strict);

            validatorMock.Setup(v => v.ValidateCredentialsAsync(parsedAccount, It.IsAny <CancellationToken>()))
            .Throws(expectedException);
            IStorageCredentialsValidator validator = validatorMock.Object;
            IStorageAccountProvider      provider  = CreateProductUnderTest(services, connectionStringProvider, parser, validator);

            Exception actualException = Assert.Throws <InvalidOperationException>(
                () => provider.GetAccountAsync(connectionStringName, CancellationToken.None).GetAwaiter().GetResult());

            Assert.Same(expectedException, actualException);
        }
Пример #7
0
        public void GetAccountAsync_WhenReadFromConfig_ReturnsParsedAccount(string connectionStringName)
        {
            string          connectionString = "valid-ignore";
            IStorageAccount parsedAccount    = Mock.Of <IStorageAccount>();

            Mock <IConnectionStringProvider> connectionStringProviderMock = new Mock <IConnectionStringProvider>(MockBehavior.Strict);

            connectionStringProviderMock.Setup(p => p.GetConnectionString(connectionStringName))
            .Returns(connectionString)
            .Verifiable();
            IConnectionStringProvider connectionStringProvider = connectionStringProviderMock.Object;

            Mock <IStorageAccountParser> parserMock = new Mock <IStorageAccountParser>(MockBehavior.Strict);
            IServiceProvider             services   = CreateServices();

            parserMock.Setup(p => p.ParseAccount(connectionString, connectionStringName, services))
            .Returns(parsedAccount)
            .Verifiable();
            IStorageAccountParser parser = parserMock.Object;

            Mock <IStorageCredentialsValidator> validatorMock = new Mock <IStorageCredentialsValidator>(
                MockBehavior.Strict);

            validatorMock.Setup(v => v.ValidateCredentialsAsync(parsedAccount, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(0))
            .Verifiable();
            IStorageCredentialsValidator validator = validatorMock.Object;

            IStorageAccountProvider provider = CreateProductUnderTest(services, connectionStringProvider, parser, validator);

            IStorageAccount actualAccount = provider.GetAccountAsync(
                connectionStringName, CancellationToken.None).GetAwaiter().GetResult();

            Assert.Same(parsedAccount, actualAccount);
            connectionStringProviderMock.Verify();
            parserMock.Verify();
            validatorMock.Verify();
        }
 private static DefaultStorageAccountProvider CreateProductUnderTest(IServiceProvider services,
     IConnectionStringProvider ambientConnectionStringProvider, IStorageAccountParser storageAccountParser,
     IStorageCredentialsValidator storageCredentialsValidator)
 {
     return new DefaultStorageAccountProvider(services, ambientConnectionStringProvider, storageAccountParser, storageCredentialsValidator);
 }