1616using System ;
1717using System . Linq ;
1818using FluentAssertions ;
19+ using MongoDB . Bson ;
1920using MongoDB . Driver . Linq ;
2021using Xunit ;
2122
2223namespace MongoDB . Driver . Tests . Linq . Linq3ImplementationTests . Jira
2324{
2425 public class CSharp4328Tests : Linq3IntegrationTest
2526 {
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 )
2831 {
2932 var collection = CreateCollection ( ) ;
3033 var startTargetDeliveryDate = new DateTime ( 2022 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
3134 var endTargetDeliveryDate = new DateTime ( 2022 , 12 , 31 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
32- var country = "USA" ;
3335
3436 var filterBuilder = Builders < SubscriptionRepositorySubscriptionModel > . Filter ;
3537 var statusFilter = filterBuilder . Where ( x => x . SubscriptionStatus == SubscriptionStatus . Active ) ;
@@ -44,16 +46,20 @@ public void Filter_using_First_should_work()
4446 }
4547
4648 var renderedFilter = Translate ( collection , filter ) ;
47- renderedFilter . Should ( ) . Be (
49+ var expectedFilter = BsonDocument . Parse (
4850 @"
4951 {
5052 SubscriptionStatus : 1,
5153 'UpcomingOrders.0.NextTargetDeliveryDate' : {
5254 $gte : ISODate('2022-01-01T00:00:00Z'),
5355 $lte : ISODate('2022-12-31T00:00:00Z')
54- },
55- 'ShippingAddress.CountryCode' : 'USA'
56+ }
5657 }" ) ;
58+ if ( ! string . IsNullOrEmpty ( country ) )
59+ {
60+ expectedFilter [ "ShippingAddress.CountryCode" ] = country ;
61+ }
62+ renderedFilter . Should ( ) . Be ( expectedFilter ) ;
5763
5864 var result = collection . Distinct ( x => x . CustomerId , filter ) . ToList ( ) ;
5965 result . Should ( ) . Equal ( 2 ) ;
0 commit comments