Exemplo n.º 1
0
 public ActionResult Create(Genre model)
 {
     try
     {
         _repo.Persist(model);
         return RedirectToAction("Index");
     }
     catch
     {
         return View("Edit", model);
     }
 }
Exemplo n.º 2
0
        public void GenreRepository_InsertUpdateDelete_Works()
        {
            // Arrange
            var repo = new GenreRepository();
            var testItem = new Genre
            {
                Name = "TestItem",
                Code = "TestItemCode",
                IsInactive = true,
                DisplayOrder = 99
            };

            // Act - Insert
            var insertedItem = repo.Persist(testItem);
            var newId = insertedItem.GenreId;

            // Assert for Insert
            Assert.IsTrue(newId > 0);
            var existingItem = repo.Fetch(newId).Single();
            Assert.IsTrue(existingItem.Name == "TestItem");
            Assert.IsTrue(existingItem.Code == "TestItemCode");
            Assert.IsTrue(existingItem.IsInactive == true);
            Assert.IsTrue(existingItem.DisplayOrder == 99);

            // Act - Update

            existingItem.Name = "TestItem1";
            existingItem.Code = "TestItemCode1";
            existingItem.IsInactive = false;
            existingItem.DisplayOrder = 10;

            repo.Persist(existingItem);

            // Assert for Update
            var updatedItem = repo.Fetch(newId).Single();
            Assert.IsTrue(updatedItem.Name == "TestItem1");
            Assert.IsTrue(updatedItem.Code == "TestItemCode1");
            Assert.IsTrue(updatedItem.IsInactive == false);
            Assert.IsTrue(updatedItem.DisplayOrder == 10);

            // Act - Delete
            updatedItem.IsMarkedForDeletion = true;
            var deletedItem = repo.Persist(updatedItem);

            // Assert for Delete
            Assert.IsNull(deletedItem);
            var emptyResult = repo.Fetch(newId);
            Assert.IsFalse(emptyResult.Any());
        }
Exemplo n.º 3
0
 public ActionResult Edit(Genre vm)
 {
     if( ModelState.IsValid)
     {
         try
         {
             vm.IsDirty = true;
             _repo.Persist(vm);
             return RedirectToAction("Index");
         }
         catch
         {
             return View();
         }
     }
     else
     {
         return View();
     }
 }
Exemplo n.º 4
0
        public void GenreRepository_InsertDelete()
        {
            // Arrange
            var repo = new GenreRepository();
            var newItem = new Genre
            {
                Code = "TestCode",
                Name = "TestName",
                IsInactive = false,
                DisplayOrder = 99
            };

            // Act for Insert
            var item = repo.Persist(newItem);
            var newId = item.GenreId;

            // Assert for Insert - Make sure local object is updated
            Assert.IsTrue(item.GenreId > 0);
            Assert.IsFalse(item.IsMarkedForDeletion);
            Assert.IsFalse(item.IsDirty);

            // Assert for Insert - Make sure refetched object is correct
            var refetch = repo.Fetch(newId).First();
            Assert.IsTrue(refetch.GenreId == newId);
            Assert.IsFalse(refetch.IsMarkedForDeletion);
            Assert.IsFalse(refetch.IsDirty);
            Assert.IsTrue(refetch.Code == "TestCode");
            Assert.IsTrue(refetch.Name == "TestName");
            Assert.IsTrue(refetch.IsInactive == false);
            Assert.IsTrue(refetch.DisplayOrder == 99);

            // Clean-up (Act for Delete)
            item.IsMarkedForDeletion = true;
            repo.Persist(item);

            // Assert for Delete
            var result = repo.Fetch(newId);
            Assert.IsFalse(result.Any());
        }
Exemplo n.º 5
0
        public void GenreRepository_InsertUpdateDelete()
        {
            // Arrange
            var repo = new GenreRepository();
            var newItem = new Genre
            {
                Code = "TestCode",
                Name = "TestName",
                IsInactive = false,
                DisplayOrder = 99
            };
            var item = repo.Persist(newItem);
            var newId = item.GenreId;

            // Act for Update
            item.Name = "XYZ";
            item.Code = "ABC";
            item.IsInactive = true;
            item.DisplayOrder = 999;
            item.IsDirty = true;
            var updatedItem = repo.Persist(item);

            Assert.IsTrue(updatedItem.IsDirty == false);
            Assert.IsTrue(updatedItem.Name == "XYZ");
            Assert.IsTrue(updatedItem.Code == "ABC");
            Assert.IsTrue(updatedItem.IsInactive);
            Assert.IsTrue(updatedItem.DisplayOrder == 999);

            // Assert for Update
            var refetch = repo.Fetch(newId).First();
            Assert.IsTrue(refetch.Name == "XYZ");

            // Clean-up (Act for Delete)
            item.IsMarkedForDeletion = true;
            repo.Persist(item);

            // Assert for Delete
            var result = repo.Fetch(newId);
            Assert.IsFalse(result.Any());
        }
Exemplo n.º 6
0
 private void New(object sender, ExecutedRoutedEventArgs e)
 {
     var newItem = new Genre();
     _genres.Add(newItem);
     ResultsListBox.SelectedItem = newItem;
 }
Exemplo n.º 7
0
        public void GenreRepository_Insert_Insertss()
        {
            // Arrange
            var repo = new GenreRepository();
            var testItem = new Genre
            {
                Name = "TestItem",
                Code = "TestItemCode",
                IsInactive = true,
                DisplayOrder = 99
            };

            // Act
            var insertedItem = repo.Persist(testItem);
            var newId = insertedItem.GenreId;

            // Assert
            Assert.IsTrue(newId > 0);
            var existingItem = repo.Fetch(newId).Single();
            Assert.IsTrue(existingItem.Name == "TestItem");
            Assert.IsTrue(existingItem.Code == "TestItemCode");
            Assert.IsTrue(existingItem.IsInactive == true);
            Assert.IsTrue(existingItem.DisplayOrder == 99);
        }
Exemplo n.º 8
0
 public ActionResult Create()
 {
     Genre model = new Genre();
     return View("Edit", model); // Create and Edit can share same view??
 }