示例#1
0
        public void CanUpdateCodeTemplate()
        {
            var template = new CodeTemplate("DomainAggregateRoot", "Entity");

            template.Update("Hello {{name}}!");

            Assert.AreEqual("DomainAggregateRoot", template.Name);
            Assert.AreEqual("Entity", template.SourceType);
            Assert.AreEqual("Hello {{name}}!", template.Value);
        }
示例#2
0
        public async Task CanGenerateCodeFromTemplate()
        {
            // Create mock repository
            var repository = new Mock <IRepository <CodeTemplate> >();

            // Create template and assign it a value
            var template = new CodeTemplate("WelcomeTemplate", "Dummy");

            template.Update(@"Welcome {{name}}!");

            repository.Setup(r => r.GetByIdAsync(It.IsAny <Guid>())).Returns(Task.FromResult(template));

            // Create service using mock repository and handlebars template engine
            var service = new CodeGenerator(repository.Object, new HandlebarsTemplateEngine());

            // Generate the code
            var result = await service.Generate(Guid.NewGuid(), new { name = "Pieter" });

            Assert.AreEqual("Welcome Pieter!", result);
        }