Permalink
Browse files

Added dotnet HtmlReport and Test

  • Loading branch information...
1 parent b5e468c commit eb8e4c994c138d8ec4da65dc4dc6aa553cfac29a @LeeWitherington LeeWitherington committed Dec 4, 2011
@@ -0,0 +1,40 @@
+using System.Collections.Generic;
+using System.IO;
+
+namespace ReportGeneratorCS
+{
+ public class HtmlReport
+ {
+ public static void report(StringWriter output, IList<Machine> machines, Robot robot)
+ {
+ output.Write("<h1>FACTORY REPORT</h1>\n");
+
+ IEnumerator<Machine> line = machines.GetEnumerator();
+ output.Write("<ul>\n");
+ while (line.MoveNext())
+ {
+ Machine machine = line.Current;
+ output.Write("<li>");
+ output.Write("Machine " + machine.Name());
+
+ if (machine.Bin() != null)
+ output.Write(" bin=" + machine.Bin());
+
+ output.Write("</li>\n");
+ }
+ output.Write("</ul>\n");
+
+ output.Write("<p>");
+ output.Write("Robot");
+ if (robot.Location() != null)
+ output.Write(" location=" + robot.Location().Name());
+
+ if (robot.Bin() != null)
+ output.Write(" bin=" + robot.Bin());
+
+ output.Write("</p>\n");
+
+ output.Write("<hr>\n");
+ }
+ }
+}
@@ -36,13 +36,17 @@
<HintPath>..\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="HtmlReport.cs" />
<Compile Include="Machine.cs" />
<Compile Include="Report.cs" />
+ <Compile Include="Tests\HtmlReportTest.cs" />
<Compile Include="Tests\ReportTest.cs" />
<Compile Include="Robot.cs" />
<Compile Include="Tests\RobotTest.cs" />
@@ -0,0 +1,38 @@
+using System.Collections.Generic;
+using System.IO;
+using NUnit.Framework;
+
+namespace ReportGeneratorCS.Tests
+{
+ [TestFixture]
+ public class HtmlReportTest {
+
+ [Test]
+ public void testReport() {
+ IList<Machine> line = new List<Machine>();
+ line.Add(new Machine("mixer", "left"));
+
+ Machine extruder = new Machine("extruder", "center");
+ extruder.Put("paste");
+ line.Add(extruder);
+
+ Machine oven = new Machine("oven", "right");
+ oven.Put("chips");
+ line.Add(oven);
+
+ Robot robot = new Robot();
+ robot.MoveTo(extruder);
+ robot.Pick();
+
+ StringWriter output = new StringWriter();
+ HtmlReport.report(output, line, robot);
+
+ string expected = "<h1>FACTORY REPORT</h1>\n"
+ + "<ul>\n<li>Machine mixer</li>\n<li>Machine extruder</li>\n"
+ + "<li>Machine oven bin=chips</li>\n</ul>\n"
+ + "<p>Robot location=extruder bin=paste</p>\n" + "<hr>\n";
+
+ Assert.That(expected, Is.EqualTo(output.ToString()));
+ }
+ }
+}
@@ -0,0 +1,39 @@
+Imports System.Collections.Generic
+Imports System.IO
+
+Namespace ReportGeneratorVB
+ Public Class HtmlReport
+ Public Shared Sub report(ByVal output As StringWriter, ByVal machines As IList(Of Machine), ByVal robot As Robot)
+ output.Write("<h1>FACTORY REPORT</h1>" & vbLf)
+
+ Dim line As IEnumerator(Of Machine) = machines.GetEnumerator()
+ output.Write("<ul>" & vbLf)
+ While line.MoveNext()
+ Dim machine As Machine = line.Current
+ output.Write("<li>")
+ output.Write("Machine " + machine.Name())
+
+ If machine.Bin() IsNot Nothing Then
+ output.Write(" bin=" + machine.Bin())
+ End If
+
+ output.Write("</li>" & vbLf)
+ End While
+ output.Write("</ul>" & vbLf)
+
+ output.Write("<p>")
+ output.Write("Robot")
+ If robot.Location() IsNot Nothing Then
+ output.Write(" location=" + robot.Location().Name())
+ End If
+
+ If robot.Bin() IsNot Nothing Then
+ output.Write(" bin=" + robot.Bin())
+ End If
+
+ output.Write("</p>" & vbLf)
+
+ output.Write("<hr>" & vbLf)
+ End Sub
+ End Class
+End Namespace
@@ -64,6 +64,7 @@
<Import Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="HtmlReport.vb" />
<Compile Include="Machine.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
@@ -82,6 +83,7 @@
</Compile>
<Compile Include="Report.vb" />
<Compile Include="Robot.vb" />
+ <Compile Include="Tests\HtmlReportTest.vb" />
<Compile Include="Tests\ReportTest.vb" />
<Compile Include="Tests\RobotTest.vb" />
</ItemGroup>
@@ -0,0 +1,34 @@
+Imports System.Collections.Generic
+Imports System.IO
+Imports NUnit.Framework
+
+Namespace ReportGeneratorVB.Tests
+ <TestFixture()> _
+ Public Class HtmlReportTest
+
+ <Test()> _
+ Public Sub testReport()
+ Dim line As IList(Of Machine) = New List(Of Machine)()
+ line.Add(New Machine("mixer", "left"))
+
+ Dim extruder As New Machine("extruder", "center")
+ extruder.Put("paste")
+ line.Add(extruder)
+
+ Dim oven As New Machine("oven", "right")
+ oven.Put("chips")
+ line.Add(oven)
+
+ Dim robot As New Robot()
+ robot.MoveTo(extruder)
+ robot.Pick()
+
+ Dim output As New StringWriter()
+ HtmlReport.report(output, line, robot)
+
+ Dim expected As String = "<h1>FACTORY REPORT</h1>" & vbLf + "<ul>" & vbLf & "<li>Machine mixer</li>" & vbLf & "<li>Machine extruder</li>" & vbLf + "<li>Machine oven bin=chips</li>" & vbLf & "</ul>" & vbLf + "<p>Robot location=extruder bin=paste</p>" & vbLf + "<hr>" & vbLf
+
+ Assert.That(expected, [Is].EqualTo(output.ToString()))
+ End Sub
+ End Class
+End Namespace

0 comments on commit eb8e4c9

Please sign in to comment.