Created
July 3, 2017 11:04
-
-
Save marzoukali/020fc9a49c8c8a1c899aec1f96c5808d to your computer and use it in GitHub Desktop.
unittest-example-9
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
[TestFixture] | |
public class PrintInvoiceCommandTests | |
{ | |
private PrintInvoiceCommand _command; | |
private AutoMoqer _mocker; | |
private Invoice _invoice; | |
private const int InvoiceId = 1; | |
private const string UserName = "mrenze"; | |
[SetUp] | |
public void SetUp() | |
{ | |
_invoice = new Invoice(); | |
_mocker = new AutoMoqer(); | |
_mocker.GetMock<IDatabase>() | |
.Setup(p => p.GetInvoice(InvoiceId)) | |
.Returns(_invoice); | |
_mocker.GetMock<IIdentityService>() | |
.Setup(p => p.GetUserName()) | |
.Returns(UserName); | |
_command = _mocker.Create<PrintInvoiceCommand>(); | |
} | |
[Test] | |
public void TestExecuteShouldPrintInvoice() | |
{ | |
_command.Execute(InvoiceId); | |
_mocker.GetMock<IInvoiceWriter>() | |
.Verify(p => p.Write(_invoice), | |
Times.Once); | |
} | |
[Test] | |
public void TestExecuteShouldLastPrintedByToCurrentUserName() | |
{ | |
_command.Execute(InvoiceId); | |
Assert.That(_invoice.LastPrintedBy, | |
Is.EqualTo(UserName)); | |
} | |
[Test] | |
public void TestExecuteShouldSaveChangesToDatabase() | |
{ | |
_command.Execute(InvoiceId); | |
_mocker.GetMock<IDatabase>() | |
.Verify(p => p.Save(), | |
Times.Once); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment