public void GetSingle_FilterReturnsNoEntities_ReturnsNull() { context.Entities.Add(new TestEntity { Name = "Test Entity One" }); context.SaveChanges(); var repo = new DataRepositoryUsingTestPersistenceContext <TestEntity>(); TestEntity resultEntity = repo.GetSingle(e => e.Name == "No entity"); Assert.IsNull(resultEntity); }
public void GetSingle_FilterReturnsManyEntities_Throws() { TestEntity testEntityOne = new TestEntity { Name = "Test Entity One" }; TestEntity testEntityTwo = new TestEntity { Name = "Test Entity Two" }; TestEntity testEntityThree = new TestEntity { Name = "Test Entity Three" }; context.Entities.AddRange(new TestEntity[] { testEntityOne, testEntityTwo, testEntityThree }); context.SaveChanges(); var repo = new DataRepositoryUsingTestPersistenceContext <TestEntity>(); Assert.Throws <DataRepositoryException>(() => repo.GetSingle(e => e.Name.Length > 0)); }
public void GetSingle_AppliesFiltering() { TestEntity testEntityOne = new TestEntity { Name = "Test Entity One" }; TestEntity testEntityTwo = new TestEntity { Name = "Test Entity Two" }; TestEntity testEntityThree = new TestEntity { Name = "Test Entity Three" }; context.Entities.AddRange(new TestEntity[] { testEntityOne, testEntityTwo, testEntityThree }); context.SaveChanges(); var repo = new DataRepositoryUsingTestPersistenceContext <TestEntity>(); TestEntity resultEntity = repo.GetSingle(e => e.Name == "Test Entity Two"); Assert.That(testEntityEqComp.Equals(resultEntity, testEntityTwo)); }
public void GetSingle_AppliesNavigationProperties() { TestEntity testEntity = new TestEntity { Name = "Test Entity" }; testEntity.ChildEntities.Add(new TestChildEntity { Name = "Test Child Entity One" }); testEntity.ChildEntities.Add(new TestChildEntity { Name = "Test Child Entity Two" }); context.Entities.Add(testEntity); context.SaveChanges(); var repo = new DataRepositoryUsingTestPersistenceContext <TestEntity>(); TestEntity resultEntity = repo.GetSingle(e => true, e => e.ChildEntities); Assert.That(resultEntity.ChildEntities.Contains(testEntity.ChildEntities[0], testEntityEqComp), $"Child entity not loaded: {testEntity.ChildEntities[0].Name}"); Assert.That(resultEntity.ChildEntities.Contains(testEntity.ChildEntities[1], testEntityEqComp), $"Child entity not loaded: {testEntity.ChildEntities[1].Name}"); }