Ejemplo n.º 1
0
        public void CanStoreAnOrderWithPayment()
        {
            long id;
              using (var session = 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 = sessionFactory.OpenSession())
              {
            var repository = new Repository<Order>(context);
            var order = repository.GetById(id);
            order.Satisfy(o => o.Location == Location.InShop
                           && o.Items.Count() == 1
                           && o.Payment != null);
              }
        }