main
 1using System.Collections.Generic;
 2using System.Text;
 3using Spec.Dox.Domain;
 4
 5namespace Spec.Dox.Presentation.Views
 6{
 7    public interface IHtmlReport
 8    {
 9        void Add(ITestContext context, IEnumerable<ITestSpecification> specifications);
10        void publish_to_same_folder_as(string test_assembly_path);
11    }
12
13    public class HtmlReport : IHtmlReport
14    {
15        readonly IReportPublisher publisher;
16        readonly StringBuilder builder;
17
18        public HtmlReport() : this(new ReportPublisher()) {}
19
20        public HtmlReport(IReportPublisher publisher)
21        {
22            this.publisher = publisher;
23            builder = new StringBuilder();
24            builder.Append("<html><head><title>Specifications Document</title></head><body>");
25        }
26
27        public void Add(ITestContext context, IEnumerable<ITestSpecification> specifications)
28        {
29            builder.AppendFormat("<h1>{0}</h1>", context.Name.Replace("_", " "));
30            builder.Append("<ul>");
31            foreach (var specification in specifications)
32            {
33                builder.AppendFormat("<li>{0}</li>", specification.Name.Replace("_", " "));
34            }
35            builder.Append("</ul>");
36        }
37
38        public void publish_to_same_folder_as(string test_assembly_path)
39        {
40            builder.Append("</body></html>");
41            publisher.Publish(builder.ToString(), test_assembly_path);
42        }
43    }
44}