public void WhenInstanciatingDbQueryContextThenReturnsObject() { // Arrange FakeDbContext context = CreateDbContext(); // Act DbQueryContext <FakeDbContext> queryContext = new DbQueryContext <FakeDbContext>(context); // Assert Assert.NotNull(queryContext); }
public void WhenDisposingQueryContexthenDisposeInnerDbContext() { // Arrange FakeDbContext context = CreateDbContext(10); DbQueryContext <FakeDbContext> queryContext = new DbQueryContext <FakeDbContext>(context); // Act queryContext.Dispose(); // Assert Assert.True(context.Disposed); }
private static FakeDbContext CreateDbContext(int count = 0) { DbConnection connection = DbConnectionFactory.CreateTransient(); FakeDbContext context = new FakeDbContext(connection); for (int i = 1; i <= count; i++) { context.Entities.Add(new FakeEntity { Property1 = "test" + i, Property2 = i }); } context.SaveChanges(); return context; }
public async Task WhenFindingItemThenRetunsEntity() { // Arrange FakeDbContext context = CreateDbContext(10); DbQueryContext <FakeDbContext> queryContext = new DbQueryContext <FakeDbContext>(context); // Act FakeEntity result = await queryContext.FindAsync <FakeEntity>("test3"); // Assert Assert.NotNull(result); Assert.Equal(3, result.Property2); Assert.Equal("test3", result.Property1); }
private static FakeDbContext CreateDbContext(int count = 0) { DbConnection connection = DbConnectionFactory.CreateTransient(); FakeDbContext context = new FakeDbContext(connection); for (int i = 1; i <= count; i++) { context.Entities.Add(new FakeEntity { Property1 = "test" + i, Property2 = i }); } context.SaveChanges(); return(context); }
public void WhenQueryingItemsThenReturnsEntities() { // Arrange FakeDbContext context = CreateDbContext(10); DbQueryContext <FakeDbContext> queryContext = new DbQueryContext <FakeDbContext>(context); // Act var query = queryContext.Query <FakeEntity>(); // Assert Assert.NotNull(query); Assert.Equal(context.Entities.Count(), query.Count()); Assert.NotNull(query.FirstOrDefault()); Assert.Equal(context.Entities.FirstOrDefault(), query.FirstOrDefault()); Assert.Equal(context.Entities.Count(item => item.Property2 >= 5), query.Count(item => item.Property2 >= 5)); }