예제 #1
0
        public void Delete_ThrowsArgumentNullExceptionIfIdIsNull()
        {
            var storage            = new Dictionary <int?, IStoreable <int?> >();
            var inMemoryRepository = new InMemoryRepository <IStoreable <int?>, int?>(storage);

            Assert.That(() => inMemoryRepository.Delete(null), Throws.ArgumentNullException.With.Message.Contains("id cannot be null"));
        }
예제 #2
0
        public void SharpRepository_Supports_Basic_Crud_Operations()
        {
            // Declare your generic InMemory Repository.
            // Check out HowToAbstractAwayTheGenericRepository.cs for cleaner ways to new up a repo.
            var repo = new InMemoryRepository<Order, int>();

            // Create
            var create = new Order { Name = "Big sale" };
            repo.Add(create);

            const int expectedOrderId = 1;
            create.OrderId.ShouldEqual(expectedOrderId);

            // Read
            var read = repo.Get(expectedOrderId);
            read.Name.ShouldEqual(create.Name);

            // Update
            read.Name = "Really big sale";
            repo.Update(read);

            var update = repo.Get(expectedOrderId);
            update.OrderId.ShouldEqual(expectedOrderId);
            update.Name.ShouldEqual(read.Name);

            // Delete
            repo.Delete(update);
            var delete = repo.Get(expectedOrderId);
            delete.ShouldBeNull();
        }
예제 #3
0
        public void Logging_Via_Aspects()
        {
            var repository = new InMemoryRepository <Contact, int>();


            var contact1 = new Contact()
            {
                Name = "Contact 1"
            };

            repository.Add(contact1);
            repository.Add(new Contact()
            {
                Name = "Contact 2"
            });
            repository.Add(new Contact()
            {
                Name = "Contact 3"
            });

            contact1.Name += " EDITED";
            repository.Update(contact1);

            repository.Delete(2);

            repository.FindAll(x => x.ContactId < 50);
        }
        public void delete_removes_from_internal_list()
        {
            var list = new List<string> { "Apple", "Ball", "Cat", "Dog" };
            var repository = new InMemoryRepository<string>(list);
            repository.Delete("Apple");

            Assert.That(list.Contains("Apple"), Is.False);
        }
        public void RemoveAnEntity()
        {
            const int entityId  = 1;
            var       storeable = new InMemoryImplementation {
                Id = entityId
            };
            var storeables = new List <InMemoryImplementation> {
                storeable
            };

            _context.Setup(context => context.Data).Returns(storeables);

            _repository.Delete(entityId);
            var actual = _repository.All();

            actual.Should().NotContain(storeable);
        }
        public void DeleteBook_Should_RemoveOneBook_FromListofBooks()
        {
            //Act
            var bookCount = _Repo.GetAll().Count();

            _Repo.Delete(2);

            //Assert
            Assert.Equal(bookCount - 1, _Repo.GetAll().Count());
        }
        public void delete_removes_from_internal_list()
        {
            var list = new List <string> {
                "Apple", "Ball", "Cat", "Dog"
            };
            var repository = new InMemoryRepository <string>(list);

            repository.Delete("Apple");

            Assert.That(list.Contains("Apple"), Is.False);
        }
예제 #8
0
 public ActionResult ConfirmDelete(String Id)
 {
     return(FindOrHttpNotFound(
                () => context.Find(Id),
                (x) =>
     {
         context.Delete(Id);
         context.Commit();
         return RedirectToHome;
     }));
 }
예제 #9
0
        public void ItThrowsNotImplementedException()
        {
            // Arrange
            var repo = new InMemoryRepository <TestEntity>();

            // Act
            var result = Record.Exception(() => repo.Delete(new TestEntity()));

            // Assert
            Assert.IsAssignableFrom <NotImplementedException>(result.GetBaseException());
            Assert.Equal("Delete is not available for TestEntity", result.Message);
        }
        public ActionResult ConfirmDelete(string Id)
        {
            ProductCategory productCategoryToDelete = context.Find(Id);

            if (productCategoryToDelete == null)
            {
                return(HttpNotFound());
            }

            context.Delete(Id);
            context.Commit();
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteCategory(string Id)
        {
            ProductCategory categoryToDelete = contextCategory.Find(Id);

            if (categoryToDelete != null)
            {
                contextCategory.Delete(categoryToDelete.Id);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(HttpNotFound());
            }
        }
        public ActionResult ConfirmDelete(string id)
        {
            Product productToDelete = context.Find(id);

            if (productToDelete == null)
            {
                return(HttpNotFound());
            }
            else
            {
                context.Delete(id);
                context.Commit();
                return(RedirectToAction("Index"));
            }
        }
예제 #13
0
        public ActionResult ConfirmDelete(string Id)
        {
            Product productToDelete = context.Find(Id);

            if (productToDelete == null)
            {
                return(HttpNotFound());
            }
            else
            {
                context.Delete(Id);
                context.Commit();
                return(View(productToDelete));
            }
        }
        public ActionResult ConfirmDelete(string sID)
        {
            ModelProduct cItemToDelete = cRepositoryProducts.Find(sID);

            if (cItemToDelete == null)
            {
                return(HttpNotFound());
            }
            else
            {
                cRepositoryProducts.Delete(sID);
                cRepositoryProducts.Commit();
                return(RedirectToAction("Index"));
            }
        }
예제 #15
0
        public void Logging_Via_Aspects()
        {
            var repository = new InMemoryRepository<Contact, int>();

            var contact1 = new Contact() {Name = "Contact 1"};
            repository.Add(contact1);
            repository.Add(new Contact() { Name = "Contact 2"});
            repository.Add(new Contact() { Name = "Contact 3"});

            contact1.Name += " EDITED";
            repository.Update(contact1);

            repository.Delete(2);

            repository.FindAll(x => x.ContactId < 50);
        }
예제 #16
0
        public void Delete_ThrowsItemNotFoundExceptionIfIdDoesNotMatch()
        {
            var item1 = new TestStoreable <int> {
                Id = 1
            };
            var item2 = new TestStoreable <int> {
                Id = 2
            };
            var item3 = new TestStoreable <int> {
                Id = 3
            };
            var inMemoryRepository = new InMemoryRepository <IStoreable <int>, int>(new Dictionary <int, IStoreable <int> > {
                [1] = item1, [2] = item2, [3] = item3
            });

            Assert.That(() => inMemoryRepository.Delete(4), Throws.InstanceOf <ItemNotFoundException>());
        }
        public void When_Delete_Then_WillRemoveExistingItem()
        {
            //Arrange
            IRepository <SearchableEntity> repository = new InMemoryRepository <SearchableEntity>();
            var existingItem = new SearchableEntity {
                Id = Guid.NewGuid(), Name = "ExistingItem"
            };

            repository.Save(existingItem);

            //Action
            repository.Delete(existingItem.Id);

            //Assert
            var result = repository.List();

            Assert.IsFalse(result.Contains(existingItem));
        }
예제 #18
0
        public void Delete_RemovesItemIfIdMatches()
        {
            var item1 = new TestStoreable <int> {
                Id = 1
            };
            var item2 = new TestStoreable <int> {
                Id = 2
            };
            var item3 = new TestStoreable <int> {
                Id = 3
            };
            var storage = new Dictionary <int, IStoreable <int> > {
                [1] = item1, [2] = item2, [3] = item3
            };
            var inMemoryRepository = new InMemoryRepository <IStoreable <int>, int>(storage);

            inMemoryRepository.Delete(2);

            Assert.That(storage, Does.Not.ContainKey(2));
        }
예제 #19
0
 public ActionResult ConfirmDelete(int id)
 {
     try
     {
         ProductCategory pToDelete = context.FindById(id);
         if (pToDelete == null)
         {
             return(HttpNotFound());
         }
         else
         {
             context.Delete(id);
             context.Commit();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception)
     {
         return(HttpNotFound());
     }
 }
예제 #20
0
        public ActionResult ConfirmDelete(string ID)
        {
            Product MyProdToDelete = MyProdRep.Find(ID);

            if (MyProdToDelete == null)
            {
                return(HttpNotFound());
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(HttpNotFound());
                }
                else
                {
                    MyProdRep.Delete(ID);
                    MyProdRep.Commit();
                    return(RedirectToAction("Index"));
                }
            }
        }
예제 #21
0
        public void SharpRepository_Supports_Basic_Crud_Operations()
        {
            // Declare your generic InMemory Repository.
            // Check out HowToAbstractAwayTheGenericRepository.cs for cleaner ways to new up a repo.
            var repo = new InMemoryRepository <Order, int>();

            // Create
            var create = new Order {
                Name = "Big sale"
            };

            repo.Add(create);

            const int expectedOrderId = 1;

            create.OrderId.ShouldBe(expectedOrderId);

            // Read
            var read = repo.Get(expectedOrderId);

            read.Name.ShouldBe(create.Name);

            // Update
            read.Name = "Really big sale";
            repo.Update(read);

            var update = repo.Get(expectedOrderId);

            update.OrderId.ShouldBe(expectedOrderId);
            update.Name.ShouldBe(read.Name);

            // Delete
            repo.Delete(update);
            var delete = repo.Get(expectedOrderId);

            delete.ShouldBeNull();
        }
예제 #22
0
 // remove Item from the repository
 private bool RemoveFromRepository(int toRemove) =>
 Repository.Delete(toRemove);
예제 #23
0
 public Song Delete(string id)
 {
     return(repository.Delete(id));
 }