Skip to content

Instantly share code, notes, and snippets.

@sverrehundeide
Created April 18, 2017 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sverrehundeide/a35715a01612ad00370518a92a7d4319 to your computer and use it in GitHub Desktop.
Save sverrehundeide/a35715a01612ad00370518a92a7d4319 to your computer and use it in GitHub Desktop.
Blog - Arrange, Act and Assert syntax for testing
[TestMethod]
public void GetCustomerById()
{
// Arrange
const int CustomerId = 5;
var repository = new CustomerRepository();
// Act
Customer customer = repository.GetCustomerById(CustomerId);
// Assert
Assert.AreEqual(CustomerId, customer);
}
[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));
}
[TestMethod]
public void GetCustomerById()
{
// Arrange
const int CustomerId = 5;
var repository = new CustomerRepository();
// Act & Assert
Assert.AreEqual(CustomerId, repository.GetCustomerById(CustomerId));
}
@sverrehundeide
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment