public void RegisterType_DuplicateType_Ignored()
        {
            List <Type> expectedTypes = new List <Type>()
            {
                typeof(Person),
            };

            LiquidTemplate target = new LiquidTemplate();

            target.RegisterType(typeof(Person));
            target.RegisterType(typeof(Person)); // duplicate

            CollectionAssert.AreEquivalent(expectedTypes, target.RegisteredTypes.ToList());
        }
示例#2
0
        /// <summary>
        /// Generates resumes from the provided JSON file.
        /// </summary>
        /// <param name="resumeJsonPath">The path to the JSON document containing the resume data.</param>
        /// <param name="outputPath">The output path to save the generated resumes to.</param>
        /// <remarks>Overwrites the output if the files already exist.</remarks>
        public void GenerateResume(string resumeJsonPath, string outputPath)
        {
            // The resume template is not provided; so create and use the default template.
            string    templateText = Assembly.GetExecutingAssembly().ReadResourceFile(DefaultMarkdownTemplateName);
            ITemplate template     = new LiquidTemplate(templateText);

            // Register the model types with the template.
            template.RegisterType(typeof(Resume));
            template.RegisterType(typeof(EducationProgram));
            template.RegisterType(typeof(Job));
            template.RegisterType(typeof(Skill));
            template.RegisterType(typeof(Address));

            // Generate the resume with the default template.
            this.GenerateResume(resumeJsonPath, outputPath, template);
        }
        public void RegisterType_Nullype_Throws()
        {
            Type type = null;

            try
            {
                LiquidTemplate target = new LiquidTemplate();
                target.RegisterType(type);
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("type", ex.ParamName);
                throw;
            }
        }
        public void Render_NullContext_Throws()
        {
            string template = "Hello {{ p.Firstname }} {{ p.Lastname }}";

            try
            {
                LiquidTemplate target = new LiquidTemplate(template);
                target.RegisterType(typeof(Person));
                target.Render(null);
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("context", ex.ParamName);
                throw;
            }
        }
        public void RegisterType_ValidType_Success()
        {
            List <Type> expectedTypes = new List <Type>()
            {
                typeof(string),
                typeof(Person),
            };

            LiquidTemplate target = new LiquidTemplate();

            foreach (Type type in expectedTypes)
            {
                target.RegisterType(type);
            }

            CollectionAssert.AreEquivalent(expectedTypes, target.RegisteredTypes.ToList());
        }
        public void Render_EmptyTemplateValidContext_EmptyReturned()
        {
            string template = string.Empty;

            Person model = new Person()
            {
                Firstname = "Jim",
                Lastname  = "Bob",
            };
            TemplateContext context = new TemplateContext("p", model);

            LiquidTemplate target = new LiquidTemplate(template);

            target.RegisterType(typeof(Person));
            string result = target.Render(context);

            Assert.AreEqual(string.Empty, result);
        }
        public void Render_ValidContext_Success()
        {
            // TODO: Setup the test to cover all features of liquid templates.
            string template = "Hello {{ p.Firstname }} {{ p.Lastname }}";

            Person model = new Person()
            {
                Firstname = "Jim",
                Lastname  = "Bob",
            };
            TemplateContext context = new TemplateContext("p", model);

            LiquidTemplate target = new LiquidTemplate(template);

            target.RegisterType(typeof(Person));
            string result = target.Render(context);

            Assert.AreEqual("Hello Jim Bob", result);
        }
        public void Render_TemplateNotSet_Throws()
        {
            Person model = new Person()
            {
                Firstname = "Jim",
                Lastname  = "Bob",
            };
            TemplateContext context = new TemplateContext("p", model);

            try
            {
                LiquidTemplate target = new LiquidTemplate();
                target.RegisterType(typeof(Person));
                target.Render(context);
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual("The template has not been parsed.", ex.Message);
                throw;
            }
        }