using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; namespace Reporting2 { [TestFixture] public class ReportingTests2 { [Test] public void Report_without_OrderItems() { var order = new Order { Number = "1234" }; Assert.That(order.ToReport(), Is.EqualTo("Order #1234" + Environment.NewLine)); } [Test] public void Report_with_one_OrderItem() { var order = new Order { Number = "1234" }; order.Add(new OrderItem(1, new Product { Name = "Visual Studio 2008" }, 500.0)); Assert.That(order.ToReport(), Is.EqualTo( "Order #1234" + Environment.NewLine + " 1 x Visual Studio 2008 á 500 EUR: 500 EUR" + Environment.NewLine)); } } public class Product { public string Name { get; set; } } public class OrderItem { private readonly int m_Amount; private readonly Product m_Product; private readonly double m_Price; public OrderItem(int amount, Product product, double price) { m_Amount = amount; m_Product = product; m_Price = price; } public int Amount { get { return m_Amount; } } public Product Product { get { return m_Product; } } public double Price { get { return m_Price; } } public string ToReport() { return string.Format(" {0} x {1} á {2} EUR: {3} EUR", Amount, Product.Name, Price, Amount * Price); } } public class Order { private readonly IList m_OrderItems = new List(); public string Number { get; set; } public string ToReport() { var result = new StringBuilder(); result.AppendLine(string.Format("Order #{0}", Number)); foreach (var item in m_OrderItems) { result.AppendLine(item.ToReport()); } return result.ToString(); } public void Add(OrderItem item) { m_OrderItems.Add(item); } } }