Created
April 18, 2017 17:18
-
-
Save sverrehundeide/a35715a01612ad00370518a92a7d4319 to your computer and use it in GitHub Desktop.
Blog - Arrange, Act and Assert syntax for testing
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
[TestMethod] | |
public void GetCustomerById() | |
{ | |
// Arrange | |
const int CustomerId = 5; | |
var repository = new CustomerRepository(); | |
// Act | |
Customer customer = repository.GetCustomerById(CustomerId); | |
// Assert | |
Assert.AreEqual(CustomerId, customer); | |
} |
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
[TestMethod] | |
public void ShouldGenerateCreditInvoiceDocumentWhenNegativeAmountNew() | |
{ | |
// Arrange | |
ICustomerService customerService = MockRepository.GenerateStub<ICustomerService>(); | |
IDocumentService documentService = MockRepository.GenerateStub<IDocumentService>(); | |
double amount = -1000; | |
Customer customer = new Customer() { Id = 12345, Name = "Name1" }; | |
customerService.Stub(stub => stub.GetCustomer(customer.Id)).Return(customer); | |
InvoicingProcess invoicingProcess = new InvoicingProcess(customerService, documentService); | |
// Act | |
invoicingProcess.Invoice(customer.Id, amount); | |
// Assert | |
documentService.AssertWasCalled(stub => stub.CreateDocument(customer, DocumentType.CreditInvoice)); | |
} |
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
[TestMethod] | |
public void GetCustomerById() | |
{ | |
// Arrange | |
const int CustomerId = 5; | |
var repository = new CustomerRepository(); | |
// Act & Assert | |
Assert.AreEqual(CustomerId, repository.GetCustomerById(CustomerId)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read full blog post at https://blog.hundeide.net/2009/02/arrange-act-and-assert-syntax-for-testing/