private void SaveItem2() { this.item2 = new Storeable { Id = 2, Description = "item2", StoreId = 2, StoreKey = 2 }; this.repo.Save(this.item2); }
private void SaveItem1() { this.item1 = new Storeable { Id = 1, Description = "item1", StoreId = 1, StoreKey = 1 }; this.repo.Save(this.item1); }
public void Should_Save_New_Item() { CreateNewRepository(); newItemToBeSaved = new Storeable { Id = 1, Name = "ItemToBeSaved" }; repository.Save(newItemToBeSaved); expected = repository.All(); Assert.IsTrue(((IEnumerable <Storeable>)expected).Contains(newItemToBeSaved)); }
public void FindById_NoItemToReturn() { //Arrange this.CreateBaseCacheItems(); //Act this.resultItem = this.repo.FindById(3); //Assert Assert.IsNull(this.resultItem); }
public void FindById_CorrectItemReturned_DemoIComparable() { //Arrange this.CreateBaseCacheItems(); //Act this.resultItem = this.repo.FindById(2); //Assert Assert.IsNotNull(this.resultItem); Assert.AreEqual(0, this.resultItem.CompareTo(this.item2)); }
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 Should_Delete_An_Existing_Item() { CreateNewRepository(); anExistingItem = new Storeable { Id = 1, Name = "AnExistingItemToBeDeleted" }; repository.Save(anExistingItem); repository.Delete(1); expected = repository.All(); Assert.IsFalse(((IEnumerable <Storeable>)expected).Contains(anExistingItem)); }
public void FindById_CorrectItemReturned() { //Arrange this.CreateBaseCacheItems(); //Act this.resultItem = this.repo.FindById(2); //Assert Assert.IsNotNull(this.resultItem); Assert.AreEqual(2, this.resultItem.Id); Assert.AreEqual("item2", this.resultItem.Description); }
public void All_ReturnsItems_FromCache() { //Arrange CacheRepository <Storeable> myCacheRepository = new CacheRepository <Storeable>(new List <Storeable>()); BusinessLogicService <Storeable> myBusinessLogicService = new BusinessLogicService <Storeable>(myCacheRepository); var storeable = new Storeable { Description = "i1", Id = 1, StoreId = 1 }; myBusinessLogicService.Save((Storeable)Convert.ChangeType(storeable, typeof(Storeable))); var resultItems = myBusinessLogicService.All(); Assert.IsNotNull(resultItems); //Assert.AreEqual(1, resultItems.Count()); }
public void SaveCalledOnce() { //Arrange var myDbRepository = new Mock <IDbRepository <Storeable> >(); var storeable = new Storeable { Description = "i1", Id = 1, StoreId = 1 }; myDbRepository.Setup(x => x.Save(storeable)).Verifiable(); BusinessLogicService <Storeable> myBusinessLogicService = new BusinessLogicService <Storeable>(myDbRepository.Object); myBusinessLogicService.Save(storeable); myDbRepository.Verify(x => x.Save(storeable), Times.Once()); }
public void All_ReturnsItems() { //Arrange var myDbRepositoryMock = new Mock <IDbRepository <Storeable> >(); var storeable = new Storeable { Description = "i1", Id = 1, StoreId = 1 }; List <Storeable> list = new List <Storeable>(); list.Add(storeable); myDbRepositoryMock.Setup(x => x.All()).Returns(() => new List <Storeable>(list)); BusinessLogicService <Storeable> myBusinessLogicService = new BusinessLogicService <Storeable>(myDbRepositoryMock.Object); var returned = myBusinessLogicService.All(); Assert.AreEqual(1, returned.Count()); }
public void Test_Find() { repository = new InMemoryRepository <Storeable>(); var firstItem = new Storeable { Id = 1, Name = "First Item" }; var secondItem = new Storeable { Id = 2, Name = "Second Item" }; var thirdItem = new Storeable { Id = 3, Name = "Third Item" }; repository.Save(firstItem); repository.Save(secondItem); repository.Save(thirdItem); var result = repository.FindById(2); Assert.AreEqual(secondItem, result); }
public void Should_Return_Correct_Item_By_Id() { CreateNewRepository(); item1 = new Storeable { Id = 1, Name = "Item1" }; item2 = new Storeable { Id = 2, Name = "Item2" }; item3 = new Storeable { Id = 3, Name = "Item3" }; repository.Save(item1); repository.Save(item2); repository.Save(item3); expected = repository.FindById(2); Assert.AreEqual(item2, expected); }