Skip to content

Commit

Permalink
#14 Include(...) after AsExpandable() (#165)
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
doboczyakos authored Feb 9, 2022
1 parent 95f71da commit f34e92c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/LinqKit.EntityFramework.Tests.Net452/DbAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public DbAsyncTests()
_db.Entities.RemoveRange(_db.Entities.ToList());
_db.Entities.AddRange(new[]
{
new Entity { Value = 1024, RelatedEntity = new RelatedEntity { Value = 2048 } },
new Entity { Value = 123 },
new Entity { Value = 67 },
new Entity { Value = 3 }
Expand Down Expand Up @@ -63,7 +64,7 @@ public async Task DbAsync_EnumerateShouldWorkAsync()
var after = task.Status;

Assert.Equal(TaskStatus.RanToCompletion, after);
Assert.Equal(3, result.Count);
Assert.Equal(4, result.Count);
}

[Fact]
Expand Down Expand Up @@ -142,5 +143,19 @@ public async Task DbAsync_ExpressionStarter_With_Optimizer()
// Verify
optimizerMock.Verify(o => o(It.IsAny<Expression>()), Times.Once);
}

[Fact]
public async Task DbAsync_IncludeAfterAsExpandableShouldWorkAsync()
{
var entity = await _db.Entities.AsNoTracking().AsExpandable().Include(e => e.RelatedEntity).Where(e => e.Value == 1024).SingleAsync();
Assert.Equal(2048, entity.RelatedEntity?.Value);
}

[Fact]
public async Task DbAsync_IncludeBeforeAsExpandableShouldWorkAsync()
{
var entity = await _db.Entities.AsNoTracking().Include(e => e.RelatedEntity).AsExpandable().Where(e => e.Value == 1024).SingleAsync();
Assert.Equal(2048, entity.RelatedEntity?.Value);
}
}
}
9 changes: 9 additions & 0 deletions tests/LinqKit.EntityFramework.Tests.Net452/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,14 @@ public class Entity
public int Id { get; set; }

public int Value { get; set; }

public RelatedEntity RelatedEntity { get; set; }
}

public class RelatedEntity
{
public int Id { get; set; }

public int Value { get; set; }
}
}
2 changes: 2 additions & 0 deletions tests/LinqKit.EntityFramework.Tests.Net452/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public TestContext(DbContextOptions options) : base(options)
}

public DbSet<Entity> Entities { get; set; }
public DbSet<RelatedEntity> RelatedEntities { get; set; }
}
#else
[DbConfigurationType(typeof(CodeConfig))]
Expand All @@ -31,6 +32,7 @@ public TestContext(string nameOrConnectionString) : base(nameOrConnectionString)
}

public DbSet<Entity> Entities { get; set; }
public DbSet<RelatedEntity> RelatedEntities { get; set; }
}

public class CodeConfig : DbConfiguration
Expand Down

0 comments on commit f34e92c

Please sign in to comment.