public void ThrowsArgumentNullReferenceException() { var testNull = new TestStoreable { Message = "Ooops" }; Assert.That(() => { _repository.Save(testNull); }, Throws.Exception.TypeOf <ArgumentNullException>()); }
public void CreateInMemoryRepository() { _repository = new InMemoryRepository <TestStoreable>(); _testStoreable1 = new TestStoreable { Id = 1, Message = "Test Storeable 1" }; _testStoreable2 = new TestStoreable { Id = 2, Message = "Test Storeable 2" }; _testStoreable3 = new TestStoreable { Id = Guid.NewGuid(), Message = "Test Storeable 3" }; _testStoreable1Different = new TestStoreable { Id = 1, Message = "Test Storeable 1 Different" }; }
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 Save_ThrowsArgumentNullExceptionIfItemIsNull() { 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.Save(null), Throws.ArgumentNullException); }
public void Get_ReturnsMatchedItem() { 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 }); var actual = inMemoryRepository.Get(2); Assert.That(actual, Is.EqualTo(item2)); }
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)); }
public void GetAll_ReturnsAllItems() { 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 }); var actual = inMemoryRepository.GetAll(); Assert.That(actual, Is.EquivalentTo(new List <TestStoreable <int> > { item1, item2, item3 })); }
public void Get_ReturnsMatchedItemForReferenceTypeId() { var item1 = new TestStoreable <TestReferenceTypeId> { Id = new TestReferenceTypeId(1) }; var item2 = new TestStoreable <TestReferenceTypeId> { Id = new TestReferenceTypeId(2) }; var item3 = new TestStoreable <TestReferenceTypeId> { Id = new TestReferenceTypeId(3) }; var storage = new Dictionary <TestReferenceTypeId, IStoreable <TestReferenceTypeId> > { [new TestReferenceTypeId(1)] = item1, [new TestReferenceTypeId(2)] = item2, [new TestReferenceTypeId(3)] = item3 }; var inMemoryRepository = new InMemoryRepository <IStoreable <TestReferenceTypeId>, TestReferenceTypeId>(storage); var actual = inMemoryRepository.Get(new TestReferenceTypeId(2)); Assert.That(actual, Is.EqualTo(item2)); }
public void Save_UpdatesExistingItemIfAlreadyInStorage() { 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); var newItem = new TestStoreable <int> { Id = 2 }; inMemoryRepository.Save(newItem); Assert.That(storage[2], Is.EqualTo(newItem)); }
public void Save_AddsItemToStorage() { 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); var newItem = new TestStoreable <int> { Id = 4 }; inMemoryRepository.Save(newItem); Assert.That(storage[4], Is.EqualTo(newItem)); }
public void ThrowsNullReferenceException() { TestStoreable testNull = null; Assert.That(() => { _repository.Save(testNull); }, Throws.Exception.TypeOf <NullReferenceException>()); }