Skip to content

Instantly share code, notes, and snippets.

@JamesBender
Last active December 24, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesBender/6751157 to your computer and use it in GitHub Desktop.
Save JamesBender/6751157 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
namespace ThirtyDaysOfTDD.UnitTests
{
class OrderService
{
private ICustomerService _customerService;
private ILoggingService _loggingService;
private IOrderDataService _orderDataService;
public OrderService(IOrderDataService orderDataService, ICustomerService customerService, ILoggingService loggingService)
{
_orderDataService = orderDataService;
_customerService = customerService;
_loggingService = loggingService;
}
public Guid PlaceOrder(Guid customerId, IShoppingCart shoppingCart)
{
var order = new Order();
// Business logic that validates order and creates Order object
var orderId = Save(order);
_customerService.AddOrderToCustomer(customerId, orderId);
_loggingService.LogNewOrder(orderId);
return orderId;
}
private Guid Save(Order order)
{
return _orderDataService.Save(order);
}
}
public interface IOrderDataService
{
Guid Save(Order order);
}
public interface ICustomerService
{
bool AddOrderToCustomer(Guid customerId, Guid orderId);
}
public interface ILoggingService
{
bool LogNewOrder(Guid orderId);
}
public interface IShoppingCart
{
}
public class Order
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment