16
16
using System ;
17
17
using System . Linq ;
18
18
using FluentAssertions ;
19
+ using MongoDB . Bson ;
19
20
using MongoDB . Driver . Linq ;
20
21
using Xunit ;
21
22
22
23
namespace MongoDB . Driver . Tests . Linq . Linq3ImplementationTests . Jira
23
24
{
24
25
public class CSharp4328Tests : Linq3IntegrationTest
25
26
{
26
- [ Fact ]
27
- public void Filter_using_First_should_work ( )
27
+ [ Theory ]
28
+ [ InlineData ( null ) ]
29
+ [ InlineData ( "USA" ) ]
30
+ public void Filter_using_First_should_work ( string country )
28
31
{
29
32
var collection = CreateCollection ( ) ;
30
33
var startTargetDeliveryDate = new DateTime ( 2022 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
31
34
var endTargetDeliveryDate = new DateTime ( 2022 , 12 , 31 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
32
- var country = "USA" ;
33
35
34
36
var filterBuilder = Builders < SubscriptionRepositorySubscriptionModel > . Filter ;
35
37
var statusFilter = filterBuilder . Where ( x => x . SubscriptionStatus == SubscriptionStatus . Active ) ;
@@ -44,16 +46,20 @@ public void Filter_using_First_should_work()
44
46
}
45
47
46
48
var renderedFilter = Translate ( collection , filter ) ;
47
- renderedFilter . Should ( ) . Be (
49
+ var expectedFilter = BsonDocument . Parse (
48
50
@"
49
51
{
50
52
SubscriptionStatus : 1,
51
53
'UpcomingOrders.0.NextTargetDeliveryDate' : {
52
54
$gte : ISODate('2022-01-01T00:00:00Z'),
53
55
$lte : ISODate('2022-12-31T00:00:00Z')
54
- },
55
- 'ShippingAddress.CountryCode' : 'USA'
56
+ }
56
57
}" ) ;
58
+ if ( ! string . IsNullOrEmpty ( country ) )
59
+ {
60
+ expectedFilter [ "ShippingAddress.CountryCode" ] = country ;
61
+ }
62
+ renderedFilter . Should ( ) . Be ( expectedFilter ) ;
57
63
58
64
var result = collection . Distinct ( x => x . CustomerId , filter ) . ToList ( ) ;
59
65
result . Should ( ) . Equal ( 2 ) ;
0 commit comments