annotate src/Hosts/RazorEngine.Hosts.Console/Program.cs @ 3:91d78452a4a0 default tip

sync
author cin
date Thu, 12 Feb 2015 00:20:38 +0300
parents 5bca2d201ad8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5bca2d201ad8 initial commit
cin
parents:
diff changeset
1 namespace RazorEngine.Hosts.Console
5bca2d201ad8 initial commit
cin
parents:
diff changeset
2 {
5bca2d201ad8 initial commit
cin
parents:
diff changeset
3 using System;
5bca2d201ad8 initial commit
cin
parents:
diff changeset
4 using System.Linq;
5bca2d201ad8 initial commit
cin
parents:
diff changeset
5
5bca2d201ad8 initial commit
cin
parents:
diff changeset
6 using Compilation;
5bca2d201ad8 initial commit
cin
parents:
diff changeset
7 using Templating;
5bca2d201ad8 initial commit
cin
parents:
diff changeset
8
5bca2d201ad8 initial commit
cin
parents:
diff changeset
9 class Program
5bca2d201ad8 initial commit
cin
parents:
diff changeset
10 {
5bca2d201ad8 initial commit
cin
parents:
diff changeset
11 static void Main(string[] args)
5bca2d201ad8 initial commit
cin
parents:
diff changeset
12 {
5bca2d201ad8 initial commit
cin
parents:
diff changeset
13 CompilerServiceBuilder.SetCompilerServiceFactory(new DefaultCompilerServiceFactory());
5bca2d201ad8 initial commit
cin
parents:
diff changeset
14
5bca2d201ad8 initial commit
cin
parents:
diff changeset
15 using (var service = new TemplateService())
5bca2d201ad8 initial commit
cin
parents:
diff changeset
16 {
5bca2d201ad8 initial commit
cin
parents:
diff changeset
17 const string template = "<h1>Age: @Model.Age</h1>";
5bca2d201ad8 initial commit
cin
parents:
diff changeset
18 var expected = Enumerable.Range(1, 10).Select(i => string.Format("<h1>Age: {0}</h1>", i)).ToList();
5bca2d201ad8 initial commit
cin
parents:
diff changeset
19 var templates = Enumerable.Repeat(template, 10).ToList();
5bca2d201ad8 initial commit
cin
parents:
diff changeset
20 var models = Enumerable.Range(1, 10).Select(i => new Person { Age = i });
5bca2d201ad8 initial commit
cin
parents:
diff changeset
21
5bca2d201ad8 initial commit
cin
parents:
diff changeset
22 var results = service.ParseMany(templates, models, null, null, true).ToList();
5bca2d201ad8 initial commit
cin
parents:
diff changeset
23
5bca2d201ad8 initial commit
cin
parents:
diff changeset
24 for (int i = 0; i < 10; i++)
5bca2d201ad8 initial commit
cin
parents:
diff changeset
25 {
5bca2d201ad8 initial commit
cin
parents:
diff changeset
26 Console.WriteLine(templates[i]);
5bca2d201ad8 initial commit
cin
parents:
diff changeset
27 Console.WriteLine(expected[i]);
5bca2d201ad8 initial commit
cin
parents:
diff changeset
28 Console.WriteLine(results[i]);
5bca2d201ad8 initial commit
cin
parents:
diff changeset
29 }
5bca2d201ad8 initial commit
cin
parents:
diff changeset
30 }
5bca2d201ad8 initial commit
cin
parents:
diff changeset
31
5bca2d201ad8 initial commit
cin
parents:
diff changeset
32 Console.ReadKey();
5bca2d201ad8 initial commit
cin
parents:
diff changeset
33 }
5bca2d201ad8 initial commit
cin
parents:
diff changeset
34 }
5bca2d201ad8 initial commit
cin
parents:
diff changeset
35
5bca2d201ad8 initial commit
cin
parents:
diff changeset
36 /// <summary>
5bca2d201ad8 initial commit
cin
parents:
diff changeset
37 /// Defines a person.
5bca2d201ad8 initial commit
cin
parents:
diff changeset
38 /// </summary>
5bca2d201ad8 initial commit
cin
parents:
diff changeset
39 [Serializable]
5bca2d201ad8 initial commit
cin
parents:
diff changeset
40 public class Person
5bca2d201ad8 initial commit
cin
parents:
diff changeset
41 {
5bca2d201ad8 initial commit
cin
parents:
diff changeset
42 #region Properties
5bca2d201ad8 initial commit
cin
parents:
diff changeset
43 /// <summary>
5bca2d201ad8 initial commit
cin
parents:
diff changeset
44 /// Gets or sets the age.
5bca2d201ad8 initial commit
cin
parents:
diff changeset
45 /// </summary>
5bca2d201ad8 initial commit
cin
parents:
diff changeset
46 public int Age { get; set; }
5bca2d201ad8 initial commit
cin
parents:
diff changeset
47
5bca2d201ad8 initial commit
cin
parents:
diff changeset
48 /// <summary>
5bca2d201ad8 initial commit
cin
parents:
diff changeset
49 /// Gets or sets the forename.
5bca2d201ad8 initial commit
cin
parents:
diff changeset
50 /// </summary>
5bca2d201ad8 initial commit
cin
parents:
diff changeset
51 public string Forename { get; set; }
5bca2d201ad8 initial commit
cin
parents:
diff changeset
52
5bca2d201ad8 initial commit
cin
parents:
diff changeset
53 /// <summary>
5bca2d201ad8 initial commit
cin
parents:
diff changeset
54 /// Gets or sets the surname.
5bca2d201ad8 initial commit
cin
parents:
diff changeset
55 /// </summary>
5bca2d201ad8 initial commit
cin
parents:
diff changeset
56 public string Surname { get; set; }
5bca2d201ad8 initial commit
cin
parents:
diff changeset
57 #endregion
5bca2d201ad8 initial commit
cin
parents:
diff changeset
58 }
5bca2d201ad8 initial commit
cin
parents:
diff changeset
59 }