Esempio n. 1
0
        public void CanStoreOneCustomizationInTwoProducts()
        {
            long customizationId;
              using (var session = sessionFactory.OpenSession())
              using (var tx = session.BeginTransaction())
              {
            var customizationRepository = new Repository<Customization>(session);
            var customization = new Customization {Name = "Milk", PossibleValues = {"skim", "semi", "whole"}};
            customizationRepository.MakePersistent(customization);
            customizationId = customization.Id;

            var productRepository = new Repository<Product>(session);
            productRepository.MakePersistent(new Product
                                         {
                                           Name = "Coffee 3",
                                           Price = 10.4m,
                                           Customizations = {customization}
                                         });
            productRepository.MakePersistent(new Product {Name = "Coffee 4", Price = 5.4m, Customizations = {customization}});

            tx.Commit();
              }

              using (var session = sessionFactory.OpenSession())
              {
            new Repository<Product>(session)
              .Retrieve(p => p.Customizations.Any(c => c.Id == customizationId))
              .Count().Should().Be.EqualTo(2);
              }
        }
        public void InitializeData()
        {
            using (var session = sessionFactory.OpenSession())
              using (var tx = session.BeginTransaction())
              {
            var milk = new Customization
                   {
                     Name = "Milk",
                     PossibleValues = {"skim", "semi", "whole"}
                   };

            var size = new Customization
                   {
                     Name = "Size",
                     PossibleValues = {"small", "medium", "large"}
                   };

            var shots = new Customization
                    {
                      Name = "Shots",
                      PossibleValues = {"single", "double", "triple"}
                    };

            var whippedCream = new Customization
                           {
                             Name = "Whipped Cream",
                             PossibleValues = {"yes", "no"}
                           };

            var kindOfCookie = new Customization
                           {
                             Name = "Kind",
                             PossibleValues = {"chocolate chip", "ginger"}
                           };

            var customizationRepository = new Repository<Customization>(session);
            customizationRepository.MakePersistent(milk, size, shots, whippedCream, kindOfCookie);
            var productRepository = new Repository<Product>(session);

            var coffees = new[] {"Latte", "Capuccino", "Espresso", "Tea"}
              .Select(
            coffeName =>
            new Product {Name = coffeName, Price = (decimal) coffeName.First()/10, Customizations = {milk, size, shots}})
              .ToArray();

            productRepository.MakePersistent(coffees);

            productRepository.MakePersistent(new Product
                                         {
                                           Name = "Hot Chocolate",
                                           Price = 10.5m,
                                           Customizations = {milk, size, whippedCream}
                                         });
            productRepository.MakePersistent(new Product {Name = "Cookie", Price = 1, Customizations = {kindOfCookie}});
            tx.Commit();
              }
        }
Esempio n. 3
0
 public void CanStoreACustomization()
 {
     long customizationId;
       using (var session = sessionFactory.OpenSession())
       using (var tx = session.BeginTransaction())
       {
     var repository = new Repository<Customization>(session);
     var customization = new Customization {Name = "Milk", PossibleValues = {"skim", "semi", "whole"}};
     repository.MakePersistent(customization);
     customizationId = customization.Id;
     tx.Commit();
       }
       using (var session = sessionFactory.OpenSession())
       {
     var repository = new Repository<Customization>(session);
     Customization readed = repository.GetById(customizationId);
     readed.Satisfy(c => c.Name == "Milk" && c.PossibleValues.SetEquals(new[] {"skim", "semi", "whole"}));
       }
 }