public void Add(Product product, int quantity) { var existing = Items.FirstOrDefault(x => x.ProductId == product.Id); if (existing == null) Items.Add((existing = new OrderLineItem())); if (quantity <= 0) Items.Remove(existing); existing.ProductId = product.Id; existing.ProductName = product.Name; existing.Price = product.Price; }
public void Can_utlize_object_oriented_programming_correctly() { // http://ravendb.net/docs/theory/document-structure-design // - Documents are not flat // - Raven is not relational // - Entities and Aggregates are important // - Associations Management // (Aggregate Roots may contain all of their // children, but even Aggregates do not live in isolation) var order = new Order(); var product = new Product { Id = "sku-12345", Name = "Peanut Butter", Price = 20.00m }; // we are adding a product to an order order.Add(product, quantity: 1); // we created a new order line item order.Items.Count.Should().Be(1); using (var store = NewDocumentStore()) { using (var session = store.OpenSession()) { session.Store(order); session.SaveChanges(); } var storeUrl = store.Configuration.ServerUrl; WaitForUserToContinueTheTest(store); } order.Id.Should().NotBeEmpty(); }