Feature: Add item to shopping cart
ShoppingCart should have add item if it doesnt exist in cart
ShoppingCart should increase quantity if item already in cart
If there is no coffee left then money should be refunded
Scenario: Add StockKeepingUnit 1234 with quantity 2 to shopping cart
Given there are 2 items of StockKeepingUnit 1234 already in cart
When I press the Add to cart button
Then total number of items should be 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added extra tracing and logging whenever a customer adds an item to their cart. | |
This should help our operation team to monitor the system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShoppingCartWithCustomerTraceLogging : ShoppingCart | |
{ | |
public override void AddCartItem(CartItem item) | |
{ | |
base.AddCartItem(item); | |
Track(CustomerAction.CartItemAddedToCart); | |
} | |
void Track(Action action) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class when_adding_a_cart_item | |
{ | |
Because customer_service_and_our_customer_journey_tracker_needs_trace_info | |
= () => shoppingCart.AddCartItem(cartItem); | |
It sends_the_correct_message_to_the_event_aggregator | |
= () => MessageHandler.Messages.ShouldContain(message => | |
message.type == CustomerActiom.CartItemAddedToCart); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class When_adding_a_cart_item | |
{ | |
[SetUp] | |
public void Because_Customer_service_and_our_customer_journey_tracker_needs_trace_info() | |
{ | |
_shoppingCart.AddCartItem(cartItem); | |
} | |
[Test] | |
public void It_sends_the_correct_message_to_the_event_aggregator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShoppingCart | |
{ | |
public IList<CartItem> Items { get; set; } | |
public decimal CartTotal { get; set; } | |
public void Add(CartItem item) | |
{ | |
if (Items.Any(x => x.StockKeepingUnit == item.StockKeepingUnit)) | |
{ | |
var i = Items.First(x => x.StockKeepingUnit == item.StockKeepingUnit); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShoppingCart | |
{ | |
public IList<CartItem> Items { get; set; } | |
public decimal CartTotal { get { return Items.Sum(item => item.Total); } } | |
public void AddCartItemAndDoTracking(CartItem item) | |
{ | |
AddOrIncreaseQuantityFor(item); | |
TrackForLoggingDebuggingAndCustomerServiceCenter(CustomerAction.CartItemAddedToCart); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShoppingCartWithCustomerTraceLogging : ShoppingCart | |
{ | |
/// <summary> | |
/// Preferred way to add item to a customers shopping cart | |
/// Will add the needed extra logging required. | |
/// </summary> | |
/// <param name="item"> A CartItem that contains the qty, sku, and item price and item total price</param> | |
public override void AddCartItem(CartItem item) | |
{ | |
base.AddCartItem(item); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShoppingCartWithCustomerTraceLogging : ShoppingCart | |
{ | |
public override void AddCartItem(CartItem item) | |
{ | |
base.AddCartItem(item); | |
Track(CustomerAction.CartItemAddedToCart); | |
} | |
void Track(Action action) | |
{ |
I hereby claim:
- I am pavsaund on github.
- I am pavsaund (https://keybase.io/pavsaund) on keybase.
- I have a public key ASBeNFUc68jSKjyUW6BYZUed8Qqq7QKmFIVguSKWofrYBwo
To claim this, I am signing this object:
NewerOlder