public async Task ListCheckpointsAsync_LogsOnInvalidCheckpoints() { var testLoggerProvider = new TestLoggerProvider(); Mock <BlobContainerClient> containerClientMock = new Mock <BlobContainerClient>(MockBehavior.Strict); containerClientMock.Setup(c => c.GetBlobsAsync(It.IsAny <BlobTraits>(), It.IsAny <BlobStates>(), It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns(AsyncPageable <BlobItem> .FromPages(new[] { Page <BlobItem> .FromValues(new[] { BlobsModelFactory.BlobItem("testnamespace/testeventhubname/testconsumergroup/checkpoint/0", false, BlobsModelFactory.BlobItemProperties(false), metadata: new Dictionary <string, string>()) }, null, Mock.Of <Response>()) })); BlobsCheckpointStore store = new BlobsCheckpointStore( containerClientMock.Object, new BasicRetryPolicy(new EventHubsRetryOptions()), _functionId, testLoggerProvider.CreateLogger("TestLogger") ); await store.ListCheckpointsAsync(_namespace, _eventHubName, _consumerGroup, CancellationToken.None); var warning = testLoggerProvider.GetAllLogMessages().Single(p => p.Level == Extensions.Logging.LogLevel.Warning); var expectedWarning = "Function 'EventHubsTriggerFunction': An invalid checkpoint was found for partition: '0' of " + "FullyQualifiedNamespace: 'TestNamespace'; EventHubName: 'TestEventHubName'; ConsumerGroup: 'TestConsumerGroup'. " + "This checkpoint is not valid and will be ignored."; Assert.AreEqual(expectedWarning, warning.FormattedMessage); testLoggerProvider.ClearAllLogMessages(); }
public TimerScheduleTests() { _loggerProvider = new TestLoggerProvider(); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(_loggerProvider); _logger = _loggerProvider.CreateLogger("Test"); }
public TimerTriggerBindingTests() { _loggerProvider = new TestLoggerProvider(); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(_loggerProvider); _logger = _loggerProvider.CreateLogger("Test"); }
public RpcFunctionInvocationDispatcherTests() { _testLoggerProvider = new TestLoggerProvider(); _testLoggerFactory = new LoggerFactory(); _testLoggerFactory.AddProvider(_testLoggerProvider); _testLogger = _testLoggerProvider.CreateLogger("FunctionDispatcherTests"); }
public EndToEndTestBase() { var filterOptions = new LoggerFilterOptions { MinLevel = LogLevel.Trace }; _testLoggerProvider = new TestLoggerProvider(); //_loggerFactory.AddProvider(); _logger = _testLoggerProvider.CreateLogger("EndToEndTests"); }
public SecretManagerTests() { _testEnvironment = new TestEnvironment(); _testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName, "test.azurewebsites.net"); _loggerProvider = new TestLoggerProvider(); var loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(_loggerProvider); _logger = _loggerProvider.CreateLogger(LogCategories.CreateFunctionCategory("test")); _hostNameProvider = new HostNameProvider(_testEnvironment); }
public void GetCheckpointsAsync_LogsOnRequestErrors() { var testLoggerProvider = new TestLoggerProvider(); Mock <BlobContainerClient> containerClientMock = new Mock <BlobContainerClient>(MockBehavior.Strict); containerClientMock.Setup(c => c.GetBlobClient(It.IsAny <string>())) .Throws(new RequestFailedException("Uh oh")); BlobCheckpointStoreInternal store = new BlobCheckpointStoreInternal( containerClientMock.Object, _functionId, testLoggerProvider.CreateLogger("TestLogger") ); Assert.ThrowsAsync <RequestFailedException>(async() => await store.GetCheckpointAsync(_namespace, _eventHubName, _consumerGroup, _partitionId, CancellationToken.None)); var warning = testLoggerProvider.GetAllLogMessages().Single(p => p.Level == LogLevel.Warning); var expectedWarning = "Function 'EventHubsTriggerFunction': An exception occurred when retrieving a checkpoint for " + "FullyQualifiedNamespace: 'TestNamespace'; EventHubName: 'TestEventHubName'; ConsumerGroup: 'TestConsumerGroup'; PartitionId: '0'."; Assert.AreEqual(expectedWarning, warning.FormattedMessage); testLoggerProvider.ClearAllLogMessages(); }
public void ListCheckpointsAsync_LogsOnRequestErrors() { var testLoggerProvider = new TestLoggerProvider(); Mock <BlobContainerClient> containerClientMock = new Mock <BlobContainerClient>(MockBehavior.Strict); containerClientMock.Setup(c => c.GetBlobsAsync(It.IsAny <BlobTraits>(), It.IsAny <BlobStates>(), It.IsAny <string>(), It.IsAny <CancellationToken>())) .Throws(new RequestFailedException("Uh oh")); BlobsCheckpointStore store = new BlobsCheckpointStore( containerClientMock.Object, new BasicRetryPolicy(new EventHubsRetryOptions()), _functionId, testLoggerProvider.CreateLogger("TestLogger") ); Assert.ThrowsAsync <RequestFailedException>(async() => await store.ListCheckpointsAsync(_namespace, _eventHubName, _consumerGroup, CancellationToken.None)); var warning = testLoggerProvider.GetAllLogMessages().Single(p => p.Level == Extensions.Logging.LogLevel.Warning); var expectedWarning = "Function 'EventHubsTriggerFunction': An exception occurred when listing checkpoints for " + "FullyQualifiedNamespace: 'TestNamespace'; EventHubName: 'TestEventHubName'; ConsumerGroup: 'TestConsumerGroup'."; Assert.AreEqual(expectedWarning, warning.FormattedMessage); testLoggerProvider.ClearAllLogMessages(); }
public async Task SecretMigrate_Conflict() { using (var directory = new TempDirectory()) { try { await _fixture.TestInitialize(SecretsRepositoryType.FileSystem, directory.Path); var loggerProvider = new TestLoggerProvider(); var fileRepo = _fixture.GetFileSystemSecretsRepository(); string hostContent = Guid.NewGuid().ToString(); string functionContent = Guid.NewGuid().ToString(); await fileRepo.WriteAsync(ScriptSecretsType.Host, "host", hostContent); await fileRepo.WriteAsync(ScriptSecretsType.Function, "test1", functionContent); _settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsiteSlotName, "Production"); _settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsiteName, "test-app"); var blobRepo = _fixture.GetBlobStorageRepository(); await blobRepo.WriteAsync(ScriptSecretsType.Host, "host", hostContent); await blobRepo.WriteAsync(ScriptSecretsType.Function, "test1", functionContent); var blobRepoMigration = _fixture.GetBlobStorageSecretsMigrationRepository(loggerProvider.CreateLogger(ScriptConstants.LogCategoryMigration)); await blobRepoMigration.ReadAsync(ScriptSecretsType.Host, "host"); var logs = loggerProvider.GetAllLogMessages().ToArray(); Assert.Contains("Conflict detected", loggerProvider.GetAllLogMessages().ToList().Last().FormattedMessage); } finally { _settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsiteSlotName, null); _settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsiteName, null); } } }
public async Task SecretMigrate_Successful() { using (var directory = new TempDirectory()) { try { await _fixture.TestInitialize(SecretsRepositoryType.FileSystem, directory.Path); var loggerProvider = new TestLoggerProvider(); var fileRepo = _fixture.GetFileSystemSecretsRepository(); string hostContent = Guid.NewGuid().ToString(); string functionContent = Guid.NewGuid().ToString(); await fileRepo.WriteAsync(ScriptSecretsType.Host, "host", hostContent); await fileRepo.WriteAsync(ScriptSecretsType.Function, "test1", functionContent); _settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsiteSlotName, "Production"); _settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsiteName, "test-app"); var blobRepoMigration = _fixture.GetBlobStorageSecretsMigrationRepository(loggerProvider.CreateLogger(ScriptConstants.LogCategoryMigration)); await blobRepoMigration.ReadAsync(ScriptSecretsType.Host, "host"); var logs = loggerProvider.GetAllLogMessages().ToArray(); Assert.Contains(logs[logs.Length - 1].FormattedMessage, "Finished successfully."); string hostContentFromBlob = await blobRepoMigration.ReadAsync(ScriptSecretsType.Host, ""); Assert.Equal(hostContent, hostContentFromBlob); string hostContentFromFunction = await blobRepoMigration.ReadAsync(ScriptSecretsType.Function, "test1"); Assert.Equal(functionContent, hostContentFromFunction); var blobRepoMigration2 = _fixture.GetBlobStorageSecretsMigrationRepository(loggerProvider.CreateLogger("")); await blobRepoMigration2.ReadAsync(ScriptSecretsType.Host, "host"); logs = loggerProvider.GetAllLogMessages().ToArray(); Assert.Contains(logs[logs.Length - 1].FormattedMessage, "Sentinel file is detected."); } finally { _settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsiteSlotName, null); _settingsManager.SetSetting(EnvironmentSettingNames.AzureWebsiteName, null); } } }