Created
July 3, 2017 10:59
-
-
Save marzoukali/ed5a42aa4c1181dcf3fe8ae61943ecca to your computer and use it in GitHub Desktop.
unittest-example-8.cs
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
// We solving the first issue by injected the real dependencies that the class depend on directly, and not injecting the whole | |
// ServiceLocator. | |
// And we solving the 2nd issue by implementing an IdentityService that we depend on to get the UserName directly. | |
public class PrintInvoiceCommand | |
{ | |
private readonly IDatabase _database; | |
private readonly IInvoiceWriter _writer; | |
private readonly IIdentityService _identity; | |
public PrintInvoiceCommand( | |
IDatabase database, | |
IInvoiceWriter writer, | |
IIdentityService identity) | |
{ | |
_database = database; | |
_writer = writer; | |
_identity = identity; | |
} | |
public void Execute(int invoiceId) | |
{ | |
var invoice = _database.GetInvoice(invoiceId); | |
_writer.Write(invoice); | |
invoice.LastPrintedBy = _identity.GetUserName(); | |
_database.Save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment