Skip to content

Instantly share code, notes, and snippets.

View Hameds's full-sized avatar
🎯
Focusing

Hamed Hameds

🎯
Focusing
View GitHub Profile
[Test]
public void WhenUserPlacesOrderWithItemThatIsInInventoryOrderFulfillmentWorkflowShouldComplete()
{
//Arrange
var shoppingCart = new ShoppingCart();
var itemId = Guid.NewGuid();
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = itemId, Quantity = 1 });
var customerId = Guid.NewGuid();
var customer = new Customer { Id = customerId };
var orderFulfillmentSessionId = Guid.NewGuid();
[Test]
public void WhenUserPlacesOrderWithItemThatIsInInventoryOrderFulfillmentWorkflowShouldComplete()
{
//Arrange
var shoppingCart = new ShoppingCart();
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = Guid.NewGuid(), Quantity = 1 });
var customerId = Guid.NewGuid();
var customer = new Customer { Id = customerId };
Mock.Arrange(() => _customerService.GetCustomer(customerId)).Returns(customer).OccursOnce();
}
using System;
using System.Collections.Generic;
namespace TddStore.Core
{
public interface IOrderFulfillmentService
{
Guid OpenSession(string user, string password);
bool IsInInventory(Guid sessionId, Guid ItemNumber, int quantity);
bool PlaceOrder(Guid sessionId, IDictionary items, string mailingAddress);
void CloseSession(Guid sessionId);
using System;
using System.Linq;
using NUnit.Framework;
using TddStore.Core;
using TddStore.Core.Exceptions;
using Telerik.JustMock;
namespace TddStore.UnitTests
{
[TestFixture]
using System;
using TddStore.Core.Exceptions;
namespace TddStore.Core
{
public class OrderService
{
private IOrderDataService _orderDataService;
private ICustomerService _customerService;
public Guid PlaceOrder(Guid customerId, ShoppingCart shoppingCart)
{
foreach (var item in shoppingCart.Items)
{
if (item.Quantity == 0)
{
throw new InvalidOrderException();
}
}
var customer = _customerService.GetCustomer(customerId);
[Test]
public void WhenAValidCustomerPlacesAValidOrderAnOrderShouldBePlaced()
{
//Arrange
var shoppingCart = new ShoppingCart();
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = Guid.NewGuid(), Quantity = 1 });
var customerId = Guid.NewGuid();
var customerToReturn = new Customer { Id = customerId, FirstName = "Fred", LastName = "Flinstone" };
Mock.Arrange(() => _customerService.GetCustomer(customerId))
[Test]
public void WhenAValidCustomerPlacesAValidOrderAnOrderShouldBePlaced()
{
//Arrange
var shoppingCart = new ShoppingCart();
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = Guid.NewGuid(), Quantity = 1 });
var customerId = Guid.NewGuid();
var expectedOrderId = Guid.NewGuid();
var customerToReturn = new Customer { Id = customerId, FirstName = "Fred", LastName = "Flinstone" };
[Test]
public void WhenAValidCustomerPlacesAValidOrderAnOrderShouldBePlaced()
{
//Arrange
var shoppingCart = new ShoppingCart();
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = Guid.NewGuid(), Quantity = 1 });
var customerId = Guid.NewGuid();
var customerToReturn = new Customer { Id = customerId, FirstName = "Fred", LastName = "Flinstone" };
//Act
[TestFixture]
class OrderServiceTests
{
private OrderService _orderService;
private IOrderDataService _orderDataService;
private ICustomerService _customerService;
[TestFixtureSetUp]
public void SetupTestFixture()
{