This is an implementation of the LateRooms Checkout Kata by Martin Steel
There is one public interface fo the Checkout, ICheckout
defined below.
public interface ICheckout
{
bool Scan(string sku);
int GetTotalPrice();
}
Scan(string sku)
Add an item to be purchased identified by its Stock Keeping Unit (SKU)
GetTotalPrice()
Once all items are added get the total cost of the items being purchased.
SKU | Unit Price | Special Price |
---|---|---|
A | 50 | 3 for 130 |
B | 30 | 2 for 45 |
C | 20 | |
D | 15 |
A concrete implementation of the ICheckout
interface can be found in the Checkout
class. The public constructor requires an IProductRepository
as an argument. The IProductRepository
interface defines a public interface for retrieving products by SKU. In production I would expect this to be a products database or equivalent.
The CheckoutTests
project uses NUnit to test the Checkout
implementation.
For testing purposes the IProductRepository
interface is mocked with Moq in the test SetUp function. The mocked implementation supports the four SKUs defined in the Kata.
- Tested in Visual Studio 2017 RC2 (should also work in earlier versions)
- Requires .NET 4.6.2
- NuGet 3 (Package restore will install NUnit)