Ejemplo n.º 1
0
        public void Test_LocationsAndItemsPersistence()
        {
            LocationRepository dbLocation = new LocationRepository();

            Location location = new Location("Test run.", 1, 0, 0, 0, 0, 0);
            dbLocation.Create(location);

            Location location2 = dbLocation.GetById(location.LocationID);
            Assert.AreEqual(location.Description, location2.Description);

            location2.Items.Add(new LocationItem("Test item"));
            dbLocation.Update(location2);

            Location location3 = dbLocation.GetById(location.LocationID);
            Assert.AreEqual(location3.Items.Count, 1);

            location3.Items[0].Name = "Test item changed";
            dbLocation.Update(location3);

            Location location4 = dbLocation.GetById(location.LocationID);
            Assert.AreEqual(location3.Items[0].Name, "Test item changed");

            dbLocation.Delete(location.LocationID);
            Location location5 = dbLocation.GetById(location.LocationID);
            Assert.AreEqual(location5, null);
        }
        public ActionResult Create(Location location)
        {
            if (ModelState.IsValid)
            {
                dbLocation.Create(location);
                return RedirectToAction("Index");
            }

            return View(location);
        }
 public void Update(Location location)
 {
     db.Entry(location).State = EntityState.Modified;
     db.SaveChanges();
 }
 public void Create(Location location)
 {
     db.Locations.Add(location);
     db.SaveChanges();
 }