Created
July 1, 2017 23:38
-
-
Save marzoukali/ab0f441496e6b6b77be1d01725738ec1 to your computer and use it in GitHub Desktop.
unittest-example-4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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