public void InitializeCartWithKnownCustomerStoresValueInCustomerId() { //will add mocking later ... using (var separateContext = new OrderSystemContext()) { if (!separateContext.Customers.Any(c => c.CustomerCookie == "CustomerCookieABCDE")) { separateContext.Customers.Add(new Customer { CustomerCookie = "CustomerCookieABCDE", DateOfBirth = DateTime.Now, FirstName = "Julie", LastName = "Lerman" }); separateContext.SaveChanges(); } } var service = new WebSiteOrderingService(new WebSiteOrderData(_context)); SetupLogging(); RevisitedCart cart = service.ItemSelected(1, 1, 9.99m, theUri, "CustomerCookieABCDE", 0); WriteLog(); Assert.AreNotEqual(0, _context.Carts.Find(cart.CartId).CustomerId); }
public void InitializeCartReturnsRevisitedCart() { //will add mocking later ... var service = new WebSiteOrderingService(new WebSiteOrderData(new OrderSystemContext())); Assert.IsInstanceOfType(service.ItemSelected(1, 1, 9.99m, theUri, null, 0), typeof(RevisitedCart)); }
public void InitializeCartReturnsRevisitedCart() { var scContext = new ShoppingCartContext { Carts = TestHelpers.MockDbSet <NewCart>() }; var service = new WebSiteOrderingService(new WebSiteOrderData(scContext, new ReferenceContext())); Assert.IsInstanceOfType(service.ItemSelected(1, 1, 9.99m, theUri, null, 0), typeof(RevisitedCart)); }
public void InitializeCartWithUnknownCustomerStoresZeroInCustomerId() { //will add mocking later ... var service = new WebSiteOrderingService(new WebSiteOrderData(_context)); SetupLogging(); RevisitedCart cart = service.ItemSelected(1, 1, 9.99m, theUri, null, 0); WriteLog(); Assert.AreEqual(0, _context.Carts.Find(cart.CartId).CustomerId); }
public void InitializeCartWithUnknownCustomerStoresZeroInCustomerId() { var newCartsInMemory = new List <NewCart>(); var scContext = new ShoppingCartContext { Carts = TestHelpers.MockDbSet(newCartsInMemory) }; var service = new WebSiteOrderingService(new WebSiteOrderData(scContext, new ReferenceContext())); service.ItemSelected(1, 1, 9.99m, theUri, null, 0); Assert.AreEqual(0, newCartsInMemory.FirstOrDefault().CustomerId); }
public ActionResult ItemSelected(int?productId, int quant, decimal unitPrice, string memberCookie, int cartId) { var createdCart = _service.ItemSelected(productId.Value, quant, unitPrice, "http://thedatafarm.com", memberCookie, cartId); ControllerContext.HttpContext.Response.Cookies.Add( CookieUtilities.BuildCartCookie(createdCart.CartCookie, createdCart.CartCookieExpires)); TempData["CartCount"] = createdCart.TotalItems; TempData["CartId"] = createdCart.CartId; return(RedirectToAction("../ProductList")); }
public void InitializeCartWithKnownCustomerStoresValueInCustomerId() { //will add mocking later ... var service = new WebSiteOrderingService(new WebSiteOrderData(_context, new ReferenceContext())); SetupLogging(); RevisitedCart cart = service.ItemSelected(1, 1, 9.99m, theUri, "CustomerCookieABCDE", 0); WriteLog(); Assert.AreNotEqual(0, _context.Carts.Find(cart.CartId).CustomerId); }
public void InitializeCartWithKnownCustomerStoresValueInCustomerId() { //will add mocking later ... //this action begs for an external service or message queue to see if //CustomerCookieABCDE exists in test database //removed the code that inserted the data into the database var service = new WebSiteOrderingService(new WebSiteOrderData(_context, _refContext)); SetupLogging(); RevisitedCart cart = service.ItemSelected(1, 1, 9.99m, theUri, "CustomerCookieABCDE", 0); WriteLog(); Assert.AreNotEqual(0, _context.Carts.Find(cart.CartId).CustomerId); }
public void InitializeCartWithKnownCustomerStoresValueInCustomerId() { var newCartsInMemory = new List <NewCart>(); var mockCustomer = new Mock <Customer>(); mockCustomer.SetupGet(c => c.CustomerCookie).Returns("CustomerCookieABCDE"); mockCustomer.SetupGet(c => c.CustomerId).Returns(1); var customersInMemory = new List <Customer> { mockCustomer.Object }; var scContext = new ShoppingCartContext { Carts = TestHelpers.MockDbSet(newCartsInMemory) }; var refcontext = new ReferenceContext { Customers = TestHelpers.MockDbSet(customersInMemory) }; var service = new WebSiteOrderingService(new WebSiteOrderData(scContext, refcontext)); service.ItemSelected(1, 1, 9.99m, theUri, "CustomerCookieABCDE", 0); Assert.AreNotEqual(0, newCartsInMemory.FirstOrDefault().CustomerId); }