예제 #1
0
        public void Test_All()
        {
            repository = new InMemoryRepository <Storeable>();
            var result = repository.All();

            Assert.IsInstanceOfType(result, typeof(IEnumerable <Storeable>));
        }
예제 #2
0
        public void InMemoryRepository_List_ReturnsIEnumerableOfCorrectType()
        {
            _repository = new InMemoryRepository <StoreableEntity>();

            _result = _repository.All();

            Assert.True(_result is IEnumerable <StoreableEntity>);
        }
예제 #3
0
        public void All_EmpyDataSet()
        {
            var booksList = new List <Book>();
            var inMemoryBookRepository = new InMemoryRepository <Book>(booksList);
            var ntities = inMemoryBookRepository.All();

            Assert.Empty(ntities);
        }
예제 #4
0
        public void All_ReturningCollectionIsNotNull()
        {
            var booksList = new List <Book>();
            var inMemoryBookRepository = new InMemoryRepository <Book>(booksList);
            var entities = inMemoryBookRepository.All();

            Assert.NotNull(entities);
        }
예제 #5
0
        public void All_EmptyList_IsEmpty()
        {
            // Arrange - create new instance of repository in memory and get all items from it
            InMemoryRepository <IStoreable> repository = new InMemoryRepository <IStoreable>();
            ICollection <IStoreable>        collection = repository.All() as ICollection <IStoreable>;

            // Assert - check that the returned collection is empty
            Assert.IsEmpty(collection);
        }
예제 #6
0
        public void Test_Save()
        {
            repository = new InMemoryRepository <Storeable>();
            var newitem = new Storeable {
                Id = 1, Name = "New Item"
            };

            repository.Save(newitem);

            var result = repository.All();

            Assert.IsTrue(((IEnumerable <Storeable>)result).Contains(newitem));
        }
예제 #7
0
        public void All_3Entites()
        {
            var booksList = new List <Book>()
            {
                new Book(),
                new Book(),
                new Book()
            };
            var inMemoryBookRepository = new InMemoryRepository <Book>(booksList);
            var entities = inMemoryBookRepository.All();

            Assert.Equal(booksList.Count, entities.Count());
        }
예제 #8
0
        public void InMemoryRepository_Save_AddsNewItem()
        {
            _repository = new InMemoryRepository <StoreableEntity>();

            var itemToBeSaved = new StoreableEntity()
            {
                Id = 1, Name = "ItemToBeSaved"
            };

            _repository.Save(itemToBeSaved);

            _result = _repository.All();
            Assert.IsTrue(((IEnumerable <StoreableEntity>)_result).Contains(itemToBeSaved));
        }
예제 #9
0
        public void InMemoryRepository_Save_UpdatesExistingItem()
        {
            _repository = new InMemoryRepository <StoreableEntity>();
            var itemToBeSaved = new StoreableEntity()
            {
                Id = 1, Name = "ItemToBeSaved"
            };

            _repository.Save(itemToBeSaved);

            _repository.Save(itemToBeSaved);

            _result = _repository.All();
            Assert.IsTrue(((IEnumerable <StoreableEntity>)_result).All(c => c == itemToBeSaved));
        }
예제 #10
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));
        }
예제 #11
0
        public void GetAll()
        {
            // Arrange
            InMemoryRepository <Object1> controller = new InMemoryRepository <Object1>();
            List <Object1> objectList = GetListObjects();

            // Act
            foreach (Object1 item in objectList)
            {
                controller.Save(item);
            }
            controller.Commmit();
            IEnumerable <Object1> results    = controller.All();
            IEnumerable <Object1> resultTest = controller.dbRepository.Values;

            // Assert
            CollectionAssert.AreEqual(results, resultTest);
        }
예제 #12
0
        public void Add_SingleItem_ContainsExactItem()
        {
            // Arrange - setup quick mock storable
            Mock <IStoreable> storableMock = new Mock <IStoreable>();

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

            // Act - save item to repository
            InMemoryRepository <IStoreable> repository = new InMemoryRepository <IStoreable>();

            repository.Save(item);

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

            Assert.IsTrue(collection.Contains(item));
        }
예제 #13
0
        public void Add_SingleItem_RetunsCorrectCount()
        {
            // Arrange - setup quick mock storable
            Mock <IStoreable> storableMock = new Mock <IStoreable>();

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

            // Act - save item to repository
            InMemoryRepository <IStoreable> repository = new InMemoryRepository <IStoreable>();

            repository.Save(item);

            // Assert - check that the collection contains exactly one item
            ICollection <IStoreable> collection = repository.All() as ICollection <IStoreable>;

            Assert.AreEqual(1, collection.Count);
        }
예제 #14
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));
        }
예제 #15
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);
        }