Skip to content

Instantly share code, notes, and snippets.

@marzoukali
Created July 1, 2017 23:38
Show Gist options
  • Save marzoukali/ab0f441496e6b6b77be1d01725738ec1 to your computer and use it in GitHub Desktop.
Save marzoukali/ab0f441496e6b6b77be1d01725738ec1 to your computer and use it in GitHub Desktop.
unittest-example-4
// PrintInvoiceCommand Class
public class PrintInvoiceCommand
{
private readonly IDatabase _database;
private readonly IPrinter _printer;
public PrintInvoiceCommand(
IDatabase database,
IPrinter printer)
{
_database = database;
_printer = printer;
}
public void Execute(int invoiceId)
{
var invoice = _database.GetInvoice(invoiceId);
var writer = new InvoiceWriter(_printer, invoice);
writer.Write();
}
}
// InvoiceWriter Class
public class InvoiceWriter
{
private readonly IPrinter _printer;
private readonly Invoice _invoice;
public InvoiceWriter(
IPrinter printer,
Invoice invoice)
{
_printer = printer;
_invoice = invoice;
_printer.SetPageLayout(new PageLayout());
if (_invoice.IsOverdue)
_printer.SetInkColor("Red");
}
public void Write()
{
_printer.WriteLine("Invoice ID: " + _invoice.Id);
// Remaining print statements would go here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment