public void Persist_Method() { Assert.Throws <ArgumentNullException>(() => new EFModelRepository <EFModelEntity>(this.connectionString).Persist(null)); var entity = new EFModelEntity { Name = "first" }; using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString)) { Assert.False(repository.Any()); Assert.True(ReferenceEquals(repository.Persist(entity), repository)); repository.Commit(); entity = repository.Single(); Assert.NotEqual(0, entity.Id); Assert.Equal("first", entity.Name); entity.Name = "second"; repository.Commit(); entity = repository.Single(); Assert.NotEqual(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 Commit_Method() { var entity = new EFModelEntity(); using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString)) { Assert.False(repository.Any()); Assert.True(ReferenceEquals(repository.Persist(entity).Commit(), repository)); Assert.True(ReferenceEquals(repository.Single(), entity)); repository.Delete(entity); Assert.True(ReferenceEquals(repository.Single(), entity)); repository.Commit(); Assert.False(repository.Any()); } }
public void Dispose_Method() { var entity = new EFModelEntity(); using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString)) { repository.Persist(entity).Dispose(); Assert.Throws <ObjectDisposedException>(() => repository.Single()); repository.Dispose(); } }