Skip to content

Instantly share code, notes, and snippets.

Added extra tracing and logging whenever a customer adds an item to their cart.
This should help our operation team to monitor the system
public class ShoppingCartWithCustomerTraceLogging : ShoppingCart
{
public override void AddCartItem(CartItem item)
{
base.AddCartItem(item);
Track(CustomerAction.CartItemAddedToCart);
}
void Track(Action action)
{
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);
}
  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
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
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);
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);
}
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);
@pavsaund
pavsaund / ShoppingCart.Decorator.cs
Last active October 19, 2016 11:16
Capturing Intent with code
public class ShoppingCartWithCustomerTraceLogging : ShoppingCart
{
public override void AddCartItem(CartItem item)
{
base.AddCartItem(item);
Track(CustomerAction.CartItemAddedToCart);
}
void Track(Action action)
{

Keybase proof

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: