public void ConnectionStringProvider_NoDashboardConnectionString_Throws() { const string DashboardConnectionEnvironmentVariable = "AzureWebJobsDashboard"; string previousConnectionString = Environment.GetEnvironmentVariable(DashboardConnectionEnvironmentVariable); try { Environment.SetEnvironmentVariable(DashboardConnectionEnvironmentVariable, null); Mock <IServiceProvider> mockServices = new Mock <IServiceProvider>(MockBehavior.Strict); IStorageAccountProvider product = new DefaultStorageAccountProvider(mockServices.Object) { StorageConnectionString = new CloudStorageAccount(new StorageCredentials("Test", new byte[0], "key"), true).ToString(exportSecrets: true) }; // Act & Assert ExceptionAssert.ThrowsInvalidOperation(() => product.GetDashboardAccountAsync(CancellationToken.None).GetAwaiter().GetResult(), "Microsoft Azure WebJobs SDK Dashboard connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways:" + Environment.NewLine + "1. Set the connection string named 'AzureWebJobsDashboard' in the connectionStrings section of the .config file in the following format " + "<add name=\"AzureWebJobsDashboard\" connectionString=\"DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY\" />, or" + Environment.NewLine + "2. Set the environment variable named 'AzureWebJobsDashboard', or" + Environment.NewLine + "3. Set corresponding property of JobHostConfiguration."); } finally { Environment.SetEnvironmentVariable(DashboardConnectionEnvironmentVariable, previousConnectionString); } }
public void ConnectionStringProvider_NoDashboardConnectionString_Throws() { var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { { "Dashboard", null } }) .Build(); IStorageAccountProvider product = new DefaultStorageAccountProvider(new AmbientConnectionStringProvider(configuration), new StorageAccountParser(new StorageClientFactory()), new DefaultStorageCredentialsValidator()) { StorageConnectionString = new CloudStorageAccount(new StorageCredentials("Test", string.Empty, "key"), true).ToString(exportSecrets: true) }; // Act & Assert ExceptionAssert.ThrowsInvalidOperation(() => product.GetDashboardAccountAsync(CancellationToken.None).GetAwaiter().GetResult(), "Microsoft Azure WebJobs SDK 'Dashboard' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways:" + Environment.NewLine + "1. Set the connection string named 'AzureWebJobsDashboard' in the connectionStrings section of the .config file in the following format " + "<add name=\"AzureWebJobsDashboard\" connectionString=\"DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY\" />, or" + Environment.NewLine + "2. Set the environment variable named 'AzureWebJobsDashboard', or" + Environment.NewLine + "3. Set corresponding property of JobHostConfiguration."); }
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); }