@@ -26,7 +26,7 @@ public async Task CreateTempMongoDbCollection_OnNonExistingCollection_SucceedsBy
2626 await using MongoDbTestContext context = await GivenCosmosMongoDbAsync ( ) ;
2727
2828 string collectionName = context . WhenCollectionNameUnavailable ( ) ;
29- TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName ) ;
29+ TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , context ) ;
3030
3131 await context . ShouldStoreCollectionAsync ( collectionName ) ;
3232
@@ -47,7 +47,7 @@ public async Task CreateTempMongoDbCollection_OnExistingCollection_SucceedsByLea
4747 Shipment shipment = CreateShipment ( ) ;
4848 BsonValue existingId = await context . WhenDocumentAvailableAsync ( collectionName , shipment ) ;
4949
50- TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName ) ;
50+ TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , context ) ;
5151 Shipment createdByUs = CreateShipment ( ) ;
5252#pragma warning disable CS0618 // Type or member is obsolete: currently still testing deprecated functionality.
5353 await collection . AddDocumentAsync ( createdByUs ) ;
@@ -77,7 +77,7 @@ public async Task CreateTempMongoDbCollectionWithCleanAllOnSetup_OnExistingColle
7777 Shipment shipment = CreateShipment ( ) ;
7878 BsonValue existingId = await context . WhenDocumentAvailableAsync ( collectionName , shipment ) ;
7979
80- TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , options =>
80+ TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , context , options =>
8181 {
8282 options . OnSetup . CleanAllDocuments ( ) ;
8383 } ) ;
@@ -105,7 +105,7 @@ public async Task CreateTempMongoDbCollectionWithCleanMatchingOnSetup_OnExisting
105105 BsonValue unmatchedId = await context . WhenDocumentAvailableAsync ( collectionName , unmatched ) ;
106106
107107 // Act
108- TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , options =>
108+ TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , context , options =>
109109 {
110110 options . OnSetup . CleanMatchingDocuments ( ( Shipment s ) => s . BoatId == ( ObjectId ) matchedId )
111111 . CleanMatchingDocuments ( ( Shipment s ) => s . BoatName == matched . BoatName ) ;
@@ -126,7 +126,7 @@ public async Task CreateTempMongoDbCollectionWithCleanAllOnTeardown_OnExistingCo
126126 await using MongoDbTestContext context = await GivenCosmosMongoDbAsync ( ) ;
127127
128128 string collectionName = await context . WhenCollectionNameAvailableAsync ( ) ;
129- TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , options =>
129+ TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , context , options =>
130130 {
131131 options . OnTeardown . CleanAllDocuments ( ) ;
132132 } ) ;
@@ -151,7 +151,7 @@ public async Task CreateTempMongoDbCollectionWithCleanMatchingOnTeardown_OnExist
151151
152152 Shipment matched = CreateShipment ( ) ;
153153 Shipment unmatched = CreateShipment ( ) ;
154- TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , options =>
154+ TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , context , options =>
155155 {
156156 options . OnTeardown . CleanMatchingDocuments ( ( Shipment s ) => s . BoatName != unmatched . BoatName )
157157 . CleanMatchingDocuments ( ( Shipment s ) => s . BoatName == matched . BoatName ) ;
@@ -182,7 +182,7 @@ public async Task CreateTempMongoDbCollectionWithSetupTeardown_OnExistingCollect
182182 BsonValue matchedOnSetupId = await context . WhenDocumentAvailableAsync ( collectionName , matchedOnSetup ) ;
183183 BsonValue unmatchedOnSetupId = await context . WhenDocumentAvailableAsync ( collectionName , unmatchedOnSetup ) ;
184184
185- TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , options =>
185+ TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , context , options =>
186186 {
187187 options . OnSetup . CleanMatchingDocuments ( ( Shipment s ) => s . BoatName == matchedOnSetup . BoatName ) ;
188188 } ) ;
@@ -225,7 +225,7 @@ public async Task CreateTempMongoDbCollection_WhenCollectionWasDeletedOutsideFix
225225 await using MongoDbTestContext context = await GivenCosmosMongoDbAsync ( ) ;
226226
227227 string collectionName = context . WhenCollectionNameUnavailable ( ) ;
228- TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName ) ;
228+ TemporaryMongoDbCollection collection = await WhenTempCollectionCreatedAsync ( collectionName , context ) ;
229229 await context . WhenCollectionDeletedAsync ( collectionName ) ;
230230
231231 // Act
@@ -235,13 +235,17 @@ public async Task CreateTempMongoDbCollection_WhenCollectionWasDeletedOutsideFix
235235 await context . ShouldNotStoreCollectionAsync ( collectionName ) ;
236236 }
237237
238- private async Task < TemporaryMongoDbCollection > WhenTempCollectionCreatedAsync ( string collectionName , Action < TemporaryMongoDbCollectionOptions > configureOptions = null )
238+ private async Task < TemporaryMongoDbCollection > WhenTempCollectionCreatedAsync ( string collectionName , MongoDbTestContext context , Action < TemporaryMongoDbCollectionOptions > configureOptions = null )
239239 {
240240 return await MongoDbTestContext . WhenMongoDbAvailableAsync ( async ( ) =>
241241 {
242- var collection = configureOptions is null
243- ? await TemporaryMongoDbCollection . CreateIfNotExistsAsync ( MongoDb . AccountResourceId , MongoDb . DatabaseName , collectionName , Logger )
244- : await TemporaryMongoDbCollection . CreateIfNotExistsAsync ( MongoDb . AccountResourceId , MongoDb . DatabaseName , collectionName , Logger , configureOptions ) ;
242+ var collection = ( Bogus . Random . Bool ( ) , configureOptions is null ) switch
243+ {
244+ ( false , false ) => await TemporaryMongoDbCollection . CreateIfNotExistsAsync ( MongoDb . AccountResourceId , MongoDb . DatabaseName , collectionName , Logger , configureOptions ) ,
245+ ( false , true ) => await TemporaryMongoDbCollection . CreateIfNotExistsAsync ( MongoDb . AccountResourceId , MongoDb . DatabaseName , collectionName , Logger ) ,
246+ ( true , false ) => await TemporaryMongoDbCollection . CreateIfNotExistsAsync ( context . Database , collectionName , Logger , configureOptions ) ,
247+ ( true , true ) => await TemporaryMongoDbCollection . CreateIfNotExistsAsync ( context . Database , collectionName , Logger )
248+ } ;
245249
246250 Assert . Equal ( collectionName , collection . Name ) ;
247251 return collection ;
0 commit comments