public OrderItem(Product product, int quantity, decimal unitPrice, IDictionary<string, string> preferences)
 {
     Product = product;
       Quantity = quantity;
       UnitPrice = unitPrice;
       Preferences = preferences;
 }
Exemple #2
0
        public void CanStoreAProduct()
        {
            //Database.SetInitializer(new DropCreateDatabaseAlways<CoffeeShopContext>());
              long id;
              using (var session = sessionFactory.OpenSession())
              using (var tx = session.BeginTransaction())
              {
            var repository = new Repository<Product>(session);
            var product = new Product
                      {
                        Name = "Coffee 1",
                        Price = 10.4m
                      };

            repository.MakePersistent(product);
            id = product.Id;
            tx.Commit();
              }

              using (var session = sessionFactory.OpenSession())
              using (session.BeginTransaction())
              {
            var repository = new Repository<Product>(session);
            Product product = repository.GetById(id);

            product.Satisfy(p => p.Name == "Coffee 1" && p.Price == 10.4m);
              }
        }
        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 = 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);
              }
        }
        public void CanChangeStatus()
        {
            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.Cancel("cascasas");
            id = order.Id;
            tx.Commit();
              }
              using (var session = sessionFactory.OpenSession())
              using (session.BeginTransaction())
              {
            session.Get<Order>(id).Status.Should().Be.EqualTo(OrderStatus.Canceled);
              }
        }
        public void VersionNumberGrowOnEachUpdate()
        {
            long id;
              int version;
              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();
            version = order.Version;
              }
              using (var session = 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);
              }
        }
 public void WhenSameTransientShouldBeTrue()
 {
     var product = new Product();
       product.Equals(product).Should().Be.True();
 }
 public void WhenComparingSameInstanceOfPersistedEntityThenShouldBeTrue()
 {
     var product = new Product {Id = 123};
       product.Equals(product)
     .Should().Be.True();
 }