Exemplo n.º 1
0
        public void Render_FullName10000Times_InUnderHalfSecond()
        {
            int occurances = 10000;

            string templateText = "{{FullName}}";
            var template = BuildTemplate(occurances, templateText);
            var message = new WelcomeMessage() { FullName = "Devon" };

            var content = new TemplateRenderer<WelcomeMessage>(template);
            var before = DateTime.Now.Ticks;

            var text = content.Render(message);

            var after = DateTime.Now.Ticks;
            var elapsedSpan = new TimeSpan(after - before);

            Assert.True(elapsedSpan.TotalSeconds < 0.5);
        }
Exemplo n.º 2
0
        public void Render_FourMergeOptions2500Times_InUnderHalfSecond()
        {
            int occurances = 2500;

            string templateText = "Hello {{FullName}} from {{Address.StreetNumber}} {{Address.StreetName}}! on {{JoinDate}}";
            var template = BuildTemplate(occurances, templateText);

            DateTime date = DateTime.Parse("2014-08-30");
            var message = new WelcomeMessage(){ FullName = "Devon", JoinDate = date, Address = new Address{ StreetNumber = 5, StreetName = "Main"} };

            var content = new TemplateRenderer<WelcomeMessage>(template);

            var before = DateTime.Now.Ticks;

            var text = content.Render(message);

            var after = DateTime.Now.Ticks;
            var elapsedSpan = new TimeSpan(after - before);

            Assert.True(elapsedSpan.TotalSeconds < 0.5);
        }
Exemplo n.º 3
0
        public void Render_TemplateWithDate_TransformsNestedProperties()
        {
            string myFormat = "yyyy-MM-dd";
            DateTime date = DateTime.Parse("2014-08-30");
            var message = new WelcomeMessage(){ FullName = "Devon", JoinDate = date, Address = new Address{ StreetNumber = 5, StreetName = "Main"} };
            var template = new Template<WelcomeMessage>("Hello {{FullName}} from {{Address.StreetNumber}} {{Address.StreetName}}! on {{JoinDate}}");
            var content = new TemplateRenderer<WelcomeMessage>(template)
            {
                RenderSettings = new RenderSettings
                {
                    DateTimeFormat = myFormat
                }
            };
            var text = content.Render(message);

            Assert.Contains("Hello Devon from 5 Main! on ", text);
            Assert.Contains("on 2014-08-30", text);
        }
Exemplo n.º 4
0
        public void Render_WithX_ReturnsString()
        {
            var message = new WelcomeMessage(){ FullName = "Devon" };
            var template = new Template<WelcomeMessage>("Hello {{FullName}}!");
            var content = new TemplateRenderer<WelcomeMessage>(template);
            var text = content.Render(message);

            Assert.False(string.IsNullOrEmpty(text));
        }
Exemplo n.º 5
0
        public void Render_WithNullProperty_ReturnsEmptyString()
        {
            var message = new WelcomeMessage(){ FullName = null };
            var template = new Template<WelcomeMessage>("Hello {{FullName}}!");
            var content = new TemplateRenderer<WelcomeMessage>(template);
            var text = content.Render(message);

            Assert.Contains("Hello !", text);
        }
Exemplo n.º 6
0
        public void Render_WithHelloWorldTemplate_ReturnsHelloDevon()
        {
            var message = new WelcomeMessage(){ FullName = "Devon" };
            var template = new Template<WelcomeMessage>("Hello {{FullName}}!");
            var content = new TemplateRenderer<WelcomeMessage>(template);
            var text = content.Render(message);

            Assert.Equal("Hello Devon!", text);
        }
Exemplo n.º 7
0
        public void Render_UsingNonGeneric_ReplacesValues()
        {
            string templateText = "Hello {{FullName}} from {{Address.StreetNumber}} {{Address.StreetName}}! on {{JoinDate}}";
            ITemplate template = BuildTemplate(1, templateText);

            var templateContent = new TemplateContent(template);
            var message = new WelcomeMessage(){ FullName = "Devon", Address = new Address{ StreetName = "Main"} };

            var text = templateContent.Render(message);

            Assert.Contains("Devon", text);
        }
Exemplo n.º 8
0
        public void Render_TemplateWithNavigationalProperties_TransformsNestedProperties()
        {
            var message = new WelcomeMessage(){ FullName = "Devon", Address = new Address{ StreetName = "Main"} };
            var template = new Template<WelcomeMessage>("Hello {{FullName}} from {{Address.StreetName}}!");
            var content = new TemplateRenderer<WelcomeMessage>(template);
            var text = content.Render(message);

            Assert.Contains("Main", text);
        }