CheckoutTests.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.Collections.Generic;
  2. using CheckoutKata;
  3. using FluentAssertions;
  4. using Xunit;
  5. namespace CheckoutKataTests
  6. {
  7. public class CheckoutTests
  8. {
  9. private class Products : IProducts
  10. {
  11. private readonly Dictionary<string, Product> _products = new Dictionary<string, Product> {
  12. {"A", new SpecialPriceProduct(50, 130, 3)},
  13. {"B", new SpecialPriceProduct(30, 45, 2)},
  14. {"C", new Product(20)}
  15. };
  16. public Product GetBySKU(string sku) => _products[sku];
  17. }
  18. [Fact]
  19. public void Scan_WithOneProductCosting50_GetTotalPriceReturns50()
  20. {
  21. var checkout = new Checkout(new Products());
  22. checkout.Scan("A");
  23. checkout.GetTotalPrice().Should().Be(50);
  24. }
  25. [Fact]
  26. public void Scan_WithTwoProductsCosting50_GetTotalPriceReturns100()
  27. {
  28. var checkout = new Checkout(new Products());
  29. checkout.Scan("A");
  30. checkout.Scan("A");
  31. checkout.GetTotalPrice().Should().Be(100);
  32. }
  33. [Fact]
  34. public void Scan_WithThreeSpecialPriceProductsCosting50_GetTotalPriceReturns130()
  35. {
  36. var checkout = new Checkout(new Products());
  37. checkout.Scan("A");
  38. checkout.Scan("A");
  39. checkout.Scan("A");
  40. checkout.GetTotalPrice().Should().Be(130);
  41. }
  42. [Fact]
  43. public void Scan_WithOneProductCosting30_GetTotalPriceReturns30()
  44. {
  45. var checkout = new Checkout(new Products());
  46. checkout.Scan("B");
  47. checkout.GetTotalPrice().Should().Be(30);
  48. }
  49. [Fact]
  50. public void Scan_WithTwoSpecialPriceProductsCosting30_GetTotalPriceReturns45()
  51. {
  52. var checkout = new Checkout(new Products());
  53. checkout.Scan("B");
  54. checkout.Scan("B");
  55. checkout.GetTotalPrice().Should().Be(45);
  56. }
  57. [Fact]
  58. public void Scan_WithThreeSpecialPriceProductsCosting30_GetTotalPriceReturns75()
  59. {
  60. var checkout = new Checkout(new Products());
  61. checkout.Scan("B");
  62. checkout.Scan("B");
  63. checkout.Scan("B");
  64. checkout.GetTotalPrice().Should().Be(75);
  65. }
  66. [Fact]
  67. public void Scan_WithOneProductCosting20_GetTotalPriceReturns20()
  68. {
  69. var checkout = new Checkout(new Products());
  70. checkout.Scan("C");
  71. checkout.GetTotalPrice().Should().Be(20);
  72. }
  73. [Fact]
  74. public void Scan_WithTwoProductsCosting20_GetTotalPriceReturns40()
  75. {
  76. var checkout = new Checkout(new Products());
  77. checkout.Scan("C");
  78. checkout.Scan("C");
  79. checkout.GetTotalPrice().Should().Be(40);
  80. }
  81. [Fact]
  82. public void Scan_WithThreeDifferentProductsCosting50_GetTotalPriceReturns95()
  83. {
  84. var checkout = new Checkout(new Products());
  85. checkout.Scan("B");
  86. checkout.Scan("A");
  87. checkout.Scan("B");
  88. checkout.GetTotalPrice().Should().Be(95);
  89. }
  90. }
  91. }