public void RenderTemplateAsyncWithResourceTemplateWithSuccess(ITemplateRenderer renderer, AzureIntegrationServicesModel model, MessagingObject messagingObject, TargetResourceTemplate resourceTemplate, string templateContent, string renderedContent, Exception e)
        {
            "Given a template renderer"
            .x(() => renderer = new LiquidTemplateRenderer(_mockLogger.Object));

            "And a model"
            .x(() => model = _model);

            "And a messaging object"
            .x(() => messagingObject = model.FindMessagingObject("ContosoMessageBus:System:FtpReceive").messagingObject);

            "And a resource template object"
            .x(() => resourceTemplate = new TargetResourceTemplate()
            {
                ResourceName = "endpointFtpReceiveLogicAppConsumption"
            });

            "And a template content"
            .x(() => templateContent = _templateResourceTemplateContent);

            "When rendering the template"
            .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderTemplateAsync(templateContent, model, null, resourceTemplate)));

            "Then the render should succeed"
            .x(() => e.Should().BeNull());

            "And the rendered content should have expected values from the model"
            .x(() =>
            {
                renderedContent.Should().NotBeNull().And.ContainAny("endpointFtpReceiveLogicAppConsumption").And.NotContainAny("{{").And.NotContainAny("}}");
            });
        }
Ejemplo n.º 2
0
        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 RenderTemplateAsyncWithIntermediaryWithSuccess(ITemplateRenderer renderer, AzureIntegrationServicesModel model, MessagingObject messagingObject, string templateContent, string renderedContent, Exception e)
        {
            "Given a template renderer"
            .x(() => renderer = new LiquidTemplateRenderer(_mockLogger.Object));

            "And a model"
            .x(() => model = _model);

            "And a messaging object"
            .x(() => messagingObject = model.FindMessagingObject("ContosoMessageBus:System:MessageAgent").messagingObject);

            "And a template content"
            .x(() => templateContent = _templateIntermediaryContent);

            "When rendering the template"
            .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderTemplateAsync(templateContent, model, messagingObject)));

            "Then the render should succeed"
            .x(() => e.Should().BeNull());

            "And the rendered content should have expected values from the model"
            .x(() =>
            {
                renderedContent.Should().NotBeNull().And.ContainAny("MessageAgent").And.NotContainAny("{{").And.NotContainAny("}}");
            });
        }
Ejemplo n.º 4
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>());
        }
Ejemplo n.º 5
0
        public string Execute()
        {
            var template = LiquidTemplateRenderer.LoadLiquidTemplate(TemplatePath);

            var generator = new LiquidTemplateRenderer();

            return(generator.Render(template, Data));
        }
        public void MigrationFileRenderStringTest()
        {
            var liquidTemplateRenderer = new LiquidTemplateRenderer();


            var templateContent = Templating.Templates.FluentMigrator.Resources.Template1;
            var expectedContent = Templating.Templates.FluentMigrator.Resources.Sample1;

            var content = liquidTemplateRenderer.Render(templateContent, sample1Model);

            Assert.AreEqual(expectedContent, content);
        }
Ejemplo n.º 7
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);
            });
        }
        public void RenderTemplateAsyncWithTemplateContentNullError(ITemplateRenderer renderer, AzureIntegrationServicesModel model, string templateContent, string renderedContent, Exception e)
        {
            "Given a template renderer"
            .x(() => renderer = new LiquidTemplateRenderer(_mockLogger.Object));

            "And a model"
            .x(() => model = _model);

            "And a null template content"
            .x(() => templateContent.Should().BeNull());

            "When rendering the template"
            .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderTemplateAsync(templateContent, model)));

            "Then the render should error"
            .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("templateContent"));

            "And the rendered content should not have a value"
            .x(() => renderedContent.Should().BeNull());
        }
Ejemplo n.º 9
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);
            });
        }
        public void RenderTemplateAsyncWithFunctionWithSuccess(ITemplateRenderer renderer, AzureIntegrationServicesModel model, string templateContent, string renderedContent, Exception e)
        {
            "Given a template renderer"
            .x(() => renderer = new LiquidTemplateRenderer(_mockLogger.Object));

            "And a model"
            .x(() => model = _model);

            "And a template content"
            .x(() => templateContent = _templateFunctionContent);

            "When rendering the template"
            .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderTemplateAsync(templateContent, model)));

            "Then the render should succeed"
            .x(() => e.Should().BeNull());

            "And the rendered content should have expected values from the model"
            .x(() =>
            {
                renderedContent.Should().NotBeNull().And.Be("messageBox").And.NotContainAny("{{").And.NotContainAny("}}");
            });
        }
        public LiquidTemplateRendererUnitTests()
        {
            _translationServiceMock = new Mock <ITranslationService>();
            _blobUrlResolverMock    = new Mock <IBlobUrlResolver>();
            _liquidTemplateRenderer = new LiquidTemplateRenderer(Options.Create(new LiquidRenderOptions()
            {
                CustomFilterTypes = new HashSet <Type> {
                    typeof(UrlFilters), typeof(TranslationFilter)
                }
            }));

            //TODO
            if (!AbstractTypeFactory <NotificationScriptObject> .AllTypeInfos.SelectMany(x => x.AllSubclasses).Contains(typeof(NotificationScriptObject)))
            {
                AbstractTypeFactory <NotificationScriptObject> .RegisterType <NotificationScriptObject>()
                .WithFactory(() => new NotificationScriptObject(_translationServiceMock.Object, _blobUrlResolverMock.Object));
            }
            else
            {
                AbstractTypeFactory <NotificationScriptObject> .OverrideType <NotificationScriptObject, NotificationScriptObject>()
                .WithFactory(() => new NotificationScriptObject(_translationServiceMock.Object, _blobUrlResolverMock.Object));
            }
        }
        public void MigrationFileRenderStreamTest()
        {
            var liquidTemplateRenderer = new LiquidTemplateRenderer();

            var    templateContent = Templating.Templates.FluentMigrator.Resources.Template1;
            var    expectedContent = Templating.Templates.FluentMigrator.Resources.Sample1;
            string content         = null;

            using (var output = new MemoryStream())
            {
                liquidTemplateRenderer.Render(templateContent, sample1Model);
                output.Seek(0, SeekOrigin.Begin);

                using (var streamReader = new StreamReader(output, true))
                {
                    content = streamReader.ReadToEnd();
                }
            }

            content = liquidTemplateRenderer.Render(templateContent, sample1Model);

            Assert.AreEqual(expectedContent, content);
        }
        public void RenderTemplateAsyncWithMissingMessagingObjectWithWarning(ITemplateRenderer renderer, AzureIntegrationServicesModel model, MessagingObject messagingObject, string templateContent, string renderedContent, Exception e)
        {
            "Given a template renderer"
            .x(() => renderer = new LiquidTemplateRenderer(_mockLogger.Object));

            "And a model"
            .x(() => model = _model);

            "And a missing messaging object"
            .x(() => messagingObject = new TopicChannel("MissingChannel")
            {
                Key = "MessageBus:MissingApp:MissingChannel"
            });

            "And a template content"
            .x(() => templateContent = _templateChannelContent);

            "When rendering the template"
            .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderTemplateAsync(templateContent, model, messagingObject)));

            "Then the render should succeed"
            .x(() => e.Should().BeNull());

            "And the rendered content should not have expected values from the model"
            .x(() =>
            {
                renderedContent.Should().NotBeNull().And.Be("").And.NotContainAny("{{").And.NotContainAny("}}");

                // Verify warning was raised
                _mockLogger.Verify(l => l.Log(
                                       It.Is <LogLevel>(l => l == LogLevel.Warning),
                                       It.IsAny <EventId>(),
                                       It.Is <It.IsAnyType>((v, t) => v.ToString().Contains("does not appear in the target model", StringComparison.CurrentCultureIgnoreCase)),
                                       It.IsAny <Exception>(),
                                       It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once);
            });
        }