Esempio n. 1
0
        public void Delete_EntityIsNotExisting_ThrowsArgumentNullException()
        {
            var booksList = new List <Book>();
            var inMemoryBookRepository = new InMemoryRepository <Book>(booksList);

            Assert.Throws <InvalidOperationException>(() => inMemoryBookRepository.Delete(1));
        }
Esempio n. 2
0
        public void Test_Delete()
        {
            repository = new InMemoryRepository <Storeable>();
            var newitem = new Storeable {
                Id = 1, Name = "New Item"
            };

            repository.Save(newitem);

            repository.Delete(1);

            var result = repository.All();

            Assert.IsFalse(((IEnumerable <Storeable>)result).Contains(newitem));
        }
Esempio n. 3
0
        public void InMemoryRepository_Delete_RemovesExistingItem()
        {
            _repository = new InMemoryRepository <StoreableEntity>();
            var itemToBeSaved = new StoreableEntity()
            {
                Id = 1, Name = "ItemToBeSaved"
            };

            _repository.Save(itemToBeSaved);

            _repository.Delete(itemToBeSaved.Id);

            _result = _repository.All();
            Assert.IsFalse(((IEnumerable <StoreableEntity>)_result).Contains(itemToBeSaved));
        }
Esempio n. 4
0
        public void Delete_1Entity()
        {
            var entity = new Book()
            {
                Id = 1
            };
            var booksList = new List <Book>()
            {
                entity
            };
            var inMemoryBookRepository = new InMemoryRepository <Book>(booksList);

            inMemoryBookRepository.Delete(entity.Id);
            Assert.Empty(booksList);
        }
Esempio n. 5
0
        public void Delete()
        {
            // Arrange
            InMemoryRepository <Object1> controller = new InMemoryRepository <Object1>();
            Object1 test = GetObject1("Test1", 4, true);

            // Act
            controller.Save(test);
            IEnumerable <Object1> resultTest = controller.dbRepository.Values;

            controller.Commmit();
            CollectionAssert.Contains(resultTest, test);
            controller.Delete(test.Id);
            controller.Commmit();

            resultTest = controller.dbRepository.Values;

            // Assert
            CollectionAssert.DoesNotContain(resultTest, test);
        }
Esempio n. 6
0
        public void Delete_InvalidId_RemovesNoItem()
        {
            // Arrange - setup quick mock storable
            Mock <IStoreable> storableMock = new Mock <IStoreable>();

            storableMock.Setup(i => i.Id).Returns(validId);
            IStoreable item = storableMock.Object;

            // Save the item to the repository
            InMemoryRepository <IStoreable> repository = new InMemoryRepository <IStoreable>();

            repository.Save(item);

            // Act - try to delete an invalid item from the repository
            repository.Delete(invalidId);

            // Assert - check that the collection does not contain the item
            ICollection <IStoreable> collection = repository.All() as ICollection <IStoreable>;

            Assert.IsTrue(collection.Contains(item));
        }
Esempio n. 7
0
        public void Rollback()
        {
            InMemoryRepository <Object1> controller = new InMemoryRepository <Object1>();
            List <Object1> objectList = GetListObjects();


            // Act
            foreach (Object1 item in objectList)
            {
                controller.Save(item);
            }
            controller.Delete(objectList[2].Id);
            objectList[2].Item2 = 2;
            controller.Update(objectList[2]);
            controller.RollBack();
            controller.Commmit();
            IEnumerable <Object1> check = controller.All();

            // Act

            // Assert
            CollectionAssert.IsEmpty(check);
        }
Esempio n. 8
0
        public void CompletedTest()
        {
            // Arrange
            InMemoryRepository <Object1> controller = new InMemoryRepository <Object1>();
            List <Object1>        objectList        = GetListObjects();
            IEnumerable <Object1> repoList          = controller.dbRepository.Values;

            // Save Act
            foreach (Object1 item in objectList)
            {
                controller.Save(item);
            }

            // Delete Act
            controller.Delete(objectList[2].Id);
            objectList[0].Item2 = 25;
            controller.Update(objectList[0]);
            controller.Commmit();

            //Embty Assert
            CollectionAssert.Contains(repoList, objectList[0]);
            CollectionAssert.Contains(repoList, objectList[1]);
            CollectionAssert.DoesNotContain(repoList, objectList[2]);
        }