11namespace QueryKit . IntegrationTests . Tests ;
22
3- using System . Linq . Expressions ;
43using Bogus ;
54using Configuration ;
65using FluentAssertions ;
@@ -12,9 +11,9 @@ namespace QueryKit.IntegrationTests.Tests;
1211using WebApiTestProject . Database ;
1312using WebApiTestProject . Entities ;
1413using WebApiTestProject . Entities . Recipes ;
15- using WebApiTestProject . Features ;
14+ using Xunit . Abstractions ;
1615
17- public class DatabaseFilteringTests : TestBase
16+ public class DatabaseFilteringTests ( ITestOutputHelper testOutputHelper ) : TestBase
1817{
1918 [ Fact ]
2019 public async Task can_filter_by_string ( )
@@ -40,6 +39,121 @@ public async Task can_filter_by_string()
4039 people [ 0 ] . Id . Should ( ) . Be ( fakePersonOne . Id ) ;
4140 }
4241
42+ [ Fact ]
43+ public async Task can_filter_by_boolean ( )
44+ {
45+ // Arrange
46+ var testingServiceScope = new TestingServiceScope ( ) ;
47+ var faker = new Faker ( ) ;
48+ var fakePersonOne = new FakeTestingPersonBuilder ( )
49+ . WithTitle ( faker . Lorem . Sentence ( ) )
50+ . WithFavorite ( true )
51+ . Build ( ) ;
52+ var fakePersonTwo = new FakeTestingPersonBuilder ( )
53+ . WithTitle ( faker . Lorem . Sentence ( ) )
54+ . WithFavorite ( false )
55+ . Build ( ) ;
56+ await testingServiceScope . InsertAsync ( fakePersonOne , fakePersonTwo ) ;
57+
58+ var input = $ """ { nameof ( TestingPerson . Title ) } == "{ fakePersonOne . Title } " && { nameof ( TestingPerson . Favorite ) } == true""" ;
59+
60+ // Act
61+ var queryablePeople = testingServiceScope . DbContext ( ) . People ;
62+ var appliedQueryable = queryablePeople . ApplyQueryKitFilter ( input ) ;
63+ var people = await appliedQueryable . ToListAsync ( ) ;
64+
65+ // Assert
66+ people . Count . Should ( ) . Be ( 1 ) ;
67+ people [ 0 ] . Id . Should ( ) . Be ( fakePersonOne . Id ) ;
68+ }
69+
70+ [ Fact ]
71+ public async Task can_filter_by_combo_multi_value_pass ( )
72+ {
73+ // Arrange
74+ var testingServiceScope = new TestingServiceScope ( ) ;
75+ var fakePersonOne = new FakeTestingPersonBuilder ( ) . Build ( ) ;
76+ var fakePersonTwo = new FakeTestingPersonBuilder ( )
77+ . WithFirstName ( fakePersonOne . FirstName )
78+ . Build ( ) ;
79+ await testingServiceScope . InsertAsync ( fakePersonOne , fakePersonTwo ) ;
80+
81+ var input = $ """ fullname @=* "{ fakePersonOne . FirstName } { fakePersonOne . LastName } " """ ;
82+ var config = new QueryKitConfiguration ( config =>
83+ {
84+ config . DerivedProperty < TestingPerson > ( tp => tp . FirstName + " " + tp . LastName ) . HasQueryName ( "fullname" ) ;
85+ } ) ;
86+
87+ // Act
88+ var queryablePeople = testingServiceScope . DbContext ( ) . People ;
89+ var appliedQueryable = queryablePeople . ApplyQueryKitFilter ( input , config ) ;
90+ var people = await appliedQueryable . ToListAsync ( ) ;
91+
92+ // Assert
93+ people . Count . Should ( ) . Be ( 1 ) ;
94+ people [ 0 ] . Id . Should ( ) . Be ( fakePersonOne . Id ) ;
95+ }
96+
97+ [ Fact ]
98+ public async Task can_filter_by_combo_complex ( )
99+ {
100+ // Arrange
101+ var testingServiceScope = new TestingServiceScope ( ) ;
102+ var fakePersonOne = new FakeTestingPersonBuilder ( )
103+ . WithAge ( 8888 )
104+ . Build ( ) ;
105+ var fakePersonTwo = new FakeTestingPersonBuilder ( )
106+ . WithFirstName ( fakePersonOne . FirstName )
107+ . Build ( ) ;
108+ await testingServiceScope . InsertAsync ( fakePersonOne , fakePersonTwo ) ;
109+
110+ var input = $ """ (fullname @=* "{ fakePersonOne . FirstName } { fakePersonOne . LastName } ") && age >= { fakePersonOne . Age } """ ;
111+ var config = new QueryKitConfiguration ( config =>
112+ {
113+ config . DerivedProperty < TestingPerson > ( tp => tp . FirstName + " " + tp . LastName ) . HasQueryName ( "fullname" ) ;
114+ } ) ;
115+
116+ // Act
117+ var queryablePeople = testingServiceScope . DbContext ( ) . People ;
118+ var appliedQueryable = queryablePeople . ApplyQueryKitFilter ( input , config ) ;
119+ var people = await appliedQueryable . ToListAsync ( ) ;
120+
121+ // Assert
122+ people . Count . Should ( ) . Be ( 1 ) ;
123+ people [ 0 ] . Id . Should ( ) . Be ( fakePersonOne . Id ) ;
124+ }
125+
126+ [ Fact ]
127+ public async Task can_filter_by_combo ( )
128+ {
129+ // Arrange
130+ var testingServiceScope = new TestingServiceScope ( ) ;
131+ var fakePersonOne = new FakeTestingPersonBuilder ( )
132+ . WithFirstName ( Guid . NewGuid ( ) . ToString ( ) )
133+ . Build ( ) ;
134+ var fakePersonTwo = new FakeTestingPersonBuilder ( ) . Build ( ) ;
135+ await testingServiceScope . InsertAsync ( fakePersonOne , fakePersonTwo ) ;
136+
137+ var input = $ """ fullname @=* "{ fakePersonOne . FirstName } " """ ;
138+ var config = new QueryKitConfiguration ( config =>
139+ {
140+ config . DerivedProperty < TestingPerson > ( tp => tp . FirstName + " " + tp . LastName ) . HasQueryName ( "fullname" ) ;
141+ } ) ;
142+
143+ // Act
144+ var queryablePeople = testingServiceScope . DbContext ( ) . People ;
145+ var appliedQueryable = queryablePeople . ApplyQueryKitFilter ( input , config ) ;
146+ var people = await appliedQueryable . ToListAsync ( ) ;
147+ // var people = testingServiceScope.DbContext().People
148+ // // .Where(p => (p.FirstName + " " + p.LastName).ToLower().Contains(fakePersonOne.FirstName.ToLower()))
149+ // // .Where(x => ((x.FirstName + " ") + x.LastName).ToLower().Contains("ito".ToLower()))
150+ // .ToList();
151+
152+ // Assert
153+ people . Count . Should ( ) . Be ( 1 ) ;
154+ people [ 0 ] . Id . Should ( ) . Be ( fakePersonOne . Id ) ;
155+ }
156+
43157 [ Fact ]
44158 public async Task can_filter_by_string_for_collection ( )
45159 {
0 commit comments