public void Test_All() { repository = new InMemoryRepository <Storeable>(); var result = repository.All(); Assert.IsInstanceOfType(result, typeof(IEnumerable <Storeable>)); }
public void InMemoryRepository_List_ReturnsIEnumerableOfCorrectType() { _repository = new InMemoryRepository <StoreableEntity>(); _result = _repository.All(); Assert.True(_result is IEnumerable <StoreableEntity>); }
public void All_EmpyDataSet() { var booksList = new List <Book>(); var inMemoryBookRepository = new InMemoryRepository <Book>(booksList); var ntities = inMemoryBookRepository.All(); Assert.Empty(ntities); }
public void All_ReturningCollectionIsNotNull() { var booksList = new List <Book>(); var inMemoryBookRepository = new InMemoryRepository <Book>(booksList); var entities = inMemoryBookRepository.All(); Assert.NotNull(entities); }
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); }
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)); }
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()); }
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)); }
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)); }
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)); }
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); }
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)); }
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); }
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)); }
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); }