123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System.Collections.Generic;
- using CheckoutKata;
- using FluentAssertions;
- using Xunit;
- namespace CheckoutKataTests
- {
- public class CheckoutTests
- {
- private class Products : IProducts
- {
- private readonly Dictionary<string, Product> _products = new Dictionary<string, Product> {
- {"A", new SpecialPriceProduct(50, 130, 3)},
- {"B", new SpecialPriceProduct(30, 45, 2)},
- {"C", new Product(20)}
- };
- public Product GetBySKU(string sku) => _products[sku];
- }
- [Fact]
- public void Scan_WithOneProductCosting50_GetTotalPriceReturns50()
- {
- var checkout = new Checkout(new Products());
- checkout.Scan("A");
- checkout.GetTotalPrice().Should().Be(50);
- }
- [Fact]
- public void Scan_WithTwoProductsCosting50_GetTotalPriceReturns100()
- {
- var checkout = new Checkout(new Products());
- checkout.Scan("A");
- checkout.Scan("A");
- checkout.GetTotalPrice().Should().Be(100);
- }
- [Fact]
- public void Scan_WithThreeSpecialPriceProductsCosting50_GetTotalPriceReturns130()
- {
- var checkout = new Checkout(new Products());
- checkout.Scan("A");
- checkout.Scan("A");
- checkout.Scan("A");
- checkout.GetTotalPrice().Should().Be(130);
- }
- [Fact]
- public void Scan_WithOneProductCosting30_GetTotalPriceReturns30()
- {
- var checkout = new Checkout(new Products());
- checkout.Scan("B");
- checkout.GetTotalPrice().Should().Be(30);
- }
- [Fact]
- public void Scan_WithTwoSpecialPriceProductsCosting30_GetTotalPriceReturns45()
- {
- var checkout = new Checkout(new Products());
- checkout.Scan("B");
- checkout.Scan("B");
- checkout.GetTotalPrice().Should().Be(45);
- }
- [Fact]
- public void Scan_WithThreeSpecialPriceProductsCosting30_GetTotalPriceReturns75()
- {
- var checkout = new Checkout(new Products());
- checkout.Scan("B");
- checkout.Scan("B");
- checkout.Scan("B");
- checkout.GetTotalPrice().Should().Be(75);
- }
- [Fact]
- public void Scan_WithOneProductCosting20_GetTotalPriceReturns20()
- {
- var checkout = new Checkout(new Products());
- checkout.Scan("C");
- checkout.GetTotalPrice().Should().Be(20);
- }
- [Fact]
- public void Scan_WithTwoProductsCosting20_GetTotalPriceReturns40()
- {
- var checkout = new Checkout(new Products());
- checkout.Scan("C");
- checkout.Scan("C");
- checkout.GetTotalPrice().Should().Be(40);
- }
- [Fact]
- public void Scan_WithThreeDifferentProductsCosting50_GetTotalPriceReturns95()
- {
- var checkout = new Checkout(new Products());
- checkout.Scan("B");
- checkout.Scan("A");
- checkout.Scan("B");
- checkout.GetTotalPrice().Should().Be(95);
- }
- }
- }
|