public void IfItemHasQuantity0_ThenReturnInvalidMessage() { var order = new Order() ; order.AddItem(new OrderItem { Quantity = 0 }); order.GetErrorMessages() .Should().Contain("Item 0: Quantity should be greater than 0."); }
private bool TryAddOrderItem(Order order, OrderItemRepresentation requestedItem) { var product = TryFindProduct(requestedItem); if (product == null) return false; var orderItem = new OrderItem(product, requestedItem.Quantity, product.Price, requestedItem.Preferences); order.AddItem(orderItem); return true; }
public void IfTheProductDoesNotAllowCustomization_ThenReturnInvalidMessage() { var product = new Product { Name = "latte", Customizations = {new Customization{Name = "size", PossibleValues = {"medium","large"}}} }; var order = new Order(); order.AddItem(new OrderItem { Quantity = 1, Product = product, Preferences = { { "milk", "lot" } } }); order.GetErrorMessages() .Should().Contain("Item 0: The product latte does not have a customization: milk/lot."); }
public void CanStoreAnOrderWithPayment() { long id; using (var session = m_sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { var productRepository = new Repository<Product>(session); var product = new Product { Name = "Latte", Price = 10.4m }; productRepository.MakePersistent(product); var orderRepository = new Repository<Order>(session); var order = new Order { Date = new DateTime(2011, 1, 1), Location = Location.InShop, }; order.AddItem(new OrderItem { Product = product, UnitPrice = 10.4m, Preferences = { {"Milk", "skim"}, {"Size", "small"} } }); orderRepository.MakePersistent(order); order.Pay("1234", "jose"); id = order.Id; tx.Commit(); } using (var context = m_sessionFactory.OpenSession()) { var repository = new Repository<Order>(context); var order = repository.GetById(id); order.Satisfy(a_o => a_o.Location == Location.InShop && a_o.Items.Count() == 1 && a_o.Payment != null); } }
public void CanChangeStatus() { long id; using (var session = m_sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { var productRepository = new Repository<Product>(session); var product = new Product {Name = "Latte", Price = 10.4m}; productRepository.MakePersistent(product); var orderRepository = new Repository<Order>(session); var order = new Order { Date = new DateTime(2011, 1, 1), Location = Location.InShop, }; order.AddItem(new OrderItem { Product = product, UnitPrice = 10.4m, Preferences = { {"Milk", "skim"}, {"Size", "small"} } }); orderRepository.MakePersistent(order); order.Cancel("cascasas"); id = order.Id; tx.Commit(); } using (var session = m_sessionFactory.OpenSession()) using (session.BeginTransaction()) { session.Get<Order>(id).Status.Should().Be.EqualTo(OrderStatus.Canceled); } }
/// <summary> /// Creates an order /// </summary> /// <param name="a_orderModel">Order dto model</param> /// <remarks> /// Json Invoke: {Location: "inShop", Items: {Name: "latte", Quantity: 5}} /// Xml invoke: /// </remarks> /// <returns>Response</returns> public HttpResponseMessage Post(OrderDto a_orderModel) { var order = new Order { Date = DateTime.Today, Location = a_orderModel.Location }; foreach (var requestedItem in a_orderModel.Items) { var product = m_productRepository.GetByName(requestedItem.Name); if (product == null) { return Request.CreateResponse(HttpStatusCode.BadRequest, string.Format("We don't offer {0}", requestedItem.Name)); } var orderItem = new OrderItem(product, requestedItem.Quantity, product.Price, requestedItem.Preferences.ToDictionary(a_x => a_x.Key, a_y => a_y.Value)); order.AddItem(orderItem); } if (!order.IsValid()) { var content = string.Join("\n", order.GetErrorMessages()); return Request.CreateResponse(HttpStatusCode.BadRequest, string.Format("Invalid entities values {0}", content)); } m_orderRepository.MakePersistent(order); //var uri = resourceLinker.GetUri<OrderResourceHandler>(orderResource => orderResource.Get(0, null), new { orderId = order.Id }); return Request.CreateResponse(HttpStatusCode.OK); }
public void VersionNumberGrowOnEachUpdate() { long id; int version; using (var session = m_sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { var productRepository = new Repository<Product>(session); var product = new Product {Name = "Latte", Price = 10.4m}; productRepository.MakePersistent(product); var orderRepository = new Repository<Order>(session); var order = new Order { Date = new DateTime(2011, 1, 1), Location = Location.InShop, }; order.AddItem(new OrderItem { Product = product, UnitPrice = 10.4m, Preferences = { {"Milk", "skim"}, {"Size", "small"} } }); orderRepository.MakePersistent(order); order.Pay("1234", "jose"); id = order.Id; tx.Commit(); version = order.Version; } using (var session = m_sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { var order = session.Get<Order>(id); order.Location = Location.TakeAway; tx.Commit(); order.Version.Should().Be.GreaterThan(version); } }