public void PutCustomerUpdatesRepository() { //// Arrange bool wasCalled = false; Guid customerKey = Guid.NewGuid(); AnonymousCustomer anonymousCustomer = CreateFakeCustomer(customerKey); var MockCustomerService = new Mock<ICustomerService>(); MockCustomerService.Setup(cs => cs.Save(anonymousCustomer, It.IsAny<bool>())).Callback(() => wasCalled = true); MerchelloContext merchelloContext = GetMerchelloContext(MockCustomerService.Object); CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext); ctrl.Request = new HttpRequestMessage(); ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); //// Act HttpResponseMessage response = ctrl.PutCustomer(anonymousCustomer); //// Assert Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); Assert.True(wasCalled); }
/// <summary> /// Test to verify that the proper error response is returned on an error /// </summary> //[Test] public void PutCustomerReturns500WhenRepositoryUpdateReturnsError() { //// Arrange Guid customerKey = Guid.NewGuid(); AnonymousCustomer anonymousCustomer = CreateFakeCustomer(customerKey); var MockCustomerService = new Mock<ICustomerService>(); MockCustomerService.Setup(cs => cs.Save(anonymousCustomer, It.IsAny<bool>())).Throws<InvalidOperationException>(); MerchelloContext merchelloContext = GetMerchelloContext(MockCustomerService.Object); CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext); ctrl.Request = new HttpRequestMessage(); ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); //// Act HttpResponseMessage response = ctrl.PutCustomer(anonymousCustomer); //// Assert Assert.AreEqual(System.Net.HttpStatusCode.NotFound, response.StatusCode); }