Created
October 18, 2013 16:43
-
-
Save JamesBender/7044286 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Linq; | |
using NUnit.Framework; | |
using TddStore.Core; | |
using TddStore.Core.Exceptions; | |
using Telerik.JustMock; | |
namespace TddStore.UnitTests | |
{ | |
[TestFixture] | |
class OrderServiceTests | |
{ | |
private OrderService _orderService; | |
private IOrderDataService _orderDataService; | |
private ICustomerService _customerService; | |
[TestFixtureSetUp] | |
public void SetupTestFixture() | |
{ | |
_orderDataService = Mock.Create<IOrderDataService>(); | |
_customerService = Mock.Create<ICustomerService>(); | |
_orderService = new OrderService(_orderDataService, _customerService); | |
} | |
[Test] | |
public void WhenUserPlacesACorrectOrderThenAnOrderNumberShouldBeReturned() | |
{ | |
//Arrange | |
var shoppingCart = new ShoppingCart(); | |
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = Guid.NewGuid(), Quantity = 0 }); | |
var customerId = Guid.NewGuid(); | |
var expectedOrderId = Guid.NewGuid(); | |
Mock.Arrange(() => _orderDataService.Save(Arg.IsAny<Order>())) | |
.Returns(expectedOrderId) | |
.OccursOnce(); | |
//Act | |
var result = _orderService.PlaceOrder(customerId, shoppingCart); | |
//Assert | |
Assert.AreEqual(expectedOrderId, result); | |
Mock.Assert(_orderDataService); | |
} | |
[Test] | |
public void WhenAUserAttemptsToOrderAnItemWithAQuantityOfZeroThrowInvalidOrderException() | |
{ | |
//Arrange | |
var shoppingCart = new ShoppingCart(); | |
shoppingCart.Items.Add(new ShoppingCartItem { ItemId = Guid.NewGuid(), Quantity = 0 }); | |
var customerId = Guid.NewGuid(); | |
var expectedOrderId = Guid.NewGuid(); | |
Mock.Arrange(() => _orderDataService.Save(Arg.IsAny<Order>())) | |
.Returns(expectedOrderId) | |
.OccursNever(); | |
//Act | |
try | |
{ | |
_orderService.PlaceOrder(customerId, shoppingCart); | |
} | |
catch(InvalidOrderException ex) | |
{ | |
//Assert | |
Mock.Assert(_orderDataService); | |
Assert.Pass(); | |
} | |
//Assert | |
Assert.Fail(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment