public void RenderConfigurationAsyncWithSuccess(IConfigurationRepository repository, ITemplateRenderer renderer, AzureIntegrationServicesModel model, string sourcePath, string targetPath, Exception e) { "Given a template renderer" .x(() => renderer = new LiquidTemplateRenderer(_mockLogger.Object)); "And a repository" .x(() => repository = new FileConfigurationRepository(renderer, _mockLogger.Object)); "And a model" .x(() => model = _model); "And a source path" .x(() => sourcePath = OkConfigPath); "And a target path" .x(() => targetPath = _tempOutputTemplatePath); "When getting the configuration" .x(async() => e = await Record.ExceptionAsync(async() => await repository.RenderConfigurationAsync(model, sourcePath, targetPath))); "Then the render should succeed" .x(() => e.Should().BeNull()); "And the output path should contain the configuration file with rendered content" .x(() => { var files = Directory.GetFiles(targetPath, "*"); files.Should().NotBeNull().And.HaveCount(1).And.ContainMatch("*aim-sample.yaml"); using var reader = new StreamReader(files.Single()); var content = reader.ReadToEnd(); content.Should().NotBeNull().And.ContainAny("Env: dev").And.NotContainAny("{{").And.NotContainAny("}}"); }); }
public void GenerateResourcesAsyncWithOperationCancelledError(IResourceGenerator generator, AzureIntegrationServicesModel model, IList <YamlStream> config, Exception e) { "Given a resource generator" .x(() => generator = new YamlResourceGenerator(_mockLogger.Object)); "And a model" .x(() => model = _model); "And configuration" .x(async() => { var renderer = new LiquidTemplateRenderer(_mockLogger.Object); var repository = new FileConfigurationRepository(renderer, _mockLogger.Object); await repository.RenderConfigurationAsync(model, OkMultiConfigPath, _tempOutputTemplatePath); config = repository.GetConfiguration(_tempOutputTemplatePath); }); "And a cancelled token" .x(() => _source.Cancel()); "When generating resources" .x(async() => e = await Record.ExceptionAsync(async() => await generator.GenerateResourcesAsync(model, config, _source.Token))); "Then the generation should error" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <OperationCanceledException>()); }
public void GetConfigurationWithPathNullError(IConfigurationRepository repository, IList <YamlStream> config, Exception e) { "Given a repository" .x(() => repository = new FileConfigurationRepository(_mockRenderer.Object, _mockLogger.Object)); "When getting the configuration with null path" .x(() => e = Record.Exception(() => config = repository.GetConfiguration(null))); "Then the get should error" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("path")); "And the config should be null" .x(() => config.Should().BeNull()); }
public void GetConfigurationWithPathNotFoundError(IConfigurationRepository repository, IList <YamlStream> config, Exception e) { "Given a repository" .x(() => repository = new FileConfigurationRepository(_mockRenderer.Object, _mockLogger.Object)); "When getting the configuration with a bad path" .x(() => e = Record.Exception(() => config = repository.GetConfiguration(@"A:\missing.yaml"))); "Then the get should error" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <DirectoryNotFoundException>()); "And the config should be null" .x(() => config.Should().BeNull()); }
public void GetBadConfigurationWithError(IConfigurationRepository repository, IList <YamlStream> config, Exception e) { "Given a repository" .x(() => repository = new FileConfigurationRepository(_mockRenderer.Object, _mockLogger.Object)); "When getting the configuration" .x(() => e = Record.Exception(() => config = repository.GetConfiguration(BadConfigPath))); "Then the get should error" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <SemanticErrorException>()); "And the config should be null" .x(() => config.Should().BeNull()); }
public void GetMultipleConfigurationWithSuccess(IConfigurationRepository repository, IList <YamlStream> config, Exception e) { "Given a repository" .x(() => repository = new FileConfigurationRepository(_mockRenderer.Object, _mockLogger.Object)); "When getting the configuration" .x(() => e = Record.Exception(() => config = repository.GetConfiguration(OkMultiConfigPath))); "Then the get should succeed" .x(() => e.Should().BeNull()); "And the config should contain 5 objects" .x(() => config.Should().NotBeNull().And.Subject.Should().HaveCount(5)); }
public void GenerateResourcesWithMultipleTargetsAsyncWithSuccess(IResourceGenerator generator, AzureIntegrationServicesModel model, IList <YamlStream> config, Exception e) { "Given a resource generator" .x(() => generator = new YamlResourceGenerator(_mockLogger.Object)); "And a model" .x(() => { model = _model; model.MigrationTarget.TargetEnvironment = AzureIntegrationServicesTargetEnvironment.Consumption; }); "And configuration" .x(async() => { var renderer = new LiquidTemplateRenderer(_mockLogger.Object); var repository = new FileConfigurationRepository(renderer, _mockLogger.Object); await repository.RenderConfigurationAsync(model, OkConfigPath, _tempOutputTemplatePath); config = repository.GetConfiguration(_tempOutputTemplatePath); }); "When generating resources" .x(async() => e = await Record.ExceptionAsync(async() => await generator.GenerateResourcesAsync(model, config, _source.Token))); "Then the generation should succeed" .x(() => e.Should().BeNull()); "And the model should have been populated with the template resources from the configuration" .x(() => { model.MigrationTarget.MessageBus.Resources.Should().HaveCount(10); var app = model.MigrationTarget.MessageBus.Applications.Where(a => a.Name == "AppA").SingleOrDefault(); app.Should().NotBeNull(); app.Resources.Should().HaveCount(2); var msg = app.Messages.SingleOrDefault(); msg.Should().NotBeNull(); msg.Resources.Should().HaveCount(1); }); "And the model should have been populated with the snippet resources from the configuration" .x(() => { var app = model.MigrationTarget.MessageBus.Applications.Where(a => a.Name == "AppA").SingleOrDefault(); app.Should().NotBeNull(); var processManagers = app.Intermediaries.Where(i => i is ProcessManager); processManagers.Should().NotBeNull().And.HaveCount(1); var processManager = processManagers.Single(); processManager.Snippets.Should().HaveCount(11); }); }
public void RenderConfigurationAsyncWithTargetPathNullError(IConfigurationRepository repository, AzureIntegrationServicesModel model, string sourcePath, string targetPath, Exception e) { "Given a repository" .x(() => repository = new FileConfigurationRepository(_mockRenderer.Object, _mockLogger.Object)); "And a model" .x(() => model = _model); "And a source path" .x(() => sourcePath = OkConfigPath); "And a null target path" .x(() => targetPath.Should().BeNull()); "When getting the configuration with null target path" .x(async() => e = await Record.ExceptionAsync(async() => await repository.RenderConfigurationAsync(model, sourcePath, targetPath))); "Then the render should error" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("targetPath")); }
public void GenerateResourcesAsyncWithMissingResourceMapKeyWithDebug(IResourceGenerator generator, AzureIntegrationServicesModel model, IList <YamlStream> config, Exception e) { "Given a resource generator" .x(() => generator = new YamlResourceGenerator(_mockLogger.Object)); "And a model with a missing application resource map key" .x(() => { model = _model; model.MigrationTarget.MessageBus.Applications.Where(a => a.Name == "System").Single().ResourceMapKey = null; }); "And configuration" .x(async() => { var renderer = new LiquidTemplateRenderer(_mockLogger.Object); var repository = new FileConfigurationRepository(renderer, _mockLogger.Object); await repository.RenderConfigurationAsync(model, OkMultiConfigPath, _tempOutputTemplatePath); config = repository.GetConfiguration(_tempOutputTemplatePath); }); "When generating resources" .x(async() => e = await Record.ExceptionAsync(async() => await generator.GenerateResourcesAsync(model, config, _source.Token))); "Then the generation should succeed" .x(() => e.Should().BeNull()); "And it should have issued a debug message" .x(() => { // Verify debug log message output once _mockLogger.Verify(l => l.Log( It.Is <LogLevel>(l => l == LogLevel.Debug), It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => v.ToString().Contains("is not associated with a resource map key", StringComparison.CurrentCultureIgnoreCase)), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once); }); }
public void RenderConfigurationAsyncWithModelNullError(IConfigurationRepository repository, AzureIntegrationServicesModel model, string sourcePath, string targetPath, Exception e) { "Given a repository" .x(() => repository = new FileConfigurationRepository(_mockRenderer.Object, _mockLogger.Object)); "And a null model" .x(() => model.Should().BeNull()); "And a source path" .x(() => sourcePath = OkConfigPath); "And a target path" .x(() => targetPath = _tempOutputTemplatePath); "When getting the configuration with null model" .x(async() => e = await Record.ExceptionAsync(async() => await repository.RenderConfigurationAsync(model, sourcePath, targetPath))); "Then the render should error" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("model")); "And the output path should be empty" .x(() => Directory.GetFiles(targetPath, "*").Should().HaveCount(0)); }