-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85e6983
commit f2c047f
Showing
2 changed files
with
84 additions
and
68 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...Codehard.Functional/Codehard.Functional.EntityFramework.Tests/QueryableExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Reflection; | ||
using LanguageExt; | ||
using Microsoft.Data.Sqlite; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
using Codehard.Functional.EntityFramework.Tests.Entities; | ||
using Codehard.Infrastructure.EntityFramework.Extensions; | ||
|
||
namespace Codehard.Functional.EntityFramework.Tests; | ||
|
||
public class QueryableExtensionsTests | ||
{ | ||
private static SqliteConnection CreateInMemoryDatabase() | ||
{ | ||
var connection = new SqliteConnection("DataSource=:memory:"); | ||
connection.Open(); | ||
return connection; | ||
} | ||
|
||
[Fact] | ||
public async Task ToListEffRt_ShouldReturnList() | ||
{ | ||
// Arrange | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var options = new DbContextOptionsBuilder<TestDbContext>() | ||
.UseSqlite(CreateInMemoryDatabase()) | ||
.Options; | ||
|
||
await using var context = new TestDbContext( | ||
options, | ||
builder => builder.ApplyConfigurationsFromAssemblyFor<TestDbContext>(assembly)); | ||
await context.Database.EnsureCreatedAsync(); | ||
|
||
var entityId = Guid.NewGuid(); | ||
var entity = new EntityA | ||
{ | ||
Id = entityId, | ||
}; | ||
|
||
context.As.Add(entity); | ||
await context.SaveChangesAsync(); | ||
|
||
var queryable = context.As.AsQueryable(); | ||
|
||
// Act | ||
var result = | ||
queryable | ||
.ToListEff() | ||
.RunAsync(EnvIO.New(token: CancellationToken.None)); | ||
|
||
// Assert | ||
var list = await result; | ||
|
||
var resultEntity = list.ThrowIfFail(); | ||
|
||
Assert.NotNull(resultEntity); | ||
Assert.Single(resultEntity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters