Skip to content

Commit 7c0e21f

Browse files
committed
tests
1 parent 3ca55b2 commit 7c0e21f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/GoatQuery/tests/DatabaseTestFixture.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Diagnostics;
3+
using Microsoft.Extensions.Logging;
24
using Testcontainers.PostgreSql;
35
using Xunit;
46

@@ -26,6 +28,17 @@ public async Task InitializeAsync()
2628
var optionsBuilder = new DbContextOptionsBuilder<TestDbContext>();
2729
optionsBuilder.UseNpgsql(connectionString);
2830

31+
// Enable EF Core logging
32+
optionsBuilder.LogTo(
33+
Console.WriteLine,
34+
new[] { DbLoggerCategory.Database.Command.Name, DbLoggerCategory.Query.Name },
35+
LogLevel.Information,
36+
DbContextLoggerOptions.DefaultWithLocalTime | DbContextLoggerOptions.SingleLine
37+
);
38+
39+
optionsBuilder.EnableSensitiveDataLogging();
40+
optionsBuilder.EnableDetailedErrors();
41+
2942
_dbContext = new TestDbContext(optionsBuilder.Options);
3043

3144
// Create database schema

src/GoatQuery/tests/Filter/FilterTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Microsoft.EntityFrameworkCore;
12
using Xunit;
23

34
public sealed class FilterTest : IClassFixture<DatabaseTestFixture>
@@ -391,7 +392,6 @@ public static IEnumerable<object[]> Parameters()
391392
new[] { TestData.Users["Egg"] }
392393
};
393394

394-
// Lambda expression tests with addresses/any
395395
yield return new object[] {
396396
"addresses/any(addr: addr/city/name eq 'New York')",
397397
new[] { TestData.Users["John"], TestData.Users["Apple"] }
@@ -508,7 +508,10 @@ public void Test_Filter(string filter, IEnumerable<User> expected)
508508
Filter = filter
509509
};
510510

511-
var result = TestData.Users.Values.AsQueryable().Apply(query);
511+
var result = _fixture.DbContext.Users.Apply(query);
512+
513+
Console.WriteLine("------------------------------------------ QUERY ------------------------------------------");
514+
Console.WriteLine(result.Value.Query.ToQueryString());
512515

513516
Assert.Equal(expected, result.Value.Query);
514517
}
@@ -528,7 +531,7 @@ public void Test_InvalidFilterReturnsError(string filter)
528531
Filter = filter
529532
};
530533

531-
var result = TestData.Users.Values.AsQueryable().Apply(query);
534+
var result = _fixture.DbContext.Users.Apply(query);
532535

533536
Assert.True(result.IsFailed);
534537
}

0 commit comments

Comments
 (0)