Created
July 2, 2017 00:27
-
-
Save marzoukali/abb372a80e9f40b25bdc7e0ba32191b3 to your computer and use it in GitHub Desktop.
unittest-example-6
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 InvoiceWriterTests | |
{ | |
private InvoiceWriter _writer; | |
private AutoMoqer _mocker; | |
private Invoice _invoice; | |
[SetUp] | |
public void SetUp() | |
{ | |
_invoice = new Invoice() | |
{ | |
Id = 1, | |
IsOverdue = false | |
}; | |
_mocker = new AutoMoqer(); | |
_writer = _mocker.Create<InvoiceWriter>(); | |
} | |
[Test] | |
public void TestWriteShouldSetPageLayout() | |
{ | |
_writer.Write(_invoice); | |
var layout = _mocker | |
.GetMock<IPageLayout>().Object; | |
_mocker.GetMock<IPrinter>() | |
.Verify(p => p.SetPageLayout(layout), | |
Times.Once); | |
} | |
[Test] | |
public void TestWriteShouldPrintOverdueInvoiceInRed() | |
{ | |
_invoice.IsOverdue = true; | |
_writer.Write(_invoice); | |
_mocker.GetMock<IPrinter>() | |
.Verify(p => p.SetInkColor("Red"), | |
Times.Once); | |
} | |
[Test] | |
public void TestWriteShouldPrintOnTimeInvoiceInDefaultColor() | |
{ | |
_writer.Write(_invoice); | |
_mocker.GetMock<IPrinter>() | |
.Verify(p => p.SetInkColor(It.IsAny<string>()), | |
Times.Never); | |
} | |
[Test] | |
[TestCase("Invoice ID: 1")] | |
// Remaining test cases would go here | |
public void TestWriteShouldPrintInvoiceNumber(string line) | |
{ | |
_writer.Write(_invoice); | |
_mocker.GetMock<IPrinter>() | |
.Verify(p => p.WriteLine(line), | |
Times.Once()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment