Esempio n. 1
0
        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>());
        }
Esempio n. 2
0
        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);
            });
        }
Esempio n. 3
0
        public void GenerateResourcesAsyncWithConfigNullError(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 null configuration"
            .x(() => config.Should().BeNull());

            "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 <ArgumentNullException>().Which.ParamName.Should().Be("config"));
        }
Esempio n. 4
0
        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);
            });
        }