Ejemplo n.º 1
0
        public void SaveChanges_GivenNewItem_ShouldPersistChanges()
        {
            //---------------Set up test pack-------------------

            using (var dbContext = GetContext())
            {
                var loanItem = new LoanItem { Name = "Strat" };
                dbContext.LoanItems.Add(loanItem);
                //---------------Assert Precondition----------------
                var itemBeforeSave = dbContext.LoanItems.SingleOrDefault(i => i.Name == "Strat");
                Assert.IsNull(itemBeforeSave);
                //---------------Execute Test ----------------------
                dbContext.SaveChanges();
                //---------------Test Result -----------------------
                var addedItem = dbContext.LoanItems.Single(i => i.Name == "Strat");
                Assert.AreEqual(loanItem, addedItem);
            }
        }
Ejemplo n.º 2
0
 public void Add(LoanItem loanItem)
 {
     _dbContext.LoanItems.Add(loanItem);
     _dbContext.SaveChanges();
 }
Ejemplo n.º 3
0
 public ActionResult Create(LoanItem loanItem)
 {
     if (!ModelState.IsValid) return View("Create", loanItem);
     _itemRepository.Add(loanItem);
     return RedirectToAction("Index");
 }
Ejemplo n.º 4
0
 public void Add(LoanItem loanItem)
 {
     _itemModels.Add(loanItem);
 }