public static void BuildOutDatabase()
        {
            var sessionFactory = CreateBuildSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var atst = new AssaultItem
                                   {
                                       Description = "AT-ST 1123",
                                       LoadValue = 6,
                                       Type = "AT-ST"
                                   };
                    var squad1 = new AssaultItem
                                     {
                                         Description = "Stormtrooper Squad 213",
                                         LoadValue = 4,
                                         Type = "Stormtrooper"
                                     };

                    session.SaveOrUpdate(atst);
                    session.SaveOrUpdate(squad1);

                    transaction.Commit();
                }
            }
        }
        static void Main()
        {
            // create our NHibernate session factory
            var sessionFactory = CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // populate the database
                using (var transaction = session.BeginTransaction())
                {
                    // create a couple of Stores each with some Products and Employees
                    //var barginBasin = new Store { Name = "Bargin Basin" };
                    //var superMart = new Store { Name = "SuperMart" };

                    //var potatoes = new Product { Name = "Potatoes", Price = 3.60 };
                    //var fish = new Product { Name = "Fish", Price = 4.49 };
                    //var milk = new Product { Name = "Milk", Price = 0.79 };
                    //var bread = new Product { Name = "Bread", Price = 1.29 };
                    //var cheese = new Product { Name = "Cheese", Price = 2.10 };
                    //var waffles = new Product { Name = "Waffles", Price = 2.41 };

                    var x = new AssaultItem {Description = "x", LoadValue = 1};
                    session.SaveOrUpdate(x);

                    // add products to the stores, there's some crossover in the products in each
                    // store, because the store-product relationship is many-to-many
                    //AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese);
                    //AddProductsToStore(superMart, bread, cheese, waffles);

                    // add employees to the stores, this relationship is a one-to-many, so one
                    // employee can only work at one store at a time
                    //AddEmployeesToStore(barginBasin, daisy, jack, sue);
                    //AddEmployeesToStore(superMart, bill, joan);

                    // save both stores, this saves everything else via cascading
                    //session.SaveOrUpdate(barginBasin);
                    //session.SaveOrUpdate(superMart);

                    transaction.Commit();
                }
            }

            //using (var session = sessionFactory.OpenSession())
            //{
            //    // retreive all stores and display them
            //    using (session.BeginTransaction())
            //    {
            //        var stores = session.CreateCriteria(typeof(AssaultItem))
            //            .List<AssaultItem>();

            //        foreach (var store in stores)
            //        {
            //            WriteStorePretty(store);
            //        }
            //    }
            //}

            Console.ReadKey();
        }
        public AssaultItem SaveAssaultItem(AssaultItem item)
        {
            int id;
            if(item.Id > 0)
            {
                _repository.Update(item);
                id = item.Id;
            }
            else
            {
                id = _repository.Save(item);
            }

            return _repository.GetById(id);
        }
 public virtual void AddAssaultItem(AssaultItem item)
 {
     item.LandingShipsLoadedOn.Add(this);
     AssaultItems.Add(item);
 }
 protected override void Because()
 {
     _item = new AssaultItem();
 }
 protected override void Before_each()
 {
     _item = new AssaultItem(2){Description = "my description", Type = "my type", LoadValue = 4};
 }
 protected override void Before_each()
 {
     _item = new AssaultItem { Description = "Dark Troopers, stormtroopers, SHOCK troopers, sCOUt troopers, at-st, Speeder BIKE, Heavy blaster"};
 }
 protected override void Because()
 {
     _repo.Update(_item);
     _savedItem = _repo.GetById(2);
 }
        protected override void Before_each()
        {
            _item = new AssaultItem {Description = "Description", Type = "Type", LoadValue = 2};

            _repo = Stub<IRepository<AssaultItem>>();
            _repo.Stub(x => x.Save(_item)).Return(9);
            _repo.Stub(x => x.GetById(9)).Return(_item);

            _service = new InventoryService(_repo);
        }
        public int CreateDb()
        {
            var sessionFactory = CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var trx = session.BeginTransaction())
                {
                    #region trooplist

                    var troopList = new List<AssaultItem>
                                        {
                                            new AssaultItem
                                                {
                                                    Description = "2 Shock Troopers, 6 Stormtroopers",
                                                    LoadValue = 4,
                                                    Type = "Shock Trooper Support Squad"
                                                },
                                            new AssaultItem
                                                {
                                                    Description = "5 Dark Troopers",
                                                    LoadValue = 4,
                                                    Type = "Dark Trooper Sqaud"
                                                },
                                            new AssaultItem
                                                {
                                                    Description = "8 Scout Troopers",
                                                    LoadValue = 4,
                                                    Type = "Scout Trooper Sqaud"
                                                },
                                            new AssaultItem
                                                {
                                                    Description = "Speeder Bike and 1 Scout Trooper",
                                                    LoadValue = 2,
                                                    Type = "Speeder Bike"
                                                },
                                            new AssaultItem
                                                {
                                                    Description = "Heavy Blaster and 2 Stormtroopers",
                                                    LoadValue = 1,
                                                    Type = "Heavy Blaster"
                                                },
                                            new AssaultItem
                                                {
                                                    Description = "AT-ST and pilot",
                                                    LoadValue = 6,
                                                    Type = "AT-ST"
                                                }
                                        };

                    var shockTroopers = new AssaultItem
                                            {
                                                Description = "6 Shock Troopers",
                                                LoadValue = 4,
                                                Type = "Shock Trooper Sqaud"
                                            };
                    var stormtroopers = new AssaultItem
                                            {
                                                Description = "9 Stormtroopers",
                                                LoadValue = 4,
                                                Type = "Standard Stormtrooper Sqaud"
                                            };

                    #endregion

                    foreach (var item in troopList)
                    {
                        session.SaveOrUpdate(item);
                    }

                    for (int i = 0; i < 11; i++)
                    {
                        var s = new LandingShip { Designation = string.Format("LS11{0}", i), Deployed = false };
                        session.SaveOrUpdate(s);
                    }

                    var landingShip = new LandingShip { Deployed = true, Designation = "LS1138" };
                    landingShip.AddAssaultItem(shockTroopers);
                    landingShip.AddAssaultItem(stormtroopers);

                    session.SaveOrUpdate(landingShip);

                    var products = new List<Product>()
                                       {
                                           new Product()
                                               {
                                                   Description = "Not your daddy's light saber.",
                                                   InStock = true,
                                                   Name = "Asajj Ventress Force FX Saber",
                                                   Price = 29.99m,
                                                   ShortName = "ForceFXSaber"
                                               },
                                           new Product()
                                               {
                                                   Description = "A replica of the original.",
                                                   InStock = true,
                                                   Name = "Anakin Skywalker Lightsaber",
                                                   Price = 32.99m,
                                                   ShortName = "SkywalkerLightsaber"
                                               },
                                           new Product()
                                               {
                                                   Description = "The perfect balance of weight and performance.",
                                                   InStock = true,
                                                   Name = "Ahsoka Lightsaber",
                                                   Price = 12.99m,
                                                   ShortName = "AhsokaLightsaber"
                                               },
                                            new Product()
                                               {
                                                   Description = "Secure your battleship with one of the finest.",
                                                   InStock = false,
                                                   Name = "Senate Security Clone",
                                                   Price = 22.99m,
                                                   ShortName = "SenateSecurityClone"
                                               },
                                            new Product()
                                               {
                                                   Description = "Bring in the big guns.",
                                                   InStock = true,
                                                   Name = "Alliance Tank Droid",
                                                   Price = 44.99m,
                                                   ShortName = "AllianceTankDrois"
                                               },
                                            new Product()
                                               {
                                                   Description = "Turbo means better!.",
                                                   InStock = true,
                                                   Name = "Clone Wars Turbo Tank",
                                                   Price = 994.99m,
                                                   ShortName = "CloneWarsTank"
                                               },
                                       };

                    foreach (var product in products)
                    {
                        session.SaveOrUpdate(product);
                    }

                    trx.Commit();

                }

            }

            int count;

            using (var session = sessionFactory.OpenSession())
            {
                using (var trx = session.BeginTransaction())
                {
                    var items = session.CreateCriteria(typeof(AssaultItem)).List<AssaultItem>();
                    count = items.Count;
                }
            }

            return count;
        }
 protected override void Before_each()
 {
     base.Before_each();
     _repo = new Repository<AssaultItem>(CreateSessionFactory());
     _item = _repo.GetAll()[0];
 }
 protected override void Because()
 {
     _result = _repo.GetById(_item.Id);
 }
 protected override void Before_each()
 {
     base.Before_each();
     _repo = new Repository<AssaultItem>(CreateSessionFactory());
     _itemToDelete = _repo.GetById(1);
 }
 protected override void Before_each()
 {
     base.Before_each();
     _repo = new Repository<AssaultItem>(CreateSessionFactory());
     _item = _repo.GetById(2);
     _item.Description = _descUpdate;
 }
        protected override void Before_each()
        {
            _item = new AssaultItem
                        {
                            Description = "Dark Trooper squad with 7 dark troopers",
                            LoadValue = 4,
                            Type = "Dark Trooper Squad"
                        };

            _service = Stub<IInventoryService>();
            _service.Stub(x => x.GetAssaultItemById(2)).Return(_item);

            _controller = new InventoryController(_service);
        }
        public ActionResult Save(AssaultItemEditModel item)
        {
            //do save
            var assaultItem = new AssaultItem(item.Id)
                                  {
                                      Description = item.Description,
                                      Type = item.Type,
                                      LoadValue = item.LoadValue
                                  };

            Service.SaveAssaultItem(assaultItem);

            var message = "Item saved successfully.";

            return this.RedirectToAction(x => x.Index(message));
        }
        protected override void Before_each()
        {
            _item = new AssaultItem { Description = "AT-AT", LoadValue = 72 };
            _service = Stub<IInventoryService>();
            _service.Stub(x => x.GetAssaultItemById(2)).Return(_item);

            _controller = new InventoryController(_service);
        }
 protected override void Before_each()
 {
     _ship = new LandingShip {Designation = "LS-1223"};
     _item = new AssaultItem {Description = "AT-ST", LoadValue = 6};
 }
 protected override void Before_each()
 {
     _item = new AssaultItem {Description = "Some Description", Type = "Lame Troopers", LoadValue = 4};
 }
 protected override void Because()
 {
     _result = _service.GetAssaultItemById(2);
 }
 protected override void Before_each()
 {
     base.Before_each();
     _repo = new Repository<AssaultItem>(CreateSessionFactory());
     _newItem = new AssaultItem
                    {
                        Description = "Shock Trooper Squad",
                        Type = "Shocktrooper",
                        LoadValue = 4
                    };
 }