public void GetCustomerThrowsWhenRepositoryReturnsNull() { // Arrange Guid customerKey = Guid.NewGuid(); var MockCustomerService = new Mock<ICustomerService>(); MockCustomerService.Setup(cs => cs.GetById(customerKey)).Returns((AnonymousCustomer)null); var MockServiceContext = new Mock<IServiceContext>(); MockServiceContext.SetupGet(sc => sc.CustomerService).Returns(MockCustomerService.Object); MerchelloContext merchelloContext = new MerchelloContext(MockServiceContext.Object); CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext); var ex = Assert.Throws<HttpResponseException>(() => ctrl.GetCustomer(Guid.Empty)); }
public void GetCustomerByKeyReturnsCorrectItemFromRepository() { // Arrange int customerId = 20; AnonymousCustomer anonymousCustomer = CreateFakeCustomer(customerId); var MockCustomerService = new Mock<ICustomerService>(); MockCustomerService.Setup(cs => cs.GetById(customerId)).Returns(anonymousCustomer); MerchelloContext merchelloContext = GetMerchelloContext(MockCustomerService.Object); CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext); //// Act var result = ctrl.GetCustomer(customerId); //// Assert Assert.AreEqual(anonymousCustomer, result); }