Giter Site home page Giter Site logo

checkout's Introduction

Checkout Kata

Requirements

Implement a solution for a checkout kata that follows the requirements below.

  • Given I have selected to add an item to the basket Then the item should be added to the basket
  • Given items have been added to the basket Then the total cost of the basket should be calculated
  • Given I have added a multiple of 3 lots of item ‘B’ to the basket Then a promotion of ‘3 for 40’ should be applied to every multiple of 3 (see: Grid 1).
  • Given I have added a multiple of 2 lots of item ‘D’ to the basket Then a promotion of ‘25% off’ should be applied to every multiple of 2 (see: Grid 1).
Item SKU Unit Price Promotion
A 10
B 15 3 for 40
C 40
D 55 25% off every 2

Solution

Checkout.Tests

Unit tests are provided in xUnit, with FluentAssertions to provide clean, readable assertion syntax. Theories with inline data are used to reduce duplication of code.

Checkout

The main checkout functionality is provided as a .net core class library. This could be added to a web app for a full user facing implementation.

The project follows SOLID principles with single responsibilty classes that are open for extension and closed for modification.

  • Item.cs is a simple POCO class to hold properties for each product.
  • Basket.cs manages the contents of the shopping basket. The basket is open for extension as the various discounts are injected into the constructor. Additional discount strategies could be added without modifying the basket code.
  • MultiItemDiscount.cs is an abstract base class which contains common code for the various concrete multi item discounts set out in the requirements. This keeps the concrete classes DRY.
  • MultiItemPercentageDiscount.cs is a concrete implementation of the 25% off every 2 items discount. The implementation is quite generic and could easily by extended to x% off every n items by passing the appropriate values to the constructor.
  • MultiItemValueDiscount.cs is a concrete implementation of the 3 for 40 discount. The implementation is quite generic and could easily by extended to £x off every n items by passing the appropriate values to the constructor.

checkout's People

Contributors

chaoticnadirs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.