public void Persist_Method() { Assert.Throws <ArgumentNullException>(() => new MemoryRepository <TestEntity>().Persist(null)); var entity = new TestEntity { Name = "first" }; using (var repository = new MemoryRepository <TestEntity>()) { Assert.False(repository.Any()); repository.Transaction(() => Assert.True(ReferenceEquals(repository.Persist(entity), repository))); entity = repository.Single(); Assert.Equal(0, entity.Id); Assert.Equal("first", entity.Name); entity.Name = "second"; repository.Transaction(() => repository.Persist(entity)); entity = repository.Single(); Assert.Equal(0, entity.Id); Assert.Equal("second", entity.Name); Assert.Equal(1, repository.Count(x => x.Name == "second")); Assert.Equal("second", repository.Single(x => x.Name == "second").Name); } }
public void Dispose_Method() { var entity = new TestEntity(); using (var repository = new MemoryRepository <TestEntity>()) { repository.Persist(entity).Dispose(); Assert.True(ReferenceEquals(repository.Single(), entity)); repository.Delete(entity).Dispose(); Assert.False(repository.Any()); } }
public void Delete_Method() { Assert.Throws <ArgumentNullException>(() => new MemoryRepository <TestEntity>().Delete(null)); var entity = new TestEntity(); using (var repository = new MemoryRepository <TestEntity>()) { repository.Transaction(() => Assert.True(ReferenceEquals(repository.Delete(entity), repository))); repository.Transaction(() => repository.Persist(entity)); repository.Transaction(() => repository.Delete(new TestEntity())); Assert.True(ReferenceEquals(repository.Single(), entity)); repository.Transaction(() => repository.Delete(entity)); Assert.False(repository.Any()); } }