From 31901fecacd7e0be0bd74434304fbdd9ec5695da Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Wed, 29 Jul 2026 18:40:09 +0200 Subject: [PATCH] CSHARP-6143: Normalize whitespace formatting across the codebase with dotnet format --- .../BenchmarkHelper.cs | 2 +- .../Bson/BsonEncodingBenchmark.cs | 2 +- .../Exporters/EvergreenExporter.cs | 2 +- .../Exporters/LocalExporter.cs | 2 +- .../MultiDoc/FindManyBenchmark.cs | 2 +- src/MongoDB.Bson/IBsonDefaults.cs | 2 +- src/MongoDB.Bson/IO/BsonBinaryReader.cs | 6 +- src/MongoDB.Bson/ObjectModel/Decimal128.cs | 4 +- .../Serialization/BsonClassMap.cs | 4 +- .../BsonClassMapSerializationProvider.cs | 2 +- .../EnumRepresentationConvention.cs | 2 +- .../ImmutableTypeClassMapConvention.cs | 2 +- .../ObjectSerializerAllowedTypesConvention.cs | 4 +- .../Serialization/IBsonSerializationDomain.cs | 2 +- .../IBsonSerializerExtensions.cs | 8 +- .../IMultipleChildSerializersConfigurable.cs | 2 +- .../Options/DateOnlyDocumentFormat.cs | 2 +- .../Serialization/Options/TimeOnlyUnits.cs | 2 +- .../Serialization/SerializerConfigurator.cs | 34 +- .../DiscriminatedInterfaceSerializer.cs | 4 +- .../Serializers/HalfSerializer.cs | 2 +- .../Serializers/ImmutableArraySerializer.cs | 2 +- .../ImmutableDictionarySerializer.cs | 2 +- .../Serializers/ImmutableHashSetSerializer.cs | 2 +- .../Serializers/ImmutableListSerializer.cs | 2 +- .../Serializers/ImmutableQueueSerializer.cs | 2 +- .../ImmutableSortedDictionarySerializer.cs | 2 +- .../ImmutableSortedSetSerializer.cs | 2 +- .../Serializers/ImmutableStackSerializer.cs | 2 +- .../Serializers/KeyValuePairSerializer.cs | 2 +- .../Serializers/MemorySerializer.cs | 3 +- .../Serializers/PrimitivesArrayReader.cs | 6 +- ...ictionaryInterfaceImplementerSerializer.cs | 4 +- .../Serializers/TimeOnlySerializer.cs | 2 +- .../SaslSteps/AWSLastSaslStep.cs | 2 +- src/MongoDB.Driver.Encryption/Binary.cs | 2 +- .../CryptClientFactory.cs | 2 +- .../CsfleSchemaBuilder.cs | 2 +- .../EncryptionOptionsExtensions.cs | 2 +- ...plicitEncryptionLibMongoCryptController.cs | 2 +- src/MongoDB.Driver.Encryption/KmsRequest.cs | 14 +- .../LibraryLoader.cs | 4 +- src/MongoDB.Driver.Encryption/LogLevel.cs | 3 +- .../Gssapi/SecurityContextFactory.cs | 56 +- .../Authentication/Oidc/AzureOidcCallback.cs | 2 +- .../Authentication/Oidc/GcpOidcCallback.cs | 2 +- .../ScramSha/ScramShaSecondSaslStep.cs | 2 +- src/MongoDB.Driver/AutoEncryptionOptions.cs | 2 +- src/MongoDB.Driver/BinaryVectorExtensions.cs | 2 +- src/MongoDB.Driver/BulkWriteUpdateOneModel.cs | 2 +- src/MongoDB.Driver/ClientSessionOptions.cs | 2 +- src/MongoDB.Driver/ClusterKey.cs | 2 +- src/MongoDB.Driver/ConvertOptions.cs | 2 +- .../Core/Bindings/CoreServerSessionPool.cs | 2 +- .../Core/Bindings/NoCoreSession.cs | 4 +- src/MongoDB.Driver/Core/Clusters/Cluster.cs | 2 +- .../Core/Clusters/ClusterFactory.cs | 2 +- .../Core/Configuration/ConnectionString.cs | 2 +- .../Socks5ProxyStreamSettings.cs | 2 +- .../Core/Configuration/TracingOptions.cs | 2 +- .../Core/Connections/ClientDocumentHelper.cs | 10 +- .../Core/Connections/ClientMetadata.cs | 2 +- .../Core/Connections/ConnectionInitializer.cs | 4 +- .../Socks5AuthenticationSettings.cs | 2 +- .../Core/Connections/Socks5Helper.cs | 2 +- .../Core/Connections/Socks5ProxySettings.cs | 2 +- .../Core/Events/CommandStartedEvent.cs | 2 +- .../Core/Logging/LogCategoryHelper.cs | 2 +- .../Operations/AsyncCursorSourceEnumerator.cs | 2 +- .../Operations/CreateCollectionOperation.cs | 6 +- .../Core/Operations/CreateViewOperation.cs | 2 +- .../CursorBatchDeserializationHelper.cs | 3 +- .../Core/Operations/RetryabilityHelper.cs | 2 +- .../RetryableDeleteCommandOperation.cs | 2 +- .../RetryableInsertCommandOperation.cs | 4 +- .../RetryableUpdateCommandOperation.cs | 2 +- .../Operations/UpdateSearchIndexOperation.cs | 2 +- .../Core/WireProtocol/CommandWireProtocol.cs | 3 +- .../Messages/CommandMessageSection.cs | 10 +- .../AutoEncryptionProviderRegistry.cs | 2 +- .../Encryption/KmsProviderRegistry.cs | 2 +- src/MongoDB.Driver/FilterDefinitionBuilder.cs | 26 +- src/MongoDB.Driver/GeoNearOptions.cs | 2 +- src/MongoDB.Driver/GridFS/GridFSBucket.cs | 4 +- .../ISetWindowFieldsPartitionExtensions.cs | 2 +- .../Ast/AstEnumExtensions.cs | 2 +- .../Linq3Implementation/Ast/AstPipeline.cs | 2 +- .../Ast/Expressions/AstCondExpression.cs | 2 +- .../Expressions/AstExpressionExtensions.cs | 4 +- .../AstMedianAccumulatorExpression.cs | 2 +- .../Ast/Expressions/AstMedianExpression.cs | 2 +- .../Expressions/AstMedianWindowExpression.cs | 4 +- .../AstPercentileAccumulatorExpression.cs | 2 +- .../Expressions/AstPercentileExpression.cs | 2 +- .../AstPercentileWindowExpression.cs | 2 +- .../AstGroupingPipelineOptimizer.cs | 2 +- .../Ast/Optimizers/AstSimplifier.cs | 6 +- .../Ast/Stages/AstStage.cs | 2 +- .../Ast/Visitors/AstNodeVisitor.cs | 2 +- .../Misc/IBsonSerializerExtensions.cs | 2 +- .../Misc/PartialEvaluator.cs | 2 +- .../Misc/SerializationHelper.cs | 2 +- .../Reflection/DateTimeConstructor.cs | 2 +- .../Reflection/EnumerableMethod.cs | 2 +- .../Reflection/MethodInfoSet.cs | 2 +- .../Reflection/MongoQueryableMethod.cs | 10 +- .../Reflection/WindowMethod.cs | 2 +- .../SerializerFinderHelperMethods.cs | 8 +- .../SerializerFinderVisitBinary.cs | 2 +- .../SerializerFinderVisitMember.cs | 4 +- .../SerializerFinderVisitMemberInit.cs | 2 +- .../SerializerFinderVisitMethodCall.cs | 16 +- .../SerializerFinderVisitUnary.cs | 2 +- .../Serializers/DictionarySerializer.cs | 2 +- .../DictionaryValueCollectionSerializer.cs | 4 +- .../KeyValuePairWrappedValueSerializer.cs | 4 +- .../ClientSideProjectionRewriter.cs | 2 +- ...essionToAggregationExpressionTranslator.cs | 2 +- ...essionToAggregationExpressionTranslator.cs | 4 +- ...MethodToAggregationExpressionTranslator.cs | 2 +- ...MethodToAggregationExpressionTranslator.cs | 4 +- ...MethodToAggregationExpressionTranslator.cs | 2 +- .../StringInOrNinMethodToFilterTranslator.cs | 2 +- ...MemberExpressionToFilterFieldTranslator.cs | 2 +- .../Linq/LinqProviderAdapter.cs | 2 +- src/MongoDB.Driver/Linq/LookupResult.cs | 6 +- src/MongoDB.Driver/MongoClientSettings.cs | 2 +- src/MongoDB.Driver/MongoCollectionImpl.cs | 2 +- src/MongoDB.Driver/MongoDatabase.cs | 2 +- src/MongoDB.Driver/MongoTelemetry.cs | 2 +- src/MongoDB.Driver/MongoUrlBuilder.cs | 2 +- src/MongoDB.Driver/OperationContext.cs | 4 +- .../PipelineStageDefinitionBuilder.cs | 4 +- .../ProjectionDefinitionBuilder.cs | 3 +- src/MongoDB.Driver/RankFusionOptions.cs | 2 +- src/MongoDB.Driver/Search/MatchCriteria.cs | 2 +- .../Search/OperatorSearchDefinitions.cs | 3 +- .../Search/RankFusionScoreDetails.cs | 2 +- .../Search/SearchDefinitionBuilder.cs | 4 +- .../Search/SearchPhraseOptions.cs | 2 +- src/MongoDB.Driver/Search/SearchRangeV2.cs | 2 +- .../Search/SearchScoreDefinitionBuilder.cs | 2 +- .../Search/SearchSpanDefinition.cs | 2 +- .../Search/SearchTextOptions.cs | 2 +- src/MongoDB.Driver/SortDirectionExtensions.cs | 2 +- .../LambdaFunction.cs | 12 +- tests/MongoDB.Bson.TestHelpers/Reflector.cs | 2 +- .../BsonExtensionMethodsTests.cs | 10 +- .../IO/BsonBinaryReaderTests.cs | 2 +- .../ObjectModel/ObjectIdTests.cs | 6 +- .../BsonClassMapSerializerTests.cs | 4 +- ...ctSerializerAllowedTypesConventionTests.cs | 4 +- .../Serialization/ExtensionMembersTests.cs | 2 +- .../BinaryVectorSerializerTests.cs | 20 +- .../Serializers/Decimal128SerializerTests.cs | 4 +- .../Serializers/DiscriminatorTests.cs | 4 +- .../ElementAppendingSerializerTests.cs | 2 +- .../ExpandoObjectSerializerTests.cs | 4 +- .../ImmutableArraySerializerTests.cs | 2 +- .../ImmutableDictionarySerializerTests.cs | 2 +- .../ImmutableHashSetSerializerTest.cs | 2 +- .../ImmutableListSerializerTests.cs | 2 +- .../ImmutableQueueSerializerTests.cs | 2 +- ...mmutableSortedDictionarySerializerTests.cs | 2 +- .../ImmutableSortedSetSerializerTests.cs | 2 +- .../ImmutableStackSerializerTests.cs | 2 +- .../SerializeAsNominalTypeSerializerTests.cs | 2 +- .../SigningRSAESPKCSCallbackTests.cs | 2 +- .../Core/CoreTestConfiguration.cs | 2 +- .../Core/EventCapturer.cs | 2 +- .../CommandStartedEventAsserter.cs | 2 +- .../Core/Logging/LogEntry.cs | 2 +- .../Core/SpanCapturer.cs | 2 +- .../MongoDatabaseFixture.cs | 4 +- .../X509CertificateLoader.cs | 2 +- .../AggregateGeoNearTests.cs | 2 +- .../AggregateRankFusionTests.cs | 6 +- .../AuthenticatorFactoryTests.cs | 3 +- .../MongoAWSAuthenticatorTests.cs | 12 +- .../Oidc/FileOidcCallbackTests.cs | 4 +- .../Authentication/PlainAuthenticatorTests.cs | 4 +- .../Authentication/SaslPrepHelperTests.cs | 7 +- .../ScramSha1AuthenticatorTests.cs | 2 +- .../ScramSha256AuthenticatorTests.cs | 8 +- .../ClientBulkWriteComplexIdTests.cs | 2 +- .../ClientSessionExtensionsTests.cs | 4 +- .../Core/Bindings/CoreSessionTests.cs | 2 +- .../Core/Clusters/ClusterDescriptionTests.cs | 4 +- .../Core/Clusters/ClusterTests.cs | 2 +- .../Core/Clusters/LoadBalancedClusterTests.cs | 2 +- .../Configuration/ClusterSettingsTests.cs | 4 +- .../Configuration/ConnectionStringTests.cs | 2 +- .../Configuration/SslStreamSettingsTests.cs | 2 +- .../ExclusiveConnectionPoolTests.cs | 8 +- .../ConnectionPools/MaintenanceHelperTests.cs | 3 +- .../Connections/ClientDocumentHelperTests.cs | 6 +- .../Core/Connections/ConnectionIdTests.cs | 4 +- .../Connections/ConnectionInitializerTests.cs | 6 +- .../Core/Connections/HelloHelperTests.cs | 8 +- .../Core/Connections/HelloResultTests.cs | 2 +- .../Socks5AuthenticationSettingsTests.cs | 2 +- .../Connections/Socks5ProxySettingsTests.cs | 2 +- .../Core/Connections/TcpStreamFactoryTests.cs | 12 +- .../Core/DeferredAsyncCursorTests.cs | 2 +- .../TraceSourceSdamEventSubscriberTests.cs | 2 +- .../Core/Misc/StreamExtensionMethodsTests.cs | 42 +- .../Core/Misc/TaskExtensionsTests.cs | 2 +- .../Operations/AggregateOperationTests.cs | 16 +- .../AggregateToCollectionOperationTests.cs | 22 +- .../Core/Operations/AsyncCursorTests.cs | 2 +- .../CompositeWriteOperationTests.cs | 2 +- .../Core/Operations/CountOperationTests.cs | 18 +- .../Operations/CreateViewOperationTests.cs | 2 +- .../Operations/DropDatabaseOperationTests.cs | 2 +- .../Operations/DropIndexOperationTests.cs | 4 +- .../EndTransactionOperationTests.cs | 2 +- .../FindOneAndDeleteOperationTests.cs | 10 +- .../FindOneAndReplaceOperationTests.cs | 16 +- .../FindOneAndUpdateOperationTests.cs | 2 +- .../Core/Operations/FindOperationTests.cs | 2 +- .../Operations/MapReduceOperationBaseTests.cs | 20 +- ...pReduceOutputToCollectionOperationTests.cs | 4 +- .../Core/Servers/HeartbeatDelayTests.cs | 2 +- .../Core/Servers/RoundTripTimeMonitorTests.cs | 2 +- .../Core/Servers/ServerMonitorTests.cs | 2 +- .../Core/Servers/TopologyVersionTests.cs | 2 +- .../DiscriminatorElementNameConflictTests.cs | 2 +- .../Encryption/ClientEncryptionTests.cs | 2 +- .../Encryption/CsfleSchemaBuilderTests.cs | 16 +- .../Encryption/EncryptOptionsTests.cs | 4 +- ...efinitionBuilderEnumComparedToEnumTests.cs | 2 +- ...FindOneAndMethodOverloadResolutionTests.cs | 2 +- .../GridFS/GridFSUploadStreamTests.cs | 2 +- .../JsonDrivenWaitForPrimaryChangeTest.cs | 2 +- .../CompareToInFilterAndProjectionTests.cs | 196 ++-- ...rtyOnCollectionTypesWhereAndSelectTests.cs | 548 +++++----- .../DictionaryContainsKeyEnumKeyTests.cs | 120 +-- .../DictionaryContainsValueTests.cs | 220 ++--- ...cumentAndListIndexerSelectAndWhereTests.cs | 932 +++++++++--------- ...mEqualityAndNumericCastWhereSelectTests.cs | 106 +- .../FilterLtDateTimeStringTests.cs | 54 +- ...rStartsWithPartialEvaluationDeleteTests.cs | 54 +- ...terAndProjectionWithFirstOverArrayTests.cs | 2 +- ...ndOneAndModifyExpressionProjectionTests.cs | 102 +- .../FindProjectScalarFieldTests.cs | 76 +- .../FindProjectSubDocumentIdTests.cs | 58 +- .../Integration/FindProjectionRenderTests.cs | 60 +- ...FindWithRawStringProjectionResultsTests.cs | 292 +++--- ...IdentityExpressionProjectionRenderTests.cs | 172 ++-- .../IsNullOrEmptyAndNullCoalescingTests.cs | 152 +-- .../Linq/Integration/MqlSubtypeTests.cs | 2 +- ...NestedAnyAndExistsInSelectAndWhereTests.cs | 262 ++--- .../Integration/NestedLookupSelectTests.cs | 280 +++--- ...tTypeIsAndGetTypeFindAndProjectionTests.cs | 766 +++++++------- .../PositionalUpdateOperatorRenderingTests.cs | 6 +- .../Integration/ReplaceOneUpsertedIdTests.cs | 50 +- ...gToLowerToUpperProjectionAndFilterTests.cs | 342 +++---- ...ateDefinitionCombinePipelineThrowsTests.cs | 58 +- ...dOnlyCollectionWithChildSerializerTests.cs | 6 +- .../Integration/UpdateSetValueObjectTests.cs | 2 +- .../UpdateWithDiscriminatorTests.cs | 2 +- ...ngIdCustomObjectIdSerializerFilterTests.cs | 102 +- ...ConvertTValueToBsonValueProjectionTests.cs | 2 +- .../IGroupingEnumerableMethodsTests.cs | 4 +- ...ndexerOverCustomDocumentSerializerTests.cs | 2 +- .../ProjectWithObjectIdSerializerTests.cs | 96 +- ...nToAggregationExpressionTranslatorTests.cs | 3 +- ...dToAggregationExpressionTranslatorTests.cs | 16 +- .../DictionaryKeysAndValuesProjectionTests.cs | 3 +- ...pFirstOrLastNestedFieldAccumulatorTests.cs | 20 +- ...dToAggregationExpressionTranslatorTests.cs | 2 +- .../NestedWhereInProjectionToFilterTests.cs | 2 +- ...derByThenByInProjectionToSortArrayTests.cs | 2 +- ...dToAggregationExpressionTranslatorTests.cs | 2 +- ...dToAggregationExpressionTranslatorTests.cs | 2 +- ...SelectBooleanConditionalProjectionTests.cs | 4 +- ...nToAggregationExpressionTranslatorTests.cs | 2 +- ...dToAggregationExpressionTranslatorTests.cs | 2 +- .../SelectMultiplyMixedIntegerTypesTests.cs | 2 +- ...ctNewArrayOfDerivedTypesProjectionTests.cs | 4 +- ...lectNullCoalescingStringProjectionTests.cs | 2 +- .../SelectStringCompareProjectionTests.cs | 2 +- .../SequenceEqualInProjectionTests.cs | 2 +- ...dToAggregationExpressionTranslatorTests.cs | 4 +- .../SkipTakeArraySlicingInProjectionTests.cs | 22 +- ...dToAggregationExpressionTranslatorTests.cs | 8 +- ...dToAggregationExpressionTranslatorTests.cs | 6 +- ...nToAggregationExpressionTranslatorTests.cs | 2 +- ...nToAggregationExpressionTranslatorTests.cs | 8 +- ...nToAggregationExpressionTranslatorTests.cs | 2 +- .../ExecutableQueryTests.cs | 2 +- .../BsonValueAsConversionFilterTests.cs | 2 +- ...onvertExpressionToFilterTranslatorTests.cs | 2 +- ...ullableValueEqualsComparisonFilterTests.cs | 152 +-- ...ngContainsStartsWithEndsWithFilterTests.cs | 2 +- .../WhereMemoryExtensionsContainsTests.cs | 2 +- .../WhereSubstringTrimAndNullableBoolTests.cs | 4 +- .../GroupBySelectNewModelProjectionTests.cs | 2 +- ...oinSelectManyWithDictionaryIndexerTests.cs | 192 ++-- ...GroupJoinWithFirstProjectionStagesTests.cs | 154 +-- .../OfTypeMethodToPipelineTranslatorTests.cs | 4 +- ...OfTypeOverDerivedHierarchyPipelineTests.cs | 3 +- ...icalDiscriminatorTypeNamesPipelineTests.cs | 238 ++--- ...placeWithUsesConfiguredElementNameTests.cs | 72 +- ...tManyOverDictionaryRepresentationsTests.cs | 332 +++---- .../UnionMethodToPipelineTranslatorTests.cs | 2 +- .../MongoQueryableTests.cs | 4 +- .../AggregateGroupTranslatorTests.cs | 2 +- .../AggregateProjectTranslatorTests.cs | 2 +- .../MongoClientSettingsTests.cs | 14 +- .../MongoUrlBuilderTests.cs | 5 +- tests/MongoDB.Driver.Tests/MongoUrlTests.cs | 2 +- .../OfTypeDiscriminatorConventionTests.cs | 2 +- .../OfTypeMongoCollectionTests.cs | 2 +- .../OfTypeSerializerTests.cs | 2 +- .../PipelineDefinitionBuilderTests.cs | 6 +- .../PipelineStageDefinitionBuilderTests.cs | 2 +- .../Samples/AggregationSample.cs | 6 +- .../Search/AtlasSearchIndexManagmentTests.cs | 4 +- .../Search/AtlasSearchTests.cs | 16 +- .../Search/SearchDefinitionBuilderTests.cs | 18 +- .../Search/VectorSearchTests.cs | 6 +- .../Specifications/UnifiedTestSpecRunner.cs | 2 +- .../auth/OidcAuthenticationProseTests.cs | 4 +- .../EncryptionTestHelper.cs | 4 +- .../prose-tests/ClientEncryptionProseTests.cs | 432 ++++---- .../crud/prose-tests/CrudProseTests.cs | 16 +- .../prose-tests/SrvPartsTests.cs | 2 +- .../RetryableReadsProseTests.cs | 2 +- .../prose-tests/PoolClearRetryability.cs | 2 +- .../prose-tests/ServerDiscoveryProseTests.cs | 2 +- .../server-selection/InWindowTestRunner.cs | 4 +- .../ServerSelectionTestHelpers.cs | 20 +- .../sessions/SessionsProseTests.cs | 2 +- .../socks5-support/Socks5SupportProseTests.cs | 10 +- .../transactions/TransactionsProseTests.cs | 2 +- .../MongoDB.Driver.Tests/SslSettingsTests.cs | 6 +- .../Matchers/UnifiedErrorMatcher.cs | 4 +- .../Matchers/UnifiedEventMatcher.cs | 3 +- .../UnifiedAppendMetadataOperation.cs | 2 +- .../UnifiedBulkWriteOperation.cs | 8 +- .../UnifiedGetSnapshotTimeOperation.cs | 2 +- .../UnifiedRewrapManyDataKeyOperation.cs | 3 +- tests/MongoDB.Driver.Tests/X509Tests.cs | 2 +- .../UnobservedExceptionTestDiscoverer.cs | 4 +- .../ArrayMethodTests.cs | 2 +- .../LibmongocryptTests.cs | 2 +- .../LoggingTests.cs | 2 +- 348 files changed, 4025 insertions(+), 4004 deletions(-) diff --git a/benchmarks/MongoDB.Driver.Benchmarks/BenchmarkHelper.cs b/benchmarks/MongoDB.Driver.Benchmarks/BenchmarkHelper.cs index 8ba7ec1a204..65c7f9b709a 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/BenchmarkHelper.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/BenchmarkHelper.cs @@ -95,4 +95,4 @@ public static IMongoClient CreateClient(string databaseToDrop = PerfTestDatabase return client; } } -} \ No newline at end of file +} diff --git a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs index 2f4f862c9f1..d1547361695 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/Bson/BsonEncodingBenchmark.cs @@ -47,7 +47,7 @@ public void Setup() _writer = new BsonBinaryWriter(_stream); _context = BsonSerializationContext.CreateRoot(_writer); _document = ReadExtendedJson(BenchmarkData.FilePath); - _documentPoco = BsonSerializer.Deserialize(_document, BenchmarkData.PocoType); + _documentPoco = BsonSerializer.Deserialize(_document, BenchmarkData.PocoType); _pocoSerializer = BsonSerializer.LookupSerializer(BenchmarkData.PocoType); } diff --git a/benchmarks/MongoDB.Driver.Benchmarks/Exporters/EvergreenExporter.cs b/benchmarks/MongoDB.Driver.Benchmarks/Exporters/EvergreenExporter.cs index 5e4c2b077ce..c81ed5a8484 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/Exporters/EvergreenExporter.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/Exporters/EvergreenExporter.cs @@ -85,4 +85,4 @@ private static void WriteScoreToResults(JsonWriter jsonWriter, string name, doub jsonWriter.WriteEndDocument(); } -} \ No newline at end of file +} diff --git a/benchmarks/MongoDB.Driver.Benchmarks/Exporters/LocalExporter.cs b/benchmarks/MongoDB.Driver.Benchmarks/Exporters/LocalExporter.cs index 25c3d26f4a2..966d2647de2 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/Exporters/LocalExporter.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/Exporters/LocalExporter.cs @@ -69,4 +69,4 @@ private static void WriteScore(StreamWriter writer, string benchName, double sco ? $"Executed {benchName}, score: {score:F3} {unit}" : $"Skipped {benchName}"); } -} \ No newline at end of file +} diff --git a/benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/FindManyBenchmark.cs b/benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/FindManyBenchmark.cs index 0c8b42542ef..ad4ed93798a 100644 --- a/benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/FindManyBenchmark.cs +++ b/benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/FindManyBenchmark.cs @@ -49,7 +49,7 @@ public void Setup() [Benchmark] public void FindManyAndEmptyCursor() { - _ = _collection.Find(Builders.Filter.Empty).ToList(); + _ = _collection.Find(Builders.Filter.Empty).ToList(); } [Benchmark] diff --git a/src/MongoDB.Bson/IBsonDefaults.cs b/src/MongoDB.Bson/IBsonDefaults.cs index 5b12054dabf..79e8b6845f1 100644 --- a/src/MongoDB.Bson/IBsonDefaults.cs +++ b/src/MongoDB.Bson/IBsonDefaults.cs @@ -31,4 +31,4 @@ internal interface IBsonDefaults /// Gets or sets the maximum allowed serialization depth. int MaxSerializationDepth { get; set; } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Bson/IO/BsonBinaryReader.cs b/src/MongoDB.Bson/IO/BsonBinaryReader.cs index 1cc9f8f255d..c9fa90969b0 100644 --- a/src/MongoDB.Bson/IO/BsonBinaryReader.cs +++ b/src/MongoDB.Bson/IO/BsonBinaryReader.cs @@ -794,13 +794,13 @@ private string GenerateDottedElementName(BsonBinaryReaderContext[] contexts, int if (context.ContextType == ContextType.Document) { - return GenerateDottedElementName(contexts, nextIndex, (context.ElementName ?? "?") + "." + elementName); + return GenerateDottedElementName(contexts, nextIndex, (context.ElementName ?? "?") + "." + elementName); } if (context.ContextType == ContextType.Array) { var indexElementName = context.ArrayIndex.ToString(NumberFormatInfo.InvariantInfo); - return GenerateDottedElementName(contexts, nextIndex, indexElementName + "." + elementName); + return GenerateDottedElementName(contexts, nextIndex, indexElementName + "." + elementName); } if (nextIndex < contexts.Length) @@ -834,7 +834,7 @@ private void PopContext() throw new FormatException($"Expected size to be {_context.Size}, not {actualSize}."); } - _context =_contextStack.Pop(); + _context = _contextStack.Pop(); } private void PushContext(BsonBinaryReaderContext newContext) diff --git a/src/MongoDB.Bson/ObjectModel/Decimal128.cs b/src/MongoDB.Bson/ObjectModel/Decimal128.cs index 33e112cf7ce..29e18bc6ea7 100644 --- a/src/MongoDB.Bson/ObjectModel/Decimal128.cs +++ b/src/MongoDB.Bson/ObjectModel/Decimal128.cs @@ -1938,7 +1938,7 @@ public int Compare(Decimal128 x, Decimal128 y) { var xType = GetDecimal128Type(x); var yType = GetDecimal128Type(y); - // .NET Framework lacks some optimizations for enums that would result in boxing and lookup overhead for the default comparer + // .NET Framework lacks some optimizations for enums that would result in boxing and lookup overhead for the default comparer #if NET6_0_OR_GREATER var result = Comparer.Default.Compare(xType, yType); #else @@ -1967,7 +1967,7 @@ private int CompareNumbers(Decimal128 x, Decimal128 y) { var xClass = GetNumberClass(x); var yClass = GetNumberClass(y); - // .NET Framework lacks some optimizations for enums that would result in boxing and lookup overhead for the default comparer + // .NET Framework lacks some optimizations for enums that would result in boxing and lookup overhead for the default comparer #if NET6_0_OR_GREATER var result = Comparer.Default.Compare(xClass, yClass); #else diff --git a/src/MongoDB.Bson/Serialization/BsonClassMap.cs b/src/MongoDB.Bson/Serialization/BsonClassMap.cs index 69e9aa678dc..3dea0b441ba 100644 --- a/src/MongoDB.Bson/Serialization/BsonClassMap.cs +++ b/src/MongoDB.Bson/Serialization/BsonClassMap.cs @@ -317,7 +317,7 @@ public static BsonClassMap LookupClassMap(Type classType) => /// /// The class. /// The class map. - public static BsonClassMap RegisterClassMap()=> + public static BsonClassMap RegisterClassMap() => BsonSerializationDomain.Default.ClassMapRegistry.RegisterClassMap(); /// @@ -400,7 +400,7 @@ public override bool Equals(object obj) return GetType().Equals(obj.GetType()) && obj is BsonClassMap other && - _frozen.Equals(true) && other._frozen.Equals(true) && // BsonClassMaps should only be equal if they are frozen + _frozen.Equals(true) && other._frozen.Equals(true) && // BsonClassMaps should only be equal if they are frozen object.Equals(_baseClassMap, other._baseClassMap) && object.Equals(_classType, other._classType) && object.Equals(_creator, other._creator) && diff --git a/src/MongoDB.Bson/Serialization/BsonClassMapSerializationProvider.cs b/src/MongoDB.Bson/Serialization/BsonClassMapSerializationProvider.cs index 79f6ea7ad69..9254709a45c 100644 --- a/src/MongoDB.Bson/Serialization/BsonClassMapSerializationProvider.cs +++ b/src/MongoDB.Bson/Serialization/BsonClassMapSerializationProvider.cs @@ -53,7 +53,7 @@ public override IBsonSerializer GetSerializer(Type type, IBsonSerializerRegistry var classMap = _serializationDomain.ClassMapRegistry.LookupClassMap(type); var classMapSerializerDefinition = typeof(BsonClassMapSerializer<>); var classMapSerializerType = classMapSerializerDefinition.MakeGenericType(type); - var bindingAttr = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; + var bindingAttr = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; return (IBsonSerializer)Activator.CreateInstance(classMapSerializerType, bindingAttr, binder: null, args: [_serializationDomain, classMap], culture: null); } diff --git a/src/MongoDB.Bson/Serialization/Conventions/EnumRepresentationConvention.cs b/src/MongoDB.Bson/Serialization/Conventions/EnumRepresentationConvention.cs index 9d20a2a16c6..a9e62979ff2 100644 --- a/src/MongoDB.Bson/Serialization/Conventions/EnumRepresentationConvention.cs +++ b/src/MongoDB.Bson/Serialization/Conventions/EnumRepresentationConvention.cs @@ -35,7 +35,7 @@ public class EnumRepresentationConvention : ConventionBase, IMemberMapConvention /// The serialization representation. 0 is used to detect representation /// from the enum itself. public EnumRepresentationConvention(BsonType representation) - :this(representation, true) + : this(representation, true) { } diff --git a/src/MongoDB.Bson/Serialization/Conventions/ImmutableTypeClassMapConvention.cs b/src/MongoDB.Bson/Serialization/Conventions/ImmutableTypeClassMapConvention.cs index 717cd61b3fd..efc40c03bb1 100644 --- a/src/MongoDB.Bson/Serialization/Conventions/ImmutableTypeClassMapConvention.cs +++ b/src/MongoDB.Bson/Serialization/Conventions/ImmutableTypeClassMapConvention.cs @@ -157,4 +157,4 @@ bool PropertyMatchesSomeConstructorParameter(ConstructorInfo constructorInfo) } } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Bson/Serialization/Conventions/ObjectSerializerAllowedTypesConvention.cs b/src/MongoDB.Bson/Serialization/Conventions/ObjectSerializerAllowedTypesConvention.cs index fd292fd9ae3..724a59ff710 100644 --- a/src/MongoDB.Bson/Serialization/Conventions/ObjectSerializerAllowedTypesConvention.cs +++ b/src/MongoDB.Bson/Serialization/Conventions/ObjectSerializerAllowedTypesConvention.cs @@ -89,7 +89,7 @@ public ObjectSerializerAllowedTypesConvention(IEnumerable allowedTypes) { var allowedTypesArray = allowedTypes.ToArray(); - _allowedDeserializationTypes = allowedTypesArray.Contains; + _allowedDeserializationTypes = allowedTypesArray.Contains; _allowedSerializationTypes = allowedTypesArray.Contains; } @@ -210,4 +210,4 @@ private IBsonSerializer Reconfigure(IBsonSerializer serializer) return null; } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Bson/Serialization/IBsonSerializationDomain.cs b/src/MongoDB.Bson/Serialization/IBsonSerializationDomain.cs index a5dc3dd69b0..d8a16e345ad 100644 --- a/src/MongoDB.Bson/Serialization/IBsonSerializationDomain.cs +++ b/src/MongoDB.Bson/Serialization/IBsonSerializationDomain.cs @@ -152,7 +152,7 @@ void RegisterGenericSerializerDefinition( /// bool UseZeroIdChecker { get; set; } - /// + /// /// Deserializes an object from a BsonDocument. /// /// The nominal type of the object. diff --git a/src/MongoDB.Bson/Serialization/IBsonSerializerExtensions.cs b/src/MongoDB.Bson/Serialization/IBsonSerializerExtensions.cs index ef88e809f09..bda390f7296 100644 --- a/src/MongoDB.Bson/Serialization/IBsonSerializerExtensions.cs +++ b/src/MongoDB.Bson/Serialization/IBsonSerializerExtensions.cs @@ -132,10 +132,10 @@ public static IDiscriminatorConvention GetDiscriminatorConvention(this IBsonSeri case IHasDiscriminatorConvention hasDiscriminatorConvention: return hasDiscriminatorConvention.DiscriminatorConvention; case IHasSerializationDomain hasSerializationDomain: - { - var serializationDomain = hasSerializationDomain.SerializationDomain; - return serializationDomain.LookupDiscriminatorConvention(serializer.ValueType); - } + { + var serializationDomain = hasSerializationDomain.SerializationDomain; + return serializationDomain.LookupDiscriminatorConvention(serializer.ValueType); + } default: return BsonSerializationDomain.Default.LookupDiscriminatorConvention(serializer.ValueType); } diff --git a/src/MongoDB.Bson/Serialization/IMultipleChildSerializersConfigurable.cs b/src/MongoDB.Bson/Serialization/IMultipleChildSerializersConfigurable.cs index 4c9a858ba8a..db6ab8454c1 100644 --- a/src/MongoDB.Bson/Serialization/IMultipleChildSerializersConfigurable.cs +++ b/src/MongoDB.Bson/Serialization/IMultipleChildSerializersConfigurable.cs @@ -35,4 +35,4 @@ public interface IMultipleChildSerializersConfigurable /// The reconfigured serializer. IBsonSerializer WithChildSerializers(IBsonSerializer[] childSerializers); } -} \ No newline at end of file +} diff --git a/src/MongoDB.Bson/Serialization/Options/DateOnlyDocumentFormat.cs b/src/MongoDB.Bson/Serialization/Options/DateOnlyDocumentFormat.cs index 525635d1574..ec2ab2c86ab 100644 --- a/src/MongoDB.Bson/Serialization/Options/DateOnlyDocumentFormat.cs +++ b/src/MongoDB.Bson/Serialization/Options/DateOnlyDocumentFormat.cs @@ -30,4 +30,4 @@ public enum DateOnlyDocumentFormat /// YearMonthDay } -} \ No newline at end of file +} diff --git a/src/MongoDB.Bson/Serialization/Options/TimeOnlyUnits.cs b/src/MongoDB.Bson/Serialization/Options/TimeOnlyUnits.cs index 0038c0bca19..1e0e9d6d86d 100644 --- a/src/MongoDB.Bson/Serialization/Options/TimeOnlyUnits.cs +++ b/src/MongoDB.Bson/Serialization/Options/TimeOnlyUnits.cs @@ -49,4 +49,4 @@ public enum TimeOnlyUnits /// Nanoseconds } -} \ No newline at end of file +} diff --git a/src/MongoDB.Bson/Serialization/SerializerConfigurator.cs b/src/MongoDB.Bson/Serialization/SerializerConfigurator.cs index d02062a1a4e..0af5285346e 100644 --- a/src/MongoDB.Bson/Serialization/SerializerConfigurator.cs +++ b/src/MongoDB.Bson/Serialization/SerializerConfigurator.cs @@ -30,30 +30,30 @@ internal static IBsonSerializer ReconfigureSerializerRecursively( { // check IMultipleChildSerializersConfigurableSerializer first because some serializers implement both interfaces case IMultipleChildSerializersConfigurable multipleChildSerializerConfigurable: - { - var anyChildSerializerWasReconfigured = false; - var reconfiguredChildSerializers = new List(); - - foreach (var childSerializer in multipleChildSerializerConfigurable.ChildSerializers) { - var reconfiguredChildSerializer = ReconfigureSerializerRecursively(childSerializer, reconfigure); - anyChildSerializerWasReconfigured |= reconfiguredChildSerializer != null; - reconfiguredChildSerializers.Add(reconfiguredChildSerializer ?? childSerializer); - } + var anyChildSerializerWasReconfigured = false; + var reconfiguredChildSerializers = new List(); + + foreach (var childSerializer in multipleChildSerializerConfigurable.ChildSerializers) + { + var reconfiguredChildSerializer = ReconfigureSerializerRecursively(childSerializer, reconfigure); + anyChildSerializerWasReconfigured |= reconfiguredChildSerializer != null; + reconfiguredChildSerializers.Add(reconfiguredChildSerializer ?? childSerializer); + } - return anyChildSerializerWasReconfigured ? multipleChildSerializerConfigurable.WithChildSerializers(reconfiguredChildSerializers.ToArray()) : null; - } + return anyChildSerializerWasReconfigured ? multipleChildSerializerConfigurable.WithChildSerializers(reconfiguredChildSerializers.ToArray()) : null; + } case IChildSerializerConfigurable childSerializerConfigurable: - { - var childSerializer = childSerializerConfigurable.ChildSerializer; - var reconfiguredChildSerializer = ReconfigureSerializerRecursively(childSerializer, reconfigure); - return reconfiguredChildSerializer != null ? childSerializerConfigurable.WithChildSerializer(reconfiguredChildSerializer) : null; - } + { + var childSerializer = childSerializerConfigurable.ChildSerializer; + var reconfiguredChildSerializer = ReconfigureSerializerRecursively(childSerializer, reconfigure); + return reconfiguredChildSerializer != null ? childSerializerConfigurable.WithChildSerializer(reconfiguredChildSerializer) : null; + } default: return reconfigure(serializer); } } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedInterfaceSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedInterfaceSerializer.cs index 853c8153570..4e494ff2bd2 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedInterfaceSerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/DiscriminatedInterfaceSerializer.cs @@ -39,7 +39,7 @@ public sealed class DiscriminatedInterfaceSerializer : IBsonDocumentSerializer, IDiscriminatedInterfaceSerializer, IHasSerializationDomain - // where TInterface is an interface + // where TInterface is an interface { #region static private static IBsonSerializer CreateInterfaceSerializer() @@ -137,7 +137,7 @@ internal DiscriminatedInterfaceSerializer(IBsonSerializationDomain serialization } _interfaceType = typeof(TInterface); - _serializationDomain = serializationDomain; + _serializationDomain = serializationDomain; _discriminatorConvention = discriminatorConvention ?? interfaceSerializer.GetDiscriminatorConvention(); _interfaceSerializer = interfaceSerializer; diff --git a/src/MongoDB.Bson/Serialization/Serializers/HalfSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/HalfSerializer.cs index 4e42c439509..e5849730286 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/HalfSerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/HalfSerializer.cs @@ -189,4 +189,4 @@ IBsonSerializer IRepresentationConfigurable.WithRepresentation(BsonType represen } } #endif -} \ No newline at end of file +} diff --git a/src/MongoDB.Bson/Serialization/Serializers/ImmutableArraySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ImmutableArraySerializer.cs index ee61d3c5613..02ee0c2d81b 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/ImmutableArraySerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/ImmutableArraySerializer.cs @@ -50,4 +50,4 @@ protected override ImmutableArray FinalizeResult(object accumulator) } } } -#endif \ No newline at end of file +#endif diff --git a/src/MongoDB.Bson/Serialization/Serializers/ImmutableDictionarySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ImmutableDictionarySerializer.cs index 179edc69f4f..3b1bc3b830e 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/ImmutableDictionarySerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/ImmutableDictionarySerializer.cs @@ -52,4 +52,4 @@ protected override ImmutableDictionary FinalizeAccumulator(ICollec } } } -#endif \ No newline at end of file +#endif diff --git a/src/MongoDB.Bson/Serialization/Serializers/ImmutableHashSetSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ImmutableHashSetSerializer.cs index 03365cc2aaa..d5dfbbf4ca9 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/ImmutableHashSetSerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/ImmutableHashSetSerializer.cs @@ -50,4 +50,4 @@ protected override ImmutableHashSet FinalizeResult(object accumulator) } } } -#endif \ No newline at end of file +#endif diff --git a/src/MongoDB.Bson/Serialization/Serializers/ImmutableListSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ImmutableListSerializer.cs index 5ed63bbfc6d..13ab7ee7be8 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/ImmutableListSerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/ImmutableListSerializer.cs @@ -50,4 +50,4 @@ protected override ImmutableList FinalizeResult(object accumulator) } } } -#endif \ No newline at end of file +#endif diff --git a/src/MongoDB.Bson/Serialization/Serializers/ImmutableQueueSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ImmutableQueueSerializer.cs index 82da999a65c..96f3fc303d6 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/ImmutableQueueSerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/ImmutableQueueSerializer.cs @@ -51,4 +51,4 @@ protected override ImmutableQueue FinalizeResult(object accumulator) } } } -#endif \ No newline at end of file +#endif diff --git a/src/MongoDB.Bson/Serialization/Serializers/ImmutableSortedDictionarySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ImmutableSortedDictionarySerializer.cs index 18583a44c7e..72fd91dc22a 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/ImmutableSortedDictionarySerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/ImmutableSortedDictionarySerializer.cs @@ -52,4 +52,4 @@ protected override ImmutableSortedDictionary FinalizeAccumulator(I } } } -#endif \ No newline at end of file +#endif diff --git a/src/MongoDB.Bson/Serialization/Serializers/ImmutableSortedSetSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ImmutableSortedSetSerializer.cs index 8a29d4d02a3..4108e7e3965 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/ImmutableSortedSetSerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/ImmutableSortedSetSerializer.cs @@ -50,4 +50,4 @@ protected override ImmutableSortedSet FinalizeResult(object accumulator) } } } -#endif \ No newline at end of file +#endif diff --git a/src/MongoDB.Bson/Serialization/Serializers/ImmutableStackSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ImmutableStackSerializer.cs index 498077840f0..158390752a5 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/ImmutableStackSerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/ImmutableStackSerializer.cs @@ -58,4 +58,4 @@ protected override ImmutableStack FinalizeResult(object accumulator) } } } -#endif \ No newline at end of file +#endif diff --git a/src/MongoDB.Bson/Serialization/Serializers/KeyValuePairSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/KeyValuePairSerializer.cs index 034922b6c99..da511ff7892 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/KeyValuePairSerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/KeyValuePairSerializer.cs @@ -26,7 +26,7 @@ public interface IKeyValuePairSerializer /// /// Gets the representation. /// - BsonType Representation { get; } + BsonType Representation { get; } } /// diff --git a/src/MongoDB.Bson/Serialization/Serializers/MemorySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/MemorySerializer.cs index f872938109d..d64bf8c3226 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/MemorySerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/MemorySerializer.cs @@ -341,7 +341,8 @@ private static (Func reader, Action( var array = bsonReader.ReadRawBsonArray(); using var buffer = ThreadStaticBuffer.RentBuffer(array.Length); - var bytes = buffer.Bytes; - array.GetBytes(0, bytes, 0, array.Length); + var bytes = buffer.Bytes; + array.GetBytes(0, bytes, 0, array.Length); var span = bytes.AsSpan(); var result = new List(); @@ -112,7 +112,7 @@ private static T[] ReadBsonArray( case ConversionType.Decimal128ToDecimal128: { var lowBits = BinaryPrimitives.ReadUInt64LittleEndian(span.Slice(index)); - var highBits = BinaryPrimitives.ReadUInt64LittleEndian(span.Slice(index + 8)); + var highBits = BinaryPrimitives.ReadUInt64LittleEndian(span.Slice(index + 8)); var v = Decimal128.ToDecimal(Decimal128.FromIEEEBits(highBits, lowBits)); value = Unsafe.As(ref v); diff --git a/src/MongoDB.Bson/Serialization/Serializers/ReadOnlyDictionaryInterfaceImplementerSerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/ReadOnlyDictionaryInterfaceImplementerSerializer.cs index 4ea4def2c98..3a1916ec98d 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/ReadOnlyDictionaryInterfaceImplementerSerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/ReadOnlyDictionaryInterfaceImplementerSerializer.cs @@ -137,8 +137,8 @@ IBsonSerializer IMultipleChildSerializersConfigurable.WithChildSerializers(IBson throw new Exception("Wrong number of child serializers passed."); } - var newKeySerializer = (IBsonSerializer)childSerializers[0]; - var newValueSerializer = (IBsonSerializer)childSerializers[1]; + var newKeySerializer = (IBsonSerializer)childSerializers[0]; + var newValueSerializer = (IBsonSerializer)childSerializers[1]; return newKeySerializer.Equals(KeySerializer) && newValueSerializer.Equals(ValueSerializer) ? this diff --git a/src/MongoDB.Bson/Serialization/Serializers/TimeOnlySerializer.cs b/src/MongoDB.Bson/Serialization/Serializers/TimeOnlySerializer.cs index c902432e3e1..40ca7b336bd 100644 --- a/src/MongoDB.Bson/Serialization/Serializers/TimeOnlySerializer.cs +++ b/src/MongoDB.Bson/Serialization/Serializers/TimeOnlySerializer.cs @@ -347,4 +347,4 @@ IBsonSerializer IRepresentationConfigurable.WithRepresentation(BsonType represen } } #endif -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver.Authentication.AWS/SaslSteps/AWSLastSaslStep.cs b/src/MongoDB.Driver.Authentication.AWS/SaslSteps/AWSLastSaslStep.cs index 7d81604edf6..a3e46135db2 100644 --- a/src/MongoDB.Driver.Authentication.AWS/SaslSteps/AWSLastSaslStep.cs +++ b/src/MongoDB.Driver.Authentication.AWS/SaslSteps/AWSLastSaslStep.cs @@ -25,7 +25,7 @@ namespace MongoDB.Driver.Authentication.AWS.SaslSteps { internal sealed class AWSLastSaslStep : ISaslStep { - private static readonly ISet __serverResponseExpectedNames = new HashSet(new []{ "h", "s" }); + private static readonly ISet __serverResponseExpectedNames = new HashSet(new[] { "h", "s" }); private readonly IClock _clock; private readonly IAWSCredentialsSource _credentialsSource; diff --git a/src/MongoDB.Driver.Encryption/Binary.cs b/src/MongoDB.Driver.Encryption/Binary.cs index ce8283b160f..77da6ef9dd0 100644 --- a/src/MongoDB.Driver.Encryption/Binary.cs +++ b/src/MongoDB.Driver.Encryption/Binary.cs @@ -141,5 +141,5 @@ protected virtual void Dispose(bool disposing) } } #endregion - } + } } diff --git a/src/MongoDB.Driver.Encryption/CryptClientFactory.cs b/src/MongoDB.Driver.Encryption/CryptClientFactory.cs index c1bb379d273..eeca91e58d0 100644 --- a/src/MongoDB.Driver.Encryption/CryptClientFactory.cs +++ b/src/MongoDB.Driver.Encryption/CryptClientFactory.cs @@ -75,7 +75,7 @@ public static CryptClient Create(CryptClientSettings cryptClientSettings) encryptedFieldsBytes = GetBytesFromMap(cryptClientSettings.EncryptedFieldsMap); } - var cryptOptions = new CryptOptions( + var cryptOptions = new CryptOptions( kmsProviders, encryptedFieldsMap: encryptedFieldsBytes, schema: schemaBytes, diff --git a/src/MongoDB.Driver.Encryption/CsfleSchemaBuilder.cs b/src/MongoDB.Driver.Encryption/CsfleSchemaBuilder.cs index 9383d183551..022ee66d03f 100644 --- a/src/MongoDB.Driver.Encryption/CsfleSchemaBuilder.cs +++ b/src/MongoDB.Driver.Encryption/CsfleSchemaBuilder.cs @@ -342,4 +342,4 @@ private static string MapCsfleEncryptionAlgorithmToString(EncryptionAlgorithm al }; } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver.Encryption/EncryptionOptionsExtensions.cs b/src/MongoDB.Driver.Encryption/EncryptionOptionsExtensions.cs index 03378b903c5..9beb844cbfe 100644 --- a/src/MongoDB.Driver.Encryption/EncryptionOptionsExtensions.cs +++ b/src/MongoDB.Driver.Encryption/EncryptionOptionsExtensions.cs @@ -73,4 +73,4 @@ private static BsonDocument CreateStringOptionsDocument( suffixOptions != null } }; -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver.Encryption/ExplicitEncryptionLibMongoCryptController.cs b/src/MongoDB.Driver.Encryption/ExplicitEncryptionLibMongoCryptController.cs index 42cfaa15b76..ef1127936e9 100644 --- a/src/MongoDB.Driver.Encryption/ExplicitEncryptionLibMongoCryptController.cs +++ b/src/MongoDB.Driver.Encryption/ExplicitEncryptionLibMongoCryptController.cs @@ -537,7 +537,7 @@ private KmsKeyId GetKmsKeyId(string kmsProvider, DataKeyOptions dataKeyOptions) BsonDocument keyMaterial = null; if (dataKeyOptions?.KeyMaterial != null) { - keyMaterial = new BsonDocument("keyMaterial", dataKeyOptions.KeyMaterial); + keyMaterial = new BsonDocument("keyMaterial", dataKeyOptions.KeyMaterial); } return new KmsKeyId( dataKeyOptionsBytes: ToBsonIfNotNull(dataKeyDocument), diff --git a/src/MongoDB.Driver.Encryption/KmsRequest.cs b/src/MongoDB.Driver.Encryption/KmsRequest.cs index a93a61c22fc..83edc8e2ba1 100644 --- a/src/MongoDB.Driver.Encryption/KmsRequest.cs +++ b/src/MongoDB.Driver.Encryption/KmsRequest.cs @@ -105,17 +105,17 @@ public Binary GetMessage() /// The response. public void Feed(byte[] buffer) { - unsafe + unsafe + { + fixed (byte* p = buffer) { - fixed (byte* p = buffer) + IntPtr ptr = (IntPtr)p; + using (PinnedBinary pinned = new PinnedBinary(ptr, (uint)buffer.Length)) { - IntPtr ptr = (IntPtr)p; - using (PinnedBinary pinned = new PinnedBinary(ptr, (uint)buffer.Length)) - { - Check(Library.mongocrypt_kms_ctx_feed(_id, pinned.Handle)); - } + Check(Library.mongocrypt_kms_ctx_feed(_id, pinned.Handle)); } } + } } void IStatus.Check(Status status) diff --git a/src/MongoDB.Driver.Encryption/LibraryLoader.cs b/src/MongoDB.Driver.Encryption/LibraryLoader.cs index 3c278457a8b..e6b171e1f83 100644 --- a/src/MongoDB.Driver.Encryption/LibraryLoader.cs +++ b/src/MongoDB.Driver.Encryption/LibraryLoader.cs @@ -183,7 +183,7 @@ static LinuxLibrary() var runtimeSuffix = IsAlpine() ? $"musl-{osArchitecture}" : $"{osArchitecture}"; - __suffixPaths = new []{ + __suffixPaths = new[]{ $"../../runtimes/linux-{runtimeSuffix}/native/", $"runtimes/linux-{runtimeSuffix}/native/", string.Empty @@ -227,7 +227,7 @@ private static bool IsAlpine() if (File.Exists(osRealesePath)) { - foreach(var line in File.ReadAllLines(osRealesePath)) + foreach (var line in File.ReadAllLines(osRealesePath)) { if (line.StartsWith(prettyName)) { diff --git a/src/MongoDB.Driver.Encryption/LogLevel.cs b/src/MongoDB.Driver.Encryption/LogLevel.cs index feebe3d3bef..cd561965833 100644 --- a/src/MongoDB.Driver.Encryption/LogLevel.cs +++ b/src/MongoDB.Driver.Encryption/LogLevel.cs @@ -16,7 +16,8 @@ namespace MongoDB.Driver.Encryption { - internal enum LogLevel { + internal enum LogLevel + { MONGOCRYPT_LOG_LEVEL_FATAL = 0, MONGOCRYPT_LOG_LEVEL_ERROR = 1, MONGOCRYPT_LOG_LEVEL_WARNING = 2, diff --git a/src/MongoDB.Driver/Authentication/Gssapi/SecurityContextFactory.cs b/src/MongoDB.Driver/Authentication/Gssapi/SecurityContextFactory.cs index 036ad62fff4..e31c86e5dd8 100644 --- a/src/MongoDB.Driver/Authentication/Gssapi/SecurityContextFactory.cs +++ b/src/MongoDB.Driver/Authentication/Gssapi/SecurityContextFactory.cs @@ -29,41 +29,41 @@ public static ISecurityContext InitializeSecurityContext(string serviceName, str switch (operatingSystemPlatform) { case OperatingSystemPlatform.Windows: - { - SspiSecurityCredential credential = null; - try { - var servicePrincipalName = $"{serviceName}/{hostname}"; - if (!string.IsNullOrEmpty(realm)) + SspiSecurityCredential credential = null; + try { - servicePrincipalName += $"@{realm}"; + var servicePrincipalName = $"{serviceName}/{hostname}"; + if (!string.IsNullOrEmpty(realm)) + { + servicePrincipalName += $"@{realm}"; + } + credential = SspiSecurityCredential.Acquire(SspiPackage.Kerberos, authorizationId, password); + return new SspiSecurityContext(servicePrincipalName, credential); + } + catch (Win32Exception) + { + credential?.Dispose(); + throw; } - credential = SspiSecurityCredential.Acquire(SspiPackage.Kerberos, authorizationId, password); - return new SspiSecurityContext(servicePrincipalName, credential); - } - catch (Win32Exception) - { - credential?.Dispose(); - throw; } - } case OperatingSystemPlatform.Linux: - { - GssapiServicePrincipalName servicePrincipalName = null; - GssapiSecurityCredential credential = null; - try - { - servicePrincipalName = GssapiServicePrincipalName.Create(serviceName, hostname, realm); - credential = GssapiSecurityCredential.Acquire(authorizationId, password); - return new GssapiSecurityContext(servicePrincipalName, credential); - } - catch (LibgssapiException) { - servicePrincipalName?.Dispose(); - credential?.Dispose(); - throw; + GssapiServicePrincipalName servicePrincipalName = null; + GssapiSecurityCredential credential = null; + try + { + servicePrincipalName = GssapiServicePrincipalName.Create(serviceName, hostname, realm); + credential = GssapiSecurityCredential.Acquire(authorizationId, password); + return new GssapiSecurityContext(servicePrincipalName, credential); + } + catch (LibgssapiException) + { + servicePrincipalName?.Dispose(); + credential?.Dispose(); + throw; + } } - } default: throw new NotSupportedException($"GSSAPI is not supported on {operatingSystemPlatform}."); } diff --git a/src/MongoDB.Driver/Authentication/Oidc/AzureOidcCallback.cs b/src/MongoDB.Driver/Authentication/Oidc/AzureOidcCallback.cs index 8b4c3100ee0..f133214f4a5 100644 --- a/src/MongoDB.Driver/Authentication/Oidc/AzureOidcCallback.cs +++ b/src/MongoDB.Driver/Authentication/Oidc/AzureOidcCallback.cs @@ -38,7 +38,7 @@ protected override (Uri Uri, (string Key, string Value)[] headers) GetHttpReques metadataUrl += $"&client_id={Uri.EscapeDataString(parameters.UserName)}"; } - return (new Uri(metadataUrl), new [] { ("Accept", "application/json"), ("Metadata", "true") }); + return (new Uri(metadataUrl), new[] { ("Accept", "application/json"), ("Metadata", "true") }); } protected override OidcAccessToken ProcessHttpResponse(Stream responseStream) diff --git a/src/MongoDB.Driver/Authentication/Oidc/GcpOidcCallback.cs b/src/MongoDB.Driver/Authentication/Oidc/GcpOidcCallback.cs index de2e7763873..ea141950af4 100644 --- a/src/MongoDB.Driver/Authentication/Oidc/GcpOidcCallback.cs +++ b/src/MongoDB.Driver/Authentication/Oidc/GcpOidcCallback.cs @@ -31,7 +31,7 @@ protected override (Uri Uri, (string Key, string Value)[] headers) GetHttpReques { var metadataUrl = $"http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience={Uri.EscapeDataString(_tokenResource)}"; - return (new Uri(metadataUrl), new[] { ("Metadata-Flavor", "Google") } ); + return (new Uri(metadataUrl), new[] { ("Metadata-Flavor", "Google") }); } protected override OidcAccessToken ProcessHttpResponse(Stream responseStream) diff --git a/src/MongoDB.Driver/Authentication/ScramSha/ScramShaSecondSaslStep.cs b/src/MongoDB.Driver/Authentication/ScramSha/ScramShaSecondSaslStep.cs index 64c04b07d45..bab1ef5e269 100644 --- a/src/MongoDB.Driver/Authentication/ScramSha/ScramShaSecondSaslStep.cs +++ b/src/MongoDB.Driver/Authentication/ScramSha/ScramShaSecondSaslStep.cs @@ -87,7 +87,7 @@ public ScramShaSecondSaslStep(IScramShaAlgorithm algorithm, UsernamePasswordCred var proof = "p=" + Convert.ToBase64String(clientProof); var clientFinalMessage = clientFinalMessageWithoutProof + "," + proof; - return(encoding.GetBytes(clientFinalMessage), new ScramShaLastSaslStep(serverSignature)); + return (encoding.GetBytes(clientFinalMessage), new ScramShaLastSaslStep(serverSignature)); } public Task<(byte[] BytesToSendToServer, ISaslStep NextStep)> ExecuteAsync( diff --git a/src/MongoDB.Driver/AutoEncryptionOptions.cs b/src/MongoDB.Driver/AutoEncryptionOptions.cs index f96a2c39067..c9864cd09be 100644 --- a/src/MongoDB.Driver/AutoEncryptionOptions.cs +++ b/src/MongoDB.Driver/AutoEncryptionOptions.cs @@ -67,7 +67,7 @@ public AutoEncryptionOptions( Optional> tlsOptions = default, Optional> encryptedFieldsMap = default, Optional bypassQueryAnalysis = default) - :this(keyVaultNamespace, kmsProviders, bypassAutoEncryption, extraOptions, keyVaultClient, schemaMap, tlsOptions, encryptedFieldsMap, bypassQueryAnalysis, keyExpiration: null) + : this(keyVaultNamespace, kmsProviders, bypassAutoEncryption, extraOptions, keyVaultClient, schemaMap, tlsOptions, encryptedFieldsMap, bypassQueryAnalysis, keyExpiration: null) { } diff --git a/src/MongoDB.Driver/BinaryVectorExtensions.cs b/src/MongoDB.Driver/BinaryVectorExtensions.cs index 93b648a3ec9..6d8d722d740 100644 --- a/src/MongoDB.Driver/BinaryVectorExtensions.cs +++ b/src/MongoDB.Driver/BinaryVectorExtensions.cs @@ -31,7 +31,7 @@ public static class BinaryVectorDriverExtensions /// The binary vector. /// A instance. public static QueryVector ToQueryVector(this BinaryVector binaryVector) - where TItem : struct => + where TItem : struct => binaryVector switch { BinaryVectorFloat32 binaryVectorFloat32 => new(binaryVectorFloat32.ToBsonBinaryData()), diff --git a/src/MongoDB.Driver/BulkWriteUpdateOneModel.cs b/src/MongoDB.Driver/BulkWriteUpdateOneModel.cs index bddbe7c614b..1c96e1178f0 100644 --- a/src/MongoDB.Driver/BulkWriteUpdateOneModel.cs +++ b/src/MongoDB.Driver/BulkWriteUpdateOneModel.cs @@ -70,7 +70,7 @@ public BulkWriteUpdateOneModel( { } - /// + /// /// Initializes a new instance of the class. /// /// Collection on which the operation should be performed. diff --git a/src/MongoDB.Driver/ClientSessionOptions.cs b/src/MongoDB.Driver/ClientSessionOptions.cs index 915d706c3ce..0618424dc2b 100644 --- a/src/MongoDB.Driver/ClientSessionOptions.cs +++ b/src/MongoDB.Driver/ClientSessionOptions.cs @@ -46,7 +46,7 @@ public class ClientSessionOptions /// /// true if snapshot reads are requested; otherwise, false. /// - public bool Snapshot { get; set;} + public bool Snapshot { get; set; } /// /// Gets or sets the snapshot time. If set, Snapshot must be true. diff --git a/src/MongoDB.Driver/ClusterKey.cs b/src/MongoDB.Driver/ClusterKey.cs index 3be367acc51..6e4bdd9c38b 100644 --- a/src/MongoDB.Driver/ClusterKey.cs +++ b/src/MongoDB.Driver/ClusterKey.cs @@ -162,7 +162,7 @@ public ClusterKey( public bool LoadBalanced => _loadBalanced; public TimeSpan LocalThreshold { get { return _localThreshold; } } public LoggingSettings LoggingSettings { get { return _loggingSettings; } } - public int MaxConnecting{ get { return _maxConnecting; } } + public int MaxConnecting { get { return _maxConnecting; } } public TimeSpan MaxConnectionIdleTime { get { return _maxConnectionIdleTime; } } public TimeSpan MaxConnectionLifeTime { get { return _maxConnectionLifeTime; } } public int MaxConnectionPoolSize { get { return _maxConnectionPoolSize; } } diff --git a/src/MongoDB.Driver/ConvertOptions.cs b/src/MongoDB.Driver/ConvertOptions.cs index f2822e85aa7..a37981b2b2f 100644 --- a/src/MongoDB.Driver/ConvertOptions.cs +++ b/src/MongoDB.Driver/ConvertOptions.cs @@ -156,4 +156,4 @@ public enum ByteOrder /// LittleEndian, } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Core/Bindings/CoreServerSessionPool.cs b/src/MongoDB.Driver/Core/Bindings/CoreServerSessionPool.cs index e0310c57c39..11356763be7 100644 --- a/src/MongoDB.Driver/Core/Bindings/CoreServerSessionPool.cs +++ b/src/MongoDB.Driver/Core/Bindings/CoreServerSessionPool.cs @@ -149,7 +149,7 @@ public void CloseAndDispose(IServer server) } } } - catch(Exception ex) + catch (Exception ex) { _logger?.LogError(ex, "Error closing server session pool for {clusterId}.", _cluster.ClusterId); } diff --git a/src/MongoDB.Driver/Core/Bindings/NoCoreSession.cs b/src/MongoDB.Driver/Core/Bindings/NoCoreSession.cs index 52a8d361820..d224a59a312 100644 --- a/src/MongoDB.Driver/Core/Bindings/NoCoreSession.cs +++ b/src/MongoDB.Driver/Core/Bindings/NoCoreSession.cs @@ -95,7 +95,7 @@ public void AbortTransaction(CancellationToken cancellationToken = default) } // TODO: CSOT: Make it public when CSOT will be ready for GA and add default value to cancellationToken parameter. - void ICoreSessionInternal.AbortTransaction(AbortTransactionOptions options, CancellationToken cancellationToken ) + void ICoreSessionInternal.AbortTransaction(AbortTransactionOptions options, CancellationToken cancellationToken) { throw new NotSupportedException("NoCoreSession does not support AbortTransaction."); } @@ -107,7 +107,7 @@ public Task AbortTransactionAsync(CancellationToken cancellationToken = default) } // TODO: CSOT: Make it public when CSOT will be ready for GA and add default value to cancellationToken parameter. - Task ICoreSessionInternal.AbortTransactionAsync(AbortTransactionOptions options, CancellationToken cancellationToken ) + Task ICoreSessionInternal.AbortTransactionAsync(AbortTransactionOptions options, CancellationToken cancellationToken) { throw new NotSupportedException("NoCoreSession does not support AbortTransactionAsync."); } diff --git a/src/MongoDB.Driver/Core/Clusters/Cluster.cs b/src/MongoDB.Driver/Core/Clusters/Cluster.cs index ce8242b47f9..e6943e73202 100644 --- a/src/MongoDB.Driver/Core/Clusters/Cluster.cs +++ b/src/MongoDB.Driver/Core/Clusters/Cluster.cs @@ -67,7 +67,7 @@ protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFact Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber)); _state = new InterlockedInt32(State.Initial); _clusterId = new ClusterId(); - _expirableClusterDescription = new (this, ClusterDescription.CreateInitial(_clusterId, _settings.DirectConnection)); + _expirableClusterDescription = new(this, ClusterDescription.CreateInitial(_clusterId, _settings.DirectConnection)); _latencyLimitingServerSelector = new LatencyLimitingServerSelector(settings.LocalThreshold); _serverSelectionWaitQueue = new ServerSelectionWaitQueue(this); _serverSessionPool = new CoreServerSessionPool(this, loggerFactory?.CreateLogger()); diff --git a/src/MongoDB.Driver/Core/Clusters/ClusterFactory.cs b/src/MongoDB.Driver/Core/Clusters/ClusterFactory.cs index 1bd77a4253e..fb7e4d31b3b 100644 --- a/src/MongoDB.Driver/Core/Clusters/ClusterFactory.cs +++ b/src/MongoDB.Driver/Core/Clusters/ClusterFactory.cs @@ -87,7 +87,7 @@ private void ProcessClusterEnvironment(ClusterSettings settings) return; } - foreach (var (host, _) in settings.EndPoints.Select(EndPointHelper.GetHostAndPort)) + foreach (var (host, _) in settings.EndPoints.Select(EndPointHelper.GetHostAndPort)) { if (LogIfCosmosDB(host) || LogIfDocumentDB(host)) { diff --git a/src/MongoDB.Driver/Core/Configuration/ConnectionString.cs b/src/MongoDB.Driver/Core/Configuration/ConnectionString.cs index f1f4910b79b..7c8ee885d8d 100644 --- a/src/MongoDB.Driver/Core/Configuration/ConnectionString.cs +++ b/src/MongoDB.Driver/Core/Configuration/ConnectionString.cs @@ -1517,7 +1517,7 @@ internal static bool HasValidParentDomain(string original, DnsEndPoint resolvedE return host.Length > original.Length && hostDotCount > originalDotCount && host.EndsWith(original, StringComparison.Ordinal) && - host[host.Length - original.Length -1 ] == '.'; + host[host.Length - original.Length - 1] == '.'; } // We check that the returned hostname has the same domain name as original diff --git a/src/MongoDB.Driver/Core/Configuration/Socks5ProxyStreamSettings.cs b/src/MongoDB.Driver/Core/Configuration/Socks5ProxyStreamSettings.cs index b87c01b0a5f..a0d2724ecb0 100644 --- a/src/MongoDB.Driver/Core/Configuration/Socks5ProxyStreamSettings.cs +++ b/src/MongoDB.Driver/Core/Configuration/Socks5ProxyStreamSettings.cs @@ -45,4 +45,4 @@ public Socks5ProxyStreamSettings(Optional socks5ProxySettin /// public Socks5ProxyStreamSettings With(Socks5ProxySettings socks5ProxySettings) => new(socks5ProxySettings); -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Core/Configuration/TracingOptions.cs b/src/MongoDB.Driver/Core/Configuration/TracingOptions.cs index 7f63c460510..bc822732073 100644 --- a/src/MongoDB.Driver/Core/Configuration/TracingOptions.cs +++ b/src/MongoDB.Driver/Core/Configuration/TracingOptions.cs @@ -83,4 +83,4 @@ public override int GetHashCode() .Hash(Disabled) .GetHashCode(); } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Core/Connections/ClientDocumentHelper.cs b/src/MongoDB.Driver/Core/Connections/ClientDocumentHelper.cs index 19268ac7295..825561b49b7 100644 --- a/src/MongoDB.Driver/Core/Connections/ClientDocumentHelper.cs +++ b/src/MongoDB.Driver/Core/Connections/ClientDocumentHelper.cs @@ -184,11 +184,11 @@ string GetRegion(string name) => int? GetMemoryMb(string name) => name switch - { - awsLambdaName => GetIntValue("AWS_LAMBDA_FUNCTION_MEMORY_SIZE"), - gcpFuncName => GetIntValue("FUNCTION_MEMORY_MB"), - _ => null, - }; + { + awsLambdaName => GetIntValue("AWS_LAMBDA_FUNCTION_MEMORY_SIZE"), + gcpFuncName => GetIntValue("FUNCTION_MEMORY_MB"), + _ => null, + }; int? GetTimeoutSec(string name) => name switch diff --git a/src/MongoDB.Driver/Core/Connections/ClientMetadata.cs b/src/MongoDB.Driver/Core/Connections/ClientMetadata.cs index 54d49875e8c..59320dd4bf9 100644 --- a/src/MongoDB.Driver/Core/Connections/ClientMetadata.cs +++ b/src/MongoDB.Driver/Core/Connections/ClientMetadata.cs @@ -64,7 +64,7 @@ public void Append(LibraryInfo libraryInfo) return; } - LibraryInfo[] updated = [..current, libraryInfo]; + LibraryInfo[] updated = [.. current, libraryInfo]; _libraryInfos = updated; _clientDocument = null; } diff --git a/src/MongoDB.Driver/Core/Connections/ConnectionInitializer.cs b/src/MongoDB.Driver/Core/Connections/ConnectionInitializer.cs index d8396a99f62..063167953e9 100644 --- a/src/MongoDB.Driver/Core/Connections/ConnectionInitializer.cs +++ b/src/MongoDB.Driver/Core/Connections/ConnectionInitializer.cs @@ -131,7 +131,7 @@ public ConnectionInitializerContext SendHello(OperationContext operationContext, throw new InvalidOperationException("Driver attempted to initialize in load balancing mode, but the server does not support this mode."); } - return new (new ConnectionDescription(connection.ConnectionId, helloResult), authenticator); + return new(new ConnectionDescription(connection.ConnectionId, helloResult), authenticator); } public async Task SendHelloAsync(OperationContext operationContext, IConnection connection) @@ -147,7 +147,7 @@ public async Task SendHelloAsync(OperationContext throw new InvalidOperationException("Driver attempted to initialize in load balancing mode, but the server does not support this mode."); } - return new (new ConnectionDescription(connection.ConnectionId, helloResult), authenticator); + return new(new ConnectionDescription(connection.ConnectionId, helloResult), authenticator); } // private methods diff --git a/src/MongoDB.Driver/Core/Connections/Socks5AuthenticationSettings.cs b/src/MongoDB.Driver/Core/Connections/Socks5AuthenticationSettings.cs index 2fbd46f58f3..0b447e049d6 100644 --- a/src/MongoDB.Driver/Core/Connections/Socks5AuthenticationSettings.cs +++ b/src/MongoDB.Driver/Core/Connections/Socks5AuthenticationSettings.cs @@ -91,4 +91,4 @@ public override int GetHashCode() => .Hash(Password) .GetHashCode(); } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Core/Connections/Socks5Helper.cs b/src/MongoDB.Driver/Core/Connections/Socks5Helper.cs index cb52d8e6028..a049140eb9d 100644 --- a/src/MongoDB.Driver/Core/Connections/Socks5Helper.cs +++ b/src/MongoDB.Driver/Core/Connections/Socks5Helper.cs @@ -335,7 +335,7 @@ private static void EnsureSocksSuccess(byte code, string operation) 0x06 => "TTL expired", 0x07 => "Command not supported", 0x08 => "Address type not supported", - _ => $"Unassigned error (0x{code:X2})" + _ => $"Unassigned error (0x{code:X2})" }; throw new IOException($"SOCKS5 {operation} failed. {message}"); diff --git a/src/MongoDB.Driver/Core/Connections/Socks5ProxySettings.cs b/src/MongoDB.Driver/Core/Connections/Socks5ProxySettings.cs index 67911164b08..535f655e72b 100644 --- a/src/MongoDB.Driver/Core/Connections/Socks5ProxySettings.cs +++ b/src/MongoDB.Driver/Core/Connections/Socks5ProxySettings.cs @@ -144,4 +144,4 @@ public override string ToString() sb.Append(" }"); return sb.ToString(); } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Core/Events/CommandStartedEvent.cs b/src/MongoDB.Driver/Core/Events/CommandStartedEvent.cs index 1ef3b2db977..f1ae0f08108 100644 --- a/src/MongoDB.Driver/Core/Events/CommandStartedEvent.cs +++ b/src/MongoDB.Driver/Core/Events/CommandStartedEvent.cs @@ -123,7 +123,7 @@ public int RequestId /// public ObjectId? ServiceId { - get { return _serviceId;} + get { return _serviceId; } } /// diff --git a/src/MongoDB.Driver/Core/Logging/LogCategoryHelper.cs b/src/MongoDB.Driver/Core/Logging/LogCategoryHelper.cs index c43d793f0c8..fa6f4e0353a 100644 --- a/src/MongoDB.Driver/Core/Logging/LogCategoryHelper.cs +++ b/src/MongoDB.Driver/Core/Logging/LogCategoryHelper.cs @@ -25,7 +25,7 @@ internal static class LogCategoryHelper { private static readonly IDictionary __catergories = new ConcurrentDictionary(); - private static readonly string[] __driverNamespaces = new [] + private static readonly string[] __driverNamespaces = new[] { "MongoDB.Bson", "MongoDB.Driver", diff --git a/src/MongoDB.Driver/Core/Operations/AsyncCursorSourceEnumerator.cs b/src/MongoDB.Driver/Core/Operations/AsyncCursorSourceEnumerator.cs index ef1d8868019..bfde450e2db 100644 --- a/src/MongoDB.Driver/Core/Operations/AsyncCursorSourceEnumerator.cs +++ b/src/MongoDB.Driver/Core/Operations/AsyncCursorSourceEnumerator.cs @@ -87,4 +87,4 @@ private void ThrowIfDisposed() } } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Core/Operations/CreateCollectionOperation.cs b/src/MongoDB.Driver/Core/Operations/CreateCollectionOperation.cs index 9ceb08eefb7..b97bae2b476 100644 --- a/src/MongoDB.Driver/Core/Operations/CreateCollectionOperation.cs +++ b/src/MongoDB.Driver/Core/Operations/CreateCollectionOperation.cs @@ -63,9 +63,9 @@ public static IWriteOperation CreateEncryptedCreateCollectionOpera CreateCollectionOperation CreateInnerCollectionOperation(string collectionName) => new(new CollectionNamespace(collectionNamespace.DatabaseNamespace.DatabaseName, collectionName), messageEncoderSettings, Feature.Csfle2QEv2) - { - ClusteredIndex = new BsonDocument { { "key", new BsonDocument("_id", 1) }, { "unique", true } } - }; + { + ClusteredIndex = new BsonDocument { { "key", new BsonDocument("_id", 1) }, { "unique", true } } + }; } #endregion diff --git a/src/MongoDB.Driver/Core/Operations/CreateViewOperation.cs b/src/MongoDB.Driver/Core/Operations/CreateViewOperation.cs index 1f45cf6efd0..889b7ac2185 100644 --- a/src/MongoDB.Driver/Core/Operations/CreateViewOperation.cs +++ b/src/MongoDB.Driver/Core/Operations/CreateViewOperation.cs @@ -186,7 +186,7 @@ internal BsonDocument CreateCommand(OperationContext operationContext, Connectio private WriteCommandOperation CreateOperation(OperationContext operationContext, ConnectionDescription connectionDescription, long? transactionNumber) { - var command = CreateCommand(operationContext, connectionDescription, transactionNumber); + var command = CreateCommand(operationContext, connectionDescription, transactionNumber); return new WriteCommandOperation(_databaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings); } } diff --git a/src/MongoDB.Driver/Core/Operations/CursorBatchDeserializationHelper.cs b/src/MongoDB.Driver/Core/Operations/CursorBatchDeserializationHelper.cs index 27ff4252dc0..2aebabbc3af 100644 --- a/src/MongoDB.Driver/Core/Operations/CursorBatchDeserializationHelper.cs +++ b/src/MongoDB.Driver/Core/Operations/CursorBatchDeserializationHelper.cs @@ -44,7 +44,8 @@ public static List DeserializeBatch(RawBsonArray batch, IB if (messageEncoderSettings != null) { readerSettings.Encoding = messageEncoderSettings.GetOrDefault(MessageEncoderSettingsName.ReadEncoding, Utf8Encodings.Strict); - }; + } + ; using (var stream = new ByteBufferStream(batch.Slice, ownsBuffer: false)) using (var reader = new BsonBinaryReader(stream, readerSettings)) diff --git a/src/MongoDB.Driver/Core/Operations/RetryabilityHelper.cs b/src/MongoDB.Driver/Core/Operations/RetryabilityHelper.cs index b242e4c02f1..508524bf25a 100644 --- a/src/MongoDB.Driver/Core/Operations/RetryabilityHelper.cs +++ b/src/MongoDB.Driver/Core/Operations/RetryabilityHelper.cs @@ -157,7 +157,7 @@ public static bool IsResumableChangeStreamException(Exception exception, int max { return true; } - if (exception is MongoCursorNotFoundException or MongoConnectionPoolPausedException ) + if (exception is MongoCursorNotFoundException or MongoConnectionPoolPausedException) { return true; } diff --git a/src/MongoDB.Driver/Core/Operations/RetryableDeleteCommandOperation.cs b/src/MongoDB.Driver/Core/Operations/RetryableDeleteCommandOperation.cs index d56b56c8530..7ebec730f9c 100644 --- a/src/MongoDB.Driver/Core/Operations/RetryableDeleteCommandOperation.cs +++ b/src/MongoDB.Driver/Core/Operations/RetryableDeleteCommandOperation.cs @@ -62,7 +62,7 @@ public BatchableSource Deletes get { return _deletes; } } - protected override BsonDocument CreateCommand(OperationContext operationContext, ConnectionDescription connectionDescription, long? transactionNumber) + protected override BsonDocument CreateCommand(OperationContext operationContext, ConnectionDescription connectionDescription, long? transactionNumber) { var readConcern = ReadConcernHelper.GetReadConcernForWriteCommand(operationContext.Session, connectionDescription); var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, WriteConcern); diff --git a/src/MongoDB.Driver/Core/Operations/RetryableInsertCommandOperation.cs b/src/MongoDB.Driver/Core/Operations/RetryableInsertCommandOperation.cs index 3c619e7e816..8f6d708e275 100644 --- a/src/MongoDB.Driver/Core/Operations/RetryableInsertCommandOperation.cs +++ b/src/MongoDB.Driver/Core/Operations/RetryableInsertCommandOperation.cs @@ -26,7 +26,7 @@ namespace MongoDB.Driver.Core.Operations { - internal sealed class RetryableInsertCommandOperation : RetryableWriteCommandOperationBase where TDocument : class + internal sealed class RetryableInsertCommandOperation : RetryableWriteCommandOperationBase where TDocument : class { private bool? _bypassDocumentValidation; private readonly CollectionNamespace _collectionNamespace; @@ -68,7 +68,7 @@ public IBsonSerializer DocumentSerializer get { return _documentSerializer; } } - protected override BsonDocument CreateCommand(OperationContext operationContext, ConnectionDescription connectionDescription, long? transactionNumber) + protected override BsonDocument CreateCommand(OperationContext operationContext, ConnectionDescription connectionDescription, long? transactionNumber) { var readConcern = ReadConcernHelper.GetReadConcernForWriteCommand(operationContext.Session, connectionDescription); var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, WriteConcern); diff --git a/src/MongoDB.Driver/Core/Operations/RetryableUpdateCommandOperation.cs b/src/MongoDB.Driver/Core/Operations/RetryableUpdateCommandOperation.cs index fee9c8455e8..dfa34065dbf 100644 --- a/src/MongoDB.Driver/Core/Operations/RetryableUpdateCommandOperation.cs +++ b/src/MongoDB.Driver/Core/Operations/RetryableUpdateCommandOperation.cs @@ -69,7 +69,7 @@ public BatchableSource Updates get { return _updates; } } - protected override BsonDocument CreateCommand(OperationContext operationContext, ConnectionDescription connectionDescription, long? transactionNumber) + protected override BsonDocument CreateCommand(OperationContext operationContext, ConnectionDescription connectionDescription, long? transactionNumber) { var readConcern = ReadConcernHelper.GetReadConcernForWriteCommand(operationContext.Session, connectionDescription); var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, WriteConcern); diff --git a/src/MongoDB.Driver/Core/Operations/UpdateSearchIndexOperation.cs b/src/MongoDB.Driver/Core/Operations/UpdateSearchIndexOperation.cs index b77ebf3761c..cd3ebfcbb9e 100644 --- a/src/MongoDB.Driver/Core/Operations/UpdateSearchIndexOperation.cs +++ b/src/MongoDB.Driver/Core/Operations/UpdateSearchIndexOperation.cs @@ -44,7 +44,7 @@ public UpdateSearchIndexOperation( MessageEncoderSettings messageEncoderSettings) { _collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace)); - _indexName = Ensure.IsNotNullOrEmpty(indexName , nameof(indexName)); + _indexName = Ensure.IsNotNullOrEmpty(indexName, nameof(indexName)); _definition = Ensure.IsNotNull(definition, nameof(definition)); _messageEncoderSettings = Ensure.IsNotNull(messageEncoderSettings, nameof(messageEncoderSettings)); } diff --git a/src/MongoDB.Driver/Core/WireProtocol/CommandWireProtocol.cs b/src/MongoDB.Driver/Core/WireProtocol/CommandWireProtocol.cs index 22e05331839..e623fcc7be1 100644 --- a/src/MongoDB.Driver/Core/WireProtocol/CommandWireProtocol.cs +++ b/src/MongoDB.Driver/Core/WireProtocol/CommandWireProtocol.cs @@ -503,7 +503,8 @@ private TCommandResult ProcessResponse(ConnectionId connectionId, ResponseComman if (_messageEncoderSettings != null) { binaryReaderSettings.Encoding = _messageEncoderSettings.GetOrDefault(MessageEncoderSettingsName.ReadEncoding, Utf8Encodings.Strict); - }; + } + ; BsonValue clusterTime; if (rawDocument.TryGetValue("$clusterTime", out clusterTime)) diff --git a/src/MongoDB.Driver/Core/WireProtocol/Messages/CommandMessageSection.cs b/src/MongoDB.Driver/Core/WireProtocol/Messages/CommandMessageSection.cs index ee738882637..eb8b6b46ea0 100644 --- a/src/MongoDB.Driver/Core/WireProtocol/Messages/CommandMessageSection.cs +++ b/src/MongoDB.Driver/Core/WireProtocol/Messages/CommandMessageSection.cs @@ -154,11 +154,11 @@ public ClientBulkWriteOpsCommandMessageSection( int? maxDocumentSize, RenderArgs renderArgs) : base(operations, maxBatchCount, maxDocumentSize) - { - Documents = operations; - IdsMap = idsMap; - RenderArgs = renderArgs; - } + { + Documents = operations; + IdsMap = idsMap; + RenderArgs = renderArgs; + } public Dictionary IdsMap { get; } public new IBatchableSource Documents { get; } diff --git a/src/MongoDB.Driver/Encryption/AutoEncryptionProviderRegistry.cs b/src/MongoDB.Driver/Encryption/AutoEncryptionProviderRegistry.cs index e0b6765249c..b2b83a4800d 100644 --- a/src/MongoDB.Driver/Encryption/AutoEncryptionProviderRegistry.cs +++ b/src/MongoDB.Driver/Encryption/AutoEncryptionProviderRegistry.cs @@ -24,7 +24,7 @@ internal sealed class AutoEncryptionProviderRegistry : IAutoEncryptionProviderRe { internal static AutoEncryptionProviderRegistry CreateDefaultInstance() => new AutoEncryptionProviderRegistry(); - private Func _autoCryptClientControllerFactory; + private Func _autoCryptClientControllerFactory; public void Register(Func factory) { diff --git a/src/MongoDB.Driver/Encryption/KmsProviderRegistry.cs b/src/MongoDB.Driver/Encryption/KmsProviderRegistry.cs index c60cbb5f00d..c53e050069a 100644 --- a/src/MongoDB.Driver/Encryption/KmsProviderRegistry.cs +++ b/src/MongoDB.Driver/Encryption/KmsProviderRegistry.cs @@ -23,7 +23,7 @@ internal sealed class KmsProviderRegistry : IKmsProviderRegistry { internal static KmsProviderRegistry CreateDefaultInstance() { - var registry = new KmsProviderRegistry(); + var registry = new KmsProviderRegistry(); registry.Register(GcpKmsProvider.ProviderName, () => GcpKmsProvider.Instance); registry.Register(AzureKmsProvider.ProviderName, () => AzureKmsProvider.Instance); return registry; diff --git a/src/MongoDB.Driver/FilterDefinitionBuilder.cs b/src/MongoDB.Driver/FilterDefinitionBuilder.cs index f28c1943690..efa4cd8a036 100644 --- a/src/MongoDB.Driver/FilterDefinitionBuilder.cs +++ b/src/MongoDB.Driver/FilterDefinitionBuilder.cs @@ -478,8 +478,8 @@ public FilterDefinition BitsAnySet(Expression /// TDocument must implement IEnumerable{TITem} when using this overload of ElemMatch. /// The implied element filter. /// An element match filter. - public FilterDefinition ElemMatch(FilterDefinition impliedElementFilter) - // where TDocument : IEnumerable (can only be checked at runtime) + public FilterDefinition ElemMatch(FilterDefinition impliedElementFilter) + // where TDocument : IEnumerable (can only be checked at runtime) { return new ElementMatchFilterDefinition(impliedElementFilter); } @@ -490,8 +490,8 @@ public FilterDefinition ElemMatch(FilterDefinition impl /// TDocument must implement IEnumerable{TITem} when using this overload of ElemMatch. /// The implied element filter. /// An element match filter. - public FilterDefinition ElemMatch(Expression> impliedElementFilter) - // where TDocument : IEnumerable (can only be checked at runtime) + public FilterDefinition ElemMatch(Expression> impliedElementFilter) + // where TDocument : IEnumerable (can only be checked at runtime) { return ElemMatch(new ExpressionFilterDefinition(impliedElementFilter)); } @@ -503,8 +503,8 @@ public FilterDefinition ElemMatch(Expression /// The field. /// The filter. /// An element match filter. - public FilterDefinition ElemMatch(FieldDefinition field, FilterDefinition filter) - // where TField : IEnumerable (can only be checked at runtime) + public FilterDefinition ElemMatch(FieldDefinition field, FilterDefinition filter) + // where TField : IEnumerable (can only be checked at runtime) { return new ElementMatchFilterDefinition(field, filter); } @@ -516,8 +516,8 @@ public FilterDefinition ElemMatch(FieldDefinition f /// The field. /// The filter. /// An element match filter. - public FilterDefinition ElemMatch(Expression>> field, FilterDefinition filter) - // where TField : IEnumerable (can only be checked at runtime) + public FilterDefinition ElemMatch(Expression>> field, FilterDefinition filter) + // where TField : IEnumerable (can only be checked at runtime) { return ElemMatch(new ExpressionFieldDefinition(field), filter); } @@ -1965,16 +1965,16 @@ internal sealed class ElementMatchFilterDefinition : FilterDef private readonly FieldDefinition _field; private readonly FilterDefinition _filter; - public ElementMatchFilterDefinition(FilterDefinition filter) - // where TDocument : IEnumerable (can only be checked at runtime) + public ElementMatchFilterDefinition(FilterDefinition filter) + // where TDocument : IEnumerable (can only be checked at runtime) { _filter = filter; // TODO: CSHARP-5517 validate type constraint } - public ElementMatchFilterDefinition(FieldDefinition field, FilterDefinition filter) - // where TField : IEnumerable (checked in Render) + public ElementMatchFilterDefinition(FieldDefinition field, FilterDefinition filter) + // where TField : IEnumerable (checked in Render) { _field = Ensure.IsNotNull(field, nameof(field)); _filter = filter; @@ -2247,7 +2247,7 @@ public override BsonDocument Render(RenderArgs args) } var discriminatorField = new AstFilterField(discriminatorConvention.ElementName); - ofTypeFilter= discriminatorConvention switch + ofTypeFilter = discriminatorConvention switch { IHierarchicalDiscriminatorConvention hierarchicalDiscriminatorConvention => DiscriminatorAstFilter.TypeIs(discriminatorField, hierarchicalDiscriminatorConvention, nominalType, actualType), IScalarDiscriminatorConvention scalarDiscriminatorConvention => DiscriminatorAstFilter.TypeIs(discriminatorField, scalarDiscriminatorConvention, nominalType, actualType), diff --git a/src/MongoDB.Driver/GeoNearOptions.cs b/src/MongoDB.Driver/GeoNearOptions.cs index 5211fa35719..4ffeaf99d9b 100644 --- a/src/MongoDB.Driver/GeoNearOptions.cs +++ b/src/MongoDB.Driver/GeoNearOptions.cs @@ -68,4 +68,4 @@ public class GeoNearOptions /// public bool? Spherical { get; set; } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/GridFS/GridFSBucket.cs b/src/MongoDB.Driver/GridFS/GridFSBucket.cs index 8eb61fe6b47..5ca9fd307b2 100644 --- a/src/MongoDB.Driver/GridFS/GridFSBucket.cs +++ b/src/MongoDB.Driver/GridFS/GridFSBucket.cs @@ -884,7 +884,7 @@ private GridFSUploadStream CreateUploadStream(IReadWriteBindingHandle b private void DownloadToStreamHelper(IReadBindingHandle binding, GridFSFileInfo fileInfo, Stream destination, GridFSDownloadOptions options, CancellationToken cancellationToken = default(CancellationToken)) { var retryReads = _database.Client.Settings.RetryReads; - using (var source = new GridFSForwardOnlyDownloadStream(this, binding.Fork(), fileInfo) { RetryReads = retryReads}) + using (var source = new GridFSForwardOnlyDownloadStream(this, binding.Fork(), fileInfo) { RetryReads = retryReads }) { var count = source.Length; var buffer = new byte[fileInfo.ChunkSizeBytes]; @@ -902,7 +902,7 @@ private GridFSUploadStream CreateUploadStream(IReadWriteBindingHandle b private async Task DownloadToStreamHelperAsync(IReadBindingHandle binding, GridFSFileInfo fileInfo, Stream destination, GridFSDownloadOptions options, CancellationToken cancellationToken = default(CancellationToken)) { var retryReads = _database.Client.Settings.RetryReads; - using (var source = new GridFSForwardOnlyDownloadStream(this, binding.Fork(), fileInfo) { RetryReads = retryReads}) + using (var source = new GridFSForwardOnlyDownloadStream(this, binding.Fork(), fileInfo) { RetryReads = retryReads }) { var count = source.Length; var buffer = new byte[fileInfo.ChunkSizeBytes]; diff --git a/src/MongoDB.Driver/Linq/ISetWindowFieldsPartitionExtensions.cs b/src/MongoDB.Driver/Linq/ISetWindowFieldsPartitionExtensions.cs index e8053b0f012..b20ca0b08d3 100644 --- a/src/MongoDB.Driver/Linq/ISetWindowFieldsPartitionExtensions.cs +++ b/src/MongoDB.Driver/Linq/ISetWindowFieldsPartitionExtensions.cs @@ -525,7 +525,7 @@ public static decimal DenseRank(this ISetWindowFieldsPartition p /// The selector that selects a value from the input document. /// The window boundaries. /// The average rate of change within the specified window. - public static decimal Derivative (this ISetWindowFieldsPartition partition, Func selector, SetWindowFieldsWindow window = null) + public static decimal Derivative(this ISetWindowFieldsPartition partition, Func selector, SetWindowFieldsWindow window = null) { throw new InvalidOperationException("This method is only intended to be used with SetWindowFields."); } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstEnumExtensions.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstEnumExtensions.cs index be6200a004f..db7b8a309bb 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstEnumExtensions.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstEnumExtensions.cs @@ -33,4 +33,4 @@ public static string Render(this ByteOrder byteOrder) }; } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstPipeline.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstPipeline.cs index f6cbd7377bd..773a680c8c7 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstPipeline.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstPipeline.cs @@ -46,7 +46,7 @@ public override AstNode Accept(AstNodeVisitor visitor) return visitor.VisitPipeline(this); } - public override BsonValue Render() + public override BsonValue Render() { return new BsonArray(_stages.Select(s => s.Render())); } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstCondExpression.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstCondExpression.cs index d48d40f01cf..91d72a91684 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstCondExpression.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstCondExpression.cs @@ -28,7 +28,7 @@ internal sealed class AstCondExpression : AstExpression public AstCondExpression(AstExpression @if, AstExpression @then, AstExpression @else) { _if = Ensure.IsNotNull(@if, nameof(@if)); - _then =Ensure.IsNotNull(@then, nameof(@then)); + _then = Ensure.IsNotNull(@then, nameof(@then)); _else = Ensure.IsNotNull(@else, nameof(@else)); } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpressionExtensions.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpressionExtensions.cs index 5de4bdfe0a3..e4aa5ac0bf4 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpressionExtensions.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpressionExtensions.cs @@ -101,7 +101,7 @@ public static bool IsStringConstant(this AstExpression expression, out string st return false; } - public static bool IsZero(this AstExpression expression) - => expression.IsConstant(out var constant) && constant == 0; // works for all numeric BSON types + public static bool IsZero(this AstExpression expression) + => expression.IsConstant(out var constant) && constant == 0; // works for all numeric BSON types } } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianAccumulatorExpression.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianAccumulatorExpression.cs index d7cc2bb085a..83f7f996219 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianAccumulatorExpression.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianAccumulatorExpression.cs @@ -60,4 +60,4 @@ public AstMedianAccumulatorExpression Update(AstExpression input) return new AstMedianAccumulatorExpression(input); } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianExpression.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianExpression.cs index a171bb9fa02..43a48b07969 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianExpression.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianExpression.cs @@ -60,4 +60,4 @@ public AstMedianExpression Update(AstExpression input) return new AstMedianExpression(input); } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianWindowExpression.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianWindowExpression.cs index fbe71c3f278..2da2d5a0379 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianWindowExpression.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstMedianWindowExpression.cs @@ -56,7 +56,7 @@ public override BsonValue Render() }; } - public AstMedianWindowExpression Update(AstExpression input, AstWindow window) + public AstMedianWindowExpression Update(AstExpression input, AstWindow window) { if (input == _input && window == _window) { @@ -66,4 +66,4 @@ public AstMedianWindowExpression Update(AstExpression input, AstWindow window) return new AstMedianWindowExpression(input, window); } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileAccumulatorExpression.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileAccumulatorExpression.cs index 77cee275402..dc7bc5d11d2 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileAccumulatorExpression.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileAccumulatorExpression.cs @@ -65,4 +65,4 @@ public AstPercentileAccumulatorExpression Update(AstExpression input, AstExpress return new AstPercentileAccumulatorExpression(input, percentiles); } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileExpression.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileExpression.cs index aab4920143d..b22f38547d7 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileExpression.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileExpression.cs @@ -65,4 +65,4 @@ public AstPercentileExpression Update(AstExpression input, AstExpression percent return new AstPercentileExpression(input, percentiles); } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileWindowExpression.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileWindowExpression.cs index 055bcfb8ef3..48d300aab4e 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileWindowExpression.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstPercentileWindowExpression.cs @@ -71,4 +71,4 @@ public AstPercentileWindowExpression Update(AstExpression input, AstExpression p return new AstPercentileWindowExpression(input, percentiles, window); } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstGroupingPipelineOptimizer.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstGroupingPipelineOptimizer.cs index 4d15a967d72..bd3de331a14 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstGroupingPipelineOptimizer.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstGroupingPipelineOptimizer.cs @@ -460,7 +460,7 @@ public override AstNode VisitPercentileExpression(AstPercentileExpression node) // => { __agg0 : { $percentile : { input: f(x => element), p: [...], method: "approximate" } } } + "$__agg0" if (IsMappedElementsField(node.Input, out var rewrittenArg)) { - var accumulatorExpression = AstExpression.PercentileAccumulator(rewrittenArg, node.Percentiles); + var accumulatorExpression = AstExpression.PercentileAccumulator(rewrittenArg, node.Percentiles); return CreateGetAccumulatorFieldExpression(accumulatorExpression); } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstSimplifier.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstSimplifier.cs index 32d4f72efe1..7c98964e378 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstSimplifier.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstSimplifier.cs @@ -486,7 +486,7 @@ innerMapExpression.In is AstComputedDocumentExpression innerComputedDocumentExpr outerComputedDocumentExpression.Fields.All(outerField => outerField.Value is AstGetFieldExpression outerGetFieldExpression && outerGetFieldExpression.Input == outerVar && - outerGetFieldExpression.FieldName is AstConstantExpression { Value : BsonString { Value : var matchingFieldName } } && + outerGetFieldExpression.FieldName is AstConstantExpression { Value: BsonString { Value: var matchingFieldName } } && innerComputedDocumentExpression.Fields.Any(innerField => innerField.Path == matchingFieldName))) { var rewrittenOuterFields = new List(); @@ -521,7 +521,7 @@ node.In is AstComputedDocumentExpression mappedDocument && mappedDocument.Fields.All(mappedField => mappedField.Value is AstGetFieldExpression mappedGetField && mappedGetField.Input == itemVar && - mappedGetField.FieldName is AstConstantExpression { Value : BsonString { Value : var matchingFieldName } } && + mappedGetField.FieldName is AstConstantExpression { Value: BsonString { Value: var matchingFieldName } } && inputFieldNames.Contains(matchingFieldName))) { var rewrittenItems = new List(); @@ -675,7 +675,7 @@ item is AstComputedDocumentExpression computedDocumentExpression && computedDocumentExpression.Fields.Count == 2 && computedDocumentExpression.Fields[0].Path == "k" && computedDocumentExpression.Fields[1].Path == "v" && - computedDocumentExpression.Fields[0].Value is AstConstantExpression { Value : { IsString : true } })) + computedDocumentExpression.Fields[0].Value is AstConstantExpression { Value: { IsString: true } })) { var computedFields = computedArrayExpression.Items.Select(KeyValuePairDocumentToComputedField); return AstExpression.ComputedDocument(computedFields); diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Stages/AstStage.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Stages/AstStage.cs index b0e8f20d341..830645a165c 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Stages/AstStage.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Stages/AstStage.cs @@ -33,7 +33,7 @@ public static AstStage Bucket( BsonValue @default = null, IEnumerable output = null) { - return new AstBucketStage(groupBy, boundaries, @default, output); + return new AstBucketStage(groupBy, boundaries, @default, output); } public static AstStage BucketAuto( diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs index 8b94898f082..9ecc361fcc2 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs @@ -72,7 +72,7 @@ public virtual AstNode VisitAccumulatorField(AstAccumulatorField node) public virtual AstNode VisitAddFieldsStage(AstAddFieldsStage node) { - return node.Update(VisitAndConvert(node.Fields)); + return node.Update(VisitAndConvert(node.Fields)); } public virtual AstNode VisitAllFilterOperation(AstAllFilterOperation node) diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/IBsonSerializerExtensions.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/IBsonSerializerExtensions.cs index ffa90c1ab7a..18c9a202199 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/IBsonSerializerExtensions.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/IBsonSerializerExtensions.cs @@ -160,6 +160,6 @@ serializer is IBsonDocumentSerializer documentSerializer && public static IBsonSerializer GetValueSerializerIfWrapped(this IBsonSerializer serializer) { - return serializer is IWrappedValueSerializer wrappedValueSerializer ? wrappedValueSerializer.ValueSerializer.GetValueSerializerIfWrapped() : serializer; + return serializer is IWrappedValueSerializer wrappedValueSerializer ? wrappedValueSerializer.ValueSerializer.GetValueSerializerIfWrapped() : serializer; } } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/PartialEvaluator.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/PartialEvaluator.cs index dd3bbbf467d..7d6305323cb 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/PartialEvaluator.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/PartialEvaluator.cs @@ -332,7 +332,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node) } return result; - } + } private bool IsCustomLinqExtensionMethod(MethodInfo method) { diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/SerializationHelper.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/SerializationHelper.cs index 9518d3f3a6b..3e19648007e 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/SerializationHelper.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Misc/SerializationHelper.cs @@ -256,7 +256,7 @@ public static BsonArray SerializeValues(IBsonSerializer itemSerializer, IEnumera writer.WriteName("_v"); writer.WriteStartArray(); var context = BsonSerializationContext.CreateRoot(writer); - foreach(var value in values) + foreach (var value in values) { itemSerializer.Serialize(context, value); } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/DateTimeConstructor.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/DateTimeConstructor.cs index ef24c8dab1e..ad98c3adbbc 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/DateTimeConstructor.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/DateTimeConstructor.cs @@ -31,7 +31,7 @@ static DateTimeConstructor() __withYearMonthDayHourMinuteSecondMillisecond = ReflectionInfo.Constructor((int year, int month, int day, int hour, int minute, int second, int millisecond) => new DateTime(year, month, day, hour, minute, second, millisecond)); } - public static ConstructorInfo WithYearMonthDay=> __withYearMonthDay; + public static ConstructorInfo WithYearMonthDay => __withYearMonthDay; public static ConstructorInfo WithYearMonthDayHourMinuteSecond => __withYearMonthDayHourMinuteSecond; public static ConstructorInfo WithYearMonthDayHourMinuteSecondMillisecond => __withYearMonthDayHourMinuteSecondMillisecond; } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/EnumerableMethod.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/EnumerableMethod.cs index 10dd7c01706..a148c6108f5 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/EnumerableMethod.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/EnumerableMethod.cs @@ -483,7 +483,7 @@ static EnumerableMethod() public static MethodInfo AverageSingleWithSelector => __averageSingleWithSelector; public static MethodInfo Bottom => __bottom; public static MethodInfo BottomN => __bottomN; - public static MethodInfo BottomNWithComputedN => __bottomNWithComputedN; + public static MethodInfo BottomNWithComputedN => __bottomNWithComputedN; public static MethodInfo Cast => __cast; public static MethodInfo Concat => __concat; public static MethodInfo Contains => __contains; diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MethodInfoSet.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MethodInfoSet.cs index db6ee6b79cc..73bad96b99f 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MethodInfoSet.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MethodInfoSet.cs @@ -40,7 +40,7 @@ public static IReadOnlyMethodInfoSet Create(IEnumerable> foreach (var methodSet in methodSets) { - hashSet.UnionWith(methodSet.Where(m => m != null)); + hashSet.UnionWith(methodSet.Where(m => m != null)); } return Create(hashSet); diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MongoQueryableMethod.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MongoQueryableMethod.cs index dd471881e5a..aef05758715 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MongoQueryableMethod.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/MongoQueryableMethod.cs @@ -511,9 +511,9 @@ static MongoQueryableMethod() __takeWithLong ]); - __standardDeviationOverloads = MethodInfoSet.Create( - [ - __standardDeviationPopulationDecimal, + __standardDeviationOverloads = MethodInfoSet.Create( + [ + __standardDeviationPopulationDecimal, __standardDeviationPopulationDecimalAsync, __standardDeviationPopulationDecimalWithSelector, __standardDeviationPopulationDecimalWithSelectorAsync, @@ -593,7 +593,7 @@ static MongoQueryableMethod() __standardDeviationSampleSingleAsync, __standardDeviationSampleSingleWithSelector, __standardDeviationSampleSingleWithSelectorAsync - ]); + ]); __standardDeviationNullableOverloads = MethodInfoSet.Create( [ @@ -764,7 +764,7 @@ static MongoQueryableMethod() __sumNullableSingleWithSelectorAsync, __sumSingleWithSelectorAsync ]); - } + } // public properties public static MethodInfo AnyAsync => __anyAsync; diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/WindowMethod.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/WindowMethod.cs index 8ad6a753360..1096032296e 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/WindowMethod.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/WindowMethod.cs @@ -230,7 +230,7 @@ static WindowMethod() __derivativeWithInt64 = ReflectionInfo.Method((ISetWindowFieldsPartition partition, Func selector, SetWindowFieldsWindow window) => partition.Derivative(selector, window)); __derivativeWithInt64AndUnit = ReflectionInfo.Method((ISetWindowFieldsPartition partition, Func selector, WindowTimeUnit unit, SetWindowFieldsWindow window) => partition.Derivative(selector, unit, window)); __derivativeWithSingle = ReflectionInfo.Method((ISetWindowFieldsPartition partition, Func selector, SetWindowFieldsWindow window) => partition.Derivative(selector, window)); - __derivativeWithSingleAndUnit = ReflectionInfo.Method((ISetWindowFieldsPartition partition, Func selector, WindowTimeUnit unit, SetWindowFieldsWindow window) => partition.Derivative(selector, unit, window));; + __derivativeWithSingleAndUnit = ReflectionInfo.Method((ISetWindowFieldsPartition partition, Func selector, WindowTimeUnit unit, SetWindowFieldsWindow window) => partition.Derivative(selector, unit, window)); ; __documentNumber = ReflectionInfo.Method((ISetWindowFieldsPartition partition) => partition.DocumentNumber()); __exponentialMovingAverageWithDecimal = ReflectionInfo.Method((ISetWindowFieldsPartition partition, Func selector, ExponentialMovingAverageWeighting weighting, SetWindowFieldsWindow window) => partition.ExponentialMovingAverage(selector, weighting, window)); __exponentialMovingAverageWithDouble = ReflectionInfo.Method((ISetWindowFieldsPartition partition, Func selector, ExponentialMovingAverageWeighting weighting, SetWindowFieldsWindow window) => partition.ExponentialMovingAverage(selector, weighting, window)); diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderHelperMethods.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderHelperMethods.cs index 9993ee0048f..a747ce4c63f 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderHelperMethods.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderHelperMethods.cs @@ -23,7 +23,7 @@ using MongoDB.Bson.Serialization.Serializers; using MongoDB.Driver.Linq.Linq3Implementation.Misc; using MongoDB.Driver.Linq.Linq3Implementation.Serializers; -using IOrderedEnumerableSerializer=MongoDB.Driver.Linq.Linq3Implementation.Serializers.IOrderedEnumerableSerializer; +using IOrderedEnumerableSerializer = MongoDB.Driver.Linq.Linq3Implementation.Serializers.IOrderedEnumerableSerializer; namespace MongoDB.Driver.Linq.Linq3Implementation.SerializerFinders; @@ -165,11 +165,11 @@ private void DeduceCollectionAndCollectionSerializers(Expression collectionExpre if (IsNotKnown(collectionExpression2) && IsKnown(collectionExpression1, out collectionSerializer1)) { - collectionSerializer2 = CreateCollectionSerializerFromCollectionSerializer(collectionExpression2.Type, collectionSerializer1); + collectionSerializer2 = CreateCollectionSerializerFromCollectionSerializer(collectionExpression2.Type, collectionSerializer1); AddNodeSerializer(collectionExpression2, collectionSerializer2); } } - + private void DeduceCollectionAndItemSerializers(Expression collectionExpression, Expression itemExpression) { DeduceItemAndCollectionSerializers(itemExpression, collectionExpression); @@ -216,7 +216,7 @@ private void DeduceSerializers(Expression expression1, Expression expression2) AddNodeSerializer(expression1, expression2Serializer); } - if (IsNotKnown(expression2) && IsKnown(expression1, out var expression1Serializer)&& expression1Serializer.ValueType == expression2.Type) + if (IsNotKnown(expression2) && IsKnown(expression1, out var expression1Serializer) && expression1Serializer.ValueType == expression2.Type) { AddNodeSerializer(expression2, expression1Serializer); } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitBinary.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitBinary.cs index f06bb736f50..5e32ae0d7bf 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitBinary.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitBinary.cs @@ -42,7 +42,7 @@ protected override Expression VisitBinary(BinaryExpression node) if (IsSymmetricalBinaryOperator(@operator)) { // expr1 op expr2 => expr1: expr2Serializer or expr2: expr1Serializer - DeduceSerializers(leftExpression, rightExpression); + DeduceSerializers(leftExpression, rightExpression); } if (@operator == ExpressionType.ArrayIndex) diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMember.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMember.cs index 80b0b7e132a..cb5e5d9644c 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMember.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMember.cs @@ -145,7 +145,7 @@ IBsonSerializer GetDictionaryPropertySerializer() throw new ExpressionNotSupportedException(node, because: "dictionary serializer does not implement IBsonDictionarySerializer"); } - var keySerializer = dictionarySerializer.KeySerializer; + var keySerializer = dictionarySerializer.KeySerializer; var valueSerializer = dictionarySerializer.ValueSerializer; return memberName switch @@ -163,7 +163,7 @@ IBsonSerializer GetIDictionaryPropertySerializer() throw new ExpressionNotSupportedException(node, because: "IDictionarySerializer does not implement IBsonDictionarySerializer"); } - var keySerializer = dictionarySerializer.KeySerializer; + var keySerializer = dictionarySerializer.KeySerializer; var valueSerializer = dictionarySerializer.ValueSerializer; return memberName switch diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMemberInit.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMemberInit.cs index b90992d9be4..01ff9cae1f5 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMemberInit.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMemberInit.cs @@ -39,7 +39,7 @@ protected override Expression VisitMemberInit(MemberInitExpression node) { if (nodeSerializer is not IBsonDocumentSerializer documentSerializer) { - throw new ExpressionNotSupportedException(node, because: $"serializer type {nodeSerializer.GetType()} does not implement IBsonDocumentSerializer interface"); + throw new ExpressionNotSupportedException(node, because: $"serializer type {nodeSerializer.GetType()} does not implement IBsonDocumentSerializer interface"); } foreach (var binding in node.Bindings) diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMethodCall.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMethodCall.cs index a5bf9768039..74a44bb24bb 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMethodCall.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMethodCall.cs @@ -408,7 +408,7 @@ private static void DeduceAggregateWithFuncMethodSerializers(SerializerFinderVis private static void DeduceAggregateWithSeedAndFuncMethodSerializers(SerializerFinderVisitor visitor, MethodCallExpression expression) { var sourceExpression = expression.Arguments[0]; - var seedExpression = expression.Arguments[1]; + var seedExpression = expression.Arguments[1]; var funcLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(expression.Method, expression.Arguments[2]); var funcAccumulatorParameter = funcLambda.Parameters[0]; var funcSourceItemParameter = funcLambda.Parameters[1]; @@ -1111,7 +1111,7 @@ private static void DeduceSelectManyWithCollectionSelectorAndResultSelectorMetho { var sourceExpression = expression.Arguments[0]; var collectionSelectorLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(expression.Method, expression.Arguments[1]); - var resultSelectorLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(expression.Method, expression.Arguments[2]); + var resultSelectorLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(expression.Method, expression.Arguments[2]); var collectionSelectorSourceItemParameter = collectionSelectorLambda.Parameters.Single(); var resultSelectorSourceItemParameter = resultSelectorLambda.Parameters[0]; @@ -1202,7 +1202,7 @@ private static void DeduceWhereSerializers(SerializerFinderVisitor visitor, Meth { var sourceExpression = expression.Arguments[0]; var predicateLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(expression.Method, expression.Arguments[1]); - var predicateParameter = predicateLambda.Parameters.Single(); + var predicateParameter = predicateLambda.Parameters.Single(); visitor.DeduceItemAndCollectionSerializers(predicateParameter, sourceExpression); visitor.DeduceCollectionAndCollectionSerializers(expression, sourceExpression); } @@ -1227,17 +1227,17 @@ private static void DeduceZipSerializers(SerializerFinderVisitor visitor, Method var secondExpression = expression.Arguments[1]; var resultSelectorLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(expression.Method, expression.Arguments[2]); var resultSelectorFirstParameter = resultSelectorLambda.Parameters[0]; - var resultSelectorSecondParameter = resultSelectorLambda.Parameters[1]; + var resultSelectorSecondParameter = resultSelectorLambda.Parameters[1]; if (visitor.IsNotKnown(resultSelectorFirstParameter) && visitor.IsKnown(firstExpression, out var firstSerializer)) { - var firstItemSerializer = ArraySerializerHelper.GetItemSerializer(firstSerializer); + var firstItemSerializer = ArraySerializerHelper.GetItemSerializer(firstSerializer); visitor.AddNodeSerializer(resultSelectorFirstParameter, firstItemSerializer); } if (visitor.IsNotKnown(resultSelectorSecondParameter) && visitor.IsKnown(secondExpression, out var secondSerializer)) { - var secondItemSerializer = ArraySerializerHelper.GetItemSerializer(secondSerializer); + var secondItemSerializer = ArraySerializerHelper.GetItemSerializer(secondSerializer); visitor.AddNodeSerializer(resultSelectorSecondParameter, secondItemSerializer); } @@ -1426,7 +1426,7 @@ private static void DeduceFirstOrLastWindowMethodsSerializers(SerializerFinderVi { var partitionExpression = expression.Arguments[0]; var selectorLambda = (LambdaExpression)expression.Arguments[1]; - DeduceWindowMethodSelectorParameterSerializer(visitor,partitionExpression, selectorLambda); + DeduceWindowMethodSelectorParameterSerializer(visitor, partitionExpression, selectorLambda); visitor.DeduceSerializers(expression, selectorLambda.Body); } @@ -1471,7 +1471,7 @@ private static void DeduceSkipOrTakeMethodSerializers(SerializerFinderVisitor vi if (expression.Method.IsOneOf(EnumerableOrQueryableMethod.SkipWhileOrTakeWhile)) { - var predicateLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(expression.Method, expression.Arguments[1]); + var predicateLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(expression.Method, expression.Arguments[1]); var predicateParameter = predicateLambda.Parameters[0]; visitor.DeduceItemAndCollectionSerializers(predicateParameter, sourceExpression); diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitUnary.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitUnary.cs index 988cc4f809d..86abeee7d0a 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitUnary.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitUnary.cs @@ -287,7 +287,7 @@ static bool IsConvertToDerivedType(Type sourceType, Type targetType) static bool IsConvertToNullableType(Type targetType, out Type valueType) { - return targetType.IsNullable(out valueType); + return targetType.IsNullable(out valueType); } static bool IsConvertIntegralTypeToEnum(Type sourceType, Type targetType) diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/DictionarySerializer.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/DictionarySerializer.cs index 0d56847649e..6e13864e067 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/DictionarySerializer.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/DictionarySerializer.cs @@ -47,5 +47,5 @@ public DictionarySerializer( protected override ICollection> CreateAccumulator() => new Dictionary(); - protected override DictionaryFinalizeAccumulator(ICollection> accumulator) => (Dictionary)accumulator; + protected override Dictionary FinalizeAccumulator(ICollection> accumulator) => (Dictionary)accumulator; } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/DictionaryValueCollectionSerializer.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/DictionaryValueCollectionSerializer.cs index e1ee050d9cd..32668be4286 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/DictionaryValueCollectionSerializer.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/DictionaryValueCollectionSerializer.cs @@ -37,9 +37,9 @@ internal class DictionaryValueCollectionSerializer : SerializerBas private readonly IBsonSerializer> _dictionarySerializer; private readonly IBsonSerializer _wrappedValueSerializer; - public DictionaryValueCollectionSerializer(IBsonSerializer keySerializer, IBsonSerializer valueSerializer) + public DictionaryValueCollectionSerializer(IBsonSerializer keySerializer, IBsonSerializer valueSerializer) { - _dictionarySerializer = (IBsonSerializer>)DictionarySerializer.Create(DictionaryRepresentation.ArrayOfDocuments, keySerializer, valueSerializer); + _dictionarySerializer = (IBsonSerializer>)DictionarySerializer.Create(DictionaryRepresentation.ArrayOfDocuments, keySerializer, valueSerializer); _wrappedValueSerializer = (IBsonSerializer)KeyValuePairWrappedValueSerializer.Create(keySerializer, valueSerializer); } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/KeyValuePairWrappedValueSerializer.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/KeyValuePairWrappedValueSerializer.cs index b2fee08e360..a47f8f96dcd 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/KeyValuePairWrappedValueSerializer.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Serializers/KeyValuePairWrappedValueSerializer.cs @@ -37,9 +37,9 @@ internal class KeyValuePairWrappedValueSerializer : SerializerBase private readonly IBsonSerializer> _keyValuePairSerializer; private readonly IBsonSerializer _valueSerializer; - public KeyValuePairWrappedValueSerializer(IBsonSerializer keySerializer, IBsonSerializer valueSerializer) + public KeyValuePairWrappedValueSerializer(IBsonSerializer keySerializer, IBsonSerializer valueSerializer) { - _keyValuePairSerializer = (IBsonSerializer>)KeyValuePairSerializer.Create(BsonType.Document, keySerializer, valueSerializer); + _keyValuePairSerializer = (IBsonSerializer>)KeyValuePairSerializer.Create(BsonType.Document, keySerializer, valueSerializer); _valueSerializer = valueSerializer; } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ClientSideProjectionRewriter.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ClientSideProjectionRewriter.cs index 35bab95e682..4c0231bbfcb 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ClientSideProjectionRewriter.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ClientSideProjectionRewriter.cs @@ -25,7 +25,7 @@ namespace MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators { - internal class ClientSideProjectionRewriter: ExpressionVisitor + internal class ClientSideProjectionRewriter : ExpressionVisitor { #region static public static (TranslatedExpression[], LambdaExpression) RewriteProjection(TranslationContext context, LambdaExpression projectionLambda, IBsonSerializer sourceSerializer) diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ExpressionToAggregationExpressionTranslator.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ExpressionToAggregationExpressionTranslator.cs index b862996795d..e67f6718c19 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ExpressionToAggregationExpressionTranslator.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ExpressionToAggregationExpressionTranslator.cs @@ -132,7 +132,7 @@ public static TranslatedExpression TranslateEnumerable(TranslationContext contex var keySerializer = dictionarySerializer.KeySerializer; var valueSerializer = dictionarySerializer.ValueSerializer; - var ast = AstExpression.ObjectToArray(aggregateExpression.Ast); + var ast = AstExpression.ObjectToArray(aggregateExpression.Ast); var arrayOfDocumentsDictionarySerializer = DictionarySerializer.Create(DictionaryRepresentation.ArrayOfDocuments, keySerializer, valueSerializer); aggregateExpression = new TranslatedExpression(expression, ast, arrayOfDocumentsDictionarySerializer); diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MemberExpressionToAggregationExpressionTranslator.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MemberExpressionToAggregationExpressionTranslator.cs index 88c195eeee5..92d1a1a8ce0 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MemberExpressionToAggregationExpressionTranslator.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MemberExpressionToAggregationExpressionTranslator.cs @@ -71,7 +71,7 @@ public static TranslatedExpression Translate(TranslationContext context, MemberE if (!DocumentSerializerHelper.AreMembersRepresentedAsFields(containerTranslation.Serializer, out _)) { - if (member is PropertyInfo propertyInfo && propertyInfo.Name == "Length") + if (member is PropertyInfo propertyInfo && propertyInfo.Name == "Length") { return LengthPropertyToAggregationExpressionTranslator.Translate(context, expression); } @@ -217,7 +217,7 @@ private static bool TryTranslateDictionaryProperty(TranslationContext context, M var keysAst = dictionaryRepresentation switch { DictionaryRepresentation.ArrayOfDocuments => AstExpression.Map(containerAst, kvpVar, AstExpression.GetField(kvpVar, "k")), - DictionaryRepresentation.ArrayOfArrays => AstExpression.Map(containerAst, kvpVar, AstExpression.ArrayElemAt(kvpVar, 0)), + DictionaryRepresentation.ArrayOfArrays => AstExpression.Map(containerAst, kvpVar, AstExpression.ArrayElemAt(kvpVar, 0)), _ => throw new ExpressionNotSupportedException(expression, $"Unexpected dictionary representation: {dictionaryRepresentation}") }; var keysSerializer = declaringTypeDefinition == typeof(Dictionary<,>) diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMethodToAggregationExpressionTranslator.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMethodToAggregationExpressionTranslator.cs index 87a95a3e095..031006abc62 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMethodToAggregationExpressionTranslator.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMethodToAggregationExpressionTranslator.cs @@ -46,7 +46,7 @@ public static TranslatedExpression Translate(TranslationContext context, MethodC sourceTranslation.Ast, selectorParameterSymbol.Var, translatedSelector.Ast); - var serializer = NestedAsQueryableSerializer.CreateIEnumerableOrNestedAsQueryableSerializer(expression.Type, itemSerializer : translatedSelector.Serializer); + var serializer = NestedAsQueryableSerializer.CreateIEnumerableOrNestedAsQueryableSerializer(expression.Type, itemSerializer: translatedSelector.Serializer); return new TranslatedExpression(expression, ast, serializer); } diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SequenceEqualMethodToAggregationExpressionTranslator.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SequenceEqualMethodToAggregationExpressionTranslator.cs index 96d26389b4f..599d77f0e4b 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SequenceEqualMethodToAggregationExpressionTranslator.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SequenceEqualMethodToAggregationExpressionTranslator.cs @@ -43,7 +43,7 @@ public static TranslatedExpression Translate(TranslationContext context, MethodC var ast = AstExpression.Let( firstVarBinding, secondVarBinding, - @in : AstExpression.And( + @in: AstExpression.And( AstExpression.Eq(AstExpression.Type(firstAst), "array"), AstExpression.Eq(AstExpression.Type(secondAst), "array"), AstExpression.Eq(AstExpression.Size(firstAst), AstExpression.Size(secondAst)), @@ -51,7 +51,7 @@ public static TranslatedExpression Translate(TranslationContext context, MethodC AstExpression.Map( input: AstExpression.Zip([firstAst, secondAst]), @as: pairVar, - @in : AstExpression.Eq(AstExpression.ArrayElemAt(pairVar, 0), AstExpression.ArrayElemAt(pairVar, 1))))) + @in: AstExpression.Eq(AstExpression.ArrayElemAt(pairVar, 0), AstExpression.ArrayElemAt(pairVar, 1))))) ); return new TranslatedExpression(expression, ast, new BooleanSerializer()); diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SigmoidMethodToAggregationExpressionTranslator.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SigmoidMethodToAggregationExpressionTranslator.cs index 12f42cefb9e..e6010baf6fb 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SigmoidMethodToAggregationExpressionTranslator.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SigmoidMethodToAggregationExpressionTranslator.cs @@ -44,4 +44,4 @@ public static TranslatedExpression Translate(TranslationContext context, MethodC throw new ExpressionNotSupportedException(expression); } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/StringInOrNinMethodToFilterTranslator.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/StringInOrNinMethodToFilterTranslator.cs index be7e6d42fc2..0aa47f2b58e 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/StringInOrNinMethodToFilterTranslator.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/StringInOrNinMethodToFilterTranslator.cs @@ -39,7 +39,7 @@ internal static class StringInOrNinMethodToFilterTranslator // public static methods public static AstFilter Translate(TranslationContext context, MethodCallExpression expression) { - var method = expression.Method; + var method = expression.Method; var arguments = expression.Arguments; if (method.IsOneOf(__translatableOverloads)) diff --git a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ToFilterFieldTranslators/MemberExpressionToFilterFieldTranslator.cs b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ToFilterFieldTranslators/MemberExpressionToFilterFieldTranslator.cs index bbeba78f6ce..7a2f4fac21b 100644 --- a/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ToFilterFieldTranslators/MemberExpressionToFilterFieldTranslator.cs +++ b/src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ToFilterFieldTranslators/MemberExpressionToFilterFieldTranslator.cs @@ -86,7 +86,7 @@ public static TranslatedFilterField Translate(TranslationContext context, Member } } - if (DocumentSerializerHelper.AreMembersRepresentedAsFields(fieldSerializer , out var documentSerializer) && + if (DocumentSerializerHelper.AreMembersRepresentedAsFields(fieldSerializer, out var documentSerializer) && documentSerializer.TryGetMemberSerializationInfo(memberExpression.Member.Name, out BsonSerializationInfo memberSerializationInfo)) { var subFieldSerializer = memberSerializationInfo.Serializer; diff --git a/src/MongoDB.Driver/Linq/LinqProviderAdapter.cs b/src/MongoDB.Driver/Linq/LinqProviderAdapter.cs index 83d71fce3ef..ef851992e50 100644 --- a/src/MongoDB.Driver/Linq/LinqProviderAdapter.cs +++ b/src/MongoDB.Driver/Linq/LinqProviderAdapter.cs @@ -147,7 +147,7 @@ internal static BsonDocument TranslateExpressionToFilter( { expression = (Expression>)LinqExpressionPreprocessor.Preprocess(expression); var parameter = expression.Parameters.Single(); - var context = TranslationContext.Create(serializationDomain, expression, initialNode: parameter, initialSerializer: documentSerializer, translationOptions: translationOptions); + var context = TranslationContext.Create(serializationDomain, expression, initialNode: parameter, initialSerializer: documentSerializer, translationOptions: translationOptions); var filter = ExpressionToFilterTranslator.TranslateLambda(context, expression, documentSerializer, asRoot: true); filter = AstSimplifier.SimplifyAndConvert(filter); diff --git a/src/MongoDB.Driver/Linq/LookupResult.cs b/src/MongoDB.Driver/Linq/LookupResult.cs index 01e00b9a39f..9ded5cf78fd 100644 --- a/src/MongoDB.Driver/Linq/LookupResult.cs +++ b/src/MongoDB.Driver/Linq/LookupResult.cs @@ -63,10 +63,10 @@ public LookupResultSerializer( IBsonSerializer resultSerializer) { _localSerializer = Ensure.IsNotNull(localSerializer, nameof(localSerializer)); - Ensure.IsNotNull(resultSerializer, nameof(resultSerializer)); + Ensure.IsNotNull(resultSerializer, nameof(resultSerializer)); - var arraySerializerType = typeof(ArraySerializer<>).MakeGenericType(resultSerializer.ValueType); - _resultsSerializer = (IBsonSerializer)Activator.CreateInstance(arraySerializerType, resultSerializer); + var arraySerializerType = typeof(ArraySerializer<>).MakeGenericType(resultSerializer.ValueType); + _resultsSerializer = (IBsonSerializer)Activator.CreateInstance(arraySerializerType, resultSerializer); } public override LookupResult Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) diff --git a/src/MongoDB.Driver/MongoClientSettings.cs b/src/MongoDB.Driver/MongoClientSettings.cs index 22b4c23a179..c601821ce8c 100644 --- a/src/MongoDB.Driver/MongoClientSettings.cs +++ b/src/MongoDB.Driver/MongoClientSettings.cs @@ -1294,7 +1294,7 @@ public override string ToString() { sb.AppendFormat("SslSettings={0};", _sslSettings); } - if(_timeout != null) + if (_timeout != null) { sb.AppendFormat("Timeout={0};", _timeout); } diff --git a/src/MongoDB.Driver/MongoCollectionImpl.cs b/src/MongoDB.Driver/MongoCollectionImpl.cs index eaf39c6815a..efa238ae965 100644 --- a/src/MongoDB.Driver/MongoCollectionImpl.cs +++ b/src/MongoDB.Driver/MongoCollectionImpl.cs @@ -796,7 +796,7 @@ private IAsyncCursor CreateAggregateToCollectionResultCursor(I var deferredCursor = new DeferredAsyncCursor( () => forkedSession.Dispose(), ct => ExecuteReadOperation(forkedSession, findOperation, ReadPreference.Primary, options?.Timeout, ct), - ct => ExecuteReadOperationAsync(forkedSession, findOperation, ReadPreference.Primary, options?.Timeout, ct)); + ct => ExecuteReadOperationAsync(forkedSession, findOperation, ReadPreference.Primary, options?.Timeout, ct)); return deferredCursor; } diff --git a/src/MongoDB.Driver/MongoDatabase.cs b/src/MongoDB.Driver/MongoDatabase.cs index ff6d08cde2a..35547290b4a 100644 --- a/src/MongoDB.Driver/MongoDatabase.cs +++ b/src/MongoDB.Driver/MongoDatabase.cs @@ -673,7 +673,7 @@ private CreateViewOperation CreateCreateViewOperation( var translationOptions = _client.Settings.TranslationOptions; var serializerRegistry = options.SerializerRegistry ?? _settings.SerializationDomain.SerializerRegistry; var documentSerializer = options.DocumentSerializer ?? serializerRegistry.GetSerializer(); - var pipelineDocuments = pipeline.Render(new (documentSerializer, serializerRegistry, translationOptions: translationOptions)).Documents; + var pipelineDocuments = pipeline.Render(new(documentSerializer, serializerRegistry, translationOptions: translationOptions)).Documents; return new CreateViewOperation(_databaseNamespace, viewName, viewOn, pipelineDocuments, GetMessageEncoderSettings()) { Collation = options.Collation, diff --git a/src/MongoDB.Driver/MongoTelemetry.cs b/src/MongoDB.Driver/MongoTelemetry.cs index 46ef6593d21..4e1a5b0daa9 100644 --- a/src/MongoDB.Driver/MongoTelemetry.cs +++ b/src/MongoDB.Driver/MongoTelemetry.cs @@ -328,4 +328,4 @@ private static bool TryGetCursorId(BsonDocument reply, out long cursorId) return false; } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/MongoUrlBuilder.cs b/src/MongoDB.Driver/MongoUrlBuilder.cs index 495567281cb..5dabf557918 100644 --- a/src/MongoDB.Driver/MongoUrlBuilder.cs +++ b/src/MongoDB.Driver/MongoUrlBuilder.cs @@ -1087,7 +1087,7 @@ public override string ToString() { query.AppendFormat("retryWrites={0}&", JsonConvert.ToString(_retryWrites.Value)); } - if(!string.IsNullOrEmpty(_proxyHost)) + if (!string.IsNullOrEmpty(_proxyHost)) { query.AppendFormat("proxyHost={0}&", _proxyHost); } diff --git a/src/MongoDB.Driver/OperationContext.cs b/src/MongoDB.Driver/OperationContext.cs index 13ee26e766d..4e53d8e751b 100644 --- a/src/MongoDB.Driver/OperationContext.cs +++ b/src/MongoDB.Driver/OperationContext.cs @@ -119,13 +119,13 @@ public void Dispose() } public OperationContext Fork() => - new (Session, Clock, InitialTimestamp, Timeout, CancellationToken) + new(Session, Clock, InitialTimestamp, Timeout, CancellationToken) { RootContext = RootContext }; internal OperationContext ForkWithOperationMetadata(string operationName, string databaseName, string collectionName, bool isTracingEnabled) => - new (Session, Clock, InitialTimestamp, Timeout, CancellationToken) + new(Session, Clock, InitialTimestamp, Timeout, CancellationToken) { RootContext = RootContext, OperationName = operationName, diff --git a/src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs b/src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs index 8a012737401..6408f9244c5 100644 --- a/src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs +++ b/src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs @@ -613,7 +613,7 @@ public static PipelineStageDefinition Facet( internal static PipelineStageDefinition GeoNear( TPoint near, GeoNearOptions options = null) - // where TPoint is either a GeoJsonPoint or a legacy coordinate array + // where TPoint is either a GeoJsonPoint or a legacy coordinate array { const string operatorName = "$geoNear"; var stage = new DelegatedPipelineStageDefinition( @@ -1297,7 +1297,7 @@ public static PipelineStageDefinition OfType( { IHierarchicalDiscriminatorConvention hierarchicalDiscriminatorConvention => DiscriminatorAstFilter.TypeIs(discriminatorField, hierarchicalDiscriminatorConvention, nominalType, actualType), IScalarDiscriminatorConvention scalarDiscriminatorConvention => DiscriminatorAstFilter.TypeIs(discriminatorField, scalarDiscriminatorConvention, nominalType, actualType), - _ => throw new NotSupportedException( "OfType is not supported with the configured discriminator convention.") + _ => throw new NotSupportedException("OfType is not supported with the configured discriminator convention.") }; } ofTypeFilter = AstSimplifier.SimplifyAndConvert(ofTypeFilter); diff --git a/src/MongoDB.Driver/ProjectionDefinitionBuilder.cs b/src/MongoDB.Driver/ProjectionDefinitionBuilder.cs index df935357aeb..c7430135ce9 100644 --- a/src/MongoDB.Driver/ProjectionDefinitionBuilder.cs +++ b/src/MongoDB.Driver/ProjectionDefinitionBuilder.cs @@ -977,7 +977,8 @@ public CombinedProjectionDefinition(IEnumerable> p if (projection is CombinedProjectionDefinition combinedProjection) { current.AddRange(combinedProjection._projections); - } else + } + else current.Add(projection); return current; }) diff --git a/src/MongoDB.Driver/RankFusionOptions.cs b/src/MongoDB.Driver/RankFusionOptions.cs index 3b20fcd5943..d5cc2479015 100644 --- a/src/MongoDB.Driver/RankFusionOptions.cs +++ b/src/MongoDB.Driver/RankFusionOptions.cs @@ -34,4 +34,4 @@ public sealed class RankFusionOptions /// public bool ScoreDetails { get; set; } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Search/MatchCriteria.cs b/src/MongoDB.Driver/Search/MatchCriteria.cs index 4f7b74aaf42..b2285321cc8 100644 --- a/src/MongoDB.Driver/Search/MatchCriteria.cs +++ b/src/MongoDB.Driver/Search/MatchCriteria.cs @@ -29,4 +29,4 @@ public enum MatchCriteria /// All } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs b/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs index 9043ccf1b6f..64c923f29f2 100644 --- a/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs +++ b/src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs @@ -121,7 +121,8 @@ private protected override BsonDocument RenderArguments( var pathPrefix = _path.Render(args).AsString; var newArgs = args .WithNewDocumentType(args.SerializerRegistry.GetSerializer()) - with { PathRenderArgs = new(pathPrefix) }; + with + { PathRenderArgs = new(pathPrefix) }; return new("operator", _operator.Render(newArgs)); } diff --git a/src/MongoDB.Driver/Search/RankFusionScoreDetails.cs b/src/MongoDB.Driver/Search/RankFusionScoreDetails.cs index c9b3156ddd7..6318dea5a51 100644 --- a/src/MongoDB.Driver/Search/RankFusionScoreDetails.cs +++ b/src/MongoDB.Driver/Search/RankFusionScoreDetails.cs @@ -57,4 +57,4 @@ public RankFusionScoreDetails(double value, string description, BsonDocument[] d [BsonElement("details")] public BsonDocument[] Details { get; } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs index 17c998baea1..dcc85376658 100644 --- a/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs +++ b/src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs @@ -123,7 +123,7 @@ public SearchDefinition Equals( FieldDefinition path, TField value, SearchScoreDefinition score = null) => - Equals(path, value, new EqualsSearchOperatorOptions { Score = score}); + Equals(path, value, new EqualsSearchOperatorOptions { Score = score }); /// /// Creates a search definition that queries for documents where an indexed field is equal @@ -187,7 +187,7 @@ public SearchDefinition Equals( Expression>> path, TField value, SearchScoreDefinition score = null) => - Equals(path, value, new EqualsSearchOperatorOptions {Score = score }); + Equals(path, value, new EqualsSearchOperatorOptions { Score = score }); /// /// Creates a search definition that queries for documents where at least one element in an indexed array field is equal diff --git a/src/MongoDB.Driver/Search/SearchPhraseOptions.cs b/src/MongoDB.Driver/Search/SearchPhraseOptions.cs index 8c239a1323e..cf647778793 100644 --- a/src/MongoDB.Driver/Search/SearchPhraseOptions.cs +++ b/src/MongoDB.Driver/Search/SearchPhraseOptions.cs @@ -35,4 +35,4 @@ public sealed class SearchPhraseOptions /// public string Synonyms { get; set; } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/Search/SearchRangeV2.cs b/src/MongoDB.Driver/Search/SearchRangeV2.cs index 005f896de4f..15f0deb1295 100644 --- a/src/MongoDB.Driver/Search/SearchRangeV2.cs +++ b/src/MongoDB.Driver/Search/SearchRangeV2.cs @@ -93,7 +93,7 @@ public static class SearchRangeV2Builder /// The value. /// Search range. public static SearchRangeV2 Gt(this SearchRangeV2 searchRange, TValue value) - => new(min: new (value), searchRange.Max); + => new(min: new(value), searchRange.Max); /// /// Creates a greater or equal than search range. diff --git a/src/MongoDB.Driver/Search/SearchScoreDefinitionBuilder.cs b/src/MongoDB.Driver/Search/SearchScoreDefinitionBuilder.cs index 362b02e4dff..b5d2a45c6b7 100644 --- a/src/MongoDB.Driver/Search/SearchScoreDefinitionBuilder.cs +++ b/src/MongoDB.Driver/Search/SearchScoreDefinitionBuilder.cs @@ -118,7 +118,7 @@ public BoostValueSearchScoreDefinition(double value) } public override BsonDocument Render(RenderArgs args) => - new("boost", new BsonDocument("value", _value)); + new("boost", new BsonDocument("value", _value)); } internal sealed class ConstantSearchScoreDefinition : SearchScoreDefinition diff --git a/src/MongoDB.Driver/Search/SearchSpanDefinition.cs b/src/MongoDB.Driver/Search/SearchSpanDefinition.cs index 7aa0481ec60..1f13407adeb 100644 --- a/src/MongoDB.Driver/Search/SearchSpanDefinition.cs +++ b/src/MongoDB.Driver/Search/SearchSpanDefinition.cs @@ -52,6 +52,6 @@ private protected enum ClauseType public virtual BsonDocument Render(RenderArgs args) => new(_clauseType.ToCamelCase(), RenderClause(args)); - private protected virtual BsonDocument RenderClause(RenderArgs args) => new (); + private protected virtual BsonDocument RenderClause(RenderArgs args) => new(); } } diff --git a/src/MongoDB.Driver/Search/SearchTextOptions.cs b/src/MongoDB.Driver/Search/SearchTextOptions.cs index ceb09e564a9..82815aaabe4 100644 --- a/src/MongoDB.Driver/Search/SearchTextOptions.cs +++ b/src/MongoDB.Driver/Search/SearchTextOptions.cs @@ -41,4 +41,4 @@ public sealed class SearchTextOptions /// public string Synonyms { get; set; } } -} \ No newline at end of file +} diff --git a/src/MongoDB.Driver/SortDirectionExtensions.cs b/src/MongoDB.Driver/SortDirectionExtensions.cs index c6b43d4ddc0..5d4452f3657 100644 --- a/src/MongoDB.Driver/SortDirectionExtensions.cs +++ b/src/MongoDB.Driver/SortDirectionExtensions.cs @@ -28,4 +28,4 @@ internal static BsonValue Render(this SortDirection direction) => _ => throw new InvalidOperationException($"Invalid sort direction: {direction}.") }; } -} \ No newline at end of file +} diff --git a/tests/FaasTests/LambdaTests/MongoDB.Driver.LambdaTest/LambdaFunction.cs b/tests/FaasTests/LambdaTests/MongoDB.Driver.LambdaTest/LambdaFunction.cs index e3505fa5140..a9bfbea6948 100644 --- a/tests/FaasTests/LambdaTests/MongoDB.Driver.LambdaTest/LambdaFunction.cs +++ b/tests/FaasTests/LambdaTests/MongoDB.Driver.LambdaTest/LambdaFunction.cs @@ -99,7 +99,7 @@ public async Task LambdaFunctionHandlerAsync(APIGateway return new APIGatewayProxyResponse { - Body = JsonSerializer.Serialize(responseBody, new JsonSerializerOptions { WriteIndented = true}), + Body = JsonSerializer.Serialize(responseBody, new JsonSerializerOptions { WriteIndented = true }), StatusCode = _serverHeartbeatWasAwaited ? 502 : 200, Headers = new Dictionary { { "Content-Type", "application/json" } } }; @@ -143,11 +143,11 @@ private void Handle(ConnectionClosedEvent @event) } private void Reset() - { - _totalHeartbeatCount = 0; - _totalHeartbeatDurationMs = 0; - _totalCommandCount = 0; - _totalCommandDurationMs = 0; + { + _totalHeartbeatCount = 0; + _totalHeartbeatDurationMs = 0; + _totalCommandCount = 0; + _totalCommandDurationMs = 0; } } } diff --git a/tests/MongoDB.Bson.TestHelpers/Reflector.cs b/tests/MongoDB.Bson.TestHelpers/Reflector.cs index ca458cb921a..0aaa7795271 100644 --- a/tests/MongoDB.Bson.TestHelpers/Reflector.cs +++ b/tests/MongoDB.Bson.TestHelpers/Reflector.cs @@ -282,7 +282,7 @@ private static MethodInfo GetDeclaredOrInheritedMethod(Type type, string name, B { if (type == null) { - throw new InvalidFilterCriteriaException($"The method name {name} has not been found in {type.Name}."); + throw new InvalidFilterCriteriaException($"The method name {name} has not been found in {type.Name}."); } var methodInfo = GetMethods(type).SingleOrDefault(); diff --git a/tests/MongoDB.Bson.Tests/BsonExtensionMethodsTests.cs b/tests/MongoDB.Bson.Tests/BsonExtensionMethodsTests.cs index 6aafcc955a0..d9c625122ff 100644 --- a/tests/MongoDB.Bson.Tests/BsonExtensionMethodsTests.cs +++ b/tests/MongoDB.Bson.Tests/BsonExtensionMethodsTests.cs @@ -70,11 +70,11 @@ public void TestToBsonWithBadEstimatedBsonSizeShouldThrowException() } [Theory] - [InlineData(13, new byte[] {}, new byte[] { 13, 0, 0, 0, 5, 118, 0, 0, 0, 0, 0, 0, 0 })] - [InlineData(18, new byte[] { 1, 2, 3, 4, 5}, new byte[] { 18, 0, 0, 0, 5, 118, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0 })] - [InlineData(32, new byte[] { 1, 2, 3, 4, 5}, new byte[] { 18, 0, 0, 0, 5, 118, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0 })] - [InlineData(12, new byte[] { 1, 2, 3, 4, 5}, new byte[] { 18, 0, 0, 0, 5, 118, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0 })] - [InlineData(0, new byte[] { 1, 2, 3, 4, 5}, new byte[] { 18, 0, 0, 0, 5, 118, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0 })] + [InlineData(13, new byte[] { }, new byte[] { 13, 0, 0, 0, 5, 118, 0, 0, 0, 0, 0, 0, 0 })] + [InlineData(18, new byte[] { 1, 2, 3, 4, 5 }, new byte[] { 18, 0, 0, 0, 5, 118, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0 })] + [InlineData(32, new byte[] { 1, 2, 3, 4, 5 }, new byte[] { 18, 0, 0, 0, 5, 118, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0 })] + [InlineData(12, new byte[] { 1, 2, 3, 4, 5 }, new byte[] { 18, 0, 0, 0, 5, 118, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0 })] + [InlineData(0, new byte[] { 1, 2, 3, 4, 5 }, new byte[] { 18, 0, 0, 0, 5, 118, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0 })] public void TestToBsonWithNonZeroEstimatedBsonSize(int estimatedBsonSize, byte[] data, byte[] expectedBson) { var document = new BsonDocument("v", new BsonBinaryData(data)); diff --git a/tests/MongoDB.Bson.Tests/IO/BsonBinaryReaderTests.cs b/tests/MongoDB.Bson.Tests/IO/BsonBinaryReaderTests.cs index c13ff294cbc..b6d64e43589 100644 --- a/tests/MongoDB.Bson.Tests/IO/BsonBinaryReaderTests.cs +++ b/tests/MongoDB.Bson.Tests/IO/BsonBinaryReaderTests.cs @@ -30,7 +30,7 @@ public class BsonBinaryReaderTests [Fact] public void Bookmarks_should_work() { - var document = new BsonDocument { { "x", 1 }, { "y", 2 }, { "z", new BsonDocument { { "a", "a"}, { "b", "b" } } } }; + var document = new BsonDocument { { "x", 1 }, { "y", 2 }, { "z", new BsonDocument { { "a", "a" }, { "b", "b" } } } }; using var memoryStream = new MemoryStream(document.ToBson()); using var bsonReader = new BsonBinaryReader(memoryStream); diff --git a/tests/MongoDB.Bson.Tests/ObjectModel/ObjectIdTests.cs b/tests/MongoDB.Bson.Tests/ObjectModel/ObjectIdTests.cs index 6d553415382..7ab3bf85a57 100644 --- a/tests/MongoDB.Bson.Tests/ObjectModel/ObjectIdTests.cs +++ b/tests/MongoDB.Bson.Tests/ObjectModel/ObjectIdTests.cs @@ -139,9 +139,9 @@ public void ToByteSpan_should_return_expected_results(byte[] data, byte[] expect public static IEnumerable ToByteSpan_TestCases() { - yield return [new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ]; - yield return [new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } ]; - yield return [new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } ]; + yield return [new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }]; + yield return [new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }]; + yield return [new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }]; } [Theory] diff --git a/tests/MongoDB.Bson.Tests/Serialization/BsonClassMapSerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/BsonClassMapSerializerTests.cs index 41e1a226580..a0efd61b80e 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/BsonClassMapSerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/BsonClassMapSerializerTests.cs @@ -50,7 +50,7 @@ static BsonClassMapSerializerTests() [Theory] [ParameterAttributeData] public void Deserialize_should_not_throw_when_all_required_elements_present( - [Values(0, 1, 8, 23, 63, 111, 127, 128, 129, 555, 1024, 2500)]int membersCount) + [Values(0, 1, 8, 23, 63, 111, 127, 128, 129, 555, 1024, 2500)] int membersCount) { var subject = BuildTypeAndGetSerializer("Prop", membersCount); var properties = Enumerable @@ -209,7 +209,7 @@ public void FastMemberMapHelper_GetMembersBitArrayLength_should_return_correctVa public void FastMemberMapHelper_GetMembersBitArray_with_span_should_use_the_provided_span() { var backingArray = new uint[] { 1, 2, 3 }; - using var bitArray = BsonClassMapSerializer.FastMemberMapHelper.GetMembersBitArray(backingArray); + using var bitArray = BsonClassMapSerializer.FastMemberMapHelper.GetMembersBitArray(backingArray); bitArray.Span.ToArray().ShouldBeEquivalentTo(new uint[] { 0, 0, 0 }); bitArray.ArrayPool.Should().Be(null); diff --git a/tests/MongoDB.Bson.Tests/Serialization/Conventions/ObjectSerializerAllowedTypesConventionTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Conventions/ObjectSerializerAllowedTypesConventionTests.cs index bdfd4901513..740b881adca 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Conventions/ObjectSerializerAllowedTypesConventionTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Conventions/ObjectSerializerAllowedTypesConventionTests.cs @@ -484,7 +484,7 @@ public void Convention_should_be_applied_during_automapping() var conventionName = Guid.NewGuid().ToString(); var subject = new ObjectSerializerAllowedTypesConvention(Assembly.GetExecutingAssembly()); - ConventionRegistry.Register(conventionName, new ConventionPack {subject}, t => t == typeof(TestClass)); + ConventionRegistry.Register(conventionName, new ConventionPack { subject }, t => t == typeof(TestClass)); var classMap = new BsonClassMap(cm => cm.AutoMap()); var memberMap = classMap.GetMemberMap("ObjectProp"); @@ -531,4 +531,4 @@ private static BsonMemberMap CreateMemberMap(Expression(TCollection collection private static (T[], byte[] VectorBson) GetTestData(BinaryVectorDataType dataType, int elementsCount, byte bitsPadding) where T : struct { - var elementsSpan = new ReadOnlySpan( - Enumerable.Range(0, elementsCount) - .Select(i => Convert.ChangeType(i, typeof(T)).As()) - .ToArray()); - var elementsBytesLittleEndian = BitConverter.IsLittleEndian - ? MemoryMarshal.Cast(elementsSpan) - : BigEndianToLittleEndian(elementsSpan, dataType); - - byte[] vectorBsonData = [(byte)dataType, bitsPadding, .. elementsBytesLittleEndian]; - return (elementsSpan.ToArray(), vectorBsonData); + var elementsSpan = new ReadOnlySpan( + Enumerable.Range(0, elementsCount) + .Select(i => Convert.ChangeType(i, typeof(T)).As()) + .ToArray()); + var elementsBytesLittleEndian = BitConverter.IsLittleEndian + ? MemoryMarshal.Cast(elementsSpan) + : BigEndianToLittleEndian(elementsSpan, dataType); + + byte[] vectorBsonData = [(byte)dataType, bitsPadding, .. elementsBytesLittleEndian]; + return (elementsSpan.ToArray(), vectorBsonData); } private static (BinaryVector, byte[] VectorBson) GetTestDataBinaryVector(BinaryVectorDataType dataType, int elementsCount, byte bitsPadding) diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/Decimal128SerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/Decimal128SerializerTests.cs index 77aeee36005..88d1e8ccd04 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/Decimal128SerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/Decimal128SerializerTests.cs @@ -132,8 +132,8 @@ public void GetHashCode_should_return_zero() public static IEnumerable SerializeSpecialValuesData() { return from bsonType in new[] { BsonType.Int64, BsonType.Int32 } - from val in new [] { Decimal128.PositiveInfinity, Decimal128.NegativeInfinity, Decimal128.QNaN } - select new object[] { bsonType, val }; + from val in new[] { Decimal128.PositiveInfinity, Decimal128.NegativeInfinity, Decimal128.QNaN } + select new object[] { bsonType, val }; } [Theory] diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/DiscriminatorTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/DiscriminatorTests.cs index 30196beed1d..427ec5891ef 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/DiscriminatorTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/DiscriminatorTests.cs @@ -113,7 +113,7 @@ public void TestDeserializeGenericTypeWithTwoTypes() { var serialized = """{ "_t" : "DerivedDocumentDouble", "_id" : 1, "Value1" : 42, "Value2" : "hello" }"""; var rehydrated = BsonSerializer.Deserialize(serialized); - rehydrated.Should().BeOfType>(); + rehydrated.Should().BeOfType>(); } [Fact] @@ -135,7 +135,7 @@ public void TestSerializeGenericTypeWithNestedType() [Fact] public void TestSerializeGenericTypeWithTwoTypes() { - var document = new DerivedDocumentDouble { Id = 1, Value1 = 42, Value2 = "hello"}; + var document = new DerivedDocumentDouble { Id = 1, Value1 = 42, Value2 = "hello" }; var serialized = document.ToJson(typeof(BaseDocument)); serialized.Should().Be("""{ "_t" : "DerivedDocumentDouble", "_id" : 1, "Value1" : 42, "Value2" : "hello" }"""); } diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ElementAppendingSerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ElementAppendingSerializerTests.cs index ecba396bc35..e7f8360e903 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ElementAppendingSerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ElementAppendingSerializerTests.cs @@ -31,7 +31,7 @@ namespace MongoDB.Bson.Tests.Serialization.Serializers { public class ElementAppendingSerializerTests { - public class C { public int X { get; set; } } + public class C { public int X { get; set; } } public class CSerializer1 : SerializerBase { } public class CSerializer2 : SerializerBase { } diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ExpandoObjectSerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ExpandoObjectSerializerTests.cs index c29ed5c03de..ab839030c92 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ExpandoObjectSerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ExpandoObjectSerializerTests.cs @@ -54,7 +54,7 @@ public void TestRoundTrip() [Fact] public void TestNestedExpandoRoundTrip() { - var document = new NestedExpando {Id = ObjectId.GenerateNewId(), ExtraData = new ExpandoObject()}; + var document = new NestedExpando { Id = ObjectId.GenerateNewId(), ExtraData = new ExpandoObject() }; var json = document.ToJson(writerSettings: new JsonWriterSettings { OutputMode = JsonOutputMode.Shell }); var expected = $"{{ \"_id\" : ObjectId(\"{document.Id}\"), \"ExtraData\" : {{ }} }}"; @@ -68,7 +68,7 @@ public void TestNestedExpandoRoundTrip() [Fact] public void TestNullNestedExpandoRoundTrip() { - var document = new NestedExpando {Id = ObjectId.GenerateNewId(), ExtraData = null}; + var document = new NestedExpando { Id = ObjectId.GenerateNewId(), ExtraData = null }; var json = document.ToJson(writerSettings: new JsonWriterSettings { OutputMode = JsonOutputMode.Shell }); var expected = $"{{ \"_id\" : ObjectId(\"{document.Id}\"), \"ExtraData\" : null }}"; diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableArraySerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableArraySerializerTests.cs index 4ce41fdb130..c8d59c60881 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableArraySerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableArraySerializerTests.cs @@ -115,4 +115,4 @@ public void Serializer_should_be_registered() } } } -#endif \ No newline at end of file +#endif diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableDictionarySerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableDictionarySerializerTests.cs index 90a38f3a00a..fc9be28d5ec 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableDictionarySerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableDictionarySerializerTests.cs @@ -142,4 +142,4 @@ public void Serializer_should_be_registered() } } } -#endif \ No newline at end of file +#endif diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableHashSetSerializerTest.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableHashSetSerializerTest.cs index ea256c57b74..a34ffadfa73 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableHashSetSerializerTest.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableHashSetSerializerTest.cs @@ -115,4 +115,4 @@ public void Serializer_should_be_registered() } } } -#endif \ No newline at end of file +#endif diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableListSerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableListSerializerTests.cs index 44a7b6dd04a..5828fdca9df 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableListSerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableListSerializerTests.cs @@ -115,4 +115,4 @@ public void Serializer_should_be_registered() } } } -#endif \ No newline at end of file +#endif diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableQueueSerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableQueueSerializerTests.cs index 2cea3a3df2d..a5be6c04386 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableQueueSerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableQueueSerializerTests.cs @@ -115,4 +115,4 @@ public void Serializer_should_be_registered() } } } -#endif \ No newline at end of file +#endif diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableSortedDictionarySerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableSortedDictionarySerializerTests.cs index a51757b04f2..6b85d17527f 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableSortedDictionarySerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableSortedDictionarySerializerTests.cs @@ -127,4 +127,4 @@ public void Serializer_should_be_registered() } } } -#endif \ No newline at end of file +#endif diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableSortedSetSerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableSortedSetSerializerTests.cs index 8cf2bf5dea7..121810432f7 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableSortedSetSerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableSortedSetSerializerTests.cs @@ -115,4 +115,4 @@ public void Serializer_should_be_registered() } } } -#endif \ No newline at end of file +#endif diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableStackSerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableStackSerializerTests.cs index 953d9328119..be241792a04 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableStackSerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/ImmutableStackSerializerTests.cs @@ -115,4 +115,4 @@ public void Serializer_should_be_registered() } } } -#endif \ No newline at end of file +#endif diff --git a/tests/MongoDB.Bson.Tests/Serialization/Serializers/SerializeAsNominalTypeSerializerTests.cs b/tests/MongoDB.Bson.Tests/Serialization/Serializers/SerializeAsNominalTypeSerializerTests.cs index 2a65399db7a..5316f74d31c 100644 --- a/tests/MongoDB.Bson.Tests/Serialization/Serializers/SerializeAsNominalTypeSerializerTests.cs +++ b/tests/MongoDB.Bson.Tests/Serialization/Serializers/SerializeAsNominalTypeSerializerTests.cs @@ -87,7 +87,7 @@ public void GetHashCode_should_return_zero() public class C { } - public class D : C { } + public class D : C { } public class CSerializer1 : SerializerBase { } diff --git a/tests/MongoDB.Driver.Encryption.Tests/SigningRSAESPKCSCallbackTests.cs b/tests/MongoDB.Driver.Encryption.Tests/SigningRSAESPKCSCallbackTests.cs index ba180426d84..66ae9126612 100644 --- a/tests/MongoDB.Driver.Encryption.Tests/SigningRSAESPKCSCallbackTests.cs +++ b/tests/MongoDB.Driver.Encryption.Tests/SigningRSAESPKCSCallbackTests.cs @@ -23,7 +23,7 @@ namespace MongoDB.Driver.Encryption.Tests { public class SigningRSAESPKCSCallbackTests { - private static string DataToSign = "data to sign"; + private static string DataToSign = "data to sign"; public static readonly string PrivateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4JOyv5z05cL18ztpknRC7CFY2gYol4DAKerdVUoDJ" + "xCTmFMf39dVUEqD0WDiw/qcRtSO1/FRut08PlSPmvbyKetsLoxlpS8lukSzEFpFK7+L+R4miFOl6HvECyg7lbC1H/WGAhIz9yZRlXhRo9qmO/fB6PV9IeYtU+1xY" diff --git a/tests/MongoDB.Driver.TestHelpers/Core/CoreTestConfiguration.cs b/tests/MongoDB.Driver.TestHelpers/Core/CoreTestConfiguration.cs index e6aae35fb8a..3257091991e 100644 --- a/tests/MongoDB.Driver.TestHelpers/Core/CoreTestConfiguration.cs +++ b/tests/MongoDB.Driver.TestHelpers/Core/CoreTestConfiguration.cs @@ -135,7 +135,7 @@ public static ClusterBuilder ConfigureCluster(ClusterBuilder builder) } return s; - });; + }); ; if (__connectionString.Value.Tls.HasValue && __connectionString.Value.Tls.Value && diff --git a/tests/MongoDB.Driver.TestHelpers/Core/EventCapturer.cs b/tests/MongoDB.Driver.TestHelpers/Core/EventCapturer.cs index 1e06e18f486..646e8af2cae 100644 --- a/tests/MongoDB.Driver.TestHelpers/Core/EventCapturer.cs +++ b/tests/MongoDB.Driver.TestHelpers/Core/EventCapturer.cs @@ -149,7 +149,7 @@ public void WaitForOrThrowIfTimeout(Func, bool> condition, T var index = Task.WaitAny(notifyTask, Task.Delay(timeout)); if (index != 0) { - throw new Exception(message != null ? message(timeout) : $"Waiting for the expected event exceeded the timeout {timeout}.") ; + throw new Exception(message != null ? message(timeout) : $"Waiting for the expected event exceeded the timeout {timeout}."); } } diff --git a/tests/MongoDB.Driver.TestHelpers/Core/JsonDrivenTests/CommandStartedEventAsserter.cs b/tests/MongoDB.Driver.TestHelpers/Core/JsonDrivenTests/CommandStartedEventAsserter.cs index 77c1109a121..4db40dbe90b 100644 --- a/tests/MongoDB.Driver.TestHelpers/Core/JsonDrivenTests/CommandStartedEventAsserter.cs +++ b/tests/MongoDB.Driver.TestHelpers/Core/JsonDrivenTests/CommandStartedEventAsserter.cs @@ -181,7 +181,7 @@ private void AssertCommandAspect(BsonDocument actualCommand, string name, BsonVa switch (expectedItem.Name) { case "escCollection": - case "ecocCollection" : + case "ecocCollection": case "eccCollection": { var collectionValue = expectedValue[expectedItem.Name]; diff --git a/tests/MongoDB.Driver.TestHelpers/Core/Logging/LogEntry.cs b/tests/MongoDB.Driver.TestHelpers/Core/Logging/LogEntry.cs index 6ad2390a778..393fda724a9 100644 --- a/tests/MongoDB.Driver.TestHelpers/Core/Logging/LogEntry.cs +++ b/tests/MongoDB.Driver.TestHelpers/Core/Logging/LogEntry.cs @@ -25,7 +25,7 @@ public sealed class LogEntry { private readonly Lazy _formatedMessage; - public DateTime Timestamp { get; } + public DateTime Timestamp { get; } public LogLevel LogLevel { get; } public string Category { get; } public int ClusterId { get; } diff --git a/tests/MongoDB.Driver.TestHelpers/Core/SpanCapturer.cs b/tests/MongoDB.Driver.TestHelpers/Core/SpanCapturer.cs index 7a32fbed5e1..7bbeb4ef083 100644 --- a/tests/MongoDB.Driver.TestHelpers/Core/SpanCapturer.cs +++ b/tests/MongoDB.Driver.TestHelpers/Core/SpanCapturer.cs @@ -44,7 +44,7 @@ public class SpanCapturer : IDisposable static SpanCapturer() { - Activity.DefaultIdFormat = ActivityIdFormat.W3C; + Activity.DefaultIdFormat = ActivityIdFormat.W3C; } public SpanCapturer() diff --git a/tests/MongoDB.Driver.TestHelpers/MongoDatabaseFixture.cs b/tests/MongoDB.Driver.TestHelpers/MongoDatabaseFixture.cs index 938e4d48913..4f15496fc75 100644 --- a/tests/MongoDB.Driver.TestHelpers/MongoDatabaseFixture.cs +++ b/tests/MongoDB.Driver.TestHelpers/MongoDatabaseFixture.cs @@ -82,9 +82,9 @@ internal void BeforeTestCase() } protected virtual void InitializeFixture() - {} + { } protected virtual void InitializeTestCase() - {} + { } } } diff --git a/tests/MongoDB.Driver.TestHelpers/X509CertificateLoader.cs b/tests/MongoDB.Driver.TestHelpers/X509CertificateLoader.cs index d07e5190659..4d0bc09f496 100644 --- a/tests/MongoDB.Driver.TestHelpers/X509CertificateLoader.cs +++ b/tests/MongoDB.Driver.TestHelpers/X509CertificateLoader.cs @@ -26,7 +26,7 @@ public static X509Certificate2 LoadCertificate(ReadOnlySpan certificateDat new(certificateData.ToArray()); public static X509Certificate2 LoadCertificateFromFile(string certificateFilename) => - new (certificateFilename); + new(certificateFilename); public static X509Certificate2 LoadPkcs12FromFile(string certificateFilename, string password) => new(certificateFilename, password); diff --git a/tests/MongoDB.Driver.Tests/AggregateGeoNearTests.cs b/tests/MongoDB.Driver.Tests/AggregateGeoNearTests.cs index 0b80fb3af78..26ef76ba527 100644 --- a/tests/MongoDB.Driver.Tests/AggregateGeoNearTests.cs +++ b/tests/MongoDB.Driver.Tests/AggregateGeoNearTests.cs @@ -177,4 +177,4 @@ protected override void InitializeFixture() } } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/AggregateRankFusionTests.cs b/tests/MongoDB.Driver.Tests/AggregateRankFusionTests.cs index 9c27686de51..e5534b35672 100644 --- a/tests/MongoDB.Driver.Tests/AggregateRankFusionTests.cs +++ b/tests/MongoDB.Driver.Tests/AggregateRankFusionTests.cs @@ -25,7 +25,7 @@ namespace MongoDB.Driver.Tests public class AggregateRankFusionTests : IntegrationTest { public AggregateRankFusionTests(ClassFixture fixture) - : base(fixture, server => server.Supports(Feature.RankFusionStage)) + : base(fixture, server => server.Supports(Feature.RankFusionStage)) { } @@ -140,7 +140,7 @@ public void RankFusion_with_score_details_should_return_expected_result() }; var result = collection.Aggregate() - .RankFusion(pipelines, new RankFusionOptions { ScoreDetails = true}) + .RankFusion(pipelines, new RankFusionOptions { ScoreDetails = true }) .Limit(1) .As() .Project(Builders.Projection @@ -187,4 +187,4 @@ protected override void InitializeFixture() } } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Authentication/AuthenticatorFactoryTests.cs b/tests/MongoDB.Driver.Tests/Authentication/AuthenticatorFactoryTests.cs index 1ab49cddd5c..8bfdf394ab4 100644 --- a/tests/MongoDB.Driver.Tests/Authentication/AuthenticatorFactoryTests.cs +++ b/tests/MongoDB.Driver.Tests/Authentication/AuthenticatorFactoryTests.cs @@ -41,7 +41,8 @@ public void Create_should_call_provided_delegate() callback.Verify(x => x(), Times.Once); } - [Fact] public void Multiple_Create_calls_should_call_provided_callback_multiple_times() + [Fact] + public void Multiple_Create_calls_should_call_provided_callback_multiple_times() { var callback = new Mock>(); var subject = new AuthenticatorFactory(callback.Object); diff --git a/tests/MongoDB.Driver.Tests/Authentication/MongoAWSAuthenticatorTests.cs b/tests/MongoDB.Driver.Tests/Authentication/MongoAWSAuthenticatorTests.cs index 6b297d2a19b..8fec48d2c33 100644 --- a/tests/MongoDB.Driver.Tests/Authentication/MongoAWSAuthenticatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Authentication/MongoAWSAuthenticatorTests.cs @@ -260,7 +260,7 @@ public async Task Authenticate_with_loadBalancedConnection_should_use_command_wi var subject = CreateAwsSaslAuthenticator(null, mockRandomByteGenerator.Object, mockClock.Object, null); - var connection = new MockConnection(__serverId, new ConnectionSettings(loadBalanced:true), null); + var connection = new MockConnection(__serverId, new ConnectionSettings(loadBalanced: true), null); var saslStartResponse = MessageHelper.BuildCommandResponse(RawBsonDocumentHelper.FromJson(saslStartCommandResponseString)); var saslContinueResponse = MessageHelper.BuildCommandResponse(RawBsonDocumentHelper.FromJson(saslContinueCommandResponseString)); connection.EnqueueCommandResponseMessage(saslStartResponse); @@ -302,7 +302,7 @@ public async Task Authenticate_should_throw_an_AuthenticationException_when_auth using var operationContext = new OperationContext(NoCoreSession.NewHandle()); var exception = async ? await Record.ExceptionAsync(() => subject.AuthenticateAsync(operationContext, connection, __descriptionCommandWireProtocol)) : - Record.Exception(() => subject.Authenticate(operationContext, connection, __descriptionCommandWireProtocol)) ; + Record.Exception(() => subject.Authenticate(operationContext, connection, __descriptionCommandWireProtocol)); exception.Should().BeOfType(); } @@ -340,7 +340,7 @@ public async Task Authenticate_should_throw_when_server_provides_invalid_host( using var operationContext = new OperationContext(NoCoreSession.NewHandle()); var exception = async ? await Record.ExceptionAsync(() => subject.AuthenticateAsync(operationContext, connection, __descriptionCommandWireProtocol)) : - Record.Exception(() => subject.Authenticate(operationContext, connection, __descriptionCommandWireProtocol)) ; + Record.Exception(() => subject.Authenticate(operationContext, connection, __descriptionCommandWireProtocol)); exception.Should().BeOfType(); exception.Message.Should().Be("Server returned an invalid sts host."); @@ -376,7 +376,7 @@ public async Task Authenticate_should_throw_when_server_provides_invalid_nonce( using var operationContext = new OperationContext(NoCoreSession.NewHandle()); var exception = async ? await Record.ExceptionAsync(() => subject.AuthenticateAsync(operationContext, connection, __descriptionCommandWireProtocol)) : - Record.Exception(() => subject.Authenticate(operationContext, connection, __descriptionCommandWireProtocol)) ; + Record.Exception(() => subject.Authenticate(operationContext, connection, __descriptionCommandWireProtocol)); exception.Should().BeOfType(); exception.Message.Should().Be("Server sent an invalid nonce."); @@ -416,7 +416,7 @@ public async Task Authenticate_should_throw_when_server_provides_unexpected_fiel using var operationContext = new OperationContext(NoCoreSession.NewHandle()); var exception = async ? await Record.ExceptionAsync(() => subject.AuthenticateAsync(operationContext, connection, __descriptionCommandWireProtocol)) : - Record.Exception(() => subject.Authenticate(operationContext, connection, __descriptionCommandWireProtocol)) ; + Record.Exception(() => subject.Authenticate(operationContext, connection, __descriptionCommandWireProtocol)); exception.Should().BeOfType(); exception.Message.Should().Be("Server returned unexpected fields: u."); @@ -511,7 +511,7 @@ private static IAuthenticator CreateAwsSaslAuthenticator( var saslContext = new SaslContext { EndPoint = __serverId.EndPoint, - ClusterEndPoints = [ __serverId.EndPoint ], + ClusterEndPoints = [__serverId.EndPoint], Identity = new MongoExternalIdentity(TestUserName), IdentityEvidence = new PasswordEvidence(TestUserPassword), Mechanism = "MONGODB-AWS", diff --git a/tests/MongoDB.Driver.Tests/Authentication/Oidc/FileOidcCallbackTests.cs b/tests/MongoDB.Driver.Tests/Authentication/Oidc/FileOidcCallbackTests.cs index 0b884640f71..9d637baa7d5 100644 --- a/tests/MongoDB.Driver.Tests/Authentication/Oidc/FileOidcCallbackTests.cs +++ b/tests/MongoDB.Driver.Tests/Authentication/Oidc/FileOidcCallbackTests.cs @@ -46,7 +46,7 @@ public void FileOidcCallback_ctor_throws_on_empty_filePath(string filePath) [Theory] [ParameterAttributeData] - public async Task GetOidcAccessToken_calls_fileSystemProvider([Values(true, false)]bool async) + public async Task GetOidcAccessToken_calls_fileSystemProvider([Values(true, false)] bool async) { var filePath = "some-file-path"; var fileContent = "some-content"; @@ -59,7 +59,7 @@ public async Task GetOidcAccessToken_calls_fileSystemProvider([Values(true, fals var oidcCallback = new FileOidcCallback(fileSystemProviderMock.Object, filePath); var result = async ? - await oidcCallback.GetOidcAccessTokenAsync(oidcParameters, default): + await oidcCallback.GetOidcAccessTokenAsync(oidcParameters, default) : oidcCallback.GetOidcAccessToken(oidcParameters, default); result.AccessToken.Should().Be(fileContent); diff --git a/tests/MongoDB.Driver.Tests/Authentication/PlainAuthenticatorTests.cs b/tests/MongoDB.Driver.Tests/Authentication/PlainAuthenticatorTests.cs index 20e5944641e..70e6d427561 100644 --- a/tests/MongoDB.Driver.Tests/Authentication/PlainAuthenticatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Authentication/PlainAuthenticatorTests.cs @@ -143,7 +143,7 @@ public async Task Authenticate_with_loadBalancedConnection_should_use_command_wi { var subject = CreatePlainSaslAuthenticator(null); - var connection = new MockConnection(__serverId, new ConnectionSettings(loadBalanced:true), null); + var connection = new MockConnection(__serverId, new ConnectionSettings(loadBalanced: true), null); var saslStartResponse = MessageHelper.BuildCommandResponse(RawBsonDocumentHelper.FromJson("{ conversationId : 0, payload : BinData(0,\"\"), done : true, ok : 1 }")); connection.EnqueueCommandResponseMessage(saslStartResponse); connection.Description = null; @@ -172,7 +172,7 @@ private static IAuthenticator CreatePlainSaslAuthenticator(ServerApi serverApi) var saslContext = new SaslContext { EndPoint = __serverId.EndPoint, - ClusterEndPoints = [ __serverId.EndPoint ], + ClusterEndPoints = [__serverId.EndPoint], Identity = new MongoExternalIdentity(TestUserSource, TestUserName), IdentityEvidence = new PasswordEvidence(TestUserPassword), Mechanism = "PLAIN", diff --git a/tests/MongoDB.Driver.Tests/Authentication/SaslPrepHelperTests.cs b/tests/MongoDB.Driver.Tests/Authentication/SaslPrepHelperTests.cs index c35b95e153c..91d5519b0ca 100644 --- a/tests/MongoDB.Driver.Tests/Authentication/SaslPrepHelperTests.cs +++ b/tests/MongoDB.Driver.Tests/Authentication/SaslPrepHelperTests.cs @@ -91,7 +91,7 @@ public void SaslPrepStored_returns_expected_output_when_passed_Rfc4013_examples( [InlineData("First character is RandALCat, but last character is not", "\u0627\u0031")] public void SaslPrep_throws_argument_exception_when_passed_Rfc4013_examples(string expectedError, string input) { - var exception = Record.Exception(()=>SaslPrepHelper.SaslPrepStored(input)); + var exception = Record.Exception(() => SaslPrepHelper.SaslPrepStored(input)); exception.Should().BeOfType().Subject.Message.Should().Be(expectedError); } @@ -110,7 +110,7 @@ public void SaslPrepStored_throws_exception_when_passed_an_undefined_codepoint() { var strWithUnassignedCodepoint = $"abc{char.ConvertFromUtf32(_unassignedCodePoint.Value)}"; - var exception = Record.Exception(()=>SaslPrepHelper.SaslPrepStored(strWithUnassignedCodepoint)); + var exception = Record.Exception(() => SaslPrepHelper.SaslPrepStored(strWithUnassignedCodepoint)); exception.Should().BeOfType(); exception.Message.Should().Be("Character at position 3 is unassigned"); @@ -125,7 +125,8 @@ private static int FindUnassignedCodePoint() if (!SaslPrepHelperReflector.IsDefined(i) && !SaslPrepHelperReflector.Prohibited(i)) { return i; - }; + } + ; } throw new Exception("Unable to find unassigned codepoint."); } diff --git a/tests/MongoDB.Driver.Tests/Authentication/ScramSha1AuthenticatorTests.cs b/tests/MongoDB.Driver.Tests/Authentication/ScramSha1AuthenticatorTests.cs index 16b052afb8f..61572f93c25 100644 --- a/tests/MongoDB.Driver.Tests/Authentication/ScramSha1AuthenticatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Authentication/ScramSha1AuthenticatorTests.cs @@ -331,7 +331,7 @@ private static SaslAuthenticator CreateScramSha1SaslAuthenticator(string clientN var saslContext = new SaslContext { EndPoint = __serverId.EndPoint, - ClusterEndPoints = [ __serverId.EndPoint ], + ClusterEndPoints = [__serverId.EndPoint], Identity = new MongoExternalIdentity(TestUserSource, TestUserName), IdentityEvidence = new PasswordEvidence(TestUserPassword), Mechanism = "SCRAM-SHA-1", diff --git a/tests/MongoDB.Driver.Tests/Authentication/ScramSha256AuthenticatorTests.cs b/tests/MongoDB.Driver.Tests/Authentication/ScramSha256AuthenticatorTests.cs index 3584907c462..0e5ee99a9d4 100644 --- a/tests/MongoDB.Driver.Tests/Authentication/ScramSha256AuthenticatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Authentication/ScramSha256AuthenticatorTests.cs @@ -168,7 +168,7 @@ public async Task Authenticate_with_loadBalancedConnection_should_use_command_wi var sentMessages = connection.GetSentMessages(); sentMessages.Count.Should().Be(2); - var expectedEndString = ", $readPreference : { mode : 'primaryPreferred' }"; + var expectedEndString = ", $readPreference : { mode : 'primaryPreferred' }"; MessageHelper.ToCommandPayload(sentMessages[0]).Should().Be($"{{ saslStart : 1, mechanism : 'SCRAM-SHA-256', payload : new BinData(0, '{ToUtf8Base64(__clientRequest1)}'), options : {{ skipEmptyExchange : true }}, $db : 'source'{expectedEndString} }}"); MessageHelper.ToCommandPayload(sentMessages[1]).Should().Be($"{{ saslContinue : 1, conversationId : 1, payload : new BinData(0, '{ToUtf8Base64(__clientRequest2)}'), $db : 'source'{expectedEndString} }}"); } @@ -328,7 +328,7 @@ public async Task Authenticate_should_not_throw_when_authentication_succeeds( expectedMessages.Add(saslStartMessage); } - var saslContinueMessage = BsonDocument.Parse($"{{ saslContinue : 1, conversationId : 1, payload : new BinData(0, '{ ToUtf8Base64(__clientRequest2)}'), '$db' : 'source' }}"); + var saslContinueMessage = BsonDocument.Parse($"{{ saslContinue : 1, conversationId : 1, payload : new BinData(0, '{ToUtf8Base64(__clientRequest2)}'), '$db' : 'source' }}"); expectedMessages.Add(saslContinueMessage); if (useLongAuthentication) @@ -399,7 +399,7 @@ public Task Authenticate_should_work_regardless_of_culture( [Values("da-DK", "en-US")] string name, [Values(false, true)] bool async) { - return SetCultureAndResetAfterTest(name, async Task() => + return SetCultureAndResetAfterTest(name, async Task () => { // ScramSha1Authenticator will have exactly the same code paths var subject = CreateScramSha256SaslAuthenticator("a", serverApi: null); @@ -451,7 +451,7 @@ private static SaslAuthenticator CreateScramSha256SaslAuthenticator(string clien var saslContext = new SaslContext { EndPoint = __serverId.EndPoint, - ClusterEndPoints = [ __serverId.EndPoint ], + ClusterEndPoints = [__serverId.EndPoint], Identity = new MongoExternalIdentity(TestUserSource, TestUserName), IdentityEvidence = new PasswordEvidence(TestUserPassword), Mechanism = "SCRAM-SHA-256", diff --git a/tests/MongoDB.Driver.Tests/ClientBulkWriteComplexIdTests.cs b/tests/MongoDB.Driver.Tests/ClientBulkWriteComplexIdTests.cs index 3a14460e18e..eb2ec723ddb 100644 --- a/tests/MongoDB.Driver.Tests/ClientBulkWriteComplexIdTests.cs +++ b/tests/MongoDB.Driver.Tests/ClientBulkWriteComplexIdTests.cs @@ -98,7 +98,7 @@ public class ClassFixture : MongoCollectionFixture { public ClassFixture() { - BsonSerializer.RegisterSerializer( new DocumentIdSerializer()); + BsonSerializer.RegisterSerializer(new DocumentIdSerializer()); } protected override IEnumerable InitialData => null; diff --git a/tests/MongoDB.Driver.Tests/ClientSessionExtensionsTests.cs b/tests/MongoDB.Driver.Tests/ClientSessionExtensionsTests.cs index 0900d52078d..4224d34c3c6 100644 --- a/tests/MongoDB.Driver.Tests/ClientSessionExtensionsTests.cs +++ b/tests/MongoDB.Driver.Tests/ClientSessionExtensionsTests.cs @@ -44,7 +44,7 @@ public void GetSnapshotTime_on_snapshot_session_returns_expected_value() var coreSessionMock = new Mock(); coreSessionMock.SetupGet(s => s.IsSnapshot).Returns(true); coreSessionMock.SetupGet(s => s.SnapshotTime).Returns(snapshotTime); - + var session = new ClientSessionHandle( Mock.Of(), new ClientSessionOptions(), @@ -60,7 +60,7 @@ public void GetSnapshotTime_on_non_snapshot_session_throws_InvalidOperationExcep { var coreSessionMock = new Mock(); coreSessionMock.SetupGet(s => s.IsSnapshot).Returns(false); - + var session = new ClientSessionHandle( Mock.Of(), new ClientSessionOptions(), diff --git a/tests/MongoDB.Driver.Tests/Core/Bindings/CoreSessionTests.cs b/tests/MongoDB.Driver.Tests/Core/Bindings/CoreSessionTests.cs index 2deed6056c0..03c33383b39 100644 --- a/tests/MongoDB.Driver.Tests/Core/Bindings/CoreSessionTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Bindings/CoreSessionTests.cs @@ -387,7 +387,7 @@ private IClusterInternal CreateMockReplicaSetCluster() var serverId = new ServerId(clusterId, endPoint); var maxWireVersion = WireVersion.SupportedWireVersionRange.Min; var servers = new[] { new ServerDescription(serverId, endPoint, state: ServerState.Connected, type: ServerType.ReplicaSetPrimary, version: WireVersion.ToServerVersion(maxWireVersion), wireVersionRange: new Range(0, maxWireVersion)) }; - var clusterDescription = new ClusterDescription(clusterId, false, null, ClusterType.ReplicaSet, servers); + var clusterDescription = new ClusterDescription(clusterId, false, null, ClusterType.ReplicaSet, servers); var mockCluster = new Mock(); mockCluster.SetupGet(m => m.Description).Returns(clusterDescription); return mockCluster.Object; diff --git a/tests/MongoDB.Driver.Tests/Core/Clusters/ClusterDescriptionTests.cs b/tests/MongoDB.Driver.Tests/Core/Clusters/ClusterDescriptionTests.cs index 0f044b5836e..b72b0e3a6ef 100644 --- a/tests/MongoDB.Driver.Tests/Core/Clusters/ClusterDescriptionTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Clusters/ClusterDescriptionTests.cs @@ -297,7 +297,7 @@ public void State_should_be_connected_if_any_server_is_connected() [Fact] public void ToString_should_return_string_representation() { - var subject = new ClusterDescription(new ClusterId(1), directConnection: false, null, ClusterType.Standalone, [ __serverDescription1 ]); + var subject = new ClusterDescription(new ClusterId(1), directConnection: false, null, ClusterType.Standalone, [__serverDescription1]); var expected = string.Format("{{ ClusterId : \"1\", Type : \"Standalone\", State : \"Disconnected\", Servers : [{0}] }}", __serverDescription1.ToString()); subject.ToString().Should().Be(expected); @@ -307,7 +307,7 @@ public void ToString_should_return_string_representation() [ParameterAttributeData] public void ToString_with_directConnection_should_return_string_representation([Values(true, false)] bool directConnection) { - var subject = new ClusterDescription(new ClusterId(1), directConnection, dnsMonitorException: null, ClusterType.Standalone, [__serverDescription1 ]); + var subject = new ClusterDescription(new ClusterId(1), directConnection, dnsMonitorException: null, ClusterType.Standalone, [__serverDescription1]); var directConnectionString = directConnection ? $", DirectConnection : \"true\"" : string.Empty; var expected = string.Format("{{ ClusterId : \"1\"{1}, Type : \"Standalone\", State : \"Disconnected\", Servers : [{0}] }}", __serverDescription1.ToString(), diff --git a/tests/MongoDB.Driver.Tests/Core/Clusters/ClusterTests.cs b/tests/MongoDB.Driver.Tests/Core/Clusters/ClusterTests.cs index cc1fa9b16e3..8fd4d3e85d9 100644 --- a/tests/MongoDB.Driver.Tests/Core/Clusters/ClusterTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Clusters/ClusterTests.cs @@ -469,7 +469,7 @@ public async Task SelectServer_should_call_custom_selector( { var selector = new DelegateServerSelector((c, s) => s); var selectedServer = async ? - await subject.SelectServerAsync(operationContext, selector): + await subject.SelectServerAsync(operationContext, selector) : subject.SelectServer(operationContext, selector); var selectedServerPort = ((DnsEndPoint)selectedServer.EndPoint).Port; diff --git a/tests/MongoDB.Driver.Tests/Core/Clusters/LoadBalancedClusterTests.cs b/tests/MongoDB.Driver.Tests/Core/Clusters/LoadBalancedClusterTests.cs index 9192da6810c..54e01ea94a0 100644 --- a/tests/MongoDB.Driver.Tests/Core/Clusters/LoadBalancedClusterTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Clusters/LoadBalancedClusterTests.cs @@ -67,7 +67,7 @@ public void Constructor_should_initialize_instance() [Theory] [ParameterAttributeData] - public void Constructor_should_handle_directConnection_correctly([Values(false, true)]bool directConnection) + public void Constructor_should_handle_directConnection_correctly([Values(false, true)] bool directConnection) { _settings = _settings.With(directConnection: directConnection); diff --git a/tests/MongoDB.Driver.Tests/Core/Configuration/ClusterSettingsTests.cs b/tests/MongoDB.Driver.Tests/Core/Configuration/ClusterSettingsTests.cs index 8d735a72103..0b7ae1c08b2 100644 --- a/tests/MongoDB.Driver.Tests/Core/Configuration/ClusterSettingsTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Configuration/ClusterSettingsTests.cs @@ -258,7 +258,7 @@ public void constructor_with_serverSelectionTimeout_should_initialize_instance() [Theory] [ParameterAttributeData] - public void Constructor_with_valid_srvMaxHosts_should_initialize_instance([Values(0,42)]int srvMaxHosts) + public void Constructor_with_valid_srvMaxHosts_should_initialize_instance([Values(0, 42)] int srvMaxHosts) { var subject = new ClusterSettings(srvMaxHosts: srvMaxHosts); @@ -472,7 +472,7 @@ public void With_serverSelectionTimeout_should_return_expected_result() [Theory] [ParameterAttributeData] - public void With_valid_srvMaxHosts_should_return_expected_result([Values(0, 42)]int srvMaxHosts) + public void With_valid_srvMaxHosts_should_return_expected_result([Values(0, 42)] int srvMaxHosts) { var subject = new ClusterSettings(srvMaxHosts: 5); diff --git a/tests/MongoDB.Driver.Tests/Core/Configuration/ConnectionStringTests.cs b/tests/MongoDB.Driver.Tests/Core/Configuration/ConnectionStringTests.cs index 1725e235332..289140353bb 100644 --- a/tests/MongoDB.Driver.Tests/Core/Configuration/ConnectionStringTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Configuration/ConnectionStringTests.cs @@ -1327,7 +1327,7 @@ public void When_proxyPassword_and_proxyUsername_are_not_specified_together(stri [Theory] [ParameterAttributeData] - public void Valid_srvMaxHosts_with_mongodbsrv_scheme_should_be_valid([Values(0, 42)]int srvMaxHosts) + public void Valid_srvMaxHosts_with_mongodbsrv_scheme_should_be_valid([Values(0, 42)] int srvMaxHosts) { var subject = new ConnectionString($"mongodb+srv://cluster0.10gen.cc/?srvMaxHosts={srvMaxHosts}"); diff --git a/tests/MongoDB.Driver.Tests/Core/Configuration/SslStreamSettingsTests.cs b/tests/MongoDB.Driver.Tests/Core/Configuration/SslStreamSettingsTests.cs index 4b9f395c25a..00d149698c6 100644 --- a/tests/MongoDB.Driver.Tests/Core/Configuration/SslStreamSettingsTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Configuration/SslStreamSettingsTests.cs @@ -64,7 +64,7 @@ public void constructor_with_checkCertificateRevocation_should_initialize_instan [Fact] public void constructor_with_clientCertificates_should_initialize_instance() { - var clientCertificates = new [] { X509CertificateLoader.LoadCertificate(__testCert) }; + var clientCertificates = new[] { X509CertificateLoader.LoadCertificate(__testCert) }; var subject = new SslStreamSettings(clientCertificates: clientCertificates); diff --git a/tests/MongoDB.Driver.Tests/Core/ConnectionPools/ExclusiveConnectionPoolTests.cs b/tests/MongoDB.Driver.Tests/Core/ConnectionPools/ExclusiveConnectionPoolTests.cs index ef0a48b715d..9db6c31d637 100644 --- a/tests/MongoDB.Driver.Tests/Core/ConnectionPools/ExclusiveConnectionPoolTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/ConnectionPools/ExclusiveConnectionPoolTests.cs @@ -1091,7 +1091,7 @@ public void Maintenance_should_call_connection_dispose_when_connection_authentic var authenticationFailedConnection = new Mock(); authenticationFailedConnection .Setup(c => c.Open(It.IsAny())) // an authentication exception is thrown from _connectionInitializer.InitializeConnection - // that in turn is called from OpenAsync + // that in turn is called from OpenAsync .Throws(authenticationException); authenticationFailedConnection.SetupGet(c => c.ConnectionId).Returns(connectionId); @@ -1228,7 +1228,8 @@ public void MaxConnecting_queue_should_be_cleared_on_pool_clear( // unblock after all in maxConnecting queue failed allInQueueFailed.Wait(); blockEstablishmentEvent.Set(); - }; + } + ; }); exceptions.Length.ShouldBeEquivalentTo(blockedInMaxConnecting); @@ -1559,7 +1560,8 @@ public void WaitQueue_should_be_cleared_on_pool_clear( SpinWait.SpinUntil(() => subject._waitQueueFreeSlots() >= blockedInQueueCount); blockEstablishmentEvent.Set(); - }; + } + ; }); exceptions.Length.ShouldBeEquivalentTo(blockedInQueueCount); diff --git a/tests/MongoDB.Driver.Tests/Core/ConnectionPools/MaintenanceHelperTests.cs b/tests/MongoDB.Driver.Tests/Core/ConnectionPools/MaintenanceHelperTests.cs index 2ed6884f400..59c06d13e3a 100644 --- a/tests/MongoDB.Driver.Tests/Core/ConnectionPools/MaintenanceHelperTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/ConnectionPools/MaintenanceHelperTests.cs @@ -79,7 +79,8 @@ public void MaintenanceHelper_should_not_leak_threads_after_stopping([RandomSeed for (int i = 0; i < attempts; i++) { StepByState(subject, random.Next(maxValue: 2)); // 0 - SetReady, 1 - Clear - }; + } + ; Thread.Sleep(random.Next(50)); StepByState(subject, state: 0); // 0 - SetReady, should be stopped by dispose } diff --git a/tests/MongoDB.Driver.Tests/Core/Connections/ClientDocumentHelperTests.cs b/tests/MongoDB.Driver.Tests/Core/Connections/ClientDocumentHelperTests.cs index 6a2c403fb58..6794d61a3b7 100644 --- a/tests/MongoDB.Driver.Tests/Core/Connections/ClientDocumentHelperTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Connections/ClientDocumentHelperTests.cs @@ -162,8 +162,8 @@ public void CreateDriverDocument_with_args_should_return_expected_result( [InlineData(false, false, "{ name : 'vercel' }")] public void CreateEnvDocument_should_return_expected_result(bool isDockerToBeDetected, bool isKubernetesToBeDetected, string expected) { - var fileSystemProviderMock = new Mock(); - var env = new List{ "VERCEL" }; + var fileSystemProviderMock = new Mock(); + var env = new List { "VERCEL" }; if (isKubernetesToBeDetected) { env.Add("KUBERNETES_SERVICE_HOST"); @@ -230,7 +230,7 @@ public void RemoveOneOptionalField_should_return_expected_result( var expectedResult = CreateClientDocument(); if (timesCalled < 5) { - var optionalFieldNames = new[] { "!env.name", "!os.type", "env.name", "platform"}; + var optionalFieldNames = new[] { "!env.name", "!os.type", "env.name", "platform" }; for (var i = 0; i < timesCalled; i++) { var dottedFieldName = optionalFieldNames[i]; diff --git a/tests/MongoDB.Driver.Tests/Core/Connections/ConnectionIdTests.cs b/tests/MongoDB.Driver.Tests/Core/Connections/ConnectionIdTests.cs index 62819b75327..860d654b00e 100644 --- a/tests/MongoDB.Driver.Tests/Core/Connections/ConnectionIdTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Connections/ConnectionIdTests.cs @@ -84,7 +84,7 @@ public void LongLocalValues_of_2_ids_should_not_be_the_same_when_automatically_c [Theory] [InlineData(0)] [InlineData(int.MaxValue)] - [InlineData((long)int.MaxValue+1)] + [InlineData((long)int.MaxValue + 1)] public void LongLocalValue_should_be_what_was_specified_in_the_constructor(long localValue) { var subject = new ConnectionId(__serverId, localValue); @@ -105,7 +105,7 @@ public void ServerValue_should_return_null_when_null() [Theory] [InlineData(0)] [InlineData(int.MaxValue)] - [InlineData((long)int.MaxValue+1)] + [InlineData((long)int.MaxValue + 1)] public void WithServerValue_should_set_the_server_value_and_leave_the_LocalValue_alone(long serverValue) { var subject = new ConnectionId(__serverId, 10) diff --git a/tests/MongoDB.Driver.Tests/Core/Connections/ConnectionInitializerTests.cs b/tests/MongoDB.Driver.Tests/Core/Connections/ConnectionInitializerTests.cs index 0dbad5ff784..5c082813011 100644 --- a/tests/MongoDB.Driver.Tests/Core/Connections/ConnectionInitializerTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Connections/ConnectionInitializerTests.cs @@ -155,7 +155,7 @@ await Record.ExceptionAsync(() => subject.SendHelloAsync(operationContext, null) [Theory] [ParameterAttributeData] public async Task InitializeConnection_should_acquire_connectionId_from_hello_response( - [Values(1, int.MaxValue, (long)int.MaxValue + 1, long.MaxValue, 1d, (double)int.MaxValue+1, (double)int.MaxValue*4)] object serverConnectionId, + [Values(1, int.MaxValue, (long)int.MaxValue + 1, long.MaxValue, 1d, (double)int.MaxValue + 1, (double)int.MaxValue * 4)] object serverConnectionId, [Values(false, true)] bool async) { var formattedServerConnectionId = $"{serverConnectionId}" + (serverConnectionId is double ? ".0" : ""); @@ -175,7 +175,7 @@ public async Task InitializeConnection_should_acquire_connectionId_from_hello_re [Theory] [ParameterAttributeData] public async Task InitializeConnection_should_acquire_connectionId_from_hello_response_without_serverApi( - [Values(1, int.MaxValue, (long)int.MaxValue + 1, long.MaxValue, 1d, (double)int.MaxValue+1, (double)int.MaxValue*4)] object serverConnectionId, + [Values(1, int.MaxValue, (long)int.MaxValue + 1, long.MaxValue, 1d, (double)int.MaxValue + 1, (double)int.MaxValue * 4)] object serverConnectionId, [Values(false, true)] bool async) { var formattedServerConnectionId = $"{serverConnectionId}" + (serverConnectionId is double ? ".0" : ""); @@ -282,7 +282,7 @@ public async Task InitializeConnection_without_serverApi_should_send_legacy_hell [ParameterAttributeData] public async Task InitializeConnection_without_serverApi_but_with_loadBalancing_should_send_hello([Values(false, true)] bool async) { - var connection = new MockConnection(__serverId, new ConnectionSettings(loadBalanced:true), null); + var connection = new MockConnection(__serverId, new ConnectionSettings(loadBalanced: true), null); var helloReply = RawBsonDocumentHelper.FromJson($"{{ ok : 1, connectionId : 1, maxWireVersion : {WireVersion.Server44}, serviceId : '{ObjectId.GenerateNewId()}' }}"); connection.EnqueueCommandResponseMessage(MessageHelper.BuildCommandResponse(helloReply)); diff --git a/tests/MongoDB.Driver.Tests/Core/Connections/HelloHelperTests.cs b/tests/MongoDB.Driver.Tests/Core/Connections/HelloHelperTests.cs index c70b3940347..db49f5fc3bb 100644 --- a/tests/MongoDB.Driver.Tests/Core/Connections/HelloHelperTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Connections/HelloHelperTests.cs @@ -30,10 +30,10 @@ public class HelloHelperTests { [Theory] [InlineData(true, false, false, "{ hello : 1, helloOk : true, backpressure: true }")] - [InlineData(false, false, false,"{ " + OppressiveLanguageConstants.LegacyHelloCommandName + " : 1, helloOk : true, backpressure: true }")] - [InlineData(false, true, false,"{ hello : 1, helloOk : true, backpressure: true }")] - [InlineData(true, true, false,"{ hello : 1, helloOk : true, backpressure: true }")] - [InlineData(false, false, true,"{ hello : 1, helloOk : true, loadBalanced : true, backpressure: true }")] + [InlineData(false, false, false, "{ " + OppressiveLanguageConstants.LegacyHelloCommandName + " : 1, helloOk : true, backpressure: true }")] + [InlineData(false, true, false, "{ hello : 1, helloOk : true, backpressure: true }")] + [InlineData(true, true, false, "{ hello : 1, helloOk : true, backpressure: true }")] + [InlineData(false, false, true, "{ hello : 1, helloOk : true, loadBalanced : true, backpressure: true }")] public void CreateCommand_should_return_correct_hello_command(bool useServerApiVersion, bool helloOk, bool loadBalanced, string expectedResult) { var serverApi = useServerApiVersion ? new ServerApi(ServerApiVersion.V1) : null; diff --git a/tests/MongoDB.Driver.Tests/Core/Connections/HelloResultTests.cs b/tests/MongoDB.Driver.Tests/Core/Connections/HelloResultTests.cs index e4eeaa1b2f4..5ad129cd8cb 100644 --- a/tests/MongoDB.Driver.Tests/Core/Connections/HelloResultTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Connections/HelloResultTests.cs @@ -35,7 +35,7 @@ public class HelloResultTests [InlineData("{ compression : ['zlib', 'snAppy'] }", new[] { CompressorType.Zlib, CompressorType.Snappy })] [InlineData("{ compression : ['noop'] }", new[] { CompressorType.Noop })] [InlineData("{ compression : ['nOop'] }", new[] { CompressorType.Noop })] - [InlineData("{ compression : ['zstd'] }", new[] { CompressorType.ZStandard})] + [InlineData("{ compression : ['zstd'] }", new[] { CompressorType.ZStandard })] [InlineData("{ compression : ['zsTd'] }", new[] { CompressorType.ZStandard })] [InlineData("{ compression : [] }", new CompressorType[0])] [InlineData("{ }", new CompressorType[0])] diff --git a/tests/MongoDB.Driver.Tests/Core/Connections/Socks5AuthenticationSettingsTests.cs b/tests/MongoDB.Driver.Tests/Core/Connections/Socks5AuthenticationSettingsTests.cs index 423f33967f8..03010dc7bf9 100644 --- a/tests/MongoDB.Driver.Tests/Core/Connections/Socks5AuthenticationSettingsTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Connections/Socks5AuthenticationSettingsTests.cs @@ -111,4 +111,4 @@ public void UsernamePasswordAuthenticationSettings_Equals_and_GetHashCode_should up1.Equals(none).Should().BeFalse(); up1.GetHashCode().Should().NotBe(none.GetHashCode()); } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Core/Connections/Socks5ProxySettingsTests.cs b/tests/MongoDB.Driver.Tests/Core/Connections/Socks5ProxySettingsTests.cs index 5ee1978839d..c7051de3f34 100644 --- a/tests/MongoDB.Driver.Tests/Core/Connections/Socks5ProxySettingsTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Connections/Socks5ProxySettingsTests.cs @@ -130,4 +130,4 @@ public void Create_should_return_expected_settings() up.Username.Should().Be("u"); up.Password.Should().Be("p"); } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Core/Connections/TcpStreamFactoryTests.cs b/tests/MongoDB.Driver.Tests/Core/Connections/TcpStreamFactoryTests.cs index a1d89524994..7ce07ef71e3 100644 --- a/tests/MongoDB.Driver.Tests/Core/Connections/TcpStreamFactoryTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Connections/TcpStreamFactoryTests.cs @@ -63,7 +63,7 @@ public void Constructor_should_throw_an_ArgumentNullException_when_tcpStreamSett [Theory] [ParameterAttributeData] - public async Task CreateStream_should_throw_a_SocketException_when_the_endpoint_could_not_be_resolved([Values(false, true)]bool async) + public async Task CreateStream_should_throw_a_SocketException_when_the_endpoint_could_not_be_resolved([Values(false, true)] bool async) { var subject = new TcpStreamFactory(); @@ -76,7 +76,7 @@ await Record.ExceptionAsync(() => subject.CreateStreamAsync(new DnsEndPoint("not [Theory] [ParameterAttributeData] - public async Task CreateStream_should_throw_when_cancellation_is_requested([Values(false, true)]bool async) + public async Task CreateStream_should_throw_when_cancellation_is_requested([Values(false, true)] bool async) { var subject = new TcpStreamFactory(); var endPoint = new IPEndPoint(new IPAddress(0x01010101), 12345); // a non-existent host and port @@ -97,7 +97,7 @@ await Record.ExceptionAsync(() => subject.CreateStreamAsync(endPoint, cancellati [Theory] [ParameterAttributeData] - public async Task CreateStream_should_throw_when_connect_timeout_has_expired([Values(false, true)]bool async) + public async Task CreateStream_should_throw_when_connect_timeout_has_expired([Values(false, true)] bool async) { var settings = new TcpStreamSettings(connectTimeout: TimeSpan.FromMilliseconds(20)); var subject = new TcpStreamFactory(settings); @@ -112,7 +112,7 @@ await Record.ExceptionAsync(() => subject.CreateStreamAsync(endPoint, Cancellati [Theory] [ParameterAttributeData] - public async Task CreateStream_should_call_the_socketConfigurator([Values(false, true)]bool async) + public async Task CreateStream_should_call_the_socketConfigurator([Values(false, true)] bool async) { RequireServer.Check(); var socketConfiguratorWasCalled = false; @@ -135,7 +135,7 @@ public async Task CreateStream_should_call_the_socketConfigurator([Values(false, [Theory] [ParameterAttributeData] - public async Task CreateStream_should_connect_to_a_running_server_and_return_a_non_null_stream([Values(false, true)]bool async) + public async Task CreateStream_should_connect_to_a_running_server_and_return_a_non_null_stream([Values(false, true)] bool async) { RequireServer.Check(); var subject = new TcpStreamFactory(); @@ -156,7 +156,7 @@ public async Task CreateStream_should_connect_to_a_running_server_and_return_a_n [Theory] [ParameterAttributeData] - public async Task SocketConfigurator_can_be_used_to_set_keepAlive([Values(false, true)]bool async) + public async Task SocketConfigurator_can_be_used_to_set_keepAlive([Values(false, true)] bool async) { RequireServer.Check(); Action socketConfigurator = s => s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); diff --git a/tests/MongoDB.Driver.Tests/Core/DeferredAsyncCursorTests.cs b/tests/MongoDB.Driver.Tests/Core/DeferredAsyncCursorTests.cs index 35df610db19..1dc2a2a83d3 100644 --- a/tests/MongoDB.Driver.Tests/Core/DeferredAsyncCursorTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/DeferredAsyncCursorTests.cs @@ -148,4 +148,4 @@ private DeferredAsyncCursor CreateSubject(Action disposeAction) _ => Mock.Of>(), _ => Task.FromResult(Mock.Of>())); } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Core/Events/TraceSourceSdamEventSubscriberTests.cs b/tests/MongoDB.Driver.Tests/Core/Events/TraceSourceSdamEventSubscriberTests.cs index fa79d3a789a..819aa4627fd 100644 --- a/tests/MongoDB.Driver.Tests/Core/Events/TraceSourceSdamEventSubscriberTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Events/TraceSourceSdamEventSubscriberTests.cs @@ -306,7 +306,7 @@ public void Handle_with_ServerHeartbeatStartedEvent_should_trace_event() const string logFileName = traceSourceName + "-log"; var @event = new ServerHeartbeatStartedEvent( new ConnectionId(new ServerId(new ClusterId(), new IPEndPoint(IPAddress.Parse("1.2.3.4"), 42))), - awaited: true); + awaited: true); var expectedLogMessage = $"{TraceSourceEventHelper.Label(@event.ConnectionId)}: sending heartbeat."; var traceSource = CreateTraceSource(logFileName, logFileName); var subject = new TraceSourceSdamEventSubscriber(traceSource); diff --git a/tests/MongoDB.Driver.Tests/Core/Misc/StreamExtensionMethodsTests.cs b/tests/MongoDB.Driver.Tests/Core/Misc/StreamExtensionMethodsTests.cs index c907a019b51..f91fc403ceb 100644 --- a/tests/MongoDB.Driver.Tests/Core/Misc/StreamExtensionMethodsTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Misc/StreamExtensionMethodsTests.cs @@ -90,7 +90,7 @@ public async Task ReadBytes_with_byte_array_should_have_expected_effect_for_part var bytes = new byte[] { 1, 2, 3 }; var n = 0; var position = 0; - int ReadPartial (byte[] buffer, int offset, int count) + int ReadPartial(byte[] buffer, int offset, int count) { var length = partition[n++]; Buffer.BlockCopy(bytes, position, buffer, offset, length); @@ -118,7 +118,7 @@ int ReadPartial (byte[] buffer, int offset, int count) [Theory] [ParameterAttributeData] - public async Task ReadBytes_with_byte_array_should_throw_when_end_of_stream_is_reached([Values(true, false)]bool async) + public async Task ReadBytes_with_byte_array_should_throw_when_end_of_stream_is_reached([Values(true, false)] bool async) { var mockStream = new Mock(); var destination = new byte[1]; @@ -136,7 +136,7 @@ await Record.ExceptionAsync(() => mockStream.Object.ReadBytesAsync(destination, [Theory] [ParameterAttributeData] - public async Task ReadBytes_with_byte_array_should_throw_when_buffer_is_null([Values(true, false)]bool async) + public async Task ReadBytes_with_byte_array_should_throw_when_buffer_is_null([Values(true, false)] bool async) { var stream = new Mock().Object; byte[] destination = null; @@ -172,8 +172,8 @@ await Record.ExceptionAsync(() => stream.ReadBytesAsync(destination, offset, cou [Theory] [ParameterAttributeData] public async Task ReadBytes_with_byte_array_should_throw_when_offset_is_invalid( - [Values(true, false)]bool async, - [Values(-1, 3)]int offset) + [Values(true, false)] bool async, + [Values(-1, 3)] int offset) { var stream = new Mock().Object; var destination = new byte[2]; @@ -188,7 +188,7 @@ await Record.ExceptionAsync(() => stream.ReadBytesAsync(destination, offset, 0)) [Theory] [ParameterAttributeData] - public async Task ReadBytes_with_byte_array_should_throw_when_stream_is_null([Values(true, false)]bool async) + public async Task ReadBytes_with_byte_array_should_throw_when_stream_is_null([Values(true, false)] bool async) { Stream stream = null; var destination = new byte[0]; @@ -203,7 +203,7 @@ await Record.ExceptionAsync(() => stream.ReadBytesAsync(destination, 0, 0)) : [Theory] [ParameterAttributeData] - public async Task ReadBytes_with_byte_array_throws_on_timeout([Values(true, false)]bool async, [Values(0, 10)]int timeout) + public async Task ReadBytes_with_byte_array_throws_on_timeout([Values(true, false)] bool async, [Values(0, 10)] int timeout) { var streamMock = new Mock(); SetupStreamRead(streamMock); @@ -220,7 +220,7 @@ await Record.ExceptionAsync(() => stream.ReadBytesAsync(destination, 0, 2, timeo [Theory] [ParameterAttributeData] - public async Task ReadBytes_with_byte_array_throws_on_cancellation([Values(true, false)]bool async) + public async Task ReadBytes_with_byte_array_throws_on_cancellation([Values(true, false)] bool async) { var streamMock = new Mock(); SetupStreamRead(streamMock); @@ -307,7 +307,7 @@ public async Task ReadBytes_with_byte_buffer_should_have_expected_effect_for_par var destination = new ByteArrayBuffer(new byte[3], 3); var n = 0; var position = 0; - int ReadPartial (byte[] buffer, int offset, int count) + int ReadPartial(byte[] buffer, int offset, int count) { var length = partition[n++]; Buffer.BlockCopy(bytes, position, buffer, offset, length); @@ -334,7 +334,7 @@ int ReadPartial (byte[] buffer, int offset, int count) [Theory] [ParameterAttributeData] - public async Task ReadBytes_with_byte_buffer_should_throw_when_end_of_stream_is_reached([Values(true, false)]bool async) + public async Task ReadBytes_with_byte_buffer_should_throw_when_end_of_stream_is_reached([Values(true, false)] bool async) { var mockStream = new Mock(); var destination = CreateMockByteBuffer(1).Object; @@ -352,7 +352,7 @@ await Record.ExceptionAsync(() => mockStream.Object.ReadBytesAsync(destination, [Theory] [ParameterAttributeData] - public async Task ReadBytes_with_byte_buffer_should_throw_when_buffer_is_null([Values(true, false)]bool async) + public async Task ReadBytes_with_byte_buffer_should_throw_when_buffer_is_null([Values(true, false)] bool async) { var stream = new Mock().Object; IByteBuffer destination = null; @@ -389,7 +389,7 @@ await Record.ExceptionAsync(() => stream.ReadBytesAsync(destination, offset, cou [ParameterAttributeData] public async Task ReadBytes_with_byte_buffer_should_throw_when_offset_is_invalid( [Values(true, false)] bool async, - [Values(-1, 3)]int offset) + [Values(-1, 3)] int offset) { var stream = new Mock().Object; var destination = CreateMockByteBuffer(2).Object; @@ -404,7 +404,7 @@ await Record.ExceptionAsync(() => stream.ReadBytesAsync(destination, offset, 0)) [Theory] [ParameterAttributeData] - public async Task ReadBytes_with_byte_buffer_should_throw_when_stream_is_null([Values(true, false)]bool async) + public async Task ReadBytes_with_byte_buffer_should_throw_when_stream_is_null([Values(true, false)] bool async) { Stream stream = null; var destination = new Mock().Object; @@ -465,7 +465,7 @@ public async Task WriteBytes_with_byte_array_should_have_expected_effect_for_off [Theory] [ParameterAttributeData] - public async Task WriteBytes_with_byte_array_should_throw_when_buffer_is_null([Values(true, false)]bool async) + public async Task WriteBytes_with_byte_array_should_throw_when_buffer_is_null([Values(true, false)] bool async) { var stream = new Mock().Object; byte[] buffer = null; @@ -501,8 +501,8 @@ await Record.ExceptionAsync(() => stream.WriteBytesAsync(source, offset, count)) [Theory] [ParameterAttributeData] public async Task WriteBytes_with_byte_array_should_throw_when_offset_is_invalid( - [Values(true, false)]bool async, - [Values(-1, 3)]int offset) + [Values(true, false)] bool async, + [Values(-1, 3)] int offset) { var stream = new Mock().Object; var source = new byte[] { 1, 2 }; @@ -517,7 +517,7 @@ await Record.ExceptionAsync(() => stream.WriteBytesAsync(source, offset, 0)) : [Theory] [ParameterAttributeData] - public async Task WriteBytes_with_byte_array_should_throw_when_stream_is_null([Values(true, false)]bool async) + public async Task WriteBytes_with_byte_array_should_throw_when_stream_is_null([Values(true, false)] bool async) { Stream stream = null; var source = new byte[] { 1, 2 }; @@ -613,7 +613,7 @@ public async Task WriteBytes_with_byte_buffer_should_have_expected_effect_for_pa [Theory] [ParameterAttributeData] - public async Task WriteBytes_with_byte_buffer_should_throw_when_buffer_is_null([Values(true, false)]bool async) + public async Task WriteBytes_with_byte_buffer_should_throw_when_buffer_is_null([Values(true, false)] bool async) { var stream = new Mock().Object; IByteBuffer buffer = null; @@ -649,8 +649,8 @@ await Record.ExceptionAsync(() => stream.WriteBytesAsync(source, offset, count)) [Theory] [ParameterAttributeData] public async Task WriteBytes_with_byte_buffer_should_throw_when_offset_is_invalid( - [Values(true, false)]bool async, - [Values(-1, 3)]int offset) + [Values(true, false)] bool async, + [Values(-1, 3)] int offset) { var stream = new Mock().Object; var source = CreateMockByteBuffer(2).Object; @@ -665,7 +665,7 @@ await Record.ExceptionAsync(() => stream.WriteBytesAsync(source, offset, 0)) : [Theory] [ParameterAttributeData] - public async Task WriteBytes_with_byte_buffer_should_throw_when_stream_is_null([Values(true, false)]bool async) + public async Task WriteBytes_with_byte_buffer_should_throw_when_stream_is_null([Values(true, false)] bool async) { Stream stream = null; var source = new Mock().Object; diff --git a/tests/MongoDB.Driver.Tests/Core/Misc/TaskExtensionsTests.cs b/tests/MongoDB.Driver.Tests/Core/Misc/TaskExtensionsTests.cs index 646ca85c69f..13b981c024a 100644 --- a/tests/MongoDB.Driver.Tests/Core/Misc/TaskExtensionsTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Misc/TaskExtensionsTests.cs @@ -71,7 +71,7 @@ await Record.ExceptionAsync(() => task.WaitAsync(Timeout.InfiniteTimeSpan, Cance [Theory] [ParameterAttributeData] - public async Task Wait_should_throw_on_cancellation([Values(true, false)]bool async) + public async Task Wait_should_throw_on_cancellation([Values(true, false)] bool async) { var task = CreateSubject(true); using var cts = new CancellationTokenSource(5); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/AggregateOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/AggregateOperationTests.cs index 281cfd83d23..d3f97137ce4 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/AggregateOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/AggregateOperationTests.cs @@ -332,7 +332,7 @@ public void CreateCommand_should_return_the_expected_result_when_AllowDiskUse_is var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -358,7 +358,7 @@ public void CreateCommand_should_return_the_expected_result_when_BatchSize_is_se }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -389,7 +389,7 @@ public void CreateCommand_should_return_the_expected_result_when_Collation_is_se var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -416,7 +416,7 @@ public void CreateCommand_should_return_expected_result_when_Comment_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -444,7 +444,7 @@ public void CreateCommand_should_return_the_expected_result_when_Hint_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -472,7 +472,7 @@ public void CreateCommand_should_return_expected_result_when_Let_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.AggregateOptionsLet.FirstSupportedWireVersion); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -501,7 +501,7 @@ public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -547,7 +547,7 @@ public void CreateCommand_should_return_the_expected_result_when_ReadConcern_is_ var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/AggregateToCollectionOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/AggregateToCollectionOperationTests.cs index 8f3b4c8404b..446e7ce7fa4 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/AggregateToCollectionOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/AggregateToCollectionOperationTests.cs @@ -305,7 +305,7 @@ public void CreateCommand_should_return_expected_result() var subject = new AggregateToCollectionOperation(_collectionNamespace, __pipeline, _messageEncoderSettings); var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -330,7 +330,7 @@ public void CreateCommand_should_return_expected_result_when_AllowDiskUse_is_set }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -356,7 +356,7 @@ public void CreateCommand_should_return_expected_result_when_BypassDocumentValid }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -383,7 +383,7 @@ public void CreateCommand_should_return_expected_result_when_Collation_is_set( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -409,7 +409,7 @@ public void CreateCommand_should_return_expected_result_when_Comment_is_set( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -436,7 +436,7 @@ public void CreateCommand_should_return_the_expected_result_when_Hint_is_set( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -463,7 +463,7 @@ public void CreateCommand_should_return_the_expected_result_when_Let_is_set( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -492,7 +492,7 @@ public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -537,7 +537,7 @@ public void CreateCommand_should_return_expected_result_when_ReadConcern_is_set( } var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -564,7 +564,7 @@ public void CreateCommand_should_return_expected_result_when_WriteConcern_is_set }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber: null); @@ -647,7 +647,7 @@ public void Execute_to_time_series_collection_should_work( var outputDatabaseName = usingDifferentOutputDatabase ? $"{inputDatabaseName}-outputdatabase-timeseries" : inputDatabaseName; var outputCollectionName = $"{inputCollectionName}-outputcollection-timeseries"; - pipeline.Add(new BsonDocument { {"$set", new BsonDocument { {"time", DateTime.Now } } } } ); + pipeline.Add(new BsonDocument { { "$set", new BsonDocument { { "time", DateTime.Now } } } }); pipeline.Add(BsonDocument.Parse($"{{ $out : {{ db : '{outputDatabaseName}', coll : '{outputCollectionName}', timeseries: {{ timeField: 'time' }} }} }}")); EnsureTestData(); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/AsyncCursorTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/AsyncCursorTests.cs index 938eabef9d4..3fe2ad26970 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/AsyncCursorTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/AsyncCursorTests.cs @@ -88,7 +88,7 @@ public void Close_should_call_supported_kill_cursors([Values(false, true)] bool [Theory] [ParameterAttributeData] - public void Close_should_dispose_cursor_only_once([Values(false, true)]bool async) + public void Close_should_dispose_cursor_only_once([Values(false, true)] bool async) { int testCursorId = 1; var mockChannelHandle = new Mock(); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/CompositeWriteOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/CompositeWriteOperationTests.cs index 994f9837189..c94d53f730a 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/CompositeWriteOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/CompositeWriteOperationTests.cs @@ -64,7 +64,7 @@ public async Task Enumerating_operations_should_be_stopped_when_error([Values(fa var healthyOperation1 = CreateHealthyOperation(new BsonDocument("operation", 1)); var faultyOperation2 = CreateFaultyOperation(testException); - var healthyOperation3= CreateHealthyOperation(new BsonDocument("operation", 3)); + var healthyOperation3 = CreateHealthyOperation(new BsonDocument("operation", 3)); var subject = new CompositeWriteOperation((healthyOperation1.Object, IsMainOperation: false), (faultyOperation2.Object, IsMainOperation: false), (healthyOperation3.Object, IsMainOperation: true)); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/CountOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/CountOperationTests.cs index 7b4acfc7147..8138cae7d57 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/CountOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/CountOperationTests.cs @@ -201,7 +201,7 @@ public void CreateCommand_should_return_expected_result() var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -225,7 +225,7 @@ public void CreateCommand_should_return_expected_result_when_Comment_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -251,7 +251,7 @@ public void CreateCommand_should_return_expected_result_when_Collation_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -277,7 +277,7 @@ public void CreateCommand_should_return_expected_result_when_Filter_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -303,7 +303,7 @@ public void CreateCommand_should_return_expected_result_when_Hint_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -328,7 +328,7 @@ public void CreateCommand_should_return_expected_result_when_Limit_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -355,7 +355,7 @@ public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -399,7 +399,7 @@ public void CreateCommand_should_return_expected_result_when_ReadConcern_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -453,7 +453,7 @@ public void CreateCommand_should_return_expected_result_when_Skip_is_set( var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/CreateViewOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/CreateViewOperationTests.cs index 706b460e208..69f46d88965 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/CreateViewOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/CreateViewOperationTests.cs @@ -1,4 +1,4 @@ -/* Copyright 2010-present MongoDB Inc. +/* Copyright 2010-present MongoDB Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/DropDatabaseOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/DropDatabaseOperationTests.cs index 987581db7f9..069705aee87 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/DropDatabaseOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/DropDatabaseOperationTests.cs @@ -55,7 +55,7 @@ public void CreateCommand_should_return_expected_result() }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/DropIndexOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/DropIndexOperationTests.cs index d8d302d2501..1261934b977 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/DropIndexOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/DropIndexOperationTests.cs @@ -139,7 +139,7 @@ public void CreateCommand_should_return_expectedResult() }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -169,7 +169,7 @@ public void CreateCommand_should_return_expected_result_when_MaxTime_is_Set(long }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/EndTransactionOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/EndTransactionOperationTests.cs index fc26569d1ea..d226ff35427 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/EndTransactionOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/EndTransactionOperationTests.cs @@ -224,7 +224,7 @@ public static BsonDocument CreateCommand(this EndTransactionOperation obj) { var methodInfo = typeof(EndTransactionOperation).GetMethod("CreateCommand", BindingFlags.NonPublic | BindingFlags.Instance, null, [typeof(OperationContext), typeof(WriteConcern)], null); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); return (BsonDocument)methodInfo.Invoke(obj, [operationContext, obj.WriteConcern]); } } diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndDeleteOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndDeleteOperationTests.cs index 1d7814291bf..53b6dd72b43 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndDeleteOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndDeleteOperationTests.cs @@ -259,7 +259,7 @@ public void CreateCommand_should_return_the_expected_result( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber); @@ -287,7 +287,7 @@ public void CreateCommand_should_return_the_expected_result_when_Collation_is_se }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -316,7 +316,7 @@ public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -361,7 +361,7 @@ public void CreateCommand_should_return_the_expected_result_when_Projection_is_s }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -388,7 +388,7 @@ public void CreateCommand_should_return_the_expected_result_when_Sort_is_set( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndReplaceOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndReplaceOperationTests.cs index c1e92a1a8eb..a56dec60f53 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndReplaceOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndReplaceOperationTests.cs @@ -279,7 +279,7 @@ public void CreateCommand_should_return_expected_result( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, transactionNumber); @@ -306,7 +306,7 @@ public void CreateCommand_should_return_expected_result_when_BypassDocumentValid }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -333,7 +333,7 @@ public void CreateCommand_should_return_expected_result_when_Collation_is_set( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -385,7 +385,7 @@ public void CreateCommand_should_return_expected_result_when_IsUpsert_is_set( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -414,7 +414,7 @@ public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -459,7 +459,7 @@ public void CreateCommand_should_return_expected_result_when_Projection_is_set( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -485,7 +485,7 @@ public void CreateCommand_should_return_expected_result_when_ReturnDocument_is_s }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); @@ -512,7 +512,7 @@ public void CreateCommand_should_return_expected_result_when_Sort_is_set( }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription, null); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndUpdateOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndUpdateOperationTests.cs index c700dd78f88..38131c65104 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndUpdateOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/FindOneAndUpdateOperationTests.cs @@ -265,7 +265,7 @@ public void WriteConcern_get_and_set_should_work( [ParameterAttributeData] public void CreateCommand_should_return_expected_result( [Values(null, "{ name : 'name' }")] string let, - [Values(null, 100L)]long? transactionNumber) + [Values(null, 100L)] long? transactionNumber) { var letDocument = let != null ? BsonDocument.Parse(let) : null; var subject = new FindOneAndUpdateOperation(_collectionNamespace, _filter, _update, BsonDocumentSerializer.Instance, _messageEncoderSettings) diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/FindOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/FindOperationTests.cs index 581e6d4c7ab..a60267aec51 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/FindOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/FindOperationTests.cs @@ -837,7 +837,7 @@ public void Execute_should_find_documents_matching_options( [Theory] [ParameterAttributeData] - public async Task Execute_should_set_operation_name([Values(false, true)]bool async) + public async Task Execute_should_set_operation_name([Values(false, true)] bool async) { RequireServer.Check(); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/MapReduceOperationBaseTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/MapReduceOperationBaseTests.cs index 15c50c637a4..2b99708eee4 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/MapReduceOperationBaseTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/MapReduceOperationBaseTests.cs @@ -123,7 +123,7 @@ public void CreateCommand_should_return_the_expected_result() var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings); var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -150,7 +150,7 @@ public void CreateCommand_should_return_the_expected_result_when_Collation_is_pr }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -178,7 +178,7 @@ public void CreateCommand_should_return_the_expected_result_when_Filter_is_provi }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -206,7 +206,7 @@ public void CreateCommand_should_return_the_expected_result_when_FinalizeFunctio }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -235,7 +235,7 @@ public void CreateCommand_should_return_the_expected_result_when_JavaScriptMode_ }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -262,7 +262,7 @@ public void CreateCommand_should_return_the_expected_result_when_Limit_is_provid }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -292,7 +292,7 @@ public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -338,7 +338,7 @@ public void CreateCommand_should_return_the_expected_result_when_Scope_is_provid }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -366,7 +366,7 @@ public void CreateCommand_should_return_the_expected_result_when_Sort_is_provide }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -393,7 +393,7 @@ public void CreateCommand_should_return_the_expected_result_when_Verbose_is_prov }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); diff --git a/tests/MongoDB.Driver.Tests/Core/Operations/MapReduceOutputToCollectionOperationTests.cs b/tests/MongoDB.Driver.Tests/Core/Operations/MapReduceOutputToCollectionOperationTests.cs index c757a348454..0ee6df9c2c1 100644 --- a/tests/MongoDB.Driver.Tests/Core/Operations/MapReduceOutputToCollectionOperationTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Operations/MapReduceOutputToCollectionOperationTests.cs @@ -214,7 +214,7 @@ public void CreateCommand_should_return_expected_result_when_BypassDocumentValid }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); @@ -244,7 +244,7 @@ public void CreateCommand_should_return_expected_result_when_WriteConcern_is_set }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); using var session = OperationTestHelper.CreateSession(); -using var operationContext = new OperationContext(session); + using var operationContext = new OperationContext(session); var result = subject.CreateCommand(operationContext, connectionDescription); diff --git a/tests/MongoDB.Driver.Tests/Core/Servers/HeartbeatDelayTests.cs b/tests/MongoDB.Driver.Tests/Core/Servers/HeartbeatDelayTests.cs index 8c2e9014e08..50e94d462e4 100644 --- a/tests/MongoDB.Driver.Tests/Core/Servers/HeartbeatDelayTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Servers/HeartbeatDelayTests.cs @@ -36,7 +36,7 @@ public void Dispose_can_be_called_multiple_times() [Theory] [ParameterAttributeData] - public void RequestHeartbeat_should_respect_to_minHeartbeatInterval([Values(10, -1)]int heartbeatIntervalInMinutes) + public void RequestHeartbeat_should_respect_to_minHeartbeatInterval([Values(10, -1)] int heartbeatIntervalInMinutes) { var heartbeatInterval = heartbeatIntervalInMinutes == -1 ? Timeout.InfiniteTimeSpan : TimeSpan.FromMinutes(heartbeatIntervalInMinutes); var minHeartbeatInterval = TimeSpan.FromSeconds(2); diff --git a/tests/MongoDB.Driver.Tests/Core/Servers/RoundTripTimeMonitorTests.cs b/tests/MongoDB.Driver.Tests/Core/Servers/RoundTripTimeMonitorTests.cs index de424f0784a..24c4a145cf8 100644 --- a/tests/MongoDB.Driver.Tests/Core/Servers/RoundTripTimeMonitorTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Servers/RoundTripTimeMonitorTests.cs @@ -202,7 +202,7 @@ public void Start_should_use_serverApi() [Fact] public void RoundTripTimeMonitor_without_serverApi_but_with_loadBalancedConnection_should_use_hello_command_to_set_up_monitoring() { - var connection = new MockConnection(__serverId, new ConnectionSettings(loadBalanced:true), null); + var connection = new MockConnection(__serverId, new ConnectionSettings(loadBalanced: true), null); var mockConnectionFactory = new Mock(); mockConnectionFactory.Setup(f => f.ConnectionSettings).Returns(() => new ConnectionSettings()); diff --git a/tests/MongoDB.Driver.Tests/Core/Servers/ServerMonitorTests.cs b/tests/MongoDB.Driver.Tests/Core/Servers/ServerMonitorTests.cs index 54e5d460959..29e34f96c90 100644 --- a/tests/MongoDB.Driver.Tests/Core/Servers/ServerMonitorTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Servers/ServerMonitorTests.cs @@ -541,7 +541,7 @@ private ServerMonitor CreateSubject( mockRoundTripTimeMonitor = new Mock(); var isRttStarted = false; - mockRoundTripTimeMonitor.Setup(m => m.Start()).Callback(() => { isRttStarted = true; }) ; + mockRoundTripTimeMonitor.Setup(m => m.Start()).Callback(() => { isRttStarted = true; }); mockRoundTripTimeMonitor.SetupGet(m => m.IsStarted).Returns(() => isRttStarted); if (captureConnectionEvents) diff --git a/tests/MongoDB.Driver.Tests/Core/Servers/TopologyVersionTests.cs b/tests/MongoDB.Driver.Tests/Core/Servers/TopologyVersionTests.cs index 559add15b80..e850d76f184 100644 --- a/tests/MongoDB.Driver.Tests/Core/Servers/TopologyVersionTests.cs +++ b/tests/MongoDB.Driver.Tests/Core/Servers/TopologyVersionTests.cs @@ -182,7 +182,7 @@ public void FromBsonDocument_should_return_TopologyDescription_when_supplied_val { var processId = ObjectId.Empty; var counter = 31L; - var topologyVersionDocument = new BsonDocument {{"processId", processId}, {"counter", counter}}; + var topologyVersionDocument = new BsonDocument { { "processId", processId }, { "counter", counter } }; TopologyVersion subject = TopologyVersion.FromBsonDocument(topologyVersionDocument); diff --git a/tests/MongoDB.Driver.Tests/DiscriminatorElementNameConflictTests.cs b/tests/MongoDB.Driver.Tests/DiscriminatorElementNameConflictTests.cs index 6658202ee7e..54b076dbf77 100644 --- a/tests/MongoDB.Driver.Tests/DiscriminatorElementNameConflictTests.cs +++ b/tests/MongoDB.Driver.Tests/DiscriminatorElementNameConflictTests.cs @@ -31,7 +31,7 @@ private class BaseDocument public string Field1 { get; set; } } - private class DerivedDocument : BaseDocument {} + private class DerivedDocument : BaseDocument { } [Fact] public void BsonClassMapSerializer_serialization_when_using_field_with_same_element_name_as_discriminator_should_throw() diff --git a/tests/MongoDB.Driver.Tests/Encryption/ClientEncryptionTests.cs b/tests/MongoDB.Driver.Tests/Encryption/ClientEncryptionTests.cs index 733ef8c586b..24059061710 100644 --- a/tests/MongoDB.Driver.Tests/Encryption/ClientEncryptionTests.cs +++ b/tests/MongoDB.Driver.Tests/Encryption/ClientEncryptionTests.cs @@ -382,7 +382,7 @@ private async ValueTask ExplicitDecryptAsync(ClientEncryption clientE async ? await clientEncryption.DecryptAsync(value) : clientEncryption.Decrypt(value); private async ValueTask ExplicitEncryptAsync(ClientEncryption clientEncryption, EncryptOptions encryptOptions, BsonValue value, bool async) => - async? await clientEncryption.EncryptAsync(value, encryptOptions) : clientEncryption.Encrypt(value, encryptOptions); + async ? await clientEncryption.EncryptAsync(value, encryptOptions) : clientEncryption.Encrypt(value, encryptOptions); private void ShouldBeArgumentNullException(Exception ex, string expectedParamName) => ex.Should().BeOfType().Which.ParamName.Should().Be(expectedParamName); } diff --git a/tests/MongoDB.Driver.Tests/Encryption/CsfleSchemaBuilderTests.cs b/tests/MongoDB.Driver.Tests/Encryption/CsfleSchemaBuilderTests.cs index 764fe1114b0..3c92b38ea72 100644 --- a/tests/MongoDB.Driver.Tests/Encryption/CsfleSchemaBuilderTests.cs +++ b/tests/MongoDB.Driver.Tests/Encryption/CsfleSchemaBuilderTests.cs @@ -61,7 +61,7 @@ public void CsfleSchemaBuilder_works_as_expected() algorithm: EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA_512_Deterministic); }); - } ); + }); }); var expected = new Dictionary @@ -280,15 +280,15 @@ public void EncryptedCollection_PatternProperty_works_as_expected(BsonType bsonT null, null, "")] - [InlineData(new[] {BsonType.Array, BsonType.String}, + [InlineData(new[] { BsonType.Array, BsonType.String }, EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA_512_Random, null, """ "bsonType": ["array", "string"], "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random" """)] - [InlineData(new[] {BsonType.Array, BsonType.String}, + [InlineData(new[] { BsonType.Array, BsonType.String }, null, KeyIdString, """ "bsonType": ["array", "string"], "keyId": [{ "$binary" : { "base64" : "b0r0cADRQB+sOfRZAqDAyA==", "subType" : "04" } }] """)] - [InlineData(new[] {BsonType.Array, BsonType.String}, + [InlineData(new[] { BsonType.Array, BsonType.String }, EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA_512_Random, KeyIdString, """ "bsonType": ["array", "string"], "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", "keyId": [{ "$binary" : { "base64" : "b0r0cADRQB+sOfRZAqDAyA==", "subType" : "04" } }] """)] @@ -454,15 +454,15 @@ public void EncryptedCollection_Property_with_expression_works_as_expected(BsonT null, null, "")] - [InlineData(new[] {BsonType.Array, BsonType.String}, + [InlineData(new[] { BsonType.Array, BsonType.String }, EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA_512_Random, null, """ "bsonType": ["array", "string"], "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random" """)] - [InlineData(new[] {BsonType.Array, BsonType.String}, + [InlineData(new[] { BsonType.Array, BsonType.String }, null, KeyIdString, """ "bsonType": ["array", "string"], "keyId": [{ "$binary" : { "base64" : "b0r0cADRQB+sOfRZAqDAyA==", "subType" : "04" } }] """)] - [InlineData(new[] {BsonType.Array, BsonType.String}, + [InlineData(new[] { BsonType.Array, BsonType.String }, EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA_512_Random, KeyIdString, """ "bsonType": ["array", "string"], "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random", "keyId": [{ "$binary" : { "base64" : "b0r0cADRQB+sOfRZAqDAyA==", "subType" : "04" } }] """)] @@ -707,4 +707,4 @@ internal class Insurance public int PolicyNumber { get; set; } } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Encryption/EncryptOptionsTests.cs b/tests/MongoDB.Driver.Tests/Encryption/EncryptOptionsTests.cs index fe481d6b488..f720e3f42e8 100644 --- a/tests/MongoDB.Driver.Tests/Encryption/EncryptOptionsTests.cs +++ b/tests/MongoDB.Driver.Tests/Encryption/EncryptOptionsTests.cs @@ -254,7 +254,7 @@ public void With_should_set_correct_values() AssertValues(subject, newAlgorithm, expectedKeyId: originalKeyId); subject = subject.With(keyId: newKeyId); - AssertValues(subject, newAlgorithm, expectedKeyId: newKeyId); + AssertValues(subject, newAlgorithm, expectedKeyId: newKeyId); var fle1WithAlternateKeyNameState = 1; subject = CreateConfiguredSubject(state: fle1WithAlternateKeyNameState); @@ -293,7 +293,7 @@ EncryptOptions CreateConfiguredSubject(int state) switch (state) { case 0: return new EncryptOptions(algorithm: originalAlgorithm, keyId: originalKeyId); - case 1: return new EncryptOptions(algorithm: originalAlgorithm, alternateKeyName: originalAlternateKeyName); + case 1: return new EncryptOptions(algorithm: originalAlgorithm, alternateKeyName: originalAlternateKeyName); case 2: return new EncryptOptions(algorithm: originalAlgorithm, keyId: originalKeyId, contentionFactor: originalContention, queryType: originalQueryType); default: throw new Exception($"Unexpected state: {state}."); } diff --git a/tests/MongoDB.Driver.Tests/FilterDefinitionBuilderEnumComparedToEnumTests.cs b/tests/MongoDB.Driver.Tests/FilterDefinitionBuilderEnumComparedToEnumTests.cs index a4457364341..335250803dc 100644 --- a/tests/MongoDB.Driver.Tests/FilterDefinitionBuilderEnumComparedToEnumTests.cs +++ b/tests/MongoDB.Driver.Tests/FilterDefinitionBuilderEnumComparedToEnumTests.cs @@ -148,7 +148,7 @@ public void Ne_with_lambda_should_render_correctly(E value, string expectedFilte { var filter = __subject.Ne(x => x.E, value); - filter.Render(__args ).Should().Be(expectedFilter); + filter.Render(__args).Should().Be(expectedFilter); } [Theory] diff --git a/tests/MongoDB.Driver.Tests/FindOneAndMethodOverloadResolutionTests.cs b/tests/MongoDB.Driver.Tests/FindOneAndMethodOverloadResolutionTests.cs index 32f5891253b..51fb7d0773b 100644 --- a/tests/MongoDB.Driver.Tests/FindOneAndMethodOverloadResolutionTests.cs +++ b/tests/MongoDB.Driver.Tests/FindOneAndMethodOverloadResolutionTests.cs @@ -43,4 +43,4 @@ private class Person public string Name { get; set; } } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/GridFS/GridFSUploadStreamTests.cs b/tests/MongoDB.Driver.Tests/GridFS/GridFSUploadStreamTests.cs index 6ba783cae04..a3dcf4f1c6e 100644 --- a/tests/MongoDB.Driver.Tests/GridFS/GridFSUploadStreamTests.cs +++ b/tests/MongoDB.Driver.Tests/GridFS/GridFSUploadStreamTests.cs @@ -103,7 +103,7 @@ public async Task Upload_of_duplicate_file_should_not_invalidate_existing_data( } var exception = async - ? await Record.ExceptionAsync(() => bucket.UploadFromBytesAsync(fileId, fileName, content2, uploadOptions)) + ? await Record.ExceptionAsync(() => bucket.UploadFromBytesAsync(fileId, fileName, content2, uploadOptions)) : Record.Exception(() => bucket.UploadFromBytes(fileId, fileName, content2, uploadOptions)); exception.Should().BeOfType>(); diff --git a/tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenWaitForPrimaryChangeTest.cs b/tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenWaitForPrimaryChangeTest.cs index d9489e761e9..5a2a41e1c6e 100644 --- a/tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenWaitForPrimaryChangeTest.cs +++ b/tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenWaitForPrimaryChangeTest.cs @@ -42,7 +42,7 @@ protected override void CallMethod(CancellationToken cancellationToken) var newPrimary = WaitForPrimaryChange(_testState.RecordedPrimary); if (newPrimary != null) { - _testState.RecordedPrimary = newPrimary ; + _testState.RecordedPrimary = newPrimary; } else { diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/CompareToInFilterAndProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/CompareToInFilterAndProjectionTests.cs index 982da7e2b52..63c799b313c 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/CompareToInFilterAndProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/CompareToInFilterAndProjectionTests.cs @@ -31,112 +31,112 @@ public CompareToInFilterAndProjectionTests(ClassFixture fixture) { } - [Theory] - [InlineData(2, "<" , 0, "{ _id : { $lt : 2 } }", new int[] { 1 })] - [InlineData(2, "<=", 0, "{ _id : { $lte : 2 } }", new int[] { 1, 2 })] - [InlineData(2, "==", 0, "{ _id : 2 }", new int[] { 2 })] - [InlineData(2, "!=", 0, "{ _id : { $ne : 2 } }", new int[] { 1, 3 })] - [InlineData(2, ">=", 0, "{ _id : { $gte : 2 } }", new int[] { 2, 3 })] - [InlineData(2, ">" , 0, "{ _id : { $gt : 2 } }", new int[] { 3 })] - public void CompareTo_filter_should_work( - int comparand, - string comparisonOperator, - int compareToResult, - string expectedFilter, - int[] expectedIds) - { - var collection = Fixture.Collection; - - Expression> predicate = comparisonOperator switch - { - "<" => x => x.Id.CompareTo(comparand) < compareToResult, - "<=" => x => x.Id.CompareTo(comparand) <= compareToResult, - "==" => x => x.Id.CompareTo(comparand) == compareToResult, - "!=" => x => x.Id.CompareTo(comparand) != compareToResult, - ">=" => x => x.Id.CompareTo(comparand) >= compareToResult, - ">" => x => x.Id.CompareTo(comparand) > compareToResult, - _ => throw new InvalidOperationException() - }; - - Implementation(collection, comparand, predicate); - - void Implementation(IMongoCollection collection, TId _, Expression> predicate) - where TModel : IIdentity - where TId : IComparable - { - var queryable = collection.AsQueryable() - .Where(predicate); - - var stages = Translate(collection, queryable); - var expectedStage = "{ $match : }".Replace("", expectedFilter); - AssertStages(stages, expectedStage); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(expectedIds); - } - } + [Theory] + [InlineData(2, "<", 0, "{ _id : { $lt : 2 } }", new int[] { 1 })] + [InlineData(2, "<=", 0, "{ _id : { $lte : 2 } }", new int[] { 1, 2 })] + [InlineData(2, "==", 0, "{ _id : 2 }", new int[] { 2 })] + [InlineData(2, "!=", 0, "{ _id : { $ne : 2 } }", new int[] { 1, 3 })] + [InlineData(2, ">=", 0, "{ _id : { $gte : 2 } }", new int[] { 2, 3 })] + [InlineData(2, ">", 0, "{ _id : { $gt : 2 } }", new int[] { 3 })] + public void CompareTo_filter_should_work( + int comparand, + string comparisonOperator, + int compareToResult, + string expectedFilter, + int[] expectedIds) + { + var collection = Fixture.Collection; - [Theory] - [InlineData(2, "<", 0, "_v : { $lt : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { true, false, false })] - [InlineData(2, "<=", 0, "_v : { $lte : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { true, true, false })] - [InlineData(2, "==", 0, "_v : { $eq : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { false, true, false })] - [InlineData(2, "!=", 0, "_v : { $ne : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { true, false, true })] - [InlineData(2, ">=", 0, "_v : { $gte : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { false, true, true })] - [InlineData(2, ">", 0, "_v : { $gt : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { false, false, true })] - public void CompareTo_expression_should_work( - int comparand, - string comparisonOperator, - int compareToResult, - string expectedProjection, - bool[] expectedResults) + Expression> predicate = comparisonOperator switch { - var collection = Fixture.Collection; - - Expression> selector = comparisonOperator switch - { - "<" => x => x.Id.CompareTo(comparand) < compareToResult, - "<=" => x => x.Id.CompareTo(comparand) <= compareToResult, - "==" => x => x.Id.CompareTo(comparand) == compareToResult, - "!=" => x => x.Id.CompareTo(comparand) != compareToResult, - ">=" => x => x.Id.CompareTo(comparand) >= compareToResult, - ">" => x => x.Id.CompareTo(comparand) > compareToResult, - _ => throw new InvalidOperationException() - }; - - Implementation(collection, comparand, selector); - - void Implementation(IMongoCollection collection, TId _, Expression> selector) - where TModel : IIdentity - where TId : IComparable - { - var queryable = collection.AsQueryable() - .Select(selector); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { , _id : 0 } }".Replace("", expectedProjection)); - - var results = queryable.ToList(); - results.Should().Equal(expectedResults); - } - } - - public interface IIdentity + "<" => x => x.Id.CompareTo(comparand) < compareToResult, + "<=" => x => x.Id.CompareTo(comparand) <= compareToResult, + "==" => x => x.Id.CompareTo(comparand) == compareToResult, + "!=" => x => x.Id.CompareTo(comparand) != compareToResult, + ">=" => x => x.Id.CompareTo(comparand) >= compareToResult, + ">" => x => x.Id.CompareTo(comparand) > compareToResult, + _ => throw new InvalidOperationException() + }; + + Implementation(collection, comparand, predicate); + + void Implementation(IMongoCollection collection, TId _, Expression> predicate) + where TModel : IIdentity + where TId : IComparable { - TId Id { get; set; } + var queryable = collection.AsQueryable() + .Where(predicate); + + var stages = Translate(collection, queryable); + var expectedStage = "{ $match : }".Replace("", expectedFilter); + AssertStages(stages, expectedStage); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(expectedIds); } + } + + [Theory] + [InlineData(2, "<", 0, "_v : { $lt : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { true, false, false })] + [InlineData(2, "<=", 0, "_v : { $lte : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { true, true, false })] + [InlineData(2, "==", 0, "_v : { $eq : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { false, true, false })] + [InlineData(2, "!=", 0, "_v : { $ne : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { true, false, true })] + [InlineData(2, ">=", 0, "_v : { $gte : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { false, true, true })] + [InlineData(2, ">", 0, "_v : { $gt : [{ $cmp : ['$_id', 2] }, 0] }", new bool[] { false, false, true })] + public void CompareTo_expression_should_work( + int comparand, + string comparisonOperator, + int compareToResult, + string expectedProjection, + bool[] expectedResults) + { + var collection = Fixture.Collection; - public class C : IIdentity + Expression> selector = comparisonOperator switch + { + "<" => x => x.Id.CompareTo(comparand) < compareToResult, + "<=" => x => x.Id.CompareTo(comparand) <= compareToResult, + "==" => x => x.Id.CompareTo(comparand) == compareToResult, + "!=" => x => x.Id.CompareTo(comparand) != compareToResult, + ">=" => x => x.Id.CompareTo(comparand) >= compareToResult, + ">" => x => x.Id.CompareTo(comparand) > compareToResult, + _ => throw new InvalidOperationException() + }; + + Implementation(collection, comparand, selector); + + void Implementation(IMongoCollection collection, TId _, Expression> selector) + where TModel : IIdentity + where TId : IComparable { - public int Id { get; set; } + var queryable = collection.AsQueryable() + .Select(selector); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { , _id : 0 } }".Replace("", expectedProjection)); + + var results = queryable.ToList(); + results.Should().Equal(expectedResults); } + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new C { Id = 1 }, + public interface IIdentity + { + TId Id { get; set; } + } + + public class C : IIdentity + { + public int Id { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1 }, new C { Id = 2 }, new C { Id = 3 } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/CountPropertyOnCollectionTypesWhereAndSelectTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/CountPropertyOnCollectionTypesWhereAndSelectTests.cs index ab79f5b6935..6851217b0dc 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/CountPropertyOnCollectionTypesWhereAndSelectTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/CountPropertyOnCollectionTypesWhereAndSelectTests.cs @@ -31,359 +31,359 @@ public class CountPropertyOnCollectionTypesWhereAndSelectTests : LinqIntegration { public CountPropertyOnCollectionTypesWhereAndSelectTests(ClassFixture fixture) : base(fixture) - { - } + { + } - [Fact] - public void Where_BitArray_Count_should_throw() - { - var collection = Fixture.Collection; + [Fact] + public void Where_BitArray_Count_should_throw() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.BitArray.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.BitArray.Count == 1); - var exception = Record.Exception(() => Translate(collection, queryable)); - exception.Should().BeOfType(); - } + var exception = Record.Exception(() => Translate(collection, queryable)); + exception.Should().BeOfType(); + } - [Fact] - public void Where_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.Count == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { Count : 1 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { Count : 1 } }"); - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Where_Dictionary_Count_should_throw() - { - var collection = Fixture.Collection; + [Fact] + public void Where_Dictionary_Count_should_throw() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.Dictionary.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.Dictionary.Count == 1); - var exception = Record.Exception(() => Translate(collection, queryable)); - exception.Should().BeOfType(); - } + var exception = Record.Exception(() => Translate(collection, queryable)); + exception.Should().BeOfType(); + } - [Fact] - public void Where_DictionaryAsArrayOfArrays_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_DictionaryAsArrayOfArrays_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.DictionaryAsArrayOfArrays.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.DictionaryAsArrayOfArrays.Count == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { DictionaryAsArrayOfArrays : { $size : 1 } } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { DictionaryAsArrayOfArrays : { $size : 1 } } }"); - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Where_DictionaryAsArrayOfDocuments_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_DictionaryAsArrayOfDocuments_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.DictionaryAsArrayOfDocuments.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.DictionaryAsArrayOfDocuments.Count == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { DictionaryAsArrayOfDocuments : { $size : 1 } } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { DictionaryAsArrayOfDocuments : { $size : 1 } } }"); - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Where_DictionaryInterface_Count_should_throw() - { - var collection = Fixture.Collection; + [Fact] + public void Where_DictionaryInterface_Count_should_throw() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.DictionaryInterface.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.DictionaryInterface.Count == 1); - var exception = Record.Exception(() => Translate(collection, queryable)); - exception.Should().BeOfType(); - } + var exception = Record.Exception(() => Translate(collection, queryable)); + exception.Should().BeOfType(); + } - [Fact] - public void Where_DictionaryInterfaceArrayOfArrays_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_DictionaryInterfaceArrayOfArrays_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.DictionaryInterfaceAsArrayOfArrays.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.DictionaryInterfaceAsArrayOfArrays.Count == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { DictionaryInterfaceAsArrayOfArrays : { $size : 1 } } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { DictionaryInterfaceAsArrayOfArrays : { $size : 1 } } }"); - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Where_DictionaryInterfaceArrayOfDocuments_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_DictionaryInterfaceArrayOfDocuments_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.DictionaryInterfaceAsArrayOfDocuments.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.DictionaryInterfaceAsArrayOfDocuments.Count == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { DictionaryInterfaceAsArrayOfDocuments : { $size : 1 } } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { DictionaryInterfaceAsArrayOfDocuments : { $size : 1 } } }"); - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Where_List_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_List_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.List.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.List.Count == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'List' : { $size : 1 } } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'List' : { $size : 1 } } }"); - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Where_ListInterface_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_ListInterface_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.ListInterface.Count == 1); + var queryable = collection.AsQueryable() + .Where(x => x.ListInterface.Count == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'ListInterface' : { $size : 1 } } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'ListInterface' : { $size : 1 } } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + [Theory] + [ParameterAttributeData] + public void Select_BitArray_Count_should_throw( + [Values(false, true)] bool enableClientSideProjections) + { + var collection = Fixture.Collection; + var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; + + var queryable = collection.AsQueryable(translationOptions) + .Select(x => x.BitArray.Count); + + if (enableClientSideProjections) + { + var stages = Translate(collection, queryable, out var outputSerializer); + AssertStages(stages, "{ $project : { _snippets : ['$BitArray'], _id : 0 } }"); + outputSerializer.Should().BeAssignableTo(); var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); + results.Should().Equal(1, 2); } - - [Theory] - [ParameterAttributeData] - public void Select_BitArray_Count_should_throw( - [Values(false, true)] bool enableClientSideProjections) + else { - var collection = Fixture.Collection; - var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; - - var queryable = collection.AsQueryable(translationOptions) - .Select(x => x.BitArray.Count); - - if (enableClientSideProjections) - { - var stages = Translate(collection, queryable, out var outputSerializer); - AssertStages(stages, "{ $project : { _snippets : ['$BitArray'], _id : 0 } }"); - outputSerializer.Should().BeAssignableTo(); - - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } - else - { - var exception = Record.Exception(() => Translate(collection, queryable)); - exception.Should().BeOfType(); - exception.Message.Should().Contain("is not represented as an array"); - } + var exception = Record.Exception(() => Translate(collection, queryable)); + exception.Should().BeOfType(); + exception.Message.Should().Contain("is not represented as an array"); } + } - [Fact] - public void Select_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Select_Count_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Select(x => x.Count); - var queryable = collection.AsQueryable() - .Select(x => x.Count); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : '$Count', _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : '$Count', _id : 0 } }"); + [Theory] + [ParameterAttributeData] + public void Select_Dictionary_Count_should_throw( + [Values(false, true)] bool enableClientSideProjections) + { + var collection = Fixture.Collection; + var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; + + var queryable = collection.AsQueryable(translationOptions) + .Select(x => x.Dictionary.Count); + + if (enableClientSideProjections) + { + var stages = Translate(collection, queryable, out var outputSerializer); + AssertStages(stages, "{ $project : { _snippets : ['$Dictionary'], _id : 0 } }"); + outputSerializer.Should().BeAssignableTo(); var results = queryable.ToList(); results.Should().Equal(1, 2); } - - [Theory] - [ParameterAttributeData] - public void Select_Dictionary_Count_should_throw( - [Values(false, true)] bool enableClientSideProjections) + else { - var collection = Fixture.Collection; - var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; - - var queryable = collection.AsQueryable(translationOptions) - .Select(x => x.Dictionary.Count); - - if (enableClientSideProjections) - { - var stages = Translate(collection, queryable, out var outputSerializer); - AssertStages(stages, "{ $project : { _snippets : ['$Dictionary'], _id : 0 } }"); - outputSerializer.Should().BeAssignableTo(); - - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } - else - { - var exception = Record.Exception(() => Translate(collection, queryable)); - exception.Should().BeOfType(); - exception.Message.Should().Contain("is not represented as an array"); - } + var exception = Record.Exception(() => Translate(collection, queryable)); + exception.Should().BeOfType(); + exception.Message.Should().Contain("is not represented as an array"); } + } - [Fact] - public void Select_DictionaryAsArrayOfArrays_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Select_DictionaryAsArrayOfArrays_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Select(x => x.DictionaryAsArrayOfArrays.Count); + var queryable = collection.AsQueryable() + .Select(x => x.DictionaryAsArrayOfArrays.Count); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $size : '$DictionaryAsArrayOfArrays' }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $size : '$DictionaryAsArrayOfArrays' }, _id : 0 } }"); - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } - [Fact] - public void Select_DictionaryAsArrayOfDocuments_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Select_DictionaryAsArrayOfDocuments_Count_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Select(x => x.DictionaryAsArrayOfDocuments.Count); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $size : '$DictionaryAsArrayOfDocuments' }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } - var queryable = collection.AsQueryable() - .Select(x => x.DictionaryAsArrayOfDocuments.Count); + [Theory] + [ParameterAttributeData] + public void Select_DictionaryInterface_Count_should_throw( + [Values(false, true)] bool enableClientSideProjections) + { + var collection = Fixture.Collection; + var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $size : '$DictionaryAsArrayOfDocuments' }, _id : 0 } }"); + var queryable = collection.AsQueryable(translationOptions) + .Select(x => x.DictionaryInterface.Count); + + if (enableClientSideProjections) + { + var stages = Translate(collection, queryable, out var outputSerializer); + AssertStages(stages, "{ $project : { _snippets : ['$DictionaryInterface'], _id : 0 } }"); + outputSerializer.Should().BeAssignableTo(); var results = queryable.ToList(); results.Should().Equal(1, 2); } - - [Theory] - [ParameterAttributeData] - public void Select_DictionaryInterface_Count_should_throw( - [Values(false, true)] bool enableClientSideProjections) + else { - var collection = Fixture.Collection; - var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; - - var queryable = collection.AsQueryable(translationOptions) - .Select(x => x.DictionaryInterface.Count); - - if (enableClientSideProjections) - { - var stages = Translate(collection, queryable, out var outputSerializer); - AssertStages(stages, "{ $project : { _snippets : ['$DictionaryInterface'], _id : 0 } }"); - outputSerializer.Should().BeAssignableTo(); - - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } - else - { - var exception = Record.Exception(() => Translate(collection, queryable)); - exception.Should().BeOfType(); - exception.Message.Should().Contain("is not represented as an array"); - } + var exception = Record.Exception(() => Translate(collection, queryable)); + exception.Should().BeOfType(); + exception.Message.Should().Contain("is not represented as an array"); } + } - [Fact] - public void Select_DictionaryInterfaceAsArrayOfArrays_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Select_DictionaryInterfaceAsArrayOfArrays_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Select(x => x.DictionaryInterfaceAsArrayOfArrays.Count); + var queryable = collection.AsQueryable() + .Select(x => x.DictionaryInterfaceAsArrayOfArrays.Count); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $size : '$DictionaryInterfaceAsArrayOfArrays' }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $size : '$DictionaryInterfaceAsArrayOfArrays' }, _id : 0 } }"); - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } - [Fact] - public void Select_DictionaryInterfaceAsArrayOfDocuments_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Select_DictionaryInterfaceAsArrayOfDocuments_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Select(x => x.DictionaryInterfaceAsArrayOfDocuments.Count); + var queryable = collection.AsQueryable() + .Select(x => x.DictionaryInterfaceAsArrayOfDocuments.Count); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $size : '$DictionaryInterfaceAsArrayOfDocuments' }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $size : '$DictionaryInterfaceAsArrayOfDocuments' }, _id : 0 } }"); - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } - [Fact] - public void Select_List_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Select_List_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Select(x => x.List.Count); + var queryable = collection.AsQueryable() + .Select(x => x.List.Count); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $size : '$List' }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $size : '$List' }, _id : 0 } }"); - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } - [Fact] - public void Select_ListInterface_Count_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Select_ListInterface_Count_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Select(x => x.ListInterface.Count); + var queryable = collection.AsQueryable() + .Select(x => x.ListInterface.Count); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $size : '$ListInterface' }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $size : '$ListInterface' }, _id : 0 } }"); - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } - public class C - { - public int Id { get; set; } - public BitArray BitArray { get; set; } - public int Count { get; set; } - public Dictionary Dictionary { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] public Dictionary DictionaryAsArrayOfArrays { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] public Dictionary DictionaryAsArrayOfDocuments { get; set; } - public IDictionary DictionaryInterface { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] public IDictionary DictionaryInterfaceAsArrayOfArrays { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] public IDictionary DictionaryInterfaceAsArrayOfDocuments { get; set; } - public List List { get; set; } - public IList ListInterface { get; set; } - } + public class C + { + public int Id { get; set; } + public BitArray BitArray { get; set; } + public int Count { get; set; } + public Dictionary Dictionary { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] public Dictionary DictionaryAsArrayOfArrays { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] public Dictionary DictionaryAsArrayOfDocuments { get; set; } + public IDictionary DictionaryInterface { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] public IDictionary DictionaryInterfaceAsArrayOfArrays { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] public IDictionary DictionaryInterfaceAsArrayOfDocuments { get; set; } + public List List { get; set; } + public IList ListInterface { get; set; } + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new C + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, BitArray = new BitArray(length: 1), @@ -411,6 +411,6 @@ public sealed class ClassFixture : MongoCollectionFixture List = new() { 1, 2 }, ListInterface = new List { 1, 2 } } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryContainsKeyEnumKeyTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryContainsKeyEnumKeyTests.cs index 4819250204c..4a1f27b8b9c 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryContainsKeyEnumKeyTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryContainsKeyEnumKeyTests.cs @@ -29,78 +29,78 @@ namespace MongoDB.Driver.Tests.Linq.Integration; public class DictionaryContainsKeyEnumKeyTests : LinqIntegrationTest { static DictionaryContainsKeyEnumKeyTests() + { + BsonClassMap.RegisterClassMap(doc => { - BsonClassMap.RegisterClassMap(doc => - { - doc.AutoMap(); - doc.MapMember(a => a.Languages) - .SetSerializer( - new DictionaryInterfaceImplementerSerializer>( - DictionaryRepresentation.Document, - new EnumSerializer(BsonType.String), - new StringSerializer() - )); - }); - } + doc.AutoMap(); + doc.MapMember(a => a.Languages) + .SetSerializer( + new DictionaryInterfaceImplementerSerializer>( + DictionaryRepresentation.Document, + new EnumSerializer(BsonType.String), + new StringSerializer() + )); + }); + } - public DictionaryContainsKeyEnumKeyTests(ClassFixture fixture) - : base(fixture) - { - } + public DictionaryContainsKeyEnumKeyTests(ClassFixture fixture) + : base(fixture) + { + } - [Fact] - public void Where_with_ContainsKey_should_work() - { - var collection = Fixture.Collection; - var language = LanguageEnum.en; + [Fact] + public void Where_with_ContainsKey_should_work() + { + var collection = Fixture.Collection; + var language = LanguageEnum.en; - var queryable = collection.AsQueryable() - .Where(x => x.Languages.ContainsKey(language)); + var queryable = collection.AsQueryable() + .Where(x => x.Languages.ContainsKey(language)); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'Languages.en' : { $exists : true } } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'Languages.en' : { $exists : true } } }"); - var result = queryable.Single(); - result.Id.Should().Be(1); - } + var result = queryable.Single(); + result.Id.Should().Be(1); + } - [Fact] - public void Select_with_ContainsKey_should_work() - { - var collection = Fixture.Collection; - var language = LanguageEnum.en; + [Fact] + public void Select_with_ContainsKey_should_work() + { + var collection = Fixture.Collection; + var language = LanguageEnum.en; - var queryable = collection.AsQueryable() - .Select(x => x.Languages.ContainsKey(language)); + var queryable = collection.AsQueryable() + .Select(x => x.Languages.ContainsKey(language)); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $ne : [{ $type : '$Languages.en' }, 'missing'] }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $ne : [{ $type : '$Languages.en' }, 'missing'] }, _id : 0 } }"); - var results = queryable.ToList(); - results.Should().Equal(true, false); - } + var results = queryable.ToList(); + results.Should().Equal(true, false); + } - public class Translation - { - public int Id { get; set; } - public Dictionary Languages { get; set; } = new(); - } + public class Translation + { + public int Id { get; set; } + public Dictionary Languages { get; set; } = new(); + } - public enum LanguageEnum - { - en, - nl, - fr, - de, - pl, - } + public enum LanguageEnum + { + en, + nl, + fr, + de, + pl, + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new Translation { Id = 1, Languages = new Dictionary { { LanguageEnum.en, "English" } } }, + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Translation { Id = 1, Languages = new Dictionary { { LanguageEnum.en, "English" } } }, new Translation { Id = 2, Languages = new Dictionary { { LanguageEnum.fr, "French" } } } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryContainsValueTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryContainsValueTests.cs index 93b55176b7c..a084d885669 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryContainsValueTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryContainsValueTests.cs @@ -29,115 +29,115 @@ public class DictionaryContainsValueTests : LinqIntegrationTest x.D1.ContainsValue(1)); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { $expr : { $reduce : { input : { $objectToArray : '$D1' }, initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : ['$$this.v', 1] } } } } } } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1, 2); - } - - [Fact] - public void Where_ContainsValue_should_work_when_representation_is_ArrayOfArrays() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Where(x => x.D2.ContainsValue(1)); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { $expr : { $reduce : { input : '$D2', initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : [{ $arrayElemAt : ['$$this', 1] }, 1] } } } } } } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1, 2); - } - - [Fact] - public void Where_ContainsValue_should_work_when_representation_is_ArrayOfDocuments() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Where(x => x.D3.ContainsValue(1)); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { D3 : { $elemMatch : { v : 1 } } } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1, 2); - } - - [Fact] - public void Select_ContainsValue_should_work_when_representation_is_Dictionary() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Select(x => x.D1.ContainsValue(1)); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $reduce : { input : { $objectToArray : '$D1' }, initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : ['$$this.v', 1] } } } } }, _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(true, true, false); - } - - [Fact] - public void Select_ContainsValue_should_work_when_representation_is_ArrayOfArrays() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Select(x => x.D2.ContainsValue(1)); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $reduce : { input : '$D2', initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : [{ $arrayElemAt : ['$$this', 1] }, 1] } } } } }, _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(true, true, false); - } - - [Fact] - public void Select_ContainsValue_should_work_when_representation_is_ArrayOfDocuments() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Select(x => x.D3.ContainsValue(1)); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $reduce : { input : '$D3', initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : ['$$this.v', 1] } } } } }, _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(true, true, false); - } - - public class User - { - public int Id { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.Document)] - public Dictionary D1 { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] - public Dictionary D2 { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] - public Dictionary D3 { get; set; } - } - - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new User + [Fact] + public void Where_ContainsValue_should_work_when_representation_is_Dictionary() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Where(x => x.D1.ContainsValue(1)); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { $expr : { $reduce : { input : { $objectToArray : '$D1' }, initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : ['$$this.v', 1] } } } } } } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1, 2); + } + + [Fact] + public void Where_ContainsValue_should_work_when_representation_is_ArrayOfArrays() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Where(x => x.D2.ContainsValue(1)); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { $expr : { $reduce : { input : '$D2', initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : [{ $arrayElemAt : ['$$this', 1] }, 1] } } } } } } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1, 2); + } + + [Fact] + public void Where_ContainsValue_should_work_when_representation_is_ArrayOfDocuments() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Where(x => x.D3.ContainsValue(1)); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { D3 : { $elemMatch : { v : 1 } } } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1, 2); + } + + [Fact] + public void Select_ContainsValue_should_work_when_representation_is_Dictionary() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Select(x => x.D1.ContainsValue(1)); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $reduce : { input : { $objectToArray : '$D1' }, initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : ['$$this.v', 1] } } } } }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(true, true, false); + } + + [Fact] + public void Select_ContainsValue_should_work_when_representation_is_ArrayOfArrays() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Select(x => x.D2.ContainsValue(1)); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $reduce : { input : '$D2', initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : [{ $arrayElemAt : ['$$this', 1] }, 1] } } } } }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(true, true, false); + } + + [Fact] + public void Select_ContainsValue_should_work_when_representation_is_ArrayOfDocuments() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Select(x => x.D3.ContainsValue(1)); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $reduce : { input : '$D3', initialValue : false, in : { $cond : { if : '$$value', then : true, else : { $eq : ['$$this.v', 1] } } } } }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(true, true, false); + } + + public class User + { + public int Id { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.Document)] + public Dictionary D1 { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] + public Dictionary D2 { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] + public Dictionary D3 { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new User { Id = 1, D1 = new() { { "A", 1 }, { "B", 2 } }, @@ -158,6 +158,6 @@ public sealed class ClassFixture : MongoCollectionFixture D2 = new() { { "A", 2 }, { "B", 3 } }, D3 = new() { { "A", 2 }, { "B", 3 } } } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryDocumentAndListIndexerSelectAndWhereTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryDocumentAndListIndexerSelectAndWhereTests.cs index 18c98571db5..11595734b7d 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryDocumentAndListIndexerSelectAndWhereTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/DictionaryDocumentAndListIndexerSelectAndWhereTests.cs @@ -29,511 +29,511 @@ public class DictionaryDocumentAndListIndexerSelectAndWhereTests : LinqIntegrati { public DictionaryDocumentAndListIndexerSelectAndWhereTests(ClassFixture fixture) : base(fixture) - { - } - - [Fact] - public void Select_Dictionary_item_with_string_using_compiler_generated_expression_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Select(x => x.Dictionary["a"]); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : '$Dictionary.a', _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(1, 0); - } - - [Fact] - public void Select_Dictionary_item_with_string_using_call_to_get_item_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Call( + { + } + + [Fact] + public void Select_Dictionary_item_with_string_using_compiler_generated_expression_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Select(x => x.Dictionary["a"]); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : '$Dictionary.a', _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 0); + } + + [Fact] + public void Select_Dictionary_item_with_string_using_call_to_get_item_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Call( + Expression.Property(x, typeof(C).GetProperty("Dictionary")), + typeof(IDictionary).GetProperty("Item").GetGetMethod(), + Expression.Constant("a")); + var parameters = new ParameterExpression[] { x }; + var selector = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Select(selector); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : '$Dictionary.a', _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 0); + } + + [Fact] + public void Select_Dictionary_item_with_string_using_MakeIndex_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.MakeIndex( + Expression.Property(x, typeof(C).GetProperty("Dictionary")), + typeof(IDictionary).GetProperty("Item"), + new Expression[] { Expression.Constant("a") }); + var parameters = new ParameterExpression[] { x }; + var selector = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Select(selector); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : '$Dictionary.a', _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 0); + } + + [Fact] + public void Select_Document_item_with_int_using_compiler_generated_expression_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Select(x => x.Document[0]); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } + + [Fact] + public void Select_Document_item_with_int_using_call_to_get_item_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Call( + Expression.Property(x, typeof(C).GetProperty("Document")), + typeof(BsonDocument).GetProperty("Item", new[] { typeof(int) }).GetGetMethod(), + Expression.Constant(0)); + var parameters = new ParameterExpression[] { x }; + var selector = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Select(selector); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } + + [Fact] + public void Select_Document_item_with_int_using_MakeIndex_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.MakeIndex( + Expression.Property(x, typeof(C).GetProperty("Document")), + typeof(BsonDocument).GetProperty("Item", new[] { typeof(int) }), + new Expression[] { Expression.Constant(0) }); + var parameters = new ParameterExpression[] { x }; + var selector = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Select(selector); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } + + [Fact] + public void Select_Document_item_with_string_using_compiler_generated_expression_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Select(x => x.Document["a"]); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : '$Document.a', _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, null); + } + + [Fact] + public void Select_Document_item_with_string_using_call_to_get_item_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Call( + Expression.Property(x, typeof(C).GetProperty("Document")), + typeof(BsonDocument).GetProperty("Item", new[] { typeof(string) }).GetGetMethod(), + Expression.Constant("a")); + var parameters = new ParameterExpression[] { x }; + var selector = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Select(selector); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : '$Document.a', _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, null); + } + + [Fact] + public void Select_Document_item_with_string_using_MakeIndex_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.MakeIndex( + Expression.Property(x, typeof(C).GetProperty("Document")), + typeof(BsonDocument).GetProperty("Item", new[] { typeof(string) }), + new Expression[] { Expression.Constant("a") }); + var parameters = new ParameterExpression[] { x }; + var selector = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Select(selector); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : '$Document.a', _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, null); + } + + [Fact] + public void Select_List_item_with_int_using_compiler_generated_expression_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Select(x => x.List[0]); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $arrayElemAt : ['$List', 0] }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } + + [Fact] + public void Select_List_item_with_int_using_call_to_get_item_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Call( + Expression.Property(x, typeof(C).GetProperty("List")), + typeof(IList).GetProperty("Item", new[] { typeof(int) }).GetGetMethod(), + Expression.Constant(0)); + var parameters = new ParameterExpression[] { x }; + var selector = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Select(selector); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $arrayElemAt : ['$List', 0] }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } + + [Fact] + public void Select_List_item_with_int_using_MakeIndex_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.MakeIndex( + Expression.Property(x, typeof(C).GetProperty("List")), + typeof(IList).GetProperty("Item", new[] { typeof(int) }), + new Expression[] { Expression.Constant(0) }); + var parameters = new ParameterExpression[] { x }; + var selector = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Select(selector); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $arrayElemAt : ['$List', 0] }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(1, 2); + } + + [Fact] + public void Where_Dictionary_item_with_string_using_compiler_generated_expression_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .Where(x => x.Dictionary["a"] == 1); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'Dictionary.a' : 1 } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + [Fact] + public void Where_Dictionary_item_with_string_using_call_to_get_item_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Equal( + Expression.Call( Expression.Property(x, typeof(C).GetProperty("Dictionary")), typeof(IDictionary).GetProperty("Item").GetGetMethod(), - Expression.Constant("a")); - var parameters = new ParameterExpression[] { x }; - var selector = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Select(selector); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : '$Dictionary.a', _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(1, 0); - } - - [Fact] - public void Select_Dictionary_item_with_string_using_MakeIndex_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.MakeIndex( + Expression.Constant("a")), + Expression.Constant(1)); + var parameters = new ParameterExpression[] { x }; + var predicate = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Where(predicate); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'Dictionary.a' : 1 } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + [Fact] + public void Where_Dictionary_item_with_string_using_MakeIndex_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Equal( + Expression.MakeIndex( Expression.Property(x, typeof(C).GetProperty("Dictionary")), typeof(IDictionary).GetProperty("Item"), - new Expression[] { Expression.Constant("a") }); - var parameters = new ParameterExpression[] { x }; - var selector = Expression.Lambda>(body, parameters); + new Expression[] { Expression.Constant("a") }), + Expression.Constant(1)); + var parameters = new ParameterExpression[] { x }; + var predicate = Expression.Lambda>(body, parameters); - var queryable = collection.AsQueryable() - .Select(selector); + var queryable = collection.AsQueryable() + .Where(predicate); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : '$Dictionary.a', _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'Dictionary.a' : 1 } }"); - var results = queryable.ToList(); - results.Should().Equal(1, 0); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Select_Document_item_with_int_using_compiler_generated_expression_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_Document_item_with_int_using_compiler_generated_expression_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Select(x => x.Document[0]); + var queryable = collection.AsQueryable() + .Where(x => x.Document[0] == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { $expr : { $eq : [{ $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, 1] } } }"); - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Select_Document_item_with_int_using_call_to_get_item_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Call( + [Fact] + public void Where_Document_item_with_int_using_call_to_get_item_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Equal( + Expression.Call( Expression.Property(x, typeof(C).GetProperty("Document")), typeof(BsonDocument).GetProperty("Item", new[] { typeof(int) }).GetGetMethod(), - Expression.Constant(0)); - var parameters = new ParameterExpression[] { x }; - var selector = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Select(selector); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } - - [Fact] - public void Select_Document_item_with_int_using_MakeIndex_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.MakeIndex( + Expression.Constant(0)), + Expression.Constant(BsonValue.Create(1), typeof(BsonValue))); + var parameters = new ParameterExpression[] { x }; + var predicate = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Where(predicate); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { $expr : { $eq : [{ $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, 1] } } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + [Fact] + public void Where_Document_item_with_int_using_MakeIndex_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Equal( + Expression.MakeIndex( Expression.Property(x, typeof(C).GetProperty("Document")), typeof(BsonDocument).GetProperty("Item", new[] { typeof(int) }), - new Expression[] { Expression.Constant(0) }); - var parameters = new ParameterExpression[] { x }; - var selector = Expression.Lambda>(body, parameters); + new Expression[] { Expression.Constant(0) }), + Expression.Constant(BsonValue.Create(1), typeof(BsonValue))); + var parameters = new ParameterExpression[] { x }; + var predicate = Expression.Lambda>(body, parameters); - var queryable = collection.AsQueryable() - .Select(selector); + var queryable = collection.AsQueryable() + .Where(predicate); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { $expr : { $eq : [{ $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, 1] } } }"); - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Select_Document_item_with_string_using_compiler_generated_expression_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_Document_item_with_string_using_compiler_generated_expression_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Select(x => x.Document["a"]); + var queryable = collection.AsQueryable() + .Where(x => x.Document["a"] == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : '$Document.a', _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'Document.a' : 1 } }"); - var results = queryable.ToList(); - results.Should().Equal(1, null); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Select_Document_item_with_string_using_call_to_get_item_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Call( + [Fact] + public void Where_Document_item_with_string_using_call_to_get_item_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Equal( + Expression.Call( Expression.Property(x, typeof(C).GetProperty("Document")), typeof(BsonDocument).GetProperty("Item", new[] { typeof(string) }).GetGetMethod(), - Expression.Constant("a")); - var parameters = new ParameterExpression[] { x }; - var selector = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Select(selector); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : '$Document.a', _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(1, null); - } - - [Fact] - public void Select_Document_item_with_string_using_MakeIndex_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.MakeIndex( + Expression.Constant("a")), + Expression.Constant(BsonValue.Create(1), typeof(BsonValue))); + var parameters = new ParameterExpression[] { x }; + var predicate = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Where(predicate); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'Document.a' : 1 } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + [Fact] + public void Where_Document_item_with_string_using_MakeIndex_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Equal( + Expression.MakeIndex( Expression.Property(x, typeof(C).GetProperty("Document")), typeof(BsonDocument).GetProperty("Item", new[] { typeof(string) }), - new Expression[] { Expression.Constant("a") }); - var parameters = new ParameterExpression[] { x }; - var selector = Expression.Lambda>(body, parameters); + new Expression[] { Expression.Constant("a") }), + Expression.Constant(BsonValue.Create(1), typeof(BsonValue))); + var parameters = new ParameterExpression[] { x }; + var predicate = Expression.Lambda>(body, parameters); - var queryable = collection.AsQueryable() - .Select(selector); + var queryable = collection.AsQueryable() + .Where(predicate); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : '$Document.a', _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'Document.a' : 1 } }"); - var results = queryable.ToList(); - results.Should().Equal(1, null); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Select_List_item_with_int_using_compiler_generated_expression_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_List_item_with_int_using_compiler_generated_expression_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Select(x => x.List[0]); + var queryable = collection.AsQueryable() + .Where(x => x.List[0] == 1); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $arrayElemAt : ['$List', 0] }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'List.0' : 1 } }"); - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Select_List_item_with_int_using_call_to_get_item_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Call( + [Fact] + public void Where_List_item_with_int_using_call_to_get_item_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Equal( + Expression.Call( Expression.Property(x, typeof(C).GetProperty("List")), typeof(IList).GetProperty("Item", new[] { typeof(int) }).GetGetMethod(), - Expression.Constant(0)); - var parameters = new ParameterExpression[] { x }; - var selector = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Select(selector); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $arrayElemAt : ['$List', 0] }, _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } - - [Fact] - public void Select_List_item_with_int_using_MakeIndex_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.MakeIndex( + Expression.Constant(0)), + Expression.Constant(1)); + var parameters = new ParameterExpression[] { x }; + var predicate = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Where(predicate); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'List.0' : 1 } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + [Fact] + public void Where_List_item_with_int_using_MakeIndex_should_work() + { + var collection = Fixture.Collection; + var x = Expression.Parameter(typeof(C), "x"); + var body = Expression.Equal( + Expression.MakeIndex( Expression.Property(x, typeof(C).GetProperty("List")), typeof(IList).GetProperty("Item", new[] { typeof(int) }), - new Expression[] { Expression.Constant(0) }); - var parameters = new ParameterExpression[] { x }; - var selector = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Select(selector); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $arrayElemAt : ['$List', 0] }, _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(1, 2); - } - - [Fact] - public void Where_Dictionary_item_with_string_using_compiler_generated_expression_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Where(x => x.Dictionary["a"] == 1); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'Dictionary.a' : 1 } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_Dictionary_item_with_string_using_call_to_get_item_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Equal( - Expression.Call( - Expression.Property(x, typeof(C).GetProperty("Dictionary")), - typeof(IDictionary).GetProperty("Item").GetGetMethod(), - Expression.Constant("a")), - Expression.Constant(1)); - var parameters = new ParameterExpression[] { x }; - var predicate = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Where(predicate); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'Dictionary.a' : 1 } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_Dictionary_item_with_string_using_MakeIndex_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Equal( - Expression.MakeIndex( - Expression.Property(x, typeof(C).GetProperty("Dictionary")), - typeof(IDictionary).GetProperty("Item"), - new Expression[] { Expression.Constant("a") }), - Expression.Constant(1)); - var parameters = new ParameterExpression[] { x }; - var predicate = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Where(predicate); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'Dictionary.a' : 1 } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_Document_item_with_int_using_compiler_generated_expression_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Where(x => x.Document[0] == 1); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { $expr : { $eq : [{ $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, 1] } } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_Document_item_with_int_using_call_to_get_item_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Equal( - Expression.Call( - Expression.Property(x, typeof(C).GetProperty("Document")), - typeof(BsonDocument).GetProperty("Item", new[] { typeof(int) }).GetGetMethod(), - Expression.Constant(0)), - Expression.Constant(BsonValue.Create(1), typeof(BsonValue))); - var parameters = new ParameterExpression[] { x }; - var predicate = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Where(predicate); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { $expr : { $eq : [{ $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, 1] } } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_Document_item_with_int_using_MakeIndex_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Equal( - Expression.MakeIndex( - Expression.Property(x, typeof(C).GetProperty("Document")), - typeof(BsonDocument).GetProperty("Item", new[] { typeof(int) }), - new Expression[] { Expression.Constant(0) }), - Expression.Constant(BsonValue.Create(1), typeof(BsonValue))); - var parameters = new ParameterExpression[] { x }; - var predicate = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Where(predicate); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { $expr : { $eq : [{ $let : { vars : { this : { $arrayElemAt : [{ $objectToArray : '$Document' }, 0] } }, in : '$$this.v' } }, 1] } } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_Document_item_with_string_using_compiler_generated_expression_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Where(x => x.Document["a"] == 1); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'Document.a' : 1 } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_Document_item_with_string_using_call_to_get_item_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Equal( - Expression.Call( - Expression.Property(x, typeof(C).GetProperty("Document")), - typeof(BsonDocument).GetProperty("Item", new[] { typeof(string) }).GetGetMethod(), - Expression.Constant("a")), - Expression.Constant(BsonValue.Create(1), typeof(BsonValue))); - var parameters = new ParameterExpression[] { x }; - var predicate = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Where(predicate); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'Document.a' : 1 } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_Document_item_with_string_using_MakeIndex_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Equal( - Expression.MakeIndex( - Expression.Property(x, typeof(C).GetProperty("Document")), - typeof(BsonDocument).GetProperty("Item", new[] { typeof(string) }), - new Expression[] { Expression.Constant("a") }), - Expression.Constant(BsonValue.Create(1), typeof(BsonValue))); - var parameters = new ParameterExpression[] { x }; - var predicate = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Where(predicate); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'Document.a' : 1 } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_List_item_with_int_using_compiler_generated_expression_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .Where(x => x.List[0] == 1); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'List.0' : 1 } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_List_item_with_int_using_call_to_get_item_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Equal( - Expression.Call( - Expression.Property(x, typeof(C).GetProperty("List")), - typeof(IList).GetProperty("Item", new[] { typeof(int) }).GetGetMethod(), - Expression.Constant(0)), - Expression.Constant(1)); - var parameters = new ParameterExpression[] { x }; - var predicate = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Where(predicate); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'List.0' : 1 } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_List_item_with_int_using_MakeIndex_should_work() - { - var collection = Fixture.Collection; - var x = Expression.Parameter(typeof(C), "x"); - var body = Expression.Equal( - Expression.MakeIndex( - Expression.Property(x, typeof(C).GetProperty("List")), - typeof(IList).GetProperty("Item", new[] { typeof(int) }), - new Expression[] { Expression.Constant(0) }), - Expression.Constant(1)); - var parameters = new ParameterExpression[] { x }; - var predicate = Expression.Lambda>(body, parameters); - - var queryable = collection.AsQueryable() - .Where(predicate); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { 'List.0' : 1 } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - public class C - { - public int Id { get; set; } - public IDictionary Dictionary { get; set; } - public BsonDocument Document { get; set; } - public IList List { get; set; } - } - - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new C { Id = 1, Dictionary = new Dictionary { ["a"] = 1 }, Document = new BsonDocument("a", 1), List = new List { 1 } }, + new Expression[] { Expression.Constant(0) }), + Expression.Constant(1)); + var parameters = new ParameterExpression[] { x }; + var predicate = Expression.Lambda>(body, parameters); + + var queryable = collection.AsQueryable() + .Where(predicate); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { 'List.0' : 1 } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + public class C + { + public int Id { get; set; } + public IDictionary Dictionary { get; set; } + public BsonDocument Document { get; set; } + public IList List { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, Dictionary = new Dictionary { ["a"] = 1 }, Document = new BsonDocument("a", 1), List = new List { 1 } }, new C { Id = 2, Dictionary = new Dictionary { ["b"] = 2 }, Document = new BsonDocument("b", 2), List = new List { 2 } } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/EnumEqualityAndNumericCastWhereSelectTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/EnumEqualityAndNumericCastWhereSelectTests.cs index dc71d53614b..a2879348c4e 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/EnumEqualityAndNumericCastWhereSelectTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/EnumEqualityAndNumericCastWhereSelectTests.cs @@ -28,75 +28,75 @@ public class EnumEqualityAndNumericCastWhereSelectTests : LinqIntegrationTest x.Status == Status.Open); + var queryable = collection.AsQueryable() + .Where(x => x.Status == Status.Open); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { Status : 1 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { Status : 1 } }"); - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } - [Fact] - public void Select_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Select_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Select(x => new { Result = (int)x.Version }); + var queryable = collection.AsQueryable() + .Select(x => new { Result = (int)x.Version }); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { Result : { $toInt : '$Version' }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { Result : { $toInt : '$Version' }, _id : 0 } }"); - var results = queryable.ToList(); - results.Select(x => x.Result).Should().Equal(1, 2); - } + var results = queryable.ToList(); + results.Select(x => x.Result).Should().Equal(1, 2); + } - [Fact] - public void Where_followed_by_Select_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Where_followed_by_Select_should_work() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .Where(x => x.Status == Status.Open) - .Select(x => new { Result = (int)x.Version }); + var queryable = collection.AsQueryable() + .Where(x => x.Status == Status.Open) + .Select(x => new { Result = (int)x.Version }); - var stages = Translate(collection, queryable); - AssertStages( - stages, - "{ $match : { Status : 1 } }", - "{ $project : { Result : { $toInt : '$Version' }, _id : 0 } }"); + var stages = Translate(collection, queryable); + AssertStages( + stages, + "{ $match : { Status : 1 } }", + "{ $project : { Result : { $toInt : '$Version' }, _id : 0 } }"); - var results = queryable.ToList(); - results.Select(x => x.Result).Should().Equal(1); - } + var results = queryable.ToList(); + results.Select(x => x.Result).Should().Equal(1); + } - public class C - { - public int Id { get; set; } - public Status Status { get; set; } - public long Version { get; set; } - } + public class C + { + public int Id { get; set; } + public Status Status { get; set; } + public long Version { get; set; } + } #pragma warning disable CA1717 // Only FlagsAttribute enums should have plural names - public enum Status { Closed, Open }; + public enum Status { Closed, Open }; #pragma warning restore CA1717 // Only FlagsAttribute enums should have plural names - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new C { Id = 1, Status = Status.Open, Version = 1L }, + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, Status = Status.Open, Version = 1L }, new C { Id = 2, Status = Status.Closed, Version = 2L } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/FilterLtDateTimeStringTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/FilterLtDateTimeStringTests.cs index d61867ef0b2..07477eceddd 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/FilterLtDateTimeStringTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/FilterLtDateTimeStringTests.cs @@ -28,38 +28,38 @@ public class FilterLtDateTimeStringTests : LinqIntegrationTest> field = x => x.CreationDate; - var myValue = "2023-04-13T01:02:03Z"; - var filter = Builders.Filter.Lt(field, myValue); + [Fact] + public void Project_dictionary_value_should_work() + { + var collection = Fixture.Collection; + Expression> field = x => x.CreationDate; + var myValue = "2023-04-13T01:02:03Z"; + var filter = Builders.Filter.Lt(field, myValue); - var find = collection.Find(filter); + var find = collection.Find(filter); - var translatedFilter = TranslateFilter(collection, filter); - translatedFilter.Should().Be("{ CreationDate : { $lt : ISODate('2023-04-13T01:02:03Z') } }"); + var translatedFilter = TranslateFilter(collection, filter); + translatedFilter.Should().Be("{ CreationDate : { $lt : ISODate('2023-04-13T01:02:03Z') } }"); - var results = find.ToList(); - results.Select(r => r.Id).Should().Equal(1); - } + var results = find.ToList(); + results.Select(r => r.Id).Should().Equal(1); + } - public class MeasurementDetails - { - public int Id { get; set; } - public DateTime CreationDate { get; set; } - } + public class MeasurementDetails + { + public int Id { get; set; } + public DateTime CreationDate { get; set; } + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new MeasurementDetails { Id = 1, CreationDate = new DateTime(2023, 04, 13, 1, 2, 2, DateTimeKind.Utc) }, + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new MeasurementDetails { Id = 1, CreationDate = new DateTime(2023, 04, 13, 1, 2, 2, DateTimeKind.Utc) }, new MeasurementDetails { Id = 2, CreationDate = new DateTime(2023, 04, 13, 1, 2, 3, DateTimeKind.Utc) } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/FilterStartsWithPartialEvaluationDeleteTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/FilterStartsWithPartialEvaluationDeleteTests.cs index 4082fc447ad..afb1584dc78 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/FilterStartsWithPartialEvaluationDeleteTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/FilterStartsWithPartialEvaluationDeleteTests.cs @@ -25,34 +25,34 @@ public class FilterStartsWithPartialEvaluationDeleteTests : LinqIntegrationTest< { public FilterStartsWithPartialEvaluationDeleteTests(ClassFixture fixture) : base(fixture) - { - } - - [Fact] - public void Filter_expression_needing_partial_evaluation_should_work() - { - var collection = Fixture.Collection; - - var param = "A"; - var result = collection.DeleteMany(mvi => mvi.Description.StartsWith(string.Format("{0}", param))); - - result.DeletedCount.Should().Be(2); - } - - public class Entity - { - public int Id { get; set; } - public string Description { get; set; } - } - - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new Entity { Id = 1, Description = "Alpha" }, + { + } + + [Fact] + public void Filter_expression_needing_partial_evaluation_should_work() + { + var collection = Fixture.Collection; + + var param = "A"; + var result = collection.DeleteMany(mvi => mvi.Description.StartsWith(string.Format("{0}", param))); + + result.DeletedCount.Should().Be(2); + } + + public class Entity + { + public int Id { get; set; } + public string Description { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Entity { Id = 1, Description = "Alpha" }, new Entity { Id = 2, Description = "Alpha2" }, new Entity { Id = 3, Description = "Bravo" }, new Entity { Id = 4, Description = "Charlie" } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/FindFilterAndProjectionWithFirstOverArrayTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/FindFilterAndProjectionWithFirstOverArrayTests.cs index ed72a765796..0adb998f3cf 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/FindFilterAndProjectionWithFirstOverArrayTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/FindFilterAndProjectionWithFirstOverArrayTests.cs @@ -65,7 +65,7 @@ public void Projection_should_translate_correctly() chain.Parts .First(p => p.Refs.Any(j => jobIds.Contains(j.id))) .Refs.First(j => jobIds.Contains(j.id)).id - });; + }); ; var projectionTranslation = TranslateFindProjection(collection, find); diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/FindOneAndModifyExpressionProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/FindOneAndModifyExpressionProjectionTests.cs index 7d5efdf49d0..f8931a27638 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/FindOneAndModifyExpressionProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/FindOneAndModifyExpressionProjectionTests.cs @@ -25,71 +25,71 @@ public class FindOneAndModifyExpressionProjectionTests : LinqIntegrationTest.Update.Set("Value", "updated"); - var options = new FindOneAndUpdateOptions - { - Projection = Builders.Projection.Expression(x => x) - }; + var update = Builders.Update.Set("Value", "updated"); + var options = new FindOneAndUpdateOptions + { + Projection = Builders.Projection.Expression(x => x) + }; - var result = collection.FindOneAndUpdate(x => x.Id == 1, update, options); + var result = collection.FindOneAndUpdate(x => x.Id == 1, update, options); - result.Id.Should().Be(1); - result.Value.Should().Be("1"); - } + result.Id.Should().Be(1); + result.Value.Should().Be("1"); + } - [Fact] - public void Find_projection_in_findoneandreplace_should_work() + [Fact] + public void Find_projection_in_findoneandreplace_should_work() + { + var collection = Fixture.Collection; + var options = new FindOneAndReplaceOptions { - var collection = Fixture.Collection; - var options = new FindOneAndReplaceOptions - { - Projection = Builders.Projection.Expression(x => x) - }; + Projection = Builders.Projection.Expression(x => x) + }; + + var result = collection.FindOneAndReplace(x => x.Id == 1, new A { Id = 1, Value = "updated" }, options); - var result = collection.FindOneAndReplace(x => x.Id == 1, new A { Id = 1, Value = "updated" }, options); + result.Id.Should().Be(1); + result.Value.Should().Be("1"); + } - result.Id.Should().Be(1); - result.Value.Should().Be("1"); - } + [Fact] + public void Find_projection_in_findoneanddelete_should_work() + { + var collection = Fixture.Collection; - [Fact] - public void Find_projection_in_findoneanddelete_should_work() + var options = new FindOneAndDeleteOptions { - var collection = Fixture.Collection; - - var options = new FindOneAndDeleteOptions - { - Projection = Builders.Projection.Expression(x => x), - }; + Projection = Builders.Projection.Expression(x => x), + }; - var result = collection.FindOneAndDelete(x => x.Id == 1, options); + var result = collection.FindOneAndDelete(x => x.Id == 1, options); - result.Id.Should().Be(1); - result.Value.Should().Be("1"); - } + result.Id.Should().Be(1); + result.Value.Should().Be("1"); + } - public class A - { - public int Id { get; set; } + public class A + { + public int Id { get; set; } - public string Value { get; set; } - } + public string Value { get; set; } + } - public sealed class ClassFixture : MongoCollectionFixture - { - public override bool InitializeDataBeforeEachTestCase => true; + public sealed class ClassFixture : MongoCollectionFixture + { + public override bool InitializeDataBeforeEachTestCase => true; - protected override IEnumerable InitialData => - [ - new A { Id = 1, Value = "1" } - ]; - } + protected override IEnumerable InitialData => + [ + new A { Id = 1, Value = "1" } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectScalarFieldTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectScalarFieldTests.cs index 7f02bed7e94..30722d974da 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectScalarFieldTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectScalarFieldTests.cs @@ -25,52 +25,52 @@ public class FindProjectScalarFieldTests : LinqIntegrationTest true) - .Project(x => x.Id); + var find = collection + .Find(_ => true) + .Project(x => x.Id); - var projection = TranslateFindProjection(collection, find); - projection.Should().Be("{ _id : 1 }"); + var projection = TranslateFindProjection(collection, find); + projection.Should().Be("{ _id : 1 }"); - var result = find.Single(); - result.Should().Be(1); - } + var result = find.Single(); + result.Should().Be(1); + } - [Fact] - public void Find_project_field_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Find_project_field_should_work() + { + var collection = Fixture.Collection; - var find = collection - .Find(_ => true) - .Project(x => x.X); + var find = collection + .Find(_ => true) + .Project(x => x.X); - var projection = TranslateFindProjection(collection, find); - projection.Should().Be("{ X : 1, _id : 0 }"); + var projection = TranslateFindProjection(collection, find); + projection.Should().Be("{ X : 1, _id : 0 }"); - var result = find.Single(); - result.Should().Be(2); - } + var result = find.Single(); + result.Should().Be(2); + } - public class C - { - public int Id { get; set; } - public int X { get; set; } - } + public class C + { + public int Id { get; set; } + public int X { get; set; } + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new C { Id = 1, X = 2 } - ]; - } + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, X = 2 } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectSubDocumentIdTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectSubDocumentIdTests.cs index 793729ac278..3775c9596b0 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectSubDocumentIdTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectSubDocumentIdTests.cs @@ -25,41 +25,41 @@ public class FindProjectSubDocumentIdTests : LinqIntegrationTest d.Status == "a").Project(d => d.SubDocument.Id); + var find = collection.Find(d => d.Status == "a").Project(d => d.SubDocument.Id); - var projection = TranslateFindProjection(collection, find); - projection.Should().Be("{ 'SubDocument._id' : 1, _id : 0 }"); + var projection = TranslateFindProjection(collection, find); + projection.Should().Be("{ 'SubDocument._id' : 1, _id : 0 }"); - var result = find.Single(); - result.Should().Be(11); - } + var result = find.Single(); + result.Should().Be(11); + } - public class Document - { - public int Id { get; set; } - public string Status { get; set; } - public SubDocument SubDocument { get; set; } - } + public class Document + { + public int Id { get; set; } + public string Status { get; set; } + public SubDocument SubDocument { get; set; } + } - public class SubDocument - { - public int Id { get; set; } - } + public class SubDocument + { + public int Id { get; set; } + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new Document { Id = 1, Status = "a", SubDocument = new SubDocument { Id = 11 } }, + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Document { Id = 1, Status = "a", SubDocument = new SubDocument { Id = 11 } }, new Document { Id = 2, Status = "b", SubDocument = new SubDocument { Id = 22 } } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectionRenderTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectionRenderTests.cs index 05c750f7156..62fc24e4c90 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectionRenderTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/FindProjectionRenderTests.cs @@ -26,35 +26,35 @@ public class FindProjectionRenderTests : LinqIntegrationTest a.Id == "1").Project(a => a.Id); - - var documentSerializer = collection.DocumentSerializer; - var serializerRegistry = BsonSerializer.SerializerRegistry; - var renderedProjection = fluentFind.Options.Projection.Render(new(documentSerializer, serializerRegistry)); - - var result = fluentFind.Single(); - result.Should().Be("1"); - } - - public class A - { - public string Id { get; set; } - } - - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new A { Id = "1" }, + { + } + + [Fact] + public void Find_projection_render_should_work() + { + var collection = Fixture.Collection; + + var fluentFind = collection.Find(a => a.Id == "1").Project(a => a.Id); + + var documentSerializer = collection.DocumentSerializer; + var serializerRegistry = BsonSerializer.SerializerRegistry; + var renderedProjection = fluentFind.Options.Projection.Render(new(documentSerializer, serializerRegistry)); + + var result = fluentFind.Single(); + result.Should().Be("1"); + } + + public class A + { + public string Id { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new A { Id = "1" }, new A { Id = "2" } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/FindWithRawStringProjectionResultsTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/FindWithRawStringProjectionResultsTests.cs index 77ffcc0ea09..2508649f391 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/FindWithRawStringProjectionResultsTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/FindWithRawStringProjectionResultsTests.cs @@ -24,150 +24,150 @@ namespace MongoDB.Driver.Tests.Linq.Integration; // Regression test for CSHARP-4734. public class FindWithRawStringProjectionResultsTests : Linq3IntegrationTest { - [Theory] - [InlineData("{ X : false }", "{ _id : 1 }")] - [InlineData("{ X : true }", "{ _id : 1, X : 2 }")] - [InlineData("{ X : 0 }", "{ _id : 1 }")] - [InlineData("{ X : 1 }", "{ _id : 1, X : 2 }")] - [InlineData("{ X : -1 }", "{ _id : 1, X : 2 }")] - [InlineData("{ X : { $numberLong : 0 } }", "{ _id : 1 }")] - [InlineData("{ X : { $numberLong : 1 } }", "{ _id : 1, X : 2 }")] - [InlineData("{ X : { $numberLong : -1 } }", "{ _id : 1, X : 2 }")] - [InlineData("{ X : 0.0 }", "{ _id : 1 }")] - [InlineData("{ X : 1.0 }", "{ _id : 1, X : 2 }")] - [InlineData("{ X : -1.0 }", "{ _id : 1, X : 2 }")] - public void Find_with_projections_that_should_work_on_all_server_versions(string projection, string expectedResult) - { - var collection = GetCollection("{ _id : 1, X : 2 }"); - - var find = collection - .Find("{}") - .Project(projection); - - var result = find.Single(); - result.Should().Be(expectedResult); - } - - [Theory] - [InlineData("{}", "{ A : { $slice : 2 } }", "{ _id : 1, A : [1, 2] }")] - [InlineData("{}", "{ A : { $slice : -2 } }", "{ _id : 1, A : [2, 3] }")] - [InlineData("{}", "{ A : { $slice : [1, 2] } }", "{ _id : 1, A : [2, 3] }")] - [InlineData("{}", "{ A : { $slice : [-3, 2] } }", "{ _id : 1, A : [1, 2] }")] - [InlineData("{}", "{ A : { $elemMatch : { $gt : 1 } } }", "{ _id : 1, A : [2] }")] - [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : true }", "{ _id : 1, A : [2] }")] - [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : 1 }", "{ _id : 1, A : [2] }")] - [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : -1 }", "{ _id : 1, A : [2] }")] - [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : { $numberLong : 1 } }", "{ _id : 1, A : [2] }")] - [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : { $numberLong : -1 } }", "{ _id : 1, A : [2] }")] - [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : 1.0 }", "{ _id : 1, A : [2] }")] - [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : -1.0 }", "{ _id : 1, A : [2] }")] - public void Find_with_array_projection_that_should_work_on_all_server_versions(string filter, string projection, string expectedResult) - { - var collection = GetCollection("{ _id : 1, A : [1, 2, 3] }"); - - var find = collection - .Find(filter) - .Project(projection); - - var result = find.Single(); - result.Should().BeEquivalentTo(expectedResult); // order of result elements varies by server version - } - - [Theory] - [InlineData("{ $text : { $search : 'coffee' } }", "{ score : { $meta : 'textScore' } }", "{ _id : 1, subject : 'coffee', score : 1.0 }")] - public void Find_with_meta_projection_that_should_work_on_all_server_versions(string filter, string projection, string expectedResult) - { - var collection = GetCollection("{ _id : 1, subject : 'coffee' }"); - var keyDefinition = new IndexKeysDefinitionBuilder().Text("subject"); - var indexModel = new CreateIndexModel(keyDefinition); - collection.Indexes.CreateOne(indexModel); - - var find = collection - .Find(filter) - .Project(projection); - - var result = find.Single(); - result.Should().Be(expectedResult); - } - - [Theory] - [InlineData("{ X : 'abc' }", "{ _id : 1, X : 'abc' }")] - [InlineData("{ X : '$Y' }", "{ _id : 1, X : 3 }")] - [InlineData("{ X : { $add : ['$X', '$Y'] } }", "{ _id : 1, X : 5 }")] - [InlineData("{ X : { $literal : true } }", "{ _id : 1, X : true }")] - [InlineData("{ X : { $literal : 1 } }", "{ _id : 1, X : 1 }")] - [InlineData("{ X : { $literal : { $numberLong : 1 } } }", "{ _id : 1, X : { $numberLong : 1 } }")] - [InlineData("{ X : { $literal : 1.0 } }", "{ _id : 1, X : 1.0 }")] - public void Find_with_projections_that_should_work_only_on_servers_newer_than_44(string projection, string expectedResult) - { - var collection = GetCollection("{ _id : 1, X : 2, Y : 3 }"); - - var find = collection - .Find("{}") - .Project(projection); - - var result = find.Single(); - result.Should().BeEquivalentTo(expectedResult); // order of result elements varies by server version - } - - [Theory] - [InlineData("{ X : { Y : 1 } }", "{ _id : 1, X : { Y : 2 } }")] - [InlineData("{ X : { Y : 0 } }", "{ _id : 1, X : { Z : 3 } }")] - [InlineData("{ X : { Y : { $numberLong : 1 } } }", "{ _id : 1, X : { Y : 2 } }")] - [InlineData("{ X : { Y : 1.0 } }", "{ _id : 1, X : { Y : 2 } }")] - public void Find_with_nested_field_projections_that_should_work_only_on_servers_newer_than_44(string projection, string expectedResult) - { - var collection = GetCollection("{ _id : 1, X : { Y : 2, Z : 3 } }"); - - var find = collection - .Find("{}") - .Project(projection); - - var result = find.Single(); - result.Should().BeEquivalentTo(expectedResult); // order of result elements varies by server version - } - - [Fact] // it is sufficient to test only one projection because the rest are tested using Find - public void FindOneAndDelete_with_projections_that_should_work_only_on_servers_newer_than_44() - { - var collection = GetCollection("{ _id : 1, X : 2, Y : 3 }"); - var filter = "{ _id : 1 }"; - var options = new FindOneAndDeleteOptions { Projection = "{ Z : '$Y' }" }; - - var result = collection.FindOneAndDelete(filter, options); - result.Should().BeEquivalentTo("{ _id : 1, Z : 3 }"); // order of result elements varies by server version - } - - [Fact] // it is sufficient to test only one projection because the rest are tested using Find - public void FindOneAndReplace_with_projections_that_should_work_only_on_servers_newer_than_44() - { - var collection = GetCollection("{ _id : 1, X : 2, Y : 3 }"); - var filter = "{ _id : 1 }"; - var replacement = BsonDocument.Parse("{ _id : 1, X : 4, Y : 5 }"); - var options = new FindOneAndReplaceOptions { Projection = "{ Z : '$Y' }", ReturnDocument = ReturnDocument.After }; - - var result = collection.FindOneAndReplace(filter, replacement, options); - result.Should().BeEquivalentTo("{ _id : 1, Z : 5 }"); // order of result elements varies by server version - } - - [Fact] // it is sufficient to test only one projection because the rest are tested using Find - public void FindOneAndUpdate_with_projections_that_should_work_only_on_servers_newer_than_44() - { - var collection = GetCollection("{ _id : 1, X : 2, Y : 3 }"); - var filter = "{ _id : 1 }"; - var update = "{ $inc : { Y : 1 } }"; - var options = new FindOneAndUpdateOptions { Projection = "{ Z : '$Y' }", ReturnDocument = ReturnDocument.After }; - - var result = collection.FindOneAndUpdate(filter, update, options); - result.Should().BeEquivalentTo("{ _id : 1, Z : 4 }"); // order of result elements varies by server version - } - - private IMongoCollection GetCollection(params string[] documents) - { - var collection = GetCollection("test"); - CreateCollection( - collection, - documents.Select(BsonDocument.Parse)); - return collection; - } + [Theory] + [InlineData("{ X : false }", "{ _id : 1 }")] + [InlineData("{ X : true }", "{ _id : 1, X : 2 }")] + [InlineData("{ X : 0 }", "{ _id : 1 }")] + [InlineData("{ X : 1 }", "{ _id : 1, X : 2 }")] + [InlineData("{ X : -1 }", "{ _id : 1, X : 2 }")] + [InlineData("{ X : { $numberLong : 0 } }", "{ _id : 1 }")] + [InlineData("{ X : { $numberLong : 1 } }", "{ _id : 1, X : 2 }")] + [InlineData("{ X : { $numberLong : -1 } }", "{ _id : 1, X : 2 }")] + [InlineData("{ X : 0.0 }", "{ _id : 1 }")] + [InlineData("{ X : 1.0 }", "{ _id : 1, X : 2 }")] + [InlineData("{ X : -1.0 }", "{ _id : 1, X : 2 }")] + public void Find_with_projections_that_should_work_on_all_server_versions(string projection, string expectedResult) + { + var collection = GetCollection("{ _id : 1, X : 2 }"); + + var find = collection + .Find("{}") + .Project(projection); + + var result = find.Single(); + result.Should().Be(expectedResult); } + + [Theory] + [InlineData("{}", "{ A : { $slice : 2 } }", "{ _id : 1, A : [1, 2] }")] + [InlineData("{}", "{ A : { $slice : -2 } }", "{ _id : 1, A : [2, 3] }")] + [InlineData("{}", "{ A : { $slice : [1, 2] } }", "{ _id : 1, A : [2, 3] }")] + [InlineData("{}", "{ A : { $slice : [-3, 2] } }", "{ _id : 1, A : [1, 2] }")] + [InlineData("{}", "{ A : { $elemMatch : { $gt : 1 } } }", "{ _id : 1, A : [2] }")] + [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : true }", "{ _id : 1, A : [2] }")] + [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : 1 }", "{ _id : 1, A : [2] }")] + [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : -1 }", "{ _id : 1, A : [2] }")] + [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : { $numberLong : 1 } }", "{ _id : 1, A : [2] }")] + [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : { $numberLong : -1 } }", "{ _id : 1, A : [2] }")] + [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : 1.0 }", "{ _id : 1, A : [2] }")] + [InlineData("{ A : { $gt : 1 } }", "{ 'A.$' : -1.0 }", "{ _id : 1, A : [2] }")] + public void Find_with_array_projection_that_should_work_on_all_server_versions(string filter, string projection, string expectedResult) + { + var collection = GetCollection("{ _id : 1, A : [1, 2, 3] }"); + + var find = collection + .Find(filter) + .Project(projection); + + var result = find.Single(); + result.Should().BeEquivalentTo(expectedResult); // order of result elements varies by server version + } + + [Theory] + [InlineData("{ $text : { $search : 'coffee' } }", "{ score : { $meta : 'textScore' } }", "{ _id : 1, subject : 'coffee', score : 1.0 }")] + public void Find_with_meta_projection_that_should_work_on_all_server_versions(string filter, string projection, string expectedResult) + { + var collection = GetCollection("{ _id : 1, subject : 'coffee' }"); + var keyDefinition = new IndexKeysDefinitionBuilder().Text("subject"); + var indexModel = new CreateIndexModel(keyDefinition); + collection.Indexes.CreateOne(indexModel); + + var find = collection + .Find(filter) + .Project(projection); + + var result = find.Single(); + result.Should().Be(expectedResult); + } + + [Theory] + [InlineData("{ X : 'abc' }", "{ _id : 1, X : 'abc' }")] + [InlineData("{ X : '$Y' }", "{ _id : 1, X : 3 }")] + [InlineData("{ X : { $add : ['$X', '$Y'] } }", "{ _id : 1, X : 5 }")] + [InlineData("{ X : { $literal : true } }", "{ _id : 1, X : true }")] + [InlineData("{ X : { $literal : 1 } }", "{ _id : 1, X : 1 }")] + [InlineData("{ X : { $literal : { $numberLong : 1 } } }", "{ _id : 1, X : { $numberLong : 1 } }")] + [InlineData("{ X : { $literal : 1.0 } }", "{ _id : 1, X : 1.0 }")] + public void Find_with_projections_that_should_work_only_on_servers_newer_than_44(string projection, string expectedResult) + { + var collection = GetCollection("{ _id : 1, X : 2, Y : 3 }"); + + var find = collection + .Find("{}") + .Project(projection); + + var result = find.Single(); + result.Should().BeEquivalentTo(expectedResult); // order of result elements varies by server version + } + + [Theory] + [InlineData("{ X : { Y : 1 } }", "{ _id : 1, X : { Y : 2 } }")] + [InlineData("{ X : { Y : 0 } }", "{ _id : 1, X : { Z : 3 } }")] + [InlineData("{ X : { Y : { $numberLong : 1 } } }", "{ _id : 1, X : { Y : 2 } }")] + [InlineData("{ X : { Y : 1.0 } }", "{ _id : 1, X : { Y : 2 } }")] + public void Find_with_nested_field_projections_that_should_work_only_on_servers_newer_than_44(string projection, string expectedResult) + { + var collection = GetCollection("{ _id : 1, X : { Y : 2, Z : 3 } }"); + + var find = collection + .Find("{}") + .Project(projection); + + var result = find.Single(); + result.Should().BeEquivalentTo(expectedResult); // order of result elements varies by server version + } + + [Fact] // it is sufficient to test only one projection because the rest are tested using Find + public void FindOneAndDelete_with_projections_that_should_work_only_on_servers_newer_than_44() + { + var collection = GetCollection("{ _id : 1, X : 2, Y : 3 }"); + var filter = "{ _id : 1 }"; + var options = new FindOneAndDeleteOptions { Projection = "{ Z : '$Y' }" }; + + var result = collection.FindOneAndDelete(filter, options); + result.Should().BeEquivalentTo("{ _id : 1, Z : 3 }"); // order of result elements varies by server version + } + + [Fact] // it is sufficient to test only one projection because the rest are tested using Find + public void FindOneAndReplace_with_projections_that_should_work_only_on_servers_newer_than_44() + { + var collection = GetCollection("{ _id : 1, X : 2, Y : 3 }"); + var filter = "{ _id : 1 }"; + var replacement = BsonDocument.Parse("{ _id : 1, X : 4, Y : 5 }"); + var options = new FindOneAndReplaceOptions { Projection = "{ Z : '$Y' }", ReturnDocument = ReturnDocument.After }; + + var result = collection.FindOneAndReplace(filter, replacement, options); + result.Should().BeEquivalentTo("{ _id : 1, Z : 5 }"); // order of result elements varies by server version + } + + [Fact] // it is sufficient to test only one projection because the rest are tested using Find + public void FindOneAndUpdate_with_projections_that_should_work_only_on_servers_newer_than_44() + { + var collection = GetCollection("{ _id : 1, X : 2, Y : 3 }"); + var filter = "{ _id : 1 }"; + var update = "{ $inc : { Y : 1 } }"; + var options = new FindOneAndUpdateOptions { Projection = "{ Z : '$Y' }", ReturnDocument = ReturnDocument.After }; + + var result = collection.FindOneAndUpdate(filter, update, options); + result.Should().BeEquivalentTo("{ _id : 1, Z : 4 }"); // order of result elements varies by server version + } + + private IMongoCollection GetCollection(params string[] documents) + { + var collection = GetCollection("test"); + CreateCollection( + collection, + documents.Select(BsonDocument.Parse)); + return collection; + } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/IdentityExpressionProjectionRenderTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/IdentityExpressionProjectionRenderTests.cs index 60bac274558..659dd472afa 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/IdentityExpressionProjectionRenderTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/IdentityExpressionProjectionRenderTests.cs @@ -26,89 +26,89 @@ namespace MongoDB.Driver.Tests.Linq.Integration; public class IdentityExpressionProjectionRenderTests : LinqIntegrationTest { public IdentityExpressionProjectionRenderTests(ClassFixture fixture) - : base(fixture) - { - } - - [Fact] - public void Find_with_identity_projection_should_work() - { - var collection = Fixture.Collection; - var projection = Builders.Projection.Expression(x => x); - - var find = collection - .Find("{}") - .Project(projection); - - var renderedProjection = TranslateFindProjection(collection, find); - renderedProjection.Should().BeNull(); - - var result = find.Single(); - result.Id.Should().Be(1); - result.X.Should().Be(2); - } - - [Fact] - public void Aggregate_Project_with_identity_projection_should_work() - { - var collection = Fixture.Collection; - var projection = Builders.Projection.Expression(x => x); - - var aggregate = collection - .Aggregate() - .Project(projection); - - var stages = Translate(collection, aggregate); - stages.Should().BeEmpty(); - - var result = aggregate.Single(); - result.Id.Should().Be(1); - result.X.Should().Be(2); - } - - [Theory] - [ParameterAttributeData] - public void ExpressionProjectionDefinition_with_identity_projection_Render_should_work( - [Values(true, false)] bool renderForFind) - { - var collection = Fixture.Collection; - var projection = new ExpressionProjectionDefinition(x => x); - var sourceSerializer = collection.DocumentSerializer; - var serializerRegistry = BsonSerializer.SerializerRegistry; - - var renderedProjection = projection.Render(new(sourceSerializer, serializerRegistry, renderForFind: renderForFind)); - - renderedProjection.Document.Should().BeNull(); - renderedProjection.ProjectionSerializer.Should().BeSameAs(sourceSerializer); - } - - [Theory] - [ParameterAttributeData] - public void FindExpressionProjectionDefinition_with_identity_projection_Render_should_work( - [Values(true, false)] bool renderForFind) - { - var collection = Fixture.Collection; - var projection = new FindExpressionProjectionDefinition(x => x); - var sourceSerializer = collection.DocumentSerializer; - var serializerRegistry = BsonSerializer.SerializerRegistry; - - var renderedProjection = projection.Render(new(sourceSerializer, serializerRegistry, renderForFind: renderForFind)); - - renderedProjection.Document.Should().BeNull(); - renderedProjection.ProjectionSerializer.Should().BeSameAs(sourceSerializer); - } - - public class C - { - public int Id { get; set; } - public int X { get; set; } - } - - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new C { Id = 1, X = 2 } - ]; - } - } + : base(fixture) + { + } + + [Fact] + public void Find_with_identity_projection_should_work() + { + var collection = Fixture.Collection; + var projection = Builders.Projection.Expression(x => x); + + var find = collection + .Find("{}") + .Project(projection); + + var renderedProjection = TranslateFindProjection(collection, find); + renderedProjection.Should().BeNull(); + + var result = find.Single(); + result.Id.Should().Be(1); + result.X.Should().Be(2); + } + + [Fact] + public void Aggregate_Project_with_identity_projection_should_work() + { + var collection = Fixture.Collection; + var projection = Builders.Projection.Expression(x => x); + + var aggregate = collection + .Aggregate() + .Project(projection); + + var stages = Translate(collection, aggregate); + stages.Should().BeEmpty(); + + var result = aggregate.Single(); + result.Id.Should().Be(1); + result.X.Should().Be(2); + } + + [Theory] + [ParameterAttributeData] + public void ExpressionProjectionDefinition_with_identity_projection_Render_should_work( + [Values(true, false)] bool renderForFind) + { + var collection = Fixture.Collection; + var projection = new ExpressionProjectionDefinition(x => x); + var sourceSerializer = collection.DocumentSerializer; + var serializerRegistry = BsonSerializer.SerializerRegistry; + + var renderedProjection = projection.Render(new(sourceSerializer, serializerRegistry, renderForFind: renderForFind)); + + renderedProjection.Document.Should().BeNull(); + renderedProjection.ProjectionSerializer.Should().BeSameAs(sourceSerializer); + } + + [Theory] + [ParameterAttributeData] + public void FindExpressionProjectionDefinition_with_identity_projection_Render_should_work( + [Values(true, false)] bool renderForFind) + { + var collection = Fixture.Collection; + var projection = new FindExpressionProjectionDefinition(x => x); + var sourceSerializer = collection.DocumentSerializer; + var serializerRegistry = BsonSerializer.SerializerRegistry; + + var renderedProjection = projection.Render(new(sourceSerializer, serializerRegistry, renderForFind: renderForFind)); + + renderedProjection.Document.Should().BeNull(); + renderedProjection.ProjectionSerializer.Should().BeSameAs(sourceSerializer); + } + + public class C + { + public int Id { get; set; } + public int X { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, X = 2 } + ]; + } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/IsNullOrEmptyAndNullCoalescingTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/IsNullOrEmptyAndNullCoalescingTests.cs index d7cd2ec613f..f1bcec93e9c 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/IsNullOrEmptyAndNullCoalescingTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/IsNullOrEmptyAndNullCoalescingTests.cs @@ -22,112 +22,112 @@ namespace MongoDB.Driver.Tests.Linq.Integration; [Trait("Category", "Integration")] // Regression test for CSHARP-2708. public class IsNullOrEmptyAndNullCoalescingTests +{ + [Fact] + public void IsNullOrEmpty_in_aggregate_match_should_work() { - [Fact] - public void IsNullOrEmpty_in_aggregate_match_should_work() - { - var collection = GetCollection(); - var subject = collection.Aggregate(); + var collection = GetCollection(); + var subject = collection.Aggregate(); - var aggregate = subject.Match(x => string.IsNullOrEmpty(x.S)); + var aggregate = subject.Match(x => string.IsNullOrEmpty(x.S)); - var stages = Linq3TestHelpers.Translate(collection, aggregate); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, aggregate); + var expectedStages = new[] + { "{ $match : { S : { $in : [null, ''] } } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void IsNullOrEmpty_with_null_coalescing_operator_in_aggregate_match_should_work() - { - var collection = GetCollection(); - var subject = collection.Aggregate(); + [Fact] + public void IsNullOrEmpty_with_null_coalescing_operator_in_aggregate_match_should_work() + { + var collection = GetCollection(); + var subject = collection.Aggregate(); - var aggregate = subject.Match(x => string.IsNullOrEmpty(x.S ?? "")); + var aggregate = subject.Match(x => string.IsNullOrEmpty(x.S ?? "")); - var stages = Linq3TestHelpers.Translate(collection, aggregate); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, aggregate); + var expectedStages = new[] + { "{ $match : { $expr : { $in : [{ $ifNull : ['$S', ''] }, [null, '']] } } }" // requires use of $expr }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Null_coalescing_operator_in_aggregate_project_should_work() - { - var collection = GetCollection(); - var subject = collection.Aggregate(); + [Fact] + public void Null_coalescing_operator_in_aggregate_project_should_work() + { + var collection = GetCollection(); + var subject = collection.Aggregate(); - var aggregate = subject.Project(x => x.S ?? ""); + var aggregate = subject.Project(x => x.S ?? ""); - var stages = Linq3TestHelpers.Translate(collection, aggregate); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, aggregate); + var expectedStages = new[] + { "{ $project : { _v : { $ifNull : ['$S', ''] }, _id : 0 } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Null_coalescing_operator_in_queryable_select_should_work() - { - var collection = GetCollection(); - var subject = collection.AsQueryable(); + [Fact] + public void Null_coalescing_operator_in_queryable_select_should_work() + { + var collection = GetCollection(); + var subject = collection.AsQueryable(); - var queryable = subject.Select(x => x.S ?? ""); + var queryable = subject.Select(x => x.S ?? ""); - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $project : { _v : { $ifNull : ['$S', ''] }, _id : 0 } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void IsNullOrEmpty_in_queryable_where_should_work() - { - var collection = GetCollection(); - var subject = collection.AsQueryable(); + [Fact] + public void IsNullOrEmpty_in_queryable_where_should_work() + { + var collection = GetCollection(); + var subject = collection.AsQueryable(); - var queryable = subject.Where(x => string.IsNullOrEmpty(x.S)); + var queryable = subject.Where(x => string.IsNullOrEmpty(x.S)); - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { S : { $in : [null, ''] } } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void IsNullOrEmpty_with_null_coalescing_operator_in_queryable_where_should_work() - { - var collection = GetCollection(); - var subject = collection.AsQueryable(); + [Fact] + public void IsNullOrEmpty_with_null_coalescing_operator_in_queryable_where_should_work() + { + var collection = GetCollection(); + var subject = collection.AsQueryable(); - var queryable = subject.Where(x => string.IsNullOrEmpty(x.S ?? "")); + var queryable = subject.Where(x => string.IsNullOrEmpty(x.S ?? "")); - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { $expr : { $in : [{ $ifNull : ['$S', ''] }, [null, '']] } } }" // requires use of $expr }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - private IMongoCollection GetCollection() - { - var client = DriverTestConfiguration.Client; - var database = client.GetDatabase("foo"); - return database.GetCollection("foo"); - } + private IMongoCollection GetCollection() + { + var client = DriverTestConfiguration.Client; + var database = client.GetDatabase("foo"); + return database.GetCollection("foo"); + } - private class C - { - public string S { get; set; } - } + private class C + { + public string S { get; set; } } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/MqlSubtypeTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/MqlSubtypeTests.cs index 020d8567eba..d807909a6da 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/MqlSubtypeTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/MqlSubtypeTests.cs @@ -45,7 +45,7 @@ public void MqlSubtype_in_where_should_work(BsonBinarySubType? subtype, int expe .Where(d => Mql.Subtype(d.Data) == subtype); var renderedStages = Translate(collection, queryable); - AssertStages(renderedStages, $"{{ $match : {{ $expr : {{ $eq : [{{ $subtype : '$Data' }}, { (subtype.HasValue ? (int)subtype : "null") }] }} }} }}"); + AssertStages(renderedStages, $"{{ $match : {{ $expr : {{ $eq : [{{ $subtype : '$Data' }}, {(subtype.HasValue ? (int)subtype : "null")}] }} }} }}"); var result = queryable.Single(); result.Id.Should().Be(expectedId); diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/NestedAnyAndExistsInSelectAndWhereTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/NestedAnyAndExistsInSelectAndWhereTests.cs index ec13a9ac82b..f4c07ee2f12 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/NestedAnyAndExistsInSelectAndWhereTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/NestedAnyAndExistsInSelectAndWhereTests.cs @@ -27,135 +27,135 @@ public class NestedAnyAndExistsInSelectAndWhereTests : LinqIntegrationTest - a.ProfilesList != null && - a.ProfilesList.Any(p => p.OrganizationIdsList.Any(o => o == organizationId))); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $and : [{ $ne : ['$ProfilesList', null] }, { $anyElementTrue : { $map : { input : '$ProfilesList', as : 'p', in : { $anyElementTrue : { $map : { input : '$$p.OrganizationIdsList', as : 'o', in : { $eq : ['$$o', 1] } } } } } } }] }, _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(true, false, false, false); - } - - [Fact] - public void Select_with_Array_Exists_should_work() - { - var collection = Fixture.Collection; - var organizationId = 1; - - var queryable = collection.AsQueryable() - .Select(a => - a.ProfilesArray != null && - Array.Exists(a.ProfilesArray, p => Array.Exists(p.OrganizationIdsArray, o => o == organizationId))); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $and : [{ $ne : ['$ProfilesArray', null] }, { $anyElementTrue : { $map : { input : '$ProfilesArray', as : 'p', in : { $anyElementTrue : { $map : { input : '$$p.OrganizationIdsArray', as : 'o', in : { $eq : ['$$o', 1] } } } } } } }] }, _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(true, false, false, false); - } - - [Fact] - public void Select_with_List_Exists_should_work() - { - var collection = Fixture.Collection; - var organizationId = 1; - - var queryable = collection.AsQueryable() - .Select(a => - a.ProfilesList != null && - a.ProfilesList.Exists(p => p.OrganizationIdsList.Exists(o => o == organizationId))); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _v : { $and : [{ $ne : ['$ProfilesList', null] }, { $anyElementTrue : { $map : { input : '$ProfilesList', as : 'p', in : { $anyElementTrue : { $map : { input : '$$p.OrganizationIdsList', as : 'o', in : { $eq : ['$$o', 1] } } } } } } }] }, _id : 0 } }"); - - var results = queryable.ToList(); - results.Should().Equal(true, false, false, false); - } - - [Fact] - public void Where_with_Any_should_work() - { - var collection = Fixture.Collection; - var organizationId = 1; - - var queryable = collection.AsQueryable() - .Where(a => - a.ProfilesList != null && - a.ProfilesList.Any(p => p.OrganizationIdsList.Any(o => o == organizationId))); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { ProfilesList : { $ne : null, $elemMatch : { OrganizationIdsList : 1 } } } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_with_Array_Exists_should_work() - { - var collection = Fixture.Collection; - var organizationId = 1; - - var queryable = collection.AsQueryable() - .Where(a => - a.ProfilesArray != null && - Array.Exists(a.ProfilesArray, p => Array.Exists(p.OrganizationIdsArray, o => o == organizationId))); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { ProfilesArray : { $ne : null, $elemMatch : { OrganizationIdsArray : 1 } } } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - [Fact] - public void Where_with_List_Exists_should_work() - { - var collection = Fixture.Collection; - var organizationId = 1; - - var queryable = collection.AsQueryable() - .Where(a => - a.ProfilesList != null && - a.ProfilesList.Exists(p => p.OrganizationIdsList.Exists(o => o == organizationId))); - - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { ProfilesList : { $ne : null, $elemMatch : { OrganizationIdsList : 1 } } } }"); - - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1); - } - - public class Account - { - public int Id { get; set; } - public Profile[] ProfilesArray { get; set; } - public List ProfilesList { get; set; } - } - - public class Profile - { - public int[] OrganizationIdsArray { get; set; } - public List OrganizationIdsList { get; set; } - } - - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new Account + { + } + + [Fact] + public void Select_with_Any_should_work() + { + var collection = Fixture.Collection; + var organizationId = 1; + + var queryable = collection.AsQueryable() + .Select(a => + a.ProfilesList != null && + a.ProfilesList.Any(p => p.OrganizationIdsList.Any(o => o == organizationId))); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $and : [{ $ne : ['$ProfilesList', null] }, { $anyElementTrue : { $map : { input : '$ProfilesList', as : 'p', in : { $anyElementTrue : { $map : { input : '$$p.OrganizationIdsList', as : 'o', in : { $eq : ['$$o', 1] } } } } } } }] }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(true, false, false, false); + } + + [Fact] + public void Select_with_Array_Exists_should_work() + { + var collection = Fixture.Collection; + var organizationId = 1; + + var queryable = collection.AsQueryable() + .Select(a => + a.ProfilesArray != null && + Array.Exists(a.ProfilesArray, p => Array.Exists(p.OrganizationIdsArray, o => o == organizationId))); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $and : [{ $ne : ['$ProfilesArray', null] }, { $anyElementTrue : { $map : { input : '$ProfilesArray', as : 'p', in : { $anyElementTrue : { $map : { input : '$$p.OrganizationIdsArray', as : 'o', in : { $eq : ['$$o', 1] } } } } } } }] }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(true, false, false, false); + } + + [Fact] + public void Select_with_List_Exists_should_work() + { + var collection = Fixture.Collection; + var organizationId = 1; + + var queryable = collection.AsQueryable() + .Select(a => + a.ProfilesList != null && + a.ProfilesList.Exists(p => p.OrganizationIdsList.Exists(o => o == organizationId))); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _v : { $and : [{ $ne : ['$ProfilesList', null] }, { $anyElementTrue : { $map : { input : '$ProfilesList', as : 'p', in : { $anyElementTrue : { $map : { input : '$$p.OrganizationIdsList', as : 'o', in : { $eq : ['$$o', 1] } } } } } } }] }, _id : 0 } }"); + + var results = queryable.ToList(); + results.Should().Equal(true, false, false, false); + } + + [Fact] + public void Where_with_Any_should_work() + { + var collection = Fixture.Collection; + var organizationId = 1; + + var queryable = collection.AsQueryable() + .Where(a => + a.ProfilesList != null && + a.ProfilesList.Any(p => p.OrganizationIdsList.Any(o => o == organizationId))); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { ProfilesList : { $ne : null, $elemMatch : { OrganizationIdsList : 1 } } } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + [Fact] + public void Where_with_Array_Exists_should_work() + { + var collection = Fixture.Collection; + var organizationId = 1; + + var queryable = collection.AsQueryable() + .Where(a => + a.ProfilesArray != null && + Array.Exists(a.ProfilesArray, p => Array.Exists(p.OrganizationIdsArray, o => o == organizationId))); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { ProfilesArray : { $ne : null, $elemMatch : { OrganizationIdsArray : 1 } } } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + [Fact] + public void Where_with_List_Exists_should_work() + { + var collection = Fixture.Collection; + var organizationId = 1; + + var queryable = collection.AsQueryable() + .Where(a => + a.ProfilesList != null && + a.ProfilesList.Exists(p => p.OrganizationIdsList.Exists(o => o == organizationId))); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { ProfilesList : { $ne : null, $elemMatch : { OrganizationIdsList : 1 } } } }"); + + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1); + } + + public class Account + { + public int Id { get; set; } + public Profile[] ProfilesArray { get; set; } + public List ProfilesList { get; set; } + } + + public class Profile + { + public int[] OrganizationIdsArray { get; set; } + public List OrganizationIdsList { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Account { Id = 1, ProfilesArray = new Profile[] { new Profile { OrganizationIdsArray = new int[] { 1 } } }, @@ -179,6 +179,6 @@ public sealed class ClassFixture : MongoCollectionFixture ProfilesArray = new Profile[] { new Profile { OrganizationIdsArray = new int[0] } }, ProfilesList = new List { new Profile { OrganizationIdsList = new List() } } } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/NestedLookupSelectTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/NestedLookupSelectTests.cs index d43907efa2d..1bd00a65cfd 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/NestedLookupSelectTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/NestedLookupSelectTests.cs @@ -25,77 +25,77 @@ namespace MongoDB.Driver.Tests.Linq.Integration; [Trait("Category", "Integration")] // Regression test for CSHARP-2723. public class NestedLookupSelectTests +{ + [Fact] + public void Nested_Select_should_work() { - [Fact] - public void Nested_Select_should_work() - { - var client = DriverTestConfiguration.Client; - var database = client.GetDatabase("foo"); - var parents = database.GetCollection("parents"); - var children = database.GetCollection("children"); - var grandChildren = database.GetCollection("grandChildren"); + var client = DriverTestConfiguration.Client; + var database = client.GetDatabase("foo"); + var parents = database.GetCollection("parents"); + var children = database.GetCollection("children"); + var grandChildren = database.GetCollection("grandChildren"); - database.DropCollection("parents"); - database.DropCollection("children"); - database.DropCollection("grandChildren"); + database.DropCollection("parents"); + database.DropCollection("children"); + database.DropCollection("grandChildren"); - parents.InsertMany(new[] - { + parents.InsertMany(new[] + { new Parent { Id = 1, Name = "parent1" }, new Parent { Id = 2, Name = "parent2" } }); - children.InsertMany(new[] - { + children.InsertMany(new[] + { new Child { Id = 1, Name = "child1", ParentId = 2 }, new Child { Id = 2, Name = "child2", ParentId = 1 } }); - grandChildren.InsertMany(new[] - { + grandChildren.InsertMany(new[] + { new GrandChild { Id = 1, Name = "grandchild1", ChildId = 2 }, new GrandChild { Id = 2, Name = "grandchild2", ChildId = 1 } }); - var aggregate = parents - .Aggregate() - .Lookup( - children, - parent => parent.Id, - child => child.ParentId, - parentProjection => parentProjection.Children) - .Lookup, ParentProjection>( - grandChildren, - let: new BsonDocument { { "children", "$Children" } }, - lookupPipeline: new BsonDocumentStagePipelineDefinition( - new[] { BsonDocument.Parse(@"{ $match : { $expr : { $and : [ { $in : [ ""$ChildId"", ""$$children._id"" ] } ] } } }") }), - childProjection => childProjection.GrandChildren) - .Project(parent => new ParentTree - { - Id = parent.Id, - ParentName = parent.Name, - Children = parent.Children - .Select(child => new ChildTree - { - Id = child.Id, - Name = child.Name, - GrandChildren = parent - .GrandChildren - .Where(gc => - gc.ChildId == - child.Id) - .Select(gc => - new GrandChildProjection() - { - Id = gc.Id, - Name = gc.Name - }) - }) - }); - - var stages = Linq3TestHelpers.Translate(parents, aggregate); - var expectedStages = new[] + var aggregate = parents + .Aggregate() + .Lookup( + children, + parent => parent.Id, + child => child.ParentId, + parentProjection => parentProjection.Children) + .Lookup, ParentProjection>( + grandChildren, + let: new BsonDocument { { "children", "$Children" } }, + lookupPipeline: new BsonDocumentStagePipelineDefinition( + new[] { BsonDocument.Parse(@"{ $match : { $expr : { $and : [ { $in : [ ""$ChildId"", ""$$children._id"" ] } ] } } }") }), + childProjection => childProjection.GrandChildren) + .Project(parent => new ParentTree { + Id = parent.Id, + ParentName = parent.Name, + Children = parent.Children + .Select(child => new ChildTree + { + Id = child.Id, + Name = child.Name, + GrandChildren = parent + .GrandChildren + .Where(gc => + gc.ChildId == + child.Id) + .Select(gc => + new GrandChildProjection() + { + Id = gc.Id, + Name = gc.Name + }) + }) + }); + + var stages = Linq3TestHelpers.Translate(parents, aggregate); + var expectedStages = new[] + { @"{ '$lookup':{ 'from':'children', @@ -153,114 +153,114 @@ public void Nested_Select_should_work() } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); + Linq3TestHelpers.AssertStages(stages, expectedStages); - var pipelineDefinition = new BsonDocumentStagePipelineDefinition(expectedStages.Select(s => BsonDocument.Parse(s))); - var resultBsonDocuments = parents.Aggregate(pipelineDefinition).ToList(); - var expectedBsonDocuments = new[] - { + var pipelineDefinition = new BsonDocumentStagePipelineDefinition(expectedStages.Select(s => BsonDocument.Parse(s))); + var resultBsonDocuments = parents.Aggregate(pipelineDefinition).ToList(); + var expectedBsonDocuments = new[] + { "{ '_id' : 1, 'ParentName' : 'parent1', 'Children' : [{ '_id' : 2, 'Name' : 'child2', 'GrandChildren' : [{ '_id' : 1, 'Name' : 'grandchild1' }] }] }", "{ '_id' : 2, 'ParentName' : 'parent2', 'Children' : [{ '_id' : 1, 'Name' : 'child1', 'GrandChildren' : [{ '_id' : 2, 'Name' : 'grandchild2' }] }] }" }; - resultBsonDocuments.Should().Equal(expectedBsonDocuments.Select(d => BsonDocument.Parse(d))); + resultBsonDocuments.Should().Equal(expectedBsonDocuments.Select(d => BsonDocument.Parse(d))); - var result = aggregate.ToList(); - var expectedResults = new[] - { + var result = aggregate.ToList(); + var expectedResults = new[] + { new ParentTree { Id = 1, ParentName = "parent1", Children = new[] { new ChildTree { Id = 2, Name = "child2", GrandChildren = new[] { new GrandChildProjection { Id = 1, Name = "grandchild1" } } } } }, new ParentTree { Id = 2, ParentName = "parent2", Children = new[] { new ChildTree { Id = 1, Name = "child1", GrandChildren = new[] { new GrandChildProjection { Id = 2, Name = "grandchild2" } } } } } }; - var parentTreeComparer = new ParentTreeComparer(); - result.Should().Equal(expectedResults, (x, y) => parentTreeComparer.Equals(x, y)); - } - - public class Parent - { - public int Id { get; set; } - public string Name { get; set; } - } + var parentTreeComparer = new ParentTreeComparer(); + result.Should().Equal(expectedResults, (x, y) => parentTreeComparer.Equals(x, y)); + } - public class Child - { - public int Id { get; set; } - public string Name { get; set; } - public int ParentId { get; set; } - } + public class Parent + { + public int Id { get; set; } + public string Name { get; set; } + } - public class GrandChild - { - public int Id { get; set; } - public string Name { get; set; } - public int ChildId { get; set; } - } + public class Child + { + public int Id { get; set; } + public string Name { get; set; } + public int ParentId { get; set; } + } - public class ParentProjection - { - public int Id { get; set; } - public string Name { get; set; } - public IEnumerable Children { get; set; } - public IEnumerable GrandChildren { get; set; } - } + public class GrandChild + { + public int Id { get; set; } + public string Name { get; set; } + public int ChildId { get; set; } + } - public class GrandChildProjection - { - public int Id { get; set; } - public string Name { get; set; } - } + public class ParentProjection + { + public int Id { get; set; } + public string Name { get; set; } + public IEnumerable Children { get; set; } + public IEnumerable GrandChildren { get; set; } + } - public class ParentTree - { - public int Id { get; set; } - public string ParentName { get; set; } - public IEnumerable Children { get; set; } - } + public class GrandChildProjection + { + public int Id { get; set; } + public string Name { get; set; } + } - public class ChildTree - { - public int Id { get; set; } - public string Name { get; set; } - public IEnumerable GrandChildren { get; set; } - } + public class ParentTree + { + public int Id { get; set; } + public string ParentName { get; set; } + public IEnumerable Children { get; set; } + } - private class ParentTreeComparer : IEqualityComparer - { - private readonly IEqualityComparer _childTreeComparer = new ChildTreeComparer(); + public class ChildTree + { + public int Id { get; set; } + public string Name { get; set; } + public IEnumerable GrandChildren { get; set; } + } - public bool Equals(ParentTree x, ParentTree y) - { - return - x.Id == y.Id && - x.ParentName == y.ParentName && - x.Children.SequenceEqual(y.Children, _childTreeComparer); - } + private class ParentTreeComparer : IEqualityComparer + { + private readonly IEqualityComparer _childTreeComparer = new ChildTreeComparer(); - public int GetHashCode(ParentTree obj) => throw new System.NotImplementedException(); + public bool Equals(ParentTree x, ParentTree y) + { + return + x.Id == y.Id && + x.ParentName == y.ParentName && + x.Children.SequenceEqual(y.Children, _childTreeComparer); } - private class ChildTreeComparer : IEqualityComparer - { - private readonly IEqualityComparer _grandChildProjectionComparer = new GrandChildProjectionComparer(); + public int GetHashCode(ParentTree obj) => throw new System.NotImplementedException(); + } - public bool Equals(ChildTree x, ChildTree y) - { - return - x.Id == y.Id && - x.Name == y.Name && - x.GrandChildren.SequenceEqual(y.GrandChildren, _grandChildProjectionComparer); - } + private class ChildTreeComparer : IEqualityComparer + { + private readonly IEqualityComparer _grandChildProjectionComparer = new GrandChildProjectionComparer(); - public int GetHashCode(ChildTree obj) => throw new System.NotImplementedException(); + public bool Equals(ChildTree x, ChildTree y) + { + return + x.Id == y.Id && + x.Name == y.Name && + x.GrandChildren.SequenceEqual(y.GrandChildren, _grandChildProjectionComparer); } - private class GrandChildProjectionComparer : IEqualityComparer - { - public bool Equals(GrandChildProjection x, GrandChildProjection y) - { - return - x.Id == y.Id && - x.Name == y.Name; - } + public int GetHashCode(ChildTree obj) => throw new System.NotImplementedException(); + } - public int GetHashCode(GrandChildProjection obj) => throw new System.NotImplementedException(); + private class GrandChildProjectionComparer : IEqualityComparer + { + public bool Equals(GrandChildProjection x, GrandChildProjection y) + { + return + x.Id == y.Id && + x.Name == y.Name; } + + public int GetHashCode(GrandChildProjection obj) => throw new System.NotImplementedException(); } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/ObjectTypeIsAndGetTypeFindAndProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/ObjectTypeIsAndGetTypeFindAndProjectionTests.cs index f1497445728..7f692d9a755 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/ObjectTypeIsAndGetTypeFindAndProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/ObjectTypeIsAndGetTypeFindAndProjectionTests.cs @@ -30,467 +30,467 @@ namespace MongoDB.Driver.Tests.Linq.Integration; public class ObjectTypeIsAndGetTypeFindAndProjectionTests : Linq3IntegrationTest { static ObjectTypeIsAndGetTypeFindAndProjectionTests() + { + BsonClassMap.RegisterClassMap(cm => { - BsonClassMap.RegisterClassMap(cm => - { - cm.AutoMap(); - Func allowedTypes = t => t == typeof(string) || t == typeof(MyActivityObject) || t == typeof(MyActivityObjectDerived); - var discriminatorConvention = new HierarchicalDiscriminatorConvention("_t"); - var objectSerializer = new ObjectSerializer(discriminatorConvention, allowedTypes); - cm.MapMember(x => x.Object).SetSerializer(objectSerializer); - }); - - BsonClassMap.RegisterClassMap>(cm => - { - cm.AutoMap(); - cm.SetIsRootClass(true); - }); - } - - [Fact] - public void Find_with_object_property_GetType_comparison_to_base_class_should_work() + cm.AutoMap(); + Func allowedTypes = t => t == typeof(string) || t == typeof(MyActivityObject) || t == typeof(MyActivityObjectDerived); + var discriminatorConvention = new HierarchicalDiscriminatorConvention("_t"); + var objectSerializer = new ObjectSerializer(discriminatorConvention, allowedTypes); + cm.MapMember(x => x.Object).SetSerializer(objectSerializer); + }); + + BsonClassMap.RegisterClassMap>(cm => { - Implementation(); - - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection1(); - var activityId = 1; - - var find = collection - .Find(x => - x.Object != null && - x.Object.GetType() == typeof(TActivityObject) && - ((TActivityObject)x.Object).Id.Equals(activityId) - ); - - var filter = TranslateFindFilter(collection, find); - var results = find.ToList(); - - filter.Should().Be("{ Object : { $ne : null }, 'Object._t.0' : { $exists : false }, 'Object._t' : 'MyActivityObject', 'Object._id' : 1 }"); - results.Select(x => x.Id).Should().Equal(3, 4); - } - } + cm.AutoMap(); + cm.SetIsRootClass(true); + }); + } - [Fact] - public void Find_with_object_property_GetType_comparison_to_derived_class_should_work() - { - Implementation(); - - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection1(); - var activityId = 1; - - var find = collection - .Find(x => - x.Object != null && - x.Object.GetType() == typeof(TActivityObject) && - ((TActivityObject)x.Object).Id.Equals(activityId) - ); - - var filter = TranslateFindFilter(collection, find); - var results = find.ToList(); - - filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : ['MyActivityObject', 'MyActivityObjectDerived'], 'Object._id' : 1 }"); - results.Select(x => x.Id).Should().Equal(6); - } - } + [Fact] + public void Find_with_object_property_GetType_comparison_to_base_class_should_work() + { + Implementation(); - [Fact] - public void Find_with_object_property_is_base_class_should_work() + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() { - Implementation(); - - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection1(); - var activityId = 1; - - var find = collection - .Find(x => - x.Object != null && - x.Object is TActivityObject && - ((TActivityObject)x.Object).Id.Equals(activityId) - ); - - var filter = TranslateFindFilter(collection, find); - var results = find.ToList(); - - filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : 'MyActivityObject', 'Object._id' : 1 }"); - results.Select(x => x.Id).Should().Equal(3, 4, 6); - } - } + var collection = GetCollection1(); + var activityId = 1; - [Fact] - public void Find_with_object_property_is_derived_class_should_work() - { - Implementation(); - - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection1(); - var activityId = 1; - - var find = collection - .Find(x => - x.Object != null && - x.Object is TActivityObject && - ((TActivityObject)x.Object).Id.Equals(activityId) - ); - - var filter = TranslateFindFilter(collection, find); - var results = find.ToList(); - - filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : 'MyActivityObjectDerived', 'Object._id' : 1 }"); - results.Select(x => x.Id).Should().Equal(6); - } - } + var find = collection + .Find(x => + x.Object != null && + x.Object.GetType() == typeof(TActivityObject) && + ((TActivityObject)x.Object).Id.Equals(activityId) + ); - [Fact] - public void Find_with_typed_property_GetType_comparison_to_base_class_should_work() - { - Implementation(); - - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection2(); - var activityId = 1; - - var find = collection - .Find(x => - x.Object != null && - x.Object.GetType() == typeof(TActivityObject) && - ((TActivityObject)(object)x.Object).Id.Equals(activityId) - ); - - var filter = TranslateFindFilter(collection, find); - var results = find.ToList(); - - filter.Should().Be("{ Object : { $ne : null }, 'Object._t.0' : { $exists : false }, 'Object._t' : 'MyActivityObject', 'Object._id' : 1 }"); - results.Select(x => x.Id).Should().Equal(3, 4); - } - } + var filter = TranslateFindFilter(collection, find); + var results = find.ToList(); - [Fact] - public void Find_with_typed_property_GetType_comparison_to_derived_class_should_work() - { - Implementation(); - - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection2(); - var activityId = 1; - - var find = collection - .Find(x => - x.Object != null && - x.Object.GetType() == typeof(TActivityObject) && - ((TActivityObject)(object)x.Object).Id.Equals(activityId) - ); - - var filter = TranslateFindFilter(collection, find); - var results = find.ToList(); - - filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : ['MyActivityObject', 'MyActivityObjectDerived'], 'Object._id' : 1 }"); - results.Select(x => x.Id).Should().Equal(6); - } + filter.Should().Be("{ Object : { $ne : null }, 'Object._t.0' : { $exists : false }, 'Object._t' : 'MyActivityObject', 'Object._id' : 1 }"); + results.Select(x => x.Id).Should().Equal(3, 4); } + } - [Fact] - public void Find_with_typed_property_is_base_class_should_work() - { - Implementation(); - - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection2(); - var activityId = 1; - - var find = collection - .Find(x => - x.Object != null && - x.Object is TActivityObject && - ((TActivityObject)(object)x.Object).Id.Equals(activityId) - ); - - var filter = TranslateFindFilter(collection, find); - var results = find.ToList(); - - filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : 'MyActivityObject', 'Object._id' : 1 }"); - results.Select(x => x.Id).Should().Equal(3, 4, 6); - } - } + [Fact] + public void Find_with_object_property_GetType_comparison_to_derived_class_should_work() + { + Implementation(); - [Fact] - public void Find_with_typed_property_is_derived_class_should_work() + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() { - Implementation(); - - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection2(); - var activityId = 1; - - var find = collection - .Find(x => - x.Object != null && - x.Object is TActivityObject && - ((TActivityObject)(object)x.Object).Id.Equals(activityId) - ); - - var filter = TranslateFindFilter(collection, find); - var results = find.ToList(); - - filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : 'MyActivityObjectDerived', 'Object._id' : 1 }"); - results.Select(x => x.Id).Should().Equal(6); - } + var collection = GetCollection1(); + var activityId = 1; + + var find = collection + .Find(x => + x.Object != null && + x.Object.GetType() == typeof(TActivityObject) && + ((TActivityObject)x.Object).Id.Equals(activityId) + ); + + var filter = TranslateFindFilter(collection, find); + var results = find.ToList(); + + filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : ['MyActivityObject', 'MyActivityObjectDerived'], 'Object._id' : 1 }"); + results.Select(x => x.Id).Should().Equal(6); } + } - [Fact] - public void Select_with_object_property_GetType_comparison_to_base_class_should_work() - { - Implementation(); + [Fact] + public void Find_with_object_property_is_base_class_should_work() + { + Implementation(); - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection1(); + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() + { + var collection = GetCollection1(); + var activityId = 1; - var queryable = collection.AsQueryable() - .Select(x => new { x.Id, R = x.Object.GetType() == typeof(TActivityObject) }); + var find = collection + .Find(x => + x.Object != null && + x.Object is TActivityObject && + ((TActivityObject)x.Object).Id.Equals(activityId) + ); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _id : '$_id', R : { $eq : ['$Object._t', 'MyActivityObject'] } } }"); + var filter = TranslateFindFilter(collection, find); + var results = find.ToList(); - var results = queryable.ToList(); - results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, true, true, true, false); - } + filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : 'MyActivityObject', 'Object._id' : 1 }"); + results.Select(x => x.Id).Should().Equal(3, 4, 6); } + } - [Fact] - public void Select_with_object_property_GetType_comparison_to_derived_class_should_work() - { - Implementation(); + [Fact] + public void Find_with_object_property_is_derived_class_should_work() + { + Implementation(); - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection1(); + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() + { + var collection = GetCollection1(); + var activityId = 1; - var queryable = collection.AsQueryable() - .Select(x => new { x.Id, R = x.Object.GetType() == typeof(TActivityObject) }); + var find = collection + .Find(x => + x.Object != null && + x.Object is TActivityObject && + ((TActivityObject)x.Object).Id.Equals(activityId) + ); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _id : '$_id', R : { $eq : ['$Object._t', ['MyActivityObject', 'MyActivityObjectDerived']] } } }"); + var filter = TranslateFindFilter(collection, find); + var results = find.ToList(); - var results = queryable.ToList(); - results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, false, false, false, true); - } + filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : 'MyActivityObjectDerived', 'Object._id' : 1 }"); + results.Select(x => x.Id).Should().Equal(6); } + } - [Fact] - public void Select_with_object_property_is_base_class_should_work() - { - Implementation(); + [Fact] + public void Find_with_typed_property_GetType_comparison_to_base_class_should_work() + { + Implementation(); - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection1(); + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() + { + var collection = GetCollection2(); + var activityId = 1; - var queryable = collection.AsQueryable() - .Select(x => new { x.Id, R = x.Object is TActivityObject }); + var find = collection + .Find(x => + x.Object != null && + x.Object.GetType() == typeof(TActivityObject) && + ((TActivityObject)(object)x.Object).Id.Equals(activityId) + ); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _id : '$_id', R : { $cond : { if : { $eq : [{ $type : '$Object._t' }, 'array'] }, then : { $in : ['MyActivityObject', '$Object._t'] }, else : { $eq : ['$Object._t', 'MyActivityObject'] } } } } }"); + var filter = TranslateFindFilter(collection, find); + var results = find.ToList(); - var results = queryable.ToList(); - results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, true, true, true, true); - } + filter.Should().Be("{ Object : { $ne : null }, 'Object._t.0' : { $exists : false }, 'Object._t' : 'MyActivityObject', 'Object._id' : 1 }"); + results.Select(x => x.Id).Should().Equal(3, 4); } + } - [Fact] - public void Select_with_object_property_is_derived_class_should_work() - { - Implementation(); + [Fact] + public void Find_with_typed_property_GetType_comparison_to_derived_class_should_work() + { + Implementation(); - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection1(); + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() + { + var collection = GetCollection2(); + var activityId = 1; - var queryable = collection.AsQueryable() - .Select(x => new { x.Id, R = x.Object is TActivityObject }); + var find = collection + .Find(x => + x.Object != null && + x.Object.GetType() == typeof(TActivityObject) && + ((TActivityObject)(object)x.Object).Id.Equals(activityId) + ); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _id : '$_id', R : { $cond : { if : { $eq : [{ $type : '$Object._t' }, 'array'] }, then : { $in : ['MyActivityObjectDerived', '$Object._t'] }, else : { $eq : ['$Object._t', 'MyActivityObjectDerived'] } } } } }"); + var filter = TranslateFindFilter(collection, find); + var results = find.ToList(); - var results = queryable.ToList(); - results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, false, false, false, true); - } + filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : ['MyActivityObject', 'MyActivityObjectDerived'], 'Object._id' : 1 }"); + results.Select(x => x.Id).Should().Equal(6); } + } - [Fact] - public void Select_with_typed_property_GetType_comparison_to_base_class_should_work() - { - Implementation(); + [Fact] + public void Find_with_typed_property_is_base_class_should_work() + { + Implementation(); - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection2(); + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() + { + var collection = GetCollection2(); + var activityId = 1; - var queryable = collection.AsQueryable() - .Select(x => new { x.Id, R = x.Object.GetType() == typeof(TActivityObject) }); + var find = collection + .Find(x => + x.Object != null && + x.Object is TActivityObject && + ((TActivityObject)(object)x.Object).Id.Equals(activityId) + ); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _id : '$_id', R : { $eq : ['$Object._t', 'MyActivityObject'] } } }"); + var filter = TranslateFindFilter(collection, find); + var results = find.ToList(); - var results = queryable.ToList(); - results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, true, true, true, false); - } + filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : 'MyActivityObject', 'Object._id' : 1 }"); + results.Select(x => x.Id).Should().Equal(3, 4, 6); } + } - [Fact] - public void Select_with_typed_property_GetType_comparison_to_derived_class_should_work() - { - Implementation(); + [Fact] + public void Find_with_typed_property_is_derived_class_should_work() + { + Implementation(); - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection2(); + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() + { + var collection = GetCollection2(); + var activityId = 1; - var queryable = collection.AsQueryable() - .Select(x => new { x.Id, R = x.Object.GetType() == typeof(TActivityObject) }); + var find = collection + .Find(x => + x.Object != null && + x.Object is TActivityObject && + ((TActivityObject)(object)x.Object).Id.Equals(activityId) + ); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _id : '$_id', R : { $eq : ['$Object._t', ['MyActivityObject', 'MyActivityObjectDerived']] } } }"); + var filter = TranslateFindFilter(collection, find); + var results = find.ToList(); - var results = queryable.ToList(); - results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, false, false, true); - } + filter.Should().Be("{ Object : { $ne : null }, 'Object._t' : 'MyActivityObjectDerived', 'Object._id' : 1 }"); + results.Select(x => x.Id).Should().Equal(6); } + } - [Fact] - public void Select_with_typed_property_is_base_class_should_work() - { - Implementation(); + [Fact] + public void Select_with_object_property_GetType_comparison_to_base_class_should_work() + { + Implementation(); - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection2(); + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() + { + var collection = GetCollection1(); - var queryable = collection.AsQueryable() - .Select(x => new { x.Id, R = x.Object is TActivityObject }); + var queryable = collection.AsQueryable() + .Select(x => new { x.Id, R = x.Object.GetType() == typeof(TActivityObject) }); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _id : '$_id', R : { $cond : { if : { $eq : [{ $type : '$Object._t' }, 'array'] }, then : { $in : ['MyActivityObject', '$Object._t'] }, else : { $eq : ['$Object._t', 'MyActivityObject'] } } } } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _id : '$_id', R : { $eq : ['$Object._t', 'MyActivityObject'] } } }"); - var results = queryable.ToList(); - results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, true, true, true, true); - } + var results = queryable.ToList(); + results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, true, true, true, false); } + } - [Fact] - public void Select_with_typed_property_is_derived_class_should_work() - { - Implementation(); + [Fact] + public void Select_with_object_property_GetType_comparison_to_derived_class_should_work() + { + Implementation(); - void Implementation() - where TActivityObject : ActivityObject - where TId : notnull, IEquatable, new() - { - var collection = GetCollection2(); + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() + { + var collection = GetCollection1(); - var queryable = collection.AsQueryable() - .Select(x => new { x.Id, R = x.Object is TActivityObject }); + var queryable = collection.AsQueryable() + .Select(x => new { x.Id, R = x.Object.GetType() == typeof(TActivityObject) }); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $project : { _id : '$_id', R : { $cond : { if : { $eq : [{ $type : '$Object._t' }, 'array'] }, then : { $in : ['MyActivityObjectDerived', '$Object._t'] }, else : { $eq : ['$Object._t', 'MyActivityObjectDerived'] } } } } }"); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _id : '$_id', R : { $eq : ['$Object._t', ['MyActivityObject', 'MyActivityObjectDerived']] } } }"); - var results = queryable.ToList(); - results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, false, false, true); - } + var results = queryable.ToList(); + results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, false, false, false, true); } + } - private IMongoCollection GetCollection1() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new Activity1 { Id = 1, Object = null }, - new Activity1 { Id = 2, Object = "abc" }, - new Activity1 { Id = 3, Object = new MyActivityObject { Id = 1 } }, - new Activity1 { Id = 4, Object = new MyActivityObject { Id = 1 } }, - new Activity1 { Id = 5, Object = new MyActivityObject { Id = 2 } }, - new Activity1 { Id = 6, Object = new MyActivityObjectDerived { Id = 1 } }); - return collection; - } + [Fact] + public void Select_with_object_property_is_base_class_should_work() + { + Implementation(); - private IMongoCollection GetCollection2() + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() { - var collection = GetCollection("test"); - CreateCollection( - collection, - new Activity2 { Id = 1, Object = null }, - new Activity2 { Id = 3, Object = new MyActivityObject { Id = 1 } }, - new Activity2 { Id = 4, Object = new MyActivityObject { Id = 1 } }, - new Activity2 { Id = 5, Object = new MyActivityObject { Id = 2 } }, - new Activity2 { Id = 6, Object = new MyActivityObjectDerived { Id = 1 } }); - return collection; + var collection = GetCollection1(); + + var queryable = collection.AsQueryable() + .Select(x => new { x.Id, R = x.Object is TActivityObject }); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _id : '$_id', R : { $cond : { if : { $eq : [{ $type : '$Object._t' }, 'array'] }, then : { $in : ['MyActivityObject', '$Object._t'] }, else : { $eq : ['$Object._t', 'MyActivityObject'] } } } } }"); + + var results = queryable.ToList(); + results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, true, true, true, true); } + } + + [Fact] + public void Select_with_object_property_is_derived_class_should_work() + { + Implementation(); - private class Activity1 + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() { - public int Id { get; set; } - public object Object { get; set; } + var collection = GetCollection1(); + + var queryable = collection.AsQueryable() + .Select(x => new { x.Id, R = x.Object is TActivityObject }); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _id : '$_id', R : { $cond : { if : { $eq : [{ $type : '$Object._t' }, 'array'] }, then : { $in : ['MyActivityObjectDerived', '$Object._t'] }, else : { $eq : ['$Object._t', 'MyActivityObjectDerived'] } } } } }"); + + var results = queryable.ToList(); + results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, false, false, false, true); } + } + + [Fact] + public void Select_with_typed_property_GetType_comparison_to_base_class_should_work() + { + Implementation(); - private class Activity2 + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() { - public int Id { get; set; } - public ActivityObject Object { get; set; } + var collection = GetCollection2(); + + var queryable = collection.AsQueryable() + .Select(x => new { x.Id, R = x.Object.GetType() == typeof(TActivityObject) }); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _id : '$_id', R : { $eq : ['$Object._t', 'MyActivityObject'] } } }"); + + var results = queryable.ToList(); + results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, true, true, true, false); } + } + + [Fact] + public void Select_with_typed_property_GetType_comparison_to_derived_class_should_work() + { + Implementation(); - private abstract class ActivityObject + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() { - public abstract TId Id { get; set; } + var collection = GetCollection2(); + + var queryable = collection.AsQueryable() + .Select(x => new { x.Id, R = x.Object.GetType() == typeof(TActivityObject) }); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _id : '$_id', R : { $eq : ['$Object._t', ['MyActivityObject', 'MyActivityObjectDerived']] } } }"); + + var results = queryable.ToList(); + results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, false, false, true); } + } - [BsonDiscriminator(RootClass = true)] - [BsonKnownTypes(typeof(MyActivityObjectDerived))] - private class MyActivityObject : ActivityObject + [Fact] + public void Select_with_typed_property_is_base_class_should_work() + { + Implementation(); + + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() { - public override int Id { get; set; } + var collection = GetCollection2(); + + var queryable = collection.AsQueryable() + .Select(x => new { x.Id, R = x.Object is TActivityObject }); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _id : '$_id', R : { $cond : { if : { $eq : [{ $type : '$Object._t' }, 'array'] }, then : { $in : ['MyActivityObject', '$Object._t'] }, else : { $eq : ['$Object._t', 'MyActivityObject'] } } } } }"); + + var results = queryable.ToList(); + results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, true, true, true, true); } + } - private class MyActivityObjectDerived : MyActivityObject + [Fact] + public void Select_with_typed_property_is_derived_class_should_work() + { + Implementation(); + + void Implementation() + where TActivityObject : ActivityObject + where TId : notnull, IEquatable, new() { + var collection = GetCollection2(); + + var queryable = collection.AsQueryable() + .Select(x => new { x.Id, R = x.Object is TActivityObject }); + + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $project : { _id : '$_id', R : { $cond : { if : { $eq : [{ $type : '$Object._t' }, 'array'] }, then : { $in : ['MyActivityObjectDerived', '$Object._t'] }, else : { $eq : ['$Object._t', 'MyActivityObjectDerived'] } } } } }"); + + var results = queryable.ToList(); + results.OrderBy(x => x.Id).Select(x => x.R).Should().Equal(false, false, false, false, true); } } + + private IMongoCollection GetCollection1() + { + var collection = GetCollection("test"); + CreateCollection( + collection, + new Activity1 { Id = 1, Object = null }, + new Activity1 { Id = 2, Object = "abc" }, + new Activity1 { Id = 3, Object = new MyActivityObject { Id = 1 } }, + new Activity1 { Id = 4, Object = new MyActivityObject { Id = 1 } }, + new Activity1 { Id = 5, Object = new MyActivityObject { Id = 2 } }, + new Activity1 { Id = 6, Object = new MyActivityObjectDerived { Id = 1 } }); + return collection; + } + + private IMongoCollection GetCollection2() + { + var collection = GetCollection("test"); + CreateCollection( + collection, + new Activity2 { Id = 1, Object = null }, + new Activity2 { Id = 3, Object = new MyActivityObject { Id = 1 } }, + new Activity2 { Id = 4, Object = new MyActivityObject { Id = 1 } }, + new Activity2 { Id = 5, Object = new MyActivityObject { Id = 2 } }, + new Activity2 { Id = 6, Object = new MyActivityObjectDerived { Id = 1 } }); + return collection; + } + + private class Activity1 + { + public int Id { get; set; } + public object Object { get; set; } + } + + private class Activity2 + { + public int Id { get; set; } + public ActivityObject Object { get; set; } + } + + private abstract class ActivityObject + { + public abstract TId Id { get; set; } + } + + [BsonDiscriminator(RootClass = true)] + [BsonKnownTypes(typeof(MyActivityObjectDerived))] + private class MyActivityObject : ActivityObject + { + public override int Id { get; set; } + } + + private class MyActivityObjectDerived : MyActivityObject + { + } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/PositionalUpdateOperatorRenderingTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/PositionalUpdateOperatorRenderingTests.cs index 456bd5332db..9488591864f 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/PositionalUpdateOperatorRenderingTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/PositionalUpdateOperatorRenderingTests.cs @@ -76,7 +76,7 @@ public void Positional_update_operator_update_documents_in_an_array_example() [Fact] public void All_positional_update_operator_update_all_elements_in_an_array_example() { - var update = Builders.Update.Inc(s => s.Grades.AllElements(), 10) ; + var update = Builders.Update.Inc(s => s.Grades.AllElements(), 10); var rendered = Render(update); rendered.Should().Be("{ $inc : { 'Grades.$[]' : 10 } }"); @@ -140,7 +140,7 @@ private BsonValue Render(UpdateDefinition update) private class C { public int Id { get; set; } - public int[] A { get; set; } + public int[] A { get; set; } } private class Student1 @@ -155,7 +155,7 @@ private class Student2 private class Grade2 { - public int Grade { get ; set; } + public int Grade { get; set; } public int Mean { get; set; } public int Std { get; set; } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/ReplaceOneUpsertedIdTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/ReplaceOneUpsertedIdTests.cs index 3b03a6f2274..212eaaa0b13 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/ReplaceOneUpsertedIdTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/ReplaceOneUpsertedIdTests.cs @@ -25,29 +25,29 @@ public class ReplaceOneUpsertedIdTests : LinqIntegrationTest { IsUpsert = true }; - var data = new Data { Id = 8, Text = "updated" }; - - var result = collection.ReplaceOne(d => true, data, options); - - result.UpsertedId.Should().Be(8); - } - - public class Data - { - public int Id { get; set; } - public string Text { get; set; } - } - - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => null; - } + { } + + [Fact] + public void ReplaceOne() + { + var collection = Fixture.Collection; + var options = new ReplaceOptions { IsUpsert = true }; + var data = new Data { Id = 8, Text = "updated" }; + + var result = collection.ReplaceOne(d => true, data, options); + + result.UpsertedId.Should().Be(8); + } + + public class Data + { + public int Id { get; set; } + public string Text { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => null; + } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/StringToLowerToUpperProjectionAndFilterTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/StringToLowerToUpperProjectionAndFilterTests.cs index 21284ef0471..c78a90641fb 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/StringToLowerToUpperProjectionAndFilterTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/StringToLowerToUpperProjectionAndFilterTests.cs @@ -22,237 +22,237 @@ namespace MongoDB.Driver.Tests.Linq.Integration; // Regression test for CSHARP-3865. [Trait("Category", "Integration")] public class StringToLowerToUpperProjectionAndFilterTests +{ + [Fact] + public void Expression_using_ToLower_should_work() { - [Fact] - public void Expression_using_ToLower_should_work() - { - var collection = GetCollection(); + var collection = GetCollection(); - var queryable = - from product in collection.AsQueryable() - select new { Result = product.FriendlyName.ToLower() }; + var queryable = + from product in collection.AsQueryable() + select new { Result = product.FriendlyName.ToLower() }; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $project : { Result : { $toLower : '$FriendlyName' }, _id : 0 } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Expression_using_ToLowerInvariant_should_work() - { - var collection = GetCollection(); + [Fact] + public void Expression_using_ToLowerInvariant_should_work() + { + var collection = GetCollection(); - var queryable = - from product in collection.AsQueryable() - select new { Result = product.FriendlyName.ToLowerInvariant() }; + var queryable = + from product in collection.AsQueryable() + select new { Result = product.FriendlyName.ToLowerInvariant() }; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $project : { Result : { $toLower : '$FriendlyName' }, _id : 0 } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Expression_using_ToUpper_should_work() - { - var collection = GetCollection(); + [Fact] + public void Expression_using_ToUpper_should_work() + { + var collection = GetCollection(); - var queryable = - from product in collection.AsQueryable() - select new { Result = product.FriendlyName.ToUpper() }; + var queryable = + from product in collection.AsQueryable() + select new { Result = product.FriendlyName.ToUpper() }; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $project : { Result : { $toUpper : '$FriendlyName' }, _id : 0 } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Expression_using_ToUpperInvariant_should_work() - { - var collection = GetCollection(); + [Fact] + public void Expression_using_ToUpperInvariant_should_work() + { + var collection = GetCollection(); - var queryable = - from product in collection.AsQueryable() - select new { Result = product.FriendlyName.ToUpperInvariant() }; + var queryable = + from product in collection.AsQueryable() + select new { Result = product.FriendlyName.ToUpperInvariant() }; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $project : { Result : { $toUpper : '$FriendlyName' }, _id : 0 } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Filter_using_ToLower_with_equality_operator_should_work() - { - var collection = GetCollection(); - var friendlyName = "Widget"; + [Fact] + public void Filter_using_ToLower_with_equality_operator_should_work() + { + var collection = GetCollection(); + var friendlyName = "Widget"; - var queryable = - from product in collection.AsQueryable() - where product.FriendlyName.ToLower() == friendlyName.ToLower() - select product; + var queryable = + from product in collection.AsQueryable() + where product.FriendlyName.ToLower() == friendlyName.ToLower() + select product; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { FriendlyName : /^widget$/is } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Filter_using_ToLower_with_Equals_should_work() - { - var collection = GetCollection(); - var friendlyName = "Widget"; + [Fact] + public void Filter_using_ToLower_with_Equals_should_work() + { + var collection = GetCollection(); + var friendlyName = "Widget"; - var queryable = - from product in collection.AsQueryable() - where product.FriendlyName.ToLower().Equals(friendlyName.ToLower()) - select product; + var queryable = + from product in collection.AsQueryable() + where product.FriendlyName.ToLower().Equals(friendlyName.ToLower()) + select product; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { FriendlyName : /^widget$/is } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Filter_using_ToLowerInvariant_with_equality_operator_should_work() - { - var collection = GetCollection(); - var friendlyName = "Widget"; + [Fact] + public void Filter_using_ToLowerInvariant_with_equality_operator_should_work() + { + var collection = GetCollection(); + var friendlyName = "Widget"; - var queryable = - from product in collection.AsQueryable() - where product.FriendlyName.ToLowerInvariant() == friendlyName.ToLower() - select product; + var queryable = + from product in collection.AsQueryable() + where product.FriendlyName.ToLowerInvariant() == friendlyName.ToLower() + select product; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { FriendlyName : /^widget$/is } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Filter_using_ToLowerInvariant_with_Equals_should_work() - { - var collection = GetCollection(); - var friendlyName = "Widget"; + [Fact] + public void Filter_using_ToLowerInvariant_with_Equals_should_work() + { + var collection = GetCollection(); + var friendlyName = "Widget"; - var queryable = - from product in collection.AsQueryable() - where product.FriendlyName.ToLowerInvariant().Equals(friendlyName.ToLower()) - select product; + var queryable = + from product in collection.AsQueryable() + where product.FriendlyName.ToLowerInvariant().Equals(friendlyName.ToLower()) + select product; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { FriendlyName : /^widget$/is } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Filter_using_ToUpper_with_equality_operator_should_work() - { - var collection = GetCollection(); - var friendlyName = "Widget"; + [Fact] + public void Filter_using_ToUpper_with_equality_operator_should_work() + { + var collection = GetCollection(); + var friendlyName = "Widget"; - var queryable = - from product in collection.AsQueryable() - where product.FriendlyName.ToUpper() == friendlyName.ToUpper() - select product; + var queryable = + from product in collection.AsQueryable() + where product.FriendlyName.ToUpper() == friendlyName.ToUpper() + select product; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { FriendlyName : /^WIDGET$/is } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Filter_using_ToUpper_with_Equals_should_work() - { - var collection = GetCollection(); - var friendlyName = "Widget"; + [Fact] + public void Filter_using_ToUpper_with_Equals_should_work() + { + var collection = GetCollection(); + var friendlyName = "Widget"; - var queryable = - from product in collection.AsQueryable() - where product.FriendlyName.ToUpper().Equals(friendlyName.ToUpper()) - select product; + var queryable = + from product in collection.AsQueryable() + where product.FriendlyName.ToUpper().Equals(friendlyName.ToUpper()) + select product; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { FriendlyName : /^WIDGET$/is } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void Filter_using_ToUpperInvariant_with_equality_operator_should_work() - { - var collection = GetCollection(); - var friendlyName = "Widget"; + [Fact] + public void Filter_using_ToUpperInvariant_with_equality_operator_should_work() + { + var collection = GetCollection(); + var friendlyName = "Widget"; - var queryable = - from product in collection.AsQueryable() - where product.FriendlyName.ToUpperInvariant() == friendlyName.ToUpper() - select product; + var queryable = + from product in collection.AsQueryable() + where product.FriendlyName.ToUpperInvariant() == friendlyName.ToUpper() + select product; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { FriendlyName : /^WIDGET$/is } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - [Fact] - public void ToUpperInvariant_with_Equals_should_work() - { - var collection = GetCollection(); - var friendlyName = "Widget"; + [Fact] + public void ToUpperInvariant_with_Equals_should_work() + { + var collection = GetCollection(); + var friendlyName = "Widget"; - var queryable = - from product in collection.AsQueryable() - where product.FriendlyName.ToUpperInvariant().Equals(friendlyName.ToUpper()) - select product; + var queryable = + from product in collection.AsQueryable() + where product.FriendlyName.ToUpperInvariant().Equals(friendlyName.ToUpper()) + select product; - var stages = Linq3TestHelpers.Translate(collection, queryable); - var expectedStages = new[] - { + var stages = Linq3TestHelpers.Translate(collection, queryable); + var expectedStages = new[] + { "{ $match : { FriendlyName : /^WIDGET$/is } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); - } + Linq3TestHelpers.AssertStages(stages, expectedStages); + } - private IMongoCollection GetCollection() - { - var client = DriverTestConfiguration.Client; - var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); - return database.GetCollection(DriverTestConfiguration.CollectionNamespace.CollectionName); - } + private IMongoCollection GetCollection() + { + var client = DriverTestConfiguration.Client; + var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); + return database.GetCollection(DriverTestConfiguration.CollectionNamespace.CollectionName); + } - private class Product - { - public int Id { get; set; } - public string FriendlyName { get; set; } - } + private class Product + { + public int Id { get; set; } + public string FriendlyName { get; set; } } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateDefinitionCombinePipelineThrowsTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateDefinitionCombinePipelineThrowsTests.cs index 8083d41b8c9..667350553ae 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateDefinitionCombinePipelineThrowsTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateDefinitionCombinePipelineThrowsTests.cs @@ -22,33 +22,33 @@ namespace MongoDB.Driver.Tests.Linq.Integration; // Regression test for CSHARP-4746. public class UpdateDefinitionCombinePipelineThrowsTests { - [Fact] - public void UpdateDefinitionBuilder_Combine_should_throw_when_PipelineUpdateDefinition_is_combined_with_another_update() - { - var pipeline = new EmptyPipelineDefinition(); - var pipelineUpdate = Builders.Update.Pipeline(pipeline); - var setUpdate = Builders.Update.Set(x => x.X, 2); - - var exception = Record.Exception(() => new UpdateDefinitionBuilder().Combine(pipelineUpdate, setUpdate)); - - exception.Should().BeOfType(); - } - - [Fact] - public void UpdateDefinitionBuilder_Combine_should_throw_when_an_update_is_combined_with_a_PipelineUpdateDefinition() - { - var setUpdate = Builders.Update.Set(x => x.X, 2); - var pipeline = new EmptyPipelineDefinition(); - var pipelineUpdate = Builders.Update.Pipeline(pipeline); - - var exception = Record.Exception(() => new UpdateDefinitionBuilder().Combine(setUpdate, pipelineUpdate)); - - exception.Should().BeOfType(); - } - - private class C - { - public int Id { get; set; } - public int X { get; set; } - } + [Fact] + public void UpdateDefinitionBuilder_Combine_should_throw_when_PipelineUpdateDefinition_is_combined_with_another_update() + { + var pipeline = new EmptyPipelineDefinition(); + var pipelineUpdate = Builders.Update.Pipeline(pipeline); + var setUpdate = Builders.Update.Set(x => x.X, 2); + + var exception = Record.Exception(() => new UpdateDefinitionBuilder().Combine(pipelineUpdate, setUpdate)); + + exception.Should().BeOfType(); + } + + [Fact] + public void UpdateDefinitionBuilder_Combine_should_throw_when_an_update_is_combined_with_a_PipelineUpdateDefinition() + { + var setUpdate = Builders.Update.Set(x => x.X, 2); + var pipeline = new EmptyPipelineDefinition(); + var pipelineUpdate = Builders.Update.Pipeline(pipeline); + + var exception = Record.Exception(() => new UpdateDefinitionBuilder().Combine(setUpdate, pipelineUpdate)); + + exception.Should().BeOfType(); + } + + private class C + { + public int Id { get; set; } + public int X { get; set; } } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateSetReadOnlyCollectionWithChildSerializerTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateSetReadOnlyCollectionWithChildSerializerTests.cs index a3282b40494..93f9c32e1c8 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateSetReadOnlyCollectionWithChildSerializerTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateSetReadOnlyCollectionWithChildSerializerTests.cs @@ -54,7 +54,7 @@ public void Update_Set_with_List_should_work() var serializerRegistry = BsonSerializer.SerializerRegistry; var documentSerializer = serializerRegistry.GetSerializer(); - var rendered = (BsonDocument)update.Render(new (documentSerializer, serializerRegistry)); + var rendered = (BsonDocument)update.Render(new(documentSerializer, serializerRegistry)); rendered.Should().Be("{ $set : { ReadOnlyCollection : ['[abc]', '[def]'] } }"); var filter = Builders.Filter.Eq(x => x.Id, 1); @@ -73,7 +73,7 @@ public void Update_Set_with_Enumerable_should_throw() var serializerRegistry = BsonSerializer.SerializerRegistry; var documentSerializer = serializerRegistry.GetSerializer(); - var rendered = (BsonDocument)update.Render(new (documentSerializer, serializerRegistry)); + var rendered = (BsonDocument)update.Render(new(documentSerializer, serializerRegistry)); rendered.Should().Be("{ $set : { ReadOnlyCollection : ['[abc]', '[def]'] } }"); var filter = Builders.Filter.Eq(x => x.Id, 1); @@ -92,7 +92,7 @@ public void Update_Set_with_Enumerable_ToList_should_work() var serializerRegistry = BsonSerializer.SerializerRegistry; var documentSerializer = serializerRegistry.GetSerializer(); - var rendered = (BsonDocument)update.Render(new (documentSerializer, serializerRegistry)); + var rendered = (BsonDocument)update.Render(new(documentSerializer, serializerRegistry)); rendered.Should().Be("{ $set : { ReadOnlyCollection : ['[abc]', '[def]'] } }"); var filter = Builders.Filter.Eq(x => x.Id, 1); diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateSetValueObjectTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateSetValueObjectTests.cs index a33a5aaa2a4..48cbea940a9 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateSetValueObjectTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateSetValueObjectTests.cs @@ -136,7 +136,7 @@ public void Test_set_A() var pipelineError = new EmptyPipelineDefinition() .Set(x => new MyDocument() { - A = new [] { 2, x.A[0] } + A = new[] { 2, x.A[0] } }); var updateError = Builders.Update.Pipeline(pipelineError); diff --git a/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateWithDiscriminatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateWithDiscriminatorTests.cs index 5373151cd1c..158f23bbeb3 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateWithDiscriminatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Integration/UpdateWithDiscriminatorTests.cs @@ -111,5 +111,5 @@ public sealed class ClassFixture : MongoCollectionFixture public override bool InitializeDataBeforeEachTestCase => true; protected override IEnumerable InitialData => null; - } + } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/SerializerFinders/StringIdCustomObjectIdSerializerFilterTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/SerializerFinders/StringIdCustomObjectIdSerializerFilterTests.cs index 1a34d543abd..199eaf61344 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/SerializerFinders/StringIdCustomObjectIdSerializerFilterTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/SerializerFinders/StringIdCustomObjectIdSerializerFilterTests.cs @@ -30,72 +30,72 @@ public class StringIdCustomObjectIdSerializerFilterTests : LinqIntegrationTest.Filter.Where(x => x.Id == id); + var filter = Builders.Filter.Where(x => x.Id == id); - var renderedFilter = filter.Render(new(collection.DocumentSerializer, BsonSerializer.SerializerRegistry)); - renderedFilter.Should().Be("{ _id : ObjectId('111111111111111111111111' ) }"); + var renderedFilter = filter.Render(new(collection.DocumentSerializer, BsonSerializer.SerializerRegistry)); + renderedFilter.Should().Be("{ _id : ObjectId('111111111111111111111111' ) }"); - var result = collection.FindSync(filter).Single(); - result.X.Should().Be(1); - } + var result = collection.FindSync(filter).Single(); + result.X.Should().Be(1); + } - public class RootDocument - { - [BsonSerializer(typeof(CustomStringRepresentedAsObjectIdSerializer))] - public string Id { get; set; } - public int X { get; set; } - } + public class RootDocument + { + [BsonSerializer(typeof(CustomStringRepresentedAsObjectIdSerializer))] + public string Id { get; set; } + public int X { get; set; } + } - // This custom serializer is a slightly modified version of the custom serializer in the JIRA ticket - // note: normally this serializer would implement IHasRepresentationSerializer - // but for testing purposes we deliberately chose not to implement it - public class CustomStringRepresentedAsObjectIdSerializer : SerializerBase + // This custom serializer is a slightly modified version of the custom serializer in the JIRA ticket + // note: normally this serializer would implement IHasRepresentationSerializer + // but for testing purposes we deliberately chose not to implement it + public class CustomStringRepresentedAsObjectIdSerializer : SerializerBase + { + public override string Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) { - public override string Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) + BsonType type = context.Reader.GetCurrentBsonType(); + switch (type) { - BsonType type = context.Reader.GetCurrentBsonType(); - switch (type) - { - case BsonType.ObjectId: return context.Reader.ReadObjectId().ToString(); - default: - var message = $"Cannot convert a {type} to a String."; - throw new NotSupportedException(message); - } + case BsonType.ObjectId: return context.Reader.ReadObjectId().ToString(); + default: + var message = $"Cannot convert a {type} to a String."; + throw new NotSupportedException(message); } + } - public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, string value) + public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, string value) + { + context.Writer.WriteObjectId(ToObjectId(value)); + } + + private static ObjectId ToObjectId(string source) + { + if (ObjectId.TryParse(source, out ObjectId returnId)) { - context.Writer.WriteObjectId(ToObjectId(value)); + return returnId; } - - private static ObjectId ToObjectId(string source) + else { - if (ObjectId.TryParse(source, out ObjectId returnId)) - { - return returnId; - } - else - { - return ObjectId.Empty; - } + return ObjectId.Empty; } } + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new RootDocument { Id = "111111111111111111111111", X = 1 }, + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new RootDocument { Id = "111111111111111111111111", X = 1 }, new RootDocument { Id = "222222222222222222222222", X = 2 } - ]; - } + ]; } +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/ConvertTValueToBsonValueProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/ConvertTValueToBsonValueProjectionTests.cs index b6ebcee9595..20e0ff0d5e4 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/ConvertTValueToBsonValueProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/ConvertTValueToBsonValueProjectionTests.cs @@ -113,7 +113,7 @@ public static IEnumerable Convert_to_BsonValue_from_TValue_should_work var valueType = __testCases[i].ValueType; var valueAsJson = __testCases[i].ValueAsJson; var projectionAsString = __testCases[i].Projection.ToString(); - yield return new object[] { valueType, i, valueAsJson, projectionAsString }; + yield return new object[] { valueType, i, valueAsJson, projectionAsString }; } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/IGroupingEnumerableMethodsTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/IGroupingEnumerableMethodsTests.cs index ef96e4e7a08..bcd45bcc9d4 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/IGroupingEnumerableMethodsTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/IGroupingEnumerableMethodsTests.cs @@ -390,7 +390,7 @@ public void IGrouping_Any_with_predicate_of_root_should_work() var queryable = collection.AsQueryable() .GroupBy(c => c.Id) - .Select(g => new { Id = g.Key, Result = g.Any(e => e.X >0) }) + .Select(g => new { Id = g.Key, Result = g.Any(e => e.X > 0) }) .OrderBy(x => x.Id); var stages = Translate(collection, queryable); @@ -940,7 +940,7 @@ public void IGrouping_Except_of_root_should_work() var queryable = collection.AsQueryable() .GroupBy(c => c.Id) - .Select(g => new { Id = g.Key, Result = g.Except(new[] { new C { Id = 1, X = 1 } }) }) + .Select(g => new { Id = g.Key, Result = g.Except(new[] { new C { Id = 1, X = 1 } }) }) .OrderBy(x => x.Id); var stages = Translate(collection, queryable); diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/IndexerOverCustomDocumentSerializerTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/IndexerOverCustomDocumentSerializerTests.cs index dc8a877ec50..0cf641ec1ce 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/IndexerOverCustomDocumentSerializerTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/IndexerOverCustomDocumentSerializerTests.cs @@ -39,7 +39,7 @@ public void Test1() var collection = Fixture.Collection; var queryable = collection.AsQueryable() - .Select(x => x.Property[0] ); + .Select(x => x.Property[0]); var exception = Record.Exception(() => queryable.ToList()); exception.Should().BeOfType(); diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/ProjectWithObjectIdSerializerTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/ProjectWithObjectIdSerializerTests.cs index 821af17b03e..6eb0407ba69 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/ProjectWithObjectIdSerializerTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Serializers/ProjectWithObjectIdSerializerTests.cs @@ -28,67 +28,67 @@ public class ProjectWithObjectIdSerializerTests : LinqIntegrationTest new EntityInfo - { - Id = ewt.Id, - Name = ewt.Name, - Towns = ewt.Towns.Select(t => t.Id) - }) - .Match(ei => ei.Id != "0102030405060708090a0b0c") - .Match(ei => ei.Towns.Contains("1102030405060708090a0b0c")); + var aggregate = collection.Aggregate() + .Project(ewt => new EntityInfo + { + Id = ewt.Id, + Name = ewt.Name, + Towns = ewt.Towns.Select(t => t.Id) + }) + .Match(ei => ei.Id != "0102030405060708090a0b0c") + .Match(ei => ei.Towns.Contains("1102030405060708090a0b0c")); - var stages = Translate(collection, aggregate); - AssertStages( - stages, - """{ $project : { _id : "$_id", Name : "$Name", Towns : "$Towns._id" } }""", - """{ $match : { _id : { $ne : { $oid : "0102030405060708090a0b0c" } } } }""", - """{ $match : { Towns : "1102030405060708090a0b0c" } }"""); + var stages = Translate(collection, aggregate); + AssertStages( + stages, + """{ $project : { _id : "$_id", Name : "$Name", Towns : "$Towns._id" } }""", + """{ $match : { _id : { $ne : { $oid : "0102030405060708090a0b0c" } } } }""", + """{ $match : { Towns : "1102030405060708090a0b0c" } }"""); - var result = aggregate.Single(); - result.Name.Should().Be("2"); - } + var result = aggregate.Single(); + result.Name.Should().Be("2"); + } - public class EntityWithTowns - { - [BsonId, BsonRepresentation(BsonType.ObjectId)] - public string Id { get; set; } + public class EntityWithTowns + { + [BsonId, BsonRepresentation(BsonType.ObjectId)] + public string Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public IEnumerable Towns { get; set; } - } + public IEnumerable Towns { get; set; } + } - public class EntityInfo - { - [BsonId, BsonRepresentation(BsonType.ObjectId)] - public string Id { get; set; } + public class EntityInfo + { + [BsonId, BsonRepresentation(BsonType.ObjectId)] + public string Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public IEnumerable Towns { get; set; } - } + public IEnumerable Towns { get; set; } + } - public class Towns - { - public string Id { get; set; } - } + public class Towns + { + public string Id { get; set; } + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new EntityWithTowns { Id = "0102030405060708090a0b0c", Name = "1", Towns = new[] { new Towns { Id = "0102030405060708090a0b0c" } } }, + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new EntityWithTowns { Id = "0102030405060708090a0b0c", Name = "1", Towns = new[] { new Towns { Id = "0102030405060708090a0b0c" } } }, new EntityWithTowns { Id = "1102030405060708090a0b0c", Name = "2", Towns = new[] { new Towns { Id = "1102030405060708090a0b0c" } } }, ]; - } + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MemberInitExpressionToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MemberInitExpressionToAggregationExpressionTranslatorTests.cs index 442b594e5fa..0612ee2ace3 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MemberInitExpressionToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MemberInitExpressionToAggregationExpressionTranslatorTests.cs @@ -133,7 +133,8 @@ public void Should_project_via_constructor_with_inheritance() results.Identifier.Should().Be(1); } - [Fact] public void Should_project_to_class_with_additional_parameters() + [Fact] + public void Should_project_to_class_with_additional_parameters() { CreateCollection(); var collection = GetCollection("data"); diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConvertMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConvertMethodToAggregationExpressionTranslatorTests.cs index b0e236f59a0..f23a9e10fad 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConvertMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConvertMethodToAggregationExpressionTranslatorTests.cs @@ -35,8 +35,8 @@ public ConvertMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) } [Theory] - [InlineData(4, ByteOrder.LittleEndian,"ogIAAA==", null)] - [InlineData(6, ByteOrder.BigEndian, "AAAAKg==", null )] + [InlineData(4, ByteOrder.LittleEndian, "ogIAAA==", null)] + [InlineData(6, ByteOrder.BigEndian, "AAAAKg==", null)] [InlineData(10, ByteOrder.BigEndian, null, "MongoCommandException")] public void Convert_to_BsonBinaryData_from_int_should_work(int id, ByteOrder byteOrder, string expectedBase64, string expectedException) { @@ -59,8 +59,8 @@ public void Convert_to_BsonBinaryData_from_int_should_work(int id, ByteOrder byt } [Theory] - [InlineData(4, ByteOrder.LittleEndian,"ogIAAA==", null)] - [InlineData(6, ByteOrder.BigEndian, "AAAAKg==", null )] + [InlineData(4, ByteOrder.LittleEndian, "ogIAAA==", null)] + [InlineData(6, ByteOrder.BigEndian, "AAAAKg==", null)] [InlineData(10, ByteOrder.BigEndian, null, "MongoCommandException")] public void Convert_to_BsonBinaryData_from_long_should_work(int id, ByteOrder byteOrder, string expectedBase64, string expectedException) { @@ -92,8 +92,8 @@ public void Convert_to_BsonBinaryData_from_long_should_work(int id, ByteOrder by } [Theory] - [InlineData(3, ByteOrder.LittleEndian,"AAAAAAAA4L8=", null)] - [InlineData(5, ByteOrder.BigEndian, "wAQAAAAAAAA=", null )] + [InlineData(3, ByteOrder.LittleEndian, "AAAAAAAA4L8=", null)] + [InlineData(5, ByteOrder.BigEndian, "wAQAAAAAAAA=", null)] [InlineData(10, ByteOrder.BigEndian, null, "MongoCommandException")] public void Convert_to_BsonBinaryData_from_double_should_work(int id, ByteOrder byteOrder, string expectedBase64, string expectedException) { @@ -290,8 +290,8 @@ public void Convert_with_format_should_be_rendered_correctly(string format, stri } [Theory] - [InlineData(3, ByteOrder.LittleEndian,"AAAAAAAA4L8=")] - [InlineData(5, ByteOrder.BigEndian, "wAQAAAAAAAA=" )] + [InlineData(3, ByteOrder.LittleEndian, "AAAAAAAA4L8=")] + [InlineData(5, ByteOrder.BigEndian, "wAQAAAAAAAA=")] public void Convert_with_byteOrder_should_be_rendered_correctly(int id, ByteOrder byteOrder, string expectedBase64) { RequireServer.Check().Supports(Feature.ConvertOperatorBinDataToFromNumeric); diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DictionaryKeysAndValuesProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DictionaryKeysAndValuesProjectionTests.cs index d180e9b0d05..47baad1e9dd 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DictionaryKeysAndValuesProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DictionaryKeysAndValuesProjectionTests.cs @@ -39,7 +39,8 @@ public void Projection_of_ArrayOfDocuments_dictionary_keys_and_values_should_wor var queryable = collection .AsQueryable() - .Select(x => new { + .Select(x => new + { Keys = x.Data.Select(y => y.Key), Values = x.Data.Select(y => y.Value) }); diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/GroupFirstOrLastNestedFieldAccumulatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/GroupFirstOrLastNestedFieldAccumulatorTests.cs index 48b8190f5e5..0bf07a9a322 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/GroupFirstOrLastNestedFieldAccumulatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/GroupFirstOrLastNestedFieldAccumulatorTests.cs @@ -42,17 +42,17 @@ public void First_or_Last_optimization_should_work(int level, int firstOrLast, s var collection = Fixture.Collection; var queryable = (level, firstOrLast) switch - { - (1, 1) => collection.Aggregate().Group(x => 1, g => g.First().X), - (1, 2) => collection.Aggregate().Group(x => 1, g => g.Last().X), - (2, 1) => collection.Aggregate().Group(x => 1, g => g.First().D.Y), - (2, 2) => collection.Aggregate().Group(x => 1, g => g.Last().D.Y), - (3, 1) => collection.Aggregate().Group(x => 1, g => g.First().D.E.Z), - (3, 2) => collection.Aggregate().Group(x => 1, g => g.Last().D.E.Z), - _ => throw new ArgumentException() - }; + { + (1, 1) => collection.Aggregate().Group(x => 1, g => g.First().X), + (1, 2) => collection.Aggregate().Group(x => 1, g => g.Last().X), + (2, 1) => collection.Aggregate().Group(x => 1, g => g.First().D.Y), + (2, 2) => collection.Aggregate().Group(x => 1, g => g.Last().D.Y), + (3, 1) => collection.Aggregate().Group(x => 1, g => g.First().D.E.Z), + (3, 2) => collection.Aggregate().Group(x => 1, g => g.Last().D.E.Z), + _ => throw new ArgumentException() + }; - var stages = Translate(collection,queryable); + var stages = Translate(collection, queryable); AssertStages( stages, expectedGroupStage, diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/MedianMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/MedianMethodToAggregationExpressionTranslatorTests.cs index 2013568bb50..85a060bda18 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/MedianMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/MedianMethodToAggregationExpressionTranslatorTests.cs @@ -457,4 +457,4 @@ public sealed class ClassFixture : MongoCollectionFixture ]; } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/NestedWhereInProjectionToFilterTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/NestedWhereInProjectionToFilterTests.cs index 410c8e0265d..e546f67897d 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/NestedWhereInProjectionToFilterTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/NestedWhereInProjectionToFilterTests.cs @@ -28,7 +28,7 @@ public void Nested_where_should_work_with_array() var collection = GetCollection(); var queryable = collection.AsQueryable() - .Select(x => new { R = x.A.Where(i => i == 1)}); + .Select(x => new { R = x.A.Where(i => i == 1) }); var stages = Translate(collection, queryable); var expectedStages = new[] diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/OrderByThenByInProjectionToSortArrayTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/OrderByThenByInProjectionToSortArrayTests.cs index f15d398da8a..868310a2bd4 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/OrderByThenByInProjectionToSortArrayTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/OrderByThenByInProjectionToSortArrayTests.cs @@ -173,7 +173,7 @@ public void OrderBy_on_entire_object_followed_by_ThenBy_should_throw( } else { - var exception = Record.Exception(() => Translate(collection,queryable)); + var exception = Record.Exception(() => Translate(collection, queryable)); exception.Should().BeOfType(); exception.Message.Should().Contain("ThenBy and ThenByDescending cannot be used when OrderBy or OrderByDescending is sorting on the entire object"); } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/PercentileMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/PercentileMethodToAggregationExpressionTranslatorTests.cs index c0f1225c245..0e8f4f52ada 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/PercentileMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/PercentileMethodToAggregationExpressionTranslatorTests.cs @@ -538,4 +538,4 @@ public sealed class ClassFixture : MongoCollectionFixture ]; } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/PickMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/PickMethodToAggregationExpressionTranslatorTests.cs index 1f7290074cd..72713ce6862 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/PickMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/PickMethodToAggregationExpressionTranslatorTests.cs @@ -349,7 +349,7 @@ public void BottomN_computing_n_based_on_the_group_key_example_using_GroupBy_wit results.Should().HaveCount(2); results[0].Id.Should().Be(new { GameId = "G1" }); results[0].GameScores.Should().Equal(33, 31, 1); - results[1].Id.Should().Be( new { GameId = "G2" }); + results[1].Id.Should().Be(new { GameId = "G2" }); results[1].GameScores.Should().Equal(10); } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectBooleanConditionalProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectBooleanConditionalProjectionTests.cs index 2722723720b..36b0f05c931 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectBooleanConditionalProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectBooleanConditionalProjectionTests.cs @@ -172,8 +172,8 @@ public void Where_simplifications_should_work(int testCase, string expectedStage public class C { public int Id { get; set; } - public bool P { get; set; } - public bool Q { get; set; } + public bool P { get; set; } + public bool Q { get; set; } public int X { get; set; } public int Y { get; set; } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectEnumComparisonToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectEnumComparisonToAggregationExpressionTranslatorTests.cs index 468a8859a3b..737081bd2e2 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectEnumComparisonToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectEnumComparisonToAggregationExpressionTranslatorTests.cs @@ -46,7 +46,7 @@ public SelectEnumComparisonToAggregationExpressionTranslatorTests(ClassFixture f } private static SelectTestCase CreateSelectTestCase( - Expression> projection, + Expression> projection, string expectedStage, params int[] expectedResults) { diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectManyMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectManyMethodToAggregationExpressionTranslatorTests.cs index 7bab47fff24..13a6fd02349 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectManyMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectManyMethodToAggregationExpressionTranslatorTests.cs @@ -405,4 +405,4 @@ public sealed class ClassFixture : MongoCollectionFixture new() { Id = 3, Cat = "B", Tags = new[] { "y", "z" } } ]; } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMultiplyMixedIntegerTypesTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMultiplyMixedIntegerTypesTests.cs index 9ca02d590d2..f67f73b69c7 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMultiplyMixedIntegerTypesTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMultiplyMixedIntegerTypesTests.cs @@ -68,6 +68,6 @@ public class C public sealed class ClassFixture : MongoCollectionFixture { protected override IEnumerable InitialData - => [ new C { Int = 1, Byte = 1 } ]; + => [new C { Int = 1, Byte = 1 }]; } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectNewArrayOfDerivedTypesProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectNewArrayOfDerivedTypesProjectionTests.cs index bf0e1eb4b80..82052f32a97 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectNewArrayOfDerivedTypesProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectNewArrayOfDerivedTypesProjectionTests.cs @@ -61,12 +61,12 @@ public abstract class Animal public sealed class Cat : Animal { - public string C { get; set; } + public string C { get; set; } } public sealed class Dog : Animal { - public int D { get; set; } + public int D { get; set; } } public sealed class ClassFixture : MongoCollectionFixture diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectNullCoalescingStringProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectNullCoalescingStringProjectionTests.cs index 4b244ac6c80..d8717543b61 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectNullCoalescingStringProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectNullCoalescingStringProjectionTests.cs @@ -113,7 +113,7 @@ public void Coalesce_with_nullable_and_nullable_types_should_work(int scenario, [InlineData(4, "{ $project : { _v : { $literal : 5 }, _id : 0 } }", new int[] { 5, 5 })] [InlineData(5, "{ $project : { _v : { $ifNull : ['$NullableInt1', 6] }, _id : 0 } }", new int[] { 6, 3 })] [InlineData(6, "{ $project : { _v : { $ifNull : ['$NullableInt1', '$Int2'] }, _id : 0 } }", new int[] { 2, 3 })] - public void Coalesce_with_nullable_and_non_nullable_types_should_work(int scenario, string expectedStage, int[] expectedResults) + public void Coalesce_with_nullable_and_non_nullable_types_should_work(int scenario, string expectedStage, int[] expectedResults) { var collection = Fixture.Collection; int? constant1 = 5; diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectStringCompareProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectStringCompareProjectionTests.cs index 8a594651a0c..19db8a4145b 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectStringCompareProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectStringCompareProjectionTests.cs @@ -807,7 +807,7 @@ public void Where_String_Compare_field_to_constant_should_work(int scenario, str [InlineData(2, true, "{ $match : { $expr : { $eq : [{ $strcasecmp : ['$A', 'B'] }, 0] } } }", new int[] { 3, 6 })] [InlineData(3, true, "{ $match : { $expr : { $eq : [{ $strcasecmp : ['$A', 'B'] }, 1] } } }", new int[] { })] [InlineData(4, true, "{ $match : { $expr : { $ne : [{ $strcasecmp : ['$A', 'B'] }, -1] } } }", new int[] { 3, 6 })] - [InlineData(5, true, "{ $match : { $expr : { $ne : [{ $strcasecmp : ['$A', 'B'] }, 0] } } }", new int[] { 1, 2, 4, 5 })] + [InlineData(5, true, "{ $match : { $expr : { $ne : [{ $strcasecmp : ['$A', 'B'] }, 0] } } }", new int[] { 1, 2, 4, 5 })] [InlineData(6, true, "{ $match : { $expr : { $ne : [{ $strcasecmp : ['$A', 'B'] }, 1] } } }", new int[] { 1, 2, 3, 4, 5, 6 })] [InlineData(7, true, "{ $match : { $expr : { $gt : [{ $strcasecmp : ['$A', 'B'] }, -1] } } }", new int[] { 3, 6 })] [InlineData(8, true, "{ $match : { $expr : { $gt : [{ $strcasecmp : ['$A', 'B'] }, 0] } } }", new int[] { })] diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SequenceEqualInProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SequenceEqualInProjectionTests.cs index eddb0e30459..3dba0bb47b3 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SequenceEqualInProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SequenceEqualInProjectionTests.cs @@ -56,7 +56,7 @@ public class C public int[] B { get; set; } } - public sealed class ClassFixture : MongoCollectionFixture + public sealed class ClassFixture : MongoCollectionFixture { protected override IEnumerable InitialData => [ diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SigmoidMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SigmoidMethodToAggregationExpressionTranslatorTests.cs index 20a7f258cdf..44b782ef224 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SigmoidMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SigmoidMethodToAggregationExpressionTranslatorTests.cs @@ -46,7 +46,7 @@ public void Sigmoid_should_work() AssertStages(stages, "{ $project : { _v : { $sigmoid : '$X' }, _id : 0 } }"); var result = queryable.ToList(); - result.Should().BeEquivalentTo(new[] { 0.7310585786300049, 0.9933071490757153, 0.999997739675702, 0.9999999992417439}); + result.Should().BeEquivalentTo(new[] { 0.7310585786300049, 0.9933071490757153, 0.999997739675702, 0.9999999992417439 }); } [Fact] @@ -85,4 +85,4 @@ public sealed class ClassFixture : MongoCollectionFixture ]; } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipTakeArraySlicingInProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipTakeArraySlicingInProjectionTests.cs index 11e20da60c4..2444d861cfe 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipTakeArraySlicingInProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipTakeArraySlicingInProjectionTests.cs @@ -48,13 +48,13 @@ public void Skip_should_work(int scenario, string expectedStage, bool withNested 1 => withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Skip(1).ToArray()) : collection.AsQueryable().Select(x => x.A.Skip(1).ToArray()), - 2 => withNestedAsQueryable ? + 2 => withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Skip(x.One).ToArray()) : collection.AsQueryable().Select(x => x.A.Skip(x.One).ToArray()), - 3 => withNestedAsQueryable ? + 3 => withNestedAsQueryable ? collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.AsQueryable().Skip(1).ToArray()) : collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.Skip(1).ToArray()), - 4 => withNestedAsQueryable ? + 4 => withNestedAsQueryable ? collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.AsQueryable().Skip(x.One).ToArray()) : collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.Skip(x.One).ToArray()), _ => throw new ArgumentException($"Invalid scenario: {scenario}", nameof(scenario)) @@ -93,25 +93,25 @@ public void Skip_Skip_should_work(int scenario, string expectedStage, bool withN 1 => withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Skip(1).Skip(2).ToArray()) : collection.AsQueryable().Select(x => x.A.Skip(1).Skip(2).ToArray()), - 2 => withNestedAsQueryable ? + 2 => withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Skip(1).Skip(x.Two).ToArray()) : collection.AsQueryable().Select(x => x.A.Skip(1).Skip(x.Two).ToArray()), - 3 => withNestedAsQueryable ? + 3 => withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Skip(x.One).Skip(2).ToArray()) : collection.AsQueryable().Select(x => x.A.Skip(x.One).Skip(2).ToArray()), - 4 => withNestedAsQueryable ? + 4 => withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Skip(x.One).Skip(x.Two).ToArray()) : collection.AsQueryable().Select(x => x.A.Skip(x.One).Skip(x.Two).ToArray()), - 5 => withNestedAsQueryable ? + 5 => withNestedAsQueryable ? collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.AsQueryable().Skip(1).Skip(2).ToArray()) : collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.Skip(1).Skip(2).ToArray()), - 6 => withNestedAsQueryable ? + 6 => withNestedAsQueryable ? collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.AsQueryable().Skip(1).Skip(x.Two).ToArray()) : collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.Skip(1).Skip(x.Two).ToArray()), - 7 => withNestedAsQueryable ? + 7 => withNestedAsQueryable ? collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.AsQueryable().Skip(x.One).Skip(2).ToArray()) : collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.Skip(x.One).Skip(2).ToArray()), - 8 => withNestedAsQueryable ? + 8 => withNestedAsQueryable ? collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.AsQueryable().Skip(x.One).Skip(x.Two).ToArray()) : collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.Skip(x.One).Skip(x.Two).ToArray()), _ => throw new ArgumentException($"Invalid scenario: {scenario}", nameof(scenario)) @@ -223,7 +223,7 @@ public void Skip_Take_Skip_should_work(int scenario, string expectedStage, bool 1 => withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Skip(2).Take(3).Skip(1).ToArray()) : collection.AsQueryable().Select(x => x.A.Skip(2).Take(3).Skip(1).ToArray()), - 2 => withNestedAsQueryable ? + 2 => withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Skip(2).Take(3).Skip(x.One).ToArray()) : collection.AsQueryable().Select(x => x.A.Skip(2).Take(3).Skip(x.One).ToArray()), 3 => withNestedAsQueryable ? diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SplitMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SplitMethodToAggregationExpressionTranslatorTests.cs index ed1b242c581..9023f9851c8 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SplitMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SplitMethodToAggregationExpressionTranslatorTests.cs @@ -50,10 +50,10 @@ public void Translate_should_throw_on_non_supported_expressions(LambdaExpression exception.Should().BeOfType(); } - private static char[] __singleCharsSeparator = [ ',' ]; - private static char[] __multipleCharsSeparator = [ ',', ';' ]; - private static string[] __singleStringsSeparator = [ "," ]; - private static string[] __multipleStringsSeparator = [ ",", ";" ]; + private static char[] __singleCharsSeparator = [',']; + private static char[] __multipleCharsSeparator = [',', ';']; + private static string[] __singleStringsSeparator = [","]; + private static string[] __multipleStringsSeparator = [",", ";"]; public static IEnumerable SupportedTestCases = [ #if NETCOREAPP || NET6_0_OR_GREATER diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WindowMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WindowMethodToAggregationExpressionTranslatorTests.cs index aa5cf67b5f0..1b4f72460c6 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WindowMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WindowMethodToAggregationExpressionTranslatorTests.cs @@ -1950,7 +1950,8 @@ public void Translate_should_return_expected_result_for_Median_with_window() .SetWindowFields( partitionBy: x => 1, sortBy: Builders.Sort.Ascending(x => x.Id), - output: p => new { + output: p => new + { Result = p.Median(x => x.Int32Field, DocumentsWindow.Create(-1, 1)) }); @@ -2579,7 +2580,8 @@ public void Translate_should_return_expected_result_for_Percentile_with_window() .SetWindowFields( partitionBy: x => 1, sortBy: Builders.Sort.Ascending(x => x.Id), - output: p => new { + output: p => new + { Result = p.Percentile(x => x.Int32Field, new[] { 0.5 }, DocumentsWindow.Create(-1, 1)) }); diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NegateExpressionToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NegateExpressionToAggregationExpressionTranslatorTests.cs index 60b3a361e15..56a0a629bc5 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NegateExpressionToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NegateExpressionToAggregationExpressionTranslatorTests.cs @@ -25,7 +25,7 @@ namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators { - public class NegateExpressionToAggregationExpressionTranslatorTests: LinqIntegrationTest + public class NegateExpressionToAggregationExpressionTranslatorTests : LinqIntegrationTest { public NegateExpressionToAggregationExpressionTranslatorTests(ClassFixture fixture) : base(fixture) diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewDictionaryExpressionToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewDictionaryExpressionToAggregationExpressionTranslatorTests.cs index 59931e8f199..a5255256e16 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewDictionaryExpressionToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewDictionaryExpressionToAggregationExpressionTranslatorTests.cs @@ -48,7 +48,7 @@ public void NewDictionary_with_KeyValuePairs_should_translate() AssertStages(stages, "{ $project : { _v : { A : '$A', B: '$B' }, _id : 0 } }"); var result = queryable.Single(); - result.Should().Equal(new Dictionary{ ["A"] = "a", ["B"] = "b" }); + result.Should().Equal(new Dictionary { ["A"] = "a", ["B"] = "b" }); } [Fact] @@ -65,7 +65,7 @@ public void NewDictionary_with_KeyValuePairs_Create_should_translate() AssertStages(stages, "{ $project : { _v : { A : '$A', B: '$B' }, _id : 0 } }"); var result = queryable.Single(); - result.Should().Equal(new Dictionary{ ["A"] = "a", ["B"] = "b" }); + result.Should().Equal(new Dictionary { ["A"] = "a", ["B"] = "b" }); } [Fact] @@ -82,7 +82,7 @@ public void NewDictionary_with_KeyValuePairs_should_translate_Guid_as_string_key AssertStages(stages, "{ $project : { _v : { $arrayToObject : [[{ k : '$GuidAsString', v : '$A' }]] }, _id : 0 } }"); var result = queryable.Single(); - result.Should().Equal(new Dictionary{ [Guid.Parse("3E9AE467-9705-4C17-9655-EE7730BCC2EE")] = "a" }); + result.Should().Equal(new Dictionary { [Guid.Parse("3E9AE467-9705-4C17-9655-EE7730BCC2EE")] = "a" }); } @@ -100,7 +100,7 @@ public void NewDictionary_with_KeyValuePairs_should_translate_dynamic_array() AssertStages(stages, "{ $project : { _v : { $arrayToObject : { $map: { input: '$Items', as: 'i', in: { k: '$$i.P', v: '$$i.W' } } } }, _id : 0 } }"); var result = queryable.Single(); - result.Should().Equal(new Dictionary{ ["x"] = "y" }); + result.Should().Equal(new Dictionary { ["x"] = "y" }); } [Fact] diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewKeyValuePairExpressionToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewKeyValuePairExpressionToAggregationExpressionTranslatorTests.cs index 46575fe696d..a20e33be241 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewKeyValuePairExpressionToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewKeyValuePairExpressionToAggregationExpressionTranslatorTests.cs @@ -34,7 +34,7 @@ public void NewKeyValuePair_should_translate() var collection = Fixture.Collection; var queryable = collection.AsQueryable() - .Select(d => new KeyValuePair("X", d.X)); + .Select(d => new KeyValuePair("X", d.X)); var stages = Translate(collection, queryable); AssertStages(stages, "{ $project : { k : 'X', v : '$X', _id : 0 } }"); diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExecutableQueryTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExecutableQueryTests.cs index b5af795df82..7c8f1ef0999 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExecutableQueryTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExecutableQueryTests.cs @@ -47,7 +47,7 @@ public void Cast_aggregation_to_object_should_work() var collection = Fixture.Collection; var queryable1 = collection.AsQueryable().GroupBy( p => p.Type, - (k, p) => new ProductAggregation {Type = k, MaxPrice = p.Select(i => i.Price).Max()}); + (k, p) => new ProductAggregation { Type = k, MaxPrice = p.Select(i => i.Price).Max() }); var queryable2 = queryable1.Provider.CreateQuery(queryable1.Expression); var results = queryable2.ToList(); diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/BsonValueAsConversionFilterTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/BsonValueAsConversionFilterTests.cs index 7568942e0ef..93a49cbcffd 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/BsonValueAsConversionFilterTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/BsonValueAsConversionFilterTests.cs @@ -386,7 +386,7 @@ private void AssertThrows(FilterDefinition fil { var documentSerializer = BsonDocumentSerializer.Instance; var serializerRegistry = BsonSerializer.SerializerRegistry; - var exception = Record.Exception(() =>filter.Render(new(documentSerializer, serializerRegistry))); + var exception = Record.Exception(() => filter.Render(new(documentSerializer, serializerRegistry))); exception.Should().BeOfType(); } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/ConvertExpressionToFilterTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/ConvertExpressionToFilterTranslatorTests.cs index 5329aab6fab..34851d643ff 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/ConvertExpressionToFilterTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/ConvertExpressionToFilterTranslatorTests.cs @@ -113,7 +113,7 @@ private IMongoCollection GetInterfaceCollection() CreateCollection( collection, new Data { Id = 1, Enum = Enum.One, NullableEnum = Enum.One, EnumAsInt = 1, EnumAsNullableInt = 1 }, - new Data { Id = 2, Enum = Enum.Two, NullableEnum = Enum.Two, EnumAsInt = 2, EnumAsNullableInt = 2, AdditionalValue = "value"}); + new Data { Id = 2, Enum = Enum.Two, NullableEnum = Enum.Two, EnumAsInt = 2, EnumAsNullableInt = 2, AdditionalValue = "value" }); return collection; } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/NullableValueEqualsComparisonFilterTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/NullableValueEqualsComparisonFilterTests.cs index ae377a06f9e..16c499d4c6e 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/NullableValueEqualsComparisonFilterTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionTranslators/NullableValueEqualsComparisonFilterTests.cs @@ -26,109 +26,109 @@ public class NullableValueEqualsComparisonFilterTests : LinqIntegrationTest x.NullableChar == 'a'); + var find = collection.Find(x => x.NullableChar == 'a'); - var filter = TranslateFindFilter(collection, find); - filter.Should().Be("""{ NullableChar : 97 }"""); + var filter = TranslateFindFilter(collection, find); + filter.Should().Be("""{ NullableChar : 97 }"""); - var result = find.Single(); - result.Id.Should().Be(1); - } + var result = find.Single(); + result.Id.Should().Be(1); + } - [Fact] - public void Find_NullableChar_equals_char_null_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Find_NullableChar_equals_char_null_should_work() + { + var collection = Fixture.Collection; - var find = collection.Find(x => x.NullableChar == null); + var find = collection.Find(x => x.NullableChar == null); - var filter = TranslateFindFilter(collection, find); - filter.Should().Be("""{ NullableChar : null }"""); + var filter = TranslateFindFilter(collection, find); + filter.Should().Be("""{ NullableChar : null }"""); - var result = find.Single(); - result.Id.Should().Be(3); - } + var result = find.Single(); + result.Id.Should().Be(3); + } - [Fact] - public void Find_NullableLong_equals_double_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Find_NullableLong_equals_double_should_work() + { + var collection = Fixture.Collection; - var find = collection.Find(x => x.NullableLong == 1.0); + var find = collection.Find(x => x.NullableLong == 1.0); - var filter = TranslateFindFilter(collection, find); - filter.Should().Be("""{ NullableLong : 1.0 }"""); + var filter = TranslateFindFilter(collection, find); + filter.Should().Be("""{ NullableLong : 1.0 }"""); - var result = find.Single(); - result.Id.Should().Be(1); - } + var result = find.Single(); + result.Id.Should().Be(1); + } - [Fact] - public void Find_NullableLong_equals_double_null_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Find_NullableLong_equals_double_null_should_work() + { + var collection = Fixture.Collection; - var find = collection.Find(x => x.NullableLong == null); + var find = collection.Find(x => x.NullableLong == null); - var filter = TranslateFindFilter(collection, find); - filter.Should().Be("""{ NullableLong : null }"""); + var filter = TranslateFindFilter(collection, find); + filter.Should().Be("""{ NullableLong : null }"""); - var result = find.Single(); - result.Id.Should().Be(3); - } + var result = find.Single(); + result.Id.Should().Be(3); + } - [Fact] - public void Find_NullableSByte_equals_int_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Find_NullableSByte_equals_int_should_work() + { + var collection = Fixture.Collection; - var find = collection.Find(x => x.NullableSByte == 1); + var find = collection.Find(x => x.NullableSByte == 1); - var filter = TranslateFindFilter(collection, find); - filter.Should().Be("""{ NullableSByte : 1 }"""); + var filter = TranslateFindFilter(collection, find); + filter.Should().Be("""{ NullableSByte : 1 }"""); - var result = find.Single(); - result.Id.Should().Be(1); - } + var result = find.Single(); + result.Id.Should().Be(1); + } - [Fact] - public void Find_NullableSByte_equals_int_null_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Find_NullableSByte_equals_int_null_should_work() + { + var collection = Fixture.Collection; - var find = collection.Find(x => x.NullableSByte == null); + var find = collection.Find(x => x.NullableSByte == null); - var filter = TranslateFindFilter(collection, find); - filter.Should().Be("""{ NullableSByte : null }"""); + var filter = TranslateFindFilter(collection, find); + filter.Should().Be("""{ NullableSByte : null }"""); - var result = find.Single(); - result.Id.Should().Be(3); - } + var result = find.Single(); + result.Id.Should().Be(3); + } - public class C - { - public int Id { get; set; } - public char? NullableChar { get; set; } - public long? NullableLong { get; set; } - public sbyte? NullableSByte { get; set; } - } + public class C + { + public int Id { get; set; } + public char? NullableChar { get; set; } + public long? NullableLong { get; set; } + public sbyte? NullableSByte { get; set; } + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new C { Id = 1, NullableChar = 'a', NullableLong = 1, NullableSByte = 1 }, + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, NullableChar = 'a', NullableLong = 1, NullableSByte = 1 }, new C { Id = 2, NullableChar = 'b', NullableLong = 2, NullableSByte = 2 }, new C { Id = 3, NullableChar = null, NullableLong = null, NullableSByte = null } - ]; + ]; + } } } -} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/StringContainsStartsWithEndsWithFilterTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/StringContainsStartsWithEndsWithFilterTests.cs index b9e47a808f8..d292abef904 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/StringContainsStartsWithEndsWithFilterTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/StringContainsStartsWithEndsWithFilterTests.cs @@ -237,7 +237,7 @@ public void Contains_with_string_constant_and_char_value_and_invalid_comparisonT var stages = Translate(collection, queryable); - AssertStages(stages); + AssertStages(stages); } #endif diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/WhereMemoryExtensionsContainsTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/WhereMemoryExtensionsContainsTests.cs index abd7541e4fa..7f0ef697e17 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/WhereMemoryExtensionsContainsTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/WhereMemoryExtensionsContainsTests.cs @@ -176,7 +176,7 @@ public sealed class ClassFixture : MongoCollectionFixture private Expression> Rewrite(Expression> predicate) { - return (Expression>)new EnumerableToMemoryExtensionsRewriter().Visit(predicate); + return (Expression>)new EnumerableToMemoryExtensionsRewriter().Visit(predicate); } public class EnumerableToMemoryExtensionsRewriter : ExpressionVisitor diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/WhereSubstringTrimAndNullableBoolTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/WhereSubstringTrimAndNullableBoolTests.cs index db20926e5f3..1fa8f04a6dd 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/WhereSubstringTrimAndNullableBoolTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/WhereSubstringTrimAndNullableBoolTests.cs @@ -77,8 +77,8 @@ public void Where_with_nullable_bool_comparison_should_work() public class C { - public int Id { get; set; } - public string Str { get; set; } + public int Id { get; set; } + public string Str { get; set; } public bool? NullableBool { get; set; } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupBySelectNewModelProjectionTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupBySelectNewModelProjectionTests.cs index a6f1fe90b14..b2596e5ea8e 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupBySelectNewModelProjectionTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupBySelectNewModelProjectionTests.cs @@ -57,7 +57,7 @@ public void Project_new_ModelAggregated_should_work() var aggregate = collection.Aggregate() .Group( x => "", - g => new { Count = g.Count()} + g => new { Count = g.Count() } ) .Project( x => new ModelAggregated diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupJoinSelectManyWithDictionaryIndexerTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupJoinSelectManyWithDictionaryIndexerTests.cs index 1b1f6e63c65..cbb73f0218a 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupJoinSelectManyWithDictionaryIndexerTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupJoinSelectManyWithDictionaryIndexerTests.cs @@ -25,118 +25,118 @@ public class GroupJoinSelectManyWithDictionaryIndexerTests : LinqIntegrationTest { public GroupJoinSelectManyWithDictionaryIndexerTests(ClassFixture fixture) : base(fixture) - { - } + { + } - [Fact] - public void Test1() - { - var awardProviderProductCollection = Fixture.AwardProviderProduct; - var productCollection = Fixture.ProductCollection; - - var querySyntax = - from p in awardProviderProductCollection.AsQueryable() - join o in productCollection.AsQueryable() on p.Sku equals o.Sku into joined - from j in joined.DefaultIfEmpty() - where p.Reference["AwardChoiceSource"] == "NORC" - select new AwardProviderProduct() - { - Id = p.Id, - Reference = p.Reference, - Sku = p.Sku - }; - - var stages = Translate(awardProviderProductCollection, querySyntax); - string[] expectedStages = - [ - "{ $project : { _outer : '$$ROOT', _id : 0 } }", + [Fact] + public void Test1() + { + var awardProviderProductCollection = Fixture.AwardProviderProduct; + var productCollection = Fixture.ProductCollection; + + var querySyntax = + from p in awardProviderProductCollection.AsQueryable() + join o in productCollection.AsQueryable() on p.Sku equals o.Sku into joined + from j in joined.DefaultIfEmpty() + where p.Reference["AwardChoiceSource"] == "NORC" + select new AwardProviderProduct() + { + Id = p.Id, + Reference = p.Reference, + Sku = p.Sku + }; + + var stages = Translate(awardProviderProductCollection, querySyntax); + string[] expectedStages = + [ + "{ $project : { _outer : '$$ROOT', _id : 0 } }", "{ $lookup : { from : 'product', localField : '_outer.Sku', foreignField : 'Sku', as : '_inner' } }", "{ $project : { p : '$_outer', joined : '$_inner', _id : 0 } }", "{ $project : { _v : { $map : { input : { $cond : { if : { $eq : [{ $size : '$joined' }, 0] }, then : [null], else : '$joined' } }, as : 'j', in : { '<>h__TransparentIdentifier0' : '$$ROOT', j : '$$j' } } }, _id : 0 } }", "{ $unwind : '$_v' }", "{ $match : { '_v.<>h__TransparentIdentifier0.p.Reference.AwardChoiceSource' : 'NORC' } }", "{ $project : { _id : '$_v.<>h__TransparentIdentifier0.p._id', Reference : '$_v.<>h__TransparentIdentifier0.p.Reference', Sku : '$_v.<>h__TransparentIdentifier0.p.Sku' } }" - ]; - AssertStages(stages, expectedStages); - - var results = querySyntax.ToList(); - results.Count.Should().Be(2); - results[0].Id.Should().Be(1); - results[0].Sku.Should().Be(1); - results[0].Reference.Values.Should().Equal("NORC"); - results[1].Id.Should().Be(2); - results[1].Sku.Should().Be(2); - results[1].Reference.Values.Should().Equal("NORC"); - - var methodSyntaxEquivalent = awardProviderProductCollection.AsQueryable() - .GroupJoin( - productCollection.AsQueryable(), - p => p.Sku, - o => o.Sku, - (p, joined) => new { p = p, joined = joined }) - .SelectMany( - TransparentIdentifier0 => TransparentIdentifier0.joined.DefaultIfEmpty(), - (TransparentIdentifier0, j) => new { TransparentIdentifier0 = TransparentIdentifier0, j = j }) - .Where( - TransparentIdentifier1 => TransparentIdentifier1.TransparentIdentifier0.p.Reference["AwardChoiceSource"] == "NORC") - .Select( - TransparentIdentifier1 => new AwardProviderProduct - { - Id = TransparentIdentifier1.TransparentIdentifier0.p.Id, - Reference = TransparentIdentifier1.TransparentIdentifier0.p.Reference, - Sku = TransparentIdentifier1.TransparentIdentifier0.p.Sku - }); - - stages = Translate(awardProviderProductCollection, methodSyntaxEquivalent); - expectedStages = expectedStages.Select(s => s.Replace("<>h__", "")).ToArray(); - AssertStages(stages, expectedStages); - - results = methodSyntaxEquivalent.ToList(); - - results = querySyntax.ToList(); - results.Count.Should().Be(2); - results[0].Id.Should().Be(1); - results[0].Sku.Should().Be(1); - results[0].Reference.Values.Should().Equal("NORC"); - results[1].Id.Should().Be(2); - results[1].Sku.Should().Be(2); - results[1].Reference.Values.Should().Equal("NORC"); - } - - public class AwardProviderProduct - { - public int Id { get; set; } - public int Sku { get; set; } - public Dictionary Reference { get; set; } - } + ]; + AssertStages(stages, expectedStages); + + var results = querySyntax.ToList(); + results.Count.Should().Be(2); + results[0].Id.Should().Be(1); + results[0].Sku.Should().Be(1); + results[0].Reference.Values.Should().Equal("NORC"); + results[1].Id.Should().Be(2); + results[1].Sku.Should().Be(2); + results[1].Reference.Values.Should().Equal("NORC"); + + var methodSyntaxEquivalent = awardProviderProductCollection.AsQueryable() + .GroupJoin( + productCollection.AsQueryable(), + p => p.Sku, + o => o.Sku, + (p, joined) => new { p = p, joined = joined }) + .SelectMany( + TransparentIdentifier0 => TransparentIdentifier0.joined.DefaultIfEmpty(), + (TransparentIdentifier0, j) => new { TransparentIdentifier0 = TransparentIdentifier0, j = j }) + .Where( + TransparentIdentifier1 => TransparentIdentifier1.TransparentIdentifier0.p.Reference["AwardChoiceSource"] == "NORC") + .Select( + TransparentIdentifier1 => new AwardProviderProduct + { + Id = TransparentIdentifier1.TransparentIdentifier0.p.Id, + Reference = TransparentIdentifier1.TransparentIdentifier0.p.Reference, + Sku = TransparentIdentifier1.TransparentIdentifier0.p.Sku + }); + + stages = Translate(awardProviderProductCollection, methodSyntaxEquivalent); + expectedStages = expectedStages.Select(s => s.Replace("<>h__", "")).ToArray(); + AssertStages(stages, expectedStages); + + results = methodSyntaxEquivalent.ToList(); + + results = querySyntax.ToList(); + results.Count.Should().Be(2); + results[0].Id.Should().Be(1); + results[0].Sku.Should().Be(1); + results[0].Reference.Values.Should().Equal("NORC"); + results[1].Id.Should().Be(2); + results[1].Sku.Should().Be(2); + results[1].Reference.Values.Should().Equal("NORC"); + } - public class Product - { - public int Id { get; set; } - public int Sku { get; set; } - } + public class AwardProviderProduct + { + public int Id { get; set; } + public int Sku { get; set; } + public Dictionary Reference { get; set; } + } - public sealed class ClassFixture : MongoDatabaseFixture - { - public IMongoCollection AwardProviderProduct { get; private set; } - public IMongoCollection ProductCollection { get; private set; } + public class Product + { + public int Id { get; set; } + public int Sku { get; set; } + } - protected override void InitializeFixture() + public sealed class ClassFixture : MongoDatabaseFixture { - AwardProviderProduct = CreateCollection("awardProviderProduct"); - ProductCollection = CreateCollection("product"); + public IMongoCollection AwardProviderProduct { get; private set; } + public IMongoCollection ProductCollection { get; private set; } - AwardProviderProduct.InsertMany([ - new AwardProviderProduct { Id = 1, Sku = 1, Reference = new Dictionary { { "AwardChoiceSource", "NORC" } } }, + protected override void InitializeFixture() + { + AwardProviderProduct = CreateCollection("awardProviderProduct"); + ProductCollection = CreateCollection("product"); + + AwardProviderProduct.InsertMany([ + new AwardProviderProduct { Id = 1, Sku = 1, Reference = new Dictionary { { "AwardChoiceSource", "NORC" } } }, new AwardProviderProduct { Id = 2, Sku = 2, Reference = new Dictionary { { "AwardChoiceSource", "NORC" } } }, new AwardProviderProduct { Id = 3, Sku = 1, Reference = new Dictionary { { "AwardChoiceSource", "abcd" } } }, new AwardProviderProduct { Id = 4, Sku = 2, Reference = new Dictionary { { "AwardChoiceSource", "abcd" } } } - ]); + ]); - ProductCollection.InsertMany([ - new Product { Id = 1, Sku = 1 } - ]); + ProductCollection.InsertMany([ + new Product { Id = 1, Sku = 1 } + ]); + } } } } -} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupJoinWithFirstProjectionStagesTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupJoinWithFirstProjectionStagesTests.cs index 35cc6ea7022..3642346d762 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupJoinWithFirstProjectionStagesTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/GroupJoinWithFirstProjectionStagesTests.cs @@ -19,96 +19,96 @@ namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators { -// Regression test for CSHARP-3435. -public class GroupJoinWithFirstProjectionStagesTests : LinqIntegrationTest -{ - public GroupJoinWithFirstProjectionStagesTests(ClassFixture fixture) - : base(fixture) - { - } - - [Fact] - public void Where_should_work() + // Regression test for CSHARP-3435. + public class GroupJoinWithFirstProjectionStagesTests : LinqIntegrationTest { - var queryable = CreateQueryable() - .Where(x => x.NormalizedUsername == "PAPLABROS"); + public GroupJoinWithFirstProjectionStagesTests(ClassFixture fixture) + : base(fixture) + { + } - var stages = Translate(Fixture.UserClaimCollection, queryable); - AssertStages( - stages, - "{ $project : { _outer : '$$ROOT', _id : 0 } }", - "{ $lookup : { from : 'Users', localField : '_outer.UserId', foreignField : '_id', as : '_inner' } }", - "{ $project : { claim : '$_outer', users : '$_inner', _id : 0 } }", - "{ $match : { 'claim.ClaimType' : 'Moderator' } }", - "{ $project : { _v : { $arrayElemAt : ['$users', 0] }, _id : 0 } }", - "{ $match : { '_v.NormalizedUsername' : 'PAPLABROS' } }"); - } + [Fact] + public void Where_should_work() + { + var queryable = CreateQueryable() + .Where(x => x.NormalizedUsername == "PAPLABROS"); - [Fact] - public void Where_with_Inject_should_work() - { - var filter = Builders.Filter.Eq(x => x.NormalizedUsername, "PAPLABROS"); - var queryable = CreateQueryable() - .Where(x => filter.Inject()); + var stages = Translate(Fixture.UserClaimCollection, queryable); + AssertStages( + stages, + "{ $project : { _outer : '$$ROOT', _id : 0 } }", + "{ $lookup : { from : 'Users', localField : '_outer.UserId', foreignField : '_id', as : '_inner' } }", + "{ $project : { claim : '$_outer', users : '$_inner', _id : 0 } }", + "{ $match : { 'claim.ClaimType' : 'Moderator' } }", + "{ $project : { _v : { $arrayElemAt : ['$users', 0] }, _id : 0 } }", + "{ $match : { '_v.NormalizedUsername' : 'PAPLABROS' } }"); + } - var stages = Translate(Fixture.UserClaimCollection, queryable); - AssertStages( - stages, - "{ $project : { _outer : '$$ROOT', _id : 0 } }", - "{ $lookup : { from : 'Users', localField : '_outer.UserId', foreignField : '_id', as : '_inner' } }", - "{ $project : { claim : '$_outer', users : '$_inner', _id : 0 } }", - "{ $match : { 'claim.ClaimType' : 'Moderator' } }", - "{ $project : { _v : { $arrayElemAt : ['$users', 0] }, _id : 0 } }", - "{ $match : { '_v.NormalizedUsername' : 'PAPLABROS' } }"); - } + [Fact] + public void Where_with_Inject_should_work() + { + var filter = Builders.Filter.Eq(x => x.NormalizedUsername, "PAPLABROS"); + var queryable = CreateQueryable() + .Where(x => filter.Inject()); - public IQueryable CreateQueryable() - { - var usersCollection = Fixture.UserCollection; - var userClaimsCollection = Fixture.UserClaimCollection; + var stages = Translate(Fixture.UserClaimCollection, queryable); + AssertStages( + stages, + "{ $project : { _outer : '$$ROOT', _id : 0 } }", + "{ $lookup : { from : 'Users', localField : '_outer.UserId', foreignField : '_id', as : '_inner' } }", + "{ $project : { claim : '$_outer', users : '$_inner', _id : 0 } }", + "{ $match : { 'claim.ClaimType' : 'Moderator' } }", + "{ $project : { _v : { $arrayElemAt : ['$users', 0] }, _id : 0 } }", + "{ $match : { '_v.NormalizedUsername' : 'PAPLABROS' } }"); + } - var queryable = - from claim in userClaimsCollection.AsQueryable() - join user in usersCollection.AsQueryable() on claim.UserId equals user.Id into users - where claim.ClaimType == "Moderator" - select users.First(); + public IQueryable CreateQueryable() + { + var usersCollection = Fixture.UserCollection; + var userClaimsCollection = Fixture.UserClaimCollection; - // this is the equivalent method syntax - // var queryable = userClaimsCollection.AsQueryable() - // .GroupJoin( - // usersCollection.AsQueryable(), - // claim => claim.UserId, - // user => user.Id, - // (claim, users) => new { claim, users }) - // .Where(x => x.claim.ClaimType == "Moderator") - // .Select(x => x.users.First()); + var queryable = + from claim in userClaimsCollection.AsQueryable() + join user in usersCollection.AsQueryable() on claim.UserId equals user.Id into users + where claim.ClaimType == "Moderator" + select users.First(); - return queryable; - } + // this is the equivalent method syntax + // var queryable = userClaimsCollection.AsQueryable() + // .GroupJoin( + // usersCollection.AsQueryable(), + // claim => claim.UserId, + // user => user.Id, + // (claim, users) => new { claim, users }) + // .Where(x => x.claim.ClaimType == "Moderator") + // .Select(x => x.users.First()); - public class User - { - public int Id { get; set; } - public string NormalizedUsername { get; set; } - } + return queryable; + } - public class UserClaim - { - public int Id { get; set; } - public int UserId { get; set; } - public string ClaimType { get; set; } - } + public class User + { + public int Id { get; set; } + public string NormalizedUsername { get; set; } + } - public sealed class ClassFixture : MongoDatabaseFixture - { - public IMongoCollection UserCollection { get; private set; } - public IMongoCollection UserClaimCollection { get; private set; } + public class UserClaim + { + public int Id { get; set; } + public int UserId { get; set; } + public string ClaimType { get; set; } + } - protected override void InitializeFixture() + public sealed class ClassFixture : MongoDatabaseFixture { - UserCollection = CreateCollection("Users"); - UserClaimCollection = CreateCollection("UserClaims"); + public IMongoCollection UserCollection { get; private set; } + public IMongoCollection UserClaimCollection { get; private set; } + + protected override void InitializeFixture() + { + UserCollection = CreateCollection("Users"); + UserClaimCollection = CreateCollection("UserClaims"); + } } } } -} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeMethodToPipelineTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeMethodToPipelineTranslatorTests.cs index 1d5d22f2b20..8a6851156ff 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeMethodToPipelineTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeMethodToPipelineTranslatorTests.cs @@ -25,7 +25,7 @@ namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators { - public class OfTypeMethodToPipelineTranslatorTests: LinqIntegrationTest + public class OfTypeMethodToPipelineTranslatorTests : LinqIntegrationTest { public OfTypeMethodToPipelineTranslatorTests(ClassFixture fixture) : base(fixture) @@ -43,7 +43,7 @@ public void OfType_should_return_expected_results() } private void AssertTypeOf(IMongoCollection collection, string expectedStage, params int[] expectedIds) - where TDocument: Entity + where TDocument : Entity { var queryable = collection .AsQueryable() diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeOverDerivedHierarchyPipelineTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeOverDerivedHierarchyPipelineTests.cs index f5dde7a0d76..104bb4e6dd6 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeOverDerivedHierarchyPipelineTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeOverDerivedHierarchyPipelineTests.cs @@ -609,5 +609,6 @@ protected override IEnumerable InitialData new Dog { Id = 2 }, new Snake { Id = 3 } ]; - } } + } + } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeWithHierarchicalDiscriminatorTypeNamesPipelineTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeWithHierarchicalDiscriminatorTypeNamesPipelineTests.cs index 83f5c909e53..b78a1c3de8f 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeWithHierarchicalDiscriminatorTypeNamesPipelineTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeWithHierarchicalDiscriminatorTypeNamesPipelineTests.cs @@ -26,161 +26,161 @@ namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators { -// Regression test for CSHARP-4040. -public class OfTypeWithHierarchicalDiscriminatorTypeNamesPipelineTests : LinqIntegrationTest -{ - public OfTypeWithHierarchicalDiscriminatorTypeNamesPipelineTests(ClassFixture fixture) - : base(fixture) - { - } - - [Fact] - public void Documents_should_serialize_as_expected() + // Regression test for CSHARP-4040. + public class OfTypeWithHierarchicalDiscriminatorTypeNamesPipelineTests : LinqIntegrationTest { - var collection = Fixture.Collection; - - var seralizedDocuments = collection.AsQueryable().As(BsonDocumentSerializer.Instance).ToList(); - - seralizedDocuments.Count.Should().Be(2); - seralizedDocuments[0].Should().Be("{ _id : 1, TypeNames : ['C', 'D'] }"); - seralizedDocuments[1].Should().Be("{ _id : 2, TypeNames : ['C', 'D', 'E'] }"); - } + public OfTypeWithHierarchicalDiscriminatorTypeNamesPipelineTests(ClassFixture fixture) + : base(fixture) + { + } - [Fact] - public void OfType_C_should_work() - { - var collection = Fixture.Collection; + [Fact] + public void Documents_should_serialize_as_expected() + { + var collection = Fixture.Collection; - var queryable = collection.AsQueryable() - .OfType(); + var seralizedDocuments = collection.AsQueryable().As(BsonDocumentSerializer.Instance).ToList(); - var stages = Translate(collection, queryable); - AssertStages(stages, []); + seralizedDocuments.Count.Should().Be(2); + seralizedDocuments[0].Should().Be("{ _id : 1, TypeNames : ['C', 'D'] }"); + seralizedDocuments[1].Should().Be("{ _id : 2, TypeNames : ['C', 'D', 'E'] }"); + } - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1, 2); - } + [Fact] + public void OfType_C_should_work() + { + var collection = Fixture.Collection; - [Fact] - public void OfType_D_should_work() - { - var collection = Fixture.Collection; + var queryable = collection.AsQueryable() + .OfType(); - var queryable = collection.AsQueryable() - .OfType(); + var stages = Translate(collection, queryable); + AssertStages(stages, []); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { TypeNames : 'D' } }"); + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1, 2); + } - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1, 2); - } + [Fact] + public void OfType_D_should_work() + { + var collection = Fixture.Collection; - [Fact] - public void OfType_E_should_work() - { - var collection = Fixture.Collection; + var queryable = collection.AsQueryable() + .OfType(); - var queryable = collection.AsQueryable() - .OfType(); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { TypeNames : 'D' } }"); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { TypeNames : 'E' } }"); + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1, 2); + } - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(2); - } + [Fact] + public void OfType_E_should_work() + { + var collection = Fixture.Collection; - [Fact] - public void Where_TypeNames_Contains_C_should_work() - { - var collection = Fixture.Collection; + var queryable = collection.AsQueryable() + .OfType(); - var queryable = collection.AsQueryable() - .Where(x => x.TypeNames.Contains("C")); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { TypeNames : 'E' } }"); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { TypeNames : 'C' } }"); + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(2); + } - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1, 2); - } + [Fact] + public void Where_TypeNames_Contains_C_should_work() + { + var collection = Fixture.Collection; - [Fact] - public void Where_TypeNames_Contains_D_should_work() - { - var collection = Fixture.Collection; + var queryable = collection.AsQueryable() + .Where(x => x.TypeNames.Contains("C")); - var queryable = collection.AsQueryable() - .Where(x => x.TypeNames.Contains("D")); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { TypeNames : 'C' } }"); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { TypeNames : 'D' } }"); + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1, 2); + } - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(1, 2); - } + [Fact] + public void Where_TypeNames_Contains_D_should_work() + { + var collection = Fixture.Collection; - [Fact] - public void Where_TypeNames_Contains_E_should_work() - { - var collection = Fixture.Collection; + var queryable = collection.AsQueryable() + .Where(x => x.TypeNames.Contains("D")); - var queryable = collection.AsQueryable() - .Where(x => x.TypeNames.Contains("E")); + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { TypeNames : 'D' } }"); - var stages = Translate(collection, queryable); - AssertStages(stages, "{ $match : { TypeNames : 'E' } }"); + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(1, 2); + } - var results = queryable.ToList(); - results.Select(x => x.Id).Should().Equal(2); - } + [Fact] + public void Where_TypeNames_Contains_E_should_work() + { + var collection = Fixture.Collection; - public abstract class C - { - public int Id { get; set; } - public virtual IReadOnlyList TypeNames => ["C"]; - } + var queryable = collection.AsQueryable() + .Where(x => x.TypeNames.Contains("E")); - public class D : C - { - public override IReadOnlyList TypeNames => ["C", "D"]; - } + var stages = Translate(collection, queryable); + AssertStages(stages, "{ $match : { TypeNames : 'E' } }"); - public class E : D - { - public override IReadOnlyList TypeNames => ["C", "D", "E"]; - } + var results = queryable.ToList(); + results.Select(x => x.Id).Should().Equal(2); + } - public sealed class ClassFixture : MongoCollectionFixture - { - public ClassFixture() + public abstract class C { - AppContext.SetSwitch("Switch.MongoDB.Driver.DisableDiscriminatorFieldConflictCheck", true); + public int Id { get; set; } + public virtual IReadOnlyList TypeNames => ["C"]; + } - var discriminatorConvention = new HierarchicalDiscriminatorConvention("TypeNames"); - BsonSerializer.RegisterDiscriminatorConvention(typeof(C), discriminatorConvention); + public class D : C + { + public override IReadOnlyList TypeNames => ["C", "D"]; + } - BsonClassMap.RegisterClassMap(cm => - { - cm.AutoMap(); - cm.SetIsRootClass(true); - cm.SetDiscriminatorIsRequired(true); - cm.MapMember(x => x.TypeNames).SetShouldSerializeMethod(_ => false); - }); + public class E : D + { + public override IReadOnlyList TypeNames => ["C", "D", "E"]; } - protected override IEnumerable InitialData => - [ - new D { Id = 1 }, + public sealed class ClassFixture : MongoCollectionFixture + { + public ClassFixture() + { + AppContext.SetSwitch("Switch.MongoDB.Driver.DisableDiscriminatorFieldConflictCheck", true); + + var discriminatorConvention = new HierarchicalDiscriminatorConvention("TypeNames"); + BsonSerializer.RegisterDiscriminatorConvention(typeof(C), discriminatorConvention); + + BsonClassMap.RegisterClassMap(cm => + { + cm.AutoMap(); + cm.SetIsRootClass(true); + cm.SetDiscriminatorIsRequired(true); + cm.MapMember(x => x.TypeNames).SetShouldSerializeMethod(_ => false); + }); + } + + protected override IEnumerable InitialData => + [ + new D { Id = 1 }, new E { Id = 2 } - ]; + ]; - public override void Dispose() - { - base.Dispose(); - AppContext.SetSwitch("Switch.MongoDB.Driver.DisableDiscriminatorFieldConflictCheck", false); + public override void Dispose() + { + base.Dispose(); + AppContext.SetSwitch("Switch.MongoDB.Driver.DisableDiscriminatorFieldConflictCheck", false); + } } } } -} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/ReplaceWithUsesConfiguredElementNameTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/ReplaceWithUsesConfiguredElementNameTests.cs index 1515f160688..914ebc57402 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/ReplaceWithUsesConfiguredElementNameTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/ReplaceWithUsesConfiguredElementNameTests.cs @@ -23,48 +23,48 @@ namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators { -// Regression test for CSHARP-4819. -public class ReplaceWithUsesConfiguredElementNameTests : LinqIntegrationTest -{ - public ReplaceWithUsesConfiguredElementNameTests(ClassFixture fixture) - : base(fixture) + // Regression test for CSHARP-4819. + public class ReplaceWithUsesConfiguredElementNameTests : LinqIntegrationTest { - } + public ReplaceWithUsesConfiguredElementNameTests(ClassFixture fixture) + : base(fixture) + { + } - [Fact] - public void ReplaceWith_should_use_configured_element_name() - { - var collection = Fixture.Collection; - var stage = PipelineStageDefinitionBuilder - .ReplaceWith((User u) => new User { UserId = u.UserId }); + [Fact] + public void ReplaceWith_should_use_configured_element_name() + { + var collection = Fixture.Collection; + var stage = PipelineStageDefinitionBuilder + .ReplaceWith((User u) => new User { UserId = u.UserId }); - var aggregate = collection.Aggregate() - .AppendStage(stage); + var aggregate = collection.Aggregate() + .AppendStage(stage); - var stages = Translate(collection, aggregate); - AssertStages( - stages, - "{ $replaceWith : { uuid : '$uuid' } }"); + var stages = Translate(collection, aggregate); + AssertStages( + stages, + "{ $replaceWith : { uuid : '$uuid' } }"); - var result = aggregate.Single(); - result.Id.Should().Be(0); - result.UserId.Should().Be(Guid.Parse("00112233-4455-6677-8899-aabbccddeeff")); - } + var result = aggregate.Single(); + result.Id.Should().Be(0); + result.UserId.Should().Be(Guid.Parse("00112233-4455-6677-8899-aabbccddeeff")); + } - public class User - { - public int Id { get; set; } - [BsonElement("uuid")] - [BsonGuidRepresentation(GuidRepresentation.Standard)] - public Guid UserId { get; set; } - } + public class User + { + public int Id { get; set; } + [BsonElement("uuid")] + [BsonGuidRepresentation(GuidRepresentation.Standard)] + public Guid UserId { get; set; } + } - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new User { Id = 1, UserId = Guid.Parse("00112233-4455-6677-8899-aabbccddeeff") } - ]; + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new User { Id = 1, UserId = Guid.Parse("00112233-4455-6677-8899-aabbccddeeff") } + ]; + } } } -} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/SelectManyOverDictionaryRepresentationsTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/SelectManyOverDictionaryRepresentationsTests.cs index 3836b7c63cb..24989fe8210 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/SelectManyOverDictionaryRepresentationsTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/SelectManyOverDictionaryRepresentationsTests.cs @@ -28,170 +28,170 @@ public class SelectManyOverDictionaryRepresentationsTests : LinqIntegrationTest< { public SelectManyOverDictionaryRepresentationsTests(ClassFixture fixture) : base(fixture) - { - } - - [Fact] - public void Nested__SelectMany_with_ArrayOfArrays_representation_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .OfType() - .Where(to => to.Name == "TestName") - .Select(to => to.DictionaryWithArrayOfArraysRepresentation.SelectMany(kvp => new KeyValuePair[] { kvp })); - - var stages = Translate(collection, queryable); - AssertStages( - stages, - "{ $match : { Name : 'TestName' } }", - "{ $project : { _v : { $reduce : { input : { $map : { input : '$DictionaryWithArrayOfArraysRepresentation', as : 'kvp', in : ['$$kvp'] } }, initialValue : [], in : { $concatArrays : ['$$value', '$$this'] } } }, _id : 0 } }"); - - var result = queryable.Single(); - result.Select(kvp => kvp.Key).Should().Equal("A", "B", "C"); - } - - [Fact] - public void Nested__SelectMany_with_ArrayOfDocuments_representation_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .OfType() - .Where(to => to.Name == "TestName") - .Select(to => to.DictionaryWithArrayOfDocumentsRepresentation.SelectMany(kvp => new KeyValuePair[] { kvp })); - - var stages = Translate(collection, queryable); - AssertStages( - stages, - "{ $match : { Name : 'TestName' } }", - "{ $project : { _v : { $reduce : { input : { $map : { input : '$DictionaryWithArrayOfDocumentsRepresentation', as : 'kvp', in : ['$$kvp'] } }, initialValue : [], in : { $concatArrays : ['$$value', '$$this'] } } }, _id : 0 } }"); - - var result = queryable.Single(); - result.Select(kvp => kvp.Key).Should().Equal("A", "B", "C"); - } - - [Fact] - public void Nested_SelectMany_with_Document_representation_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .OfType() - .Where(to => to.Name == "TestName") - .Select(to => to.DictionaryWithDocumentRepresentation.SelectMany(kvp => new KeyValuePair[] { kvp })); - - var stages = Translate(collection, queryable); - AssertStages( - stages, - "{ $match : { Name : 'TestName' } }", - "{ $project : { _v : { $reduce : { input : { $map : { input : { $objectToArray : '$DictionaryWithDocumentRepresentation' }, as : 'kvp', in : ['$$kvp'] } }, initialValue : [], in : { $concatArrays : ['$$value', '$$this'] } } }, _id : 0 } }"); - - var result = queryable.Single(); - result.Select(kvp => kvp.Key).Should().Equal("A", "B", "C"); - } - - [Fact] - public void Top_level_SelectMany_with_ArrayOfArrays_representation_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .OfType() - .Where(to => to.Name == "TestName") - .SelectMany(to => to.DictionaryWithArrayOfArraysRepresentation); - - var stages = Translate(collection, queryable); - AssertStages( - stages, - "{ $match : { Name : 'TestName' } }", - "{ $project : { _v : '$DictionaryWithArrayOfArraysRepresentation', _id : 0 } }", - "{ $unwind : '$_v' }"); - - var results = queryable.ToList(); - results.Count.Should().Be(3); - results[0].Key.Should().Be("A"); - results[0].Value.Should().Be("a"); - results[1].Key.Should().Be("B"); - results[1].Value.Should().Be("b"); - results[2].Key.Should().Be("C"); - results[2].Value.Should().Be("c"); - } - - [Fact] - public void Top_level_SelectMany_with_ArrayOfDocuments_representation_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .OfType() - .Where(to => to.Name == "TestName") - .SelectMany(to => to.DictionaryWithArrayOfDocumentsRepresentation); - - var stages = Translate(collection, queryable); - AssertStages( - stages, - "{ $match : { Name : 'TestName' } }", - "{ $project : { _v : '$DictionaryWithArrayOfDocumentsRepresentation', _id : 0 } }", - "{ $unwind : '$_v' }"); - - var results = queryable.ToList(); - results.Count.Should().Be(3); - results[0].Key.Should().Be("A"); - results[0].Value.Should().Be("a"); - results[1].Key.Should().Be("B"); - results[1].Value.Should().Be("b"); - results[2].Key.Should().Be("C"); - results[2].Value.Should().Be("c"); - } - - [Fact] - public void Top_level_SelectMany_with_Document_representation_should_work() - { - var collection = Fixture.Collection; - - var queryable = collection.AsQueryable() - .OfType() - .Where(to => to.Name == "TestName") - .SelectMany(to => to.DictionaryWithDocumentRepresentation); - - var stages = Translate(collection, queryable); - AssertStages( - stages, - "{ $match : { Name : 'TestName' } }", - "{ $project : { _v : { $objectToArray : '$DictionaryWithDocumentRepresentation' }, _id : 0 } }", - "{ $unwind : '$_v' }"); - - var results = queryable.ToList(); - results.Count.Should().Be(3); - results[0].Key.Should().Be("A"); - results[0].Value.Should().Be("a"); - results[1].Key.Should().Be("B"); - results[1].Value.Should().Be("b"); - results[2].Key.Should().Be("C"); - results[2].Value.Should().Be("c"); - } - - public class C - { - public int Id { get; set; } - public string Name {get;set;} - - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] - public Dictionary DictionaryWithArrayOfArraysRepresentation { get; set; } = new Dictionary(); - - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] - public Dictionary DictionaryWithArrayOfDocumentsRepresentation { get; set; } = new Dictionary(); - - [BsonDictionaryOptions(DictionaryRepresentation.Document)] - public Dictionary DictionaryWithDocumentRepresentation { get; set; } = new Dictionary(); - } - - public sealed class ClassFixture : MongoCollectionFixture - { - protected override IEnumerable InitialData => - [ - new C + { + } + + [Fact] + public void Nested__SelectMany_with_ArrayOfArrays_representation_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .OfType() + .Where(to => to.Name == "TestName") + .Select(to => to.DictionaryWithArrayOfArraysRepresentation.SelectMany(kvp => new KeyValuePair[] { kvp })); + + var stages = Translate(collection, queryable); + AssertStages( + stages, + "{ $match : { Name : 'TestName' } }", + "{ $project : { _v : { $reduce : { input : { $map : { input : '$DictionaryWithArrayOfArraysRepresentation', as : 'kvp', in : ['$$kvp'] } }, initialValue : [], in : { $concatArrays : ['$$value', '$$this'] } } }, _id : 0 } }"); + + var result = queryable.Single(); + result.Select(kvp => kvp.Key).Should().Equal("A", "B", "C"); + } + + [Fact] + public void Nested__SelectMany_with_ArrayOfDocuments_representation_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .OfType() + .Where(to => to.Name == "TestName") + .Select(to => to.DictionaryWithArrayOfDocumentsRepresentation.SelectMany(kvp => new KeyValuePair[] { kvp })); + + var stages = Translate(collection, queryable); + AssertStages( + stages, + "{ $match : { Name : 'TestName' } }", + "{ $project : { _v : { $reduce : { input : { $map : { input : '$DictionaryWithArrayOfDocumentsRepresentation', as : 'kvp', in : ['$$kvp'] } }, initialValue : [], in : { $concatArrays : ['$$value', '$$this'] } } }, _id : 0 } }"); + + var result = queryable.Single(); + result.Select(kvp => kvp.Key).Should().Equal("A", "B", "C"); + } + + [Fact] + public void Nested_SelectMany_with_Document_representation_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .OfType() + .Where(to => to.Name == "TestName") + .Select(to => to.DictionaryWithDocumentRepresentation.SelectMany(kvp => new KeyValuePair[] { kvp })); + + var stages = Translate(collection, queryable); + AssertStages( + stages, + "{ $match : { Name : 'TestName' } }", + "{ $project : { _v : { $reduce : { input : { $map : { input : { $objectToArray : '$DictionaryWithDocumentRepresentation' }, as : 'kvp', in : ['$$kvp'] } }, initialValue : [], in : { $concatArrays : ['$$value', '$$this'] } } }, _id : 0 } }"); + + var result = queryable.Single(); + result.Select(kvp => kvp.Key).Should().Equal("A", "B", "C"); + } + + [Fact] + public void Top_level_SelectMany_with_ArrayOfArrays_representation_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .OfType() + .Where(to => to.Name == "TestName") + .SelectMany(to => to.DictionaryWithArrayOfArraysRepresentation); + + var stages = Translate(collection, queryable); + AssertStages( + stages, + "{ $match : { Name : 'TestName' } }", + "{ $project : { _v : '$DictionaryWithArrayOfArraysRepresentation', _id : 0 } }", + "{ $unwind : '$_v' }"); + + var results = queryable.ToList(); + results.Count.Should().Be(3); + results[0].Key.Should().Be("A"); + results[0].Value.Should().Be("a"); + results[1].Key.Should().Be("B"); + results[1].Value.Should().Be("b"); + results[2].Key.Should().Be("C"); + results[2].Value.Should().Be("c"); + } + + [Fact] + public void Top_level_SelectMany_with_ArrayOfDocuments_representation_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .OfType() + .Where(to => to.Name == "TestName") + .SelectMany(to => to.DictionaryWithArrayOfDocumentsRepresentation); + + var stages = Translate(collection, queryable); + AssertStages( + stages, + "{ $match : { Name : 'TestName' } }", + "{ $project : { _v : '$DictionaryWithArrayOfDocumentsRepresentation', _id : 0 } }", + "{ $unwind : '$_v' }"); + + var results = queryable.ToList(); + results.Count.Should().Be(3); + results[0].Key.Should().Be("A"); + results[0].Value.Should().Be("a"); + results[1].Key.Should().Be("B"); + results[1].Value.Should().Be("b"); + results[2].Key.Should().Be("C"); + results[2].Value.Should().Be("c"); + } + + [Fact] + public void Top_level_SelectMany_with_Document_representation_should_work() + { + var collection = Fixture.Collection; + + var queryable = collection.AsQueryable() + .OfType() + .Where(to => to.Name == "TestName") + .SelectMany(to => to.DictionaryWithDocumentRepresentation); + + var stages = Translate(collection, queryable); + AssertStages( + stages, + "{ $match : { Name : 'TestName' } }", + "{ $project : { _v : { $objectToArray : '$DictionaryWithDocumentRepresentation' }, _id : 0 } }", + "{ $unwind : '$_v' }"); + + var results = queryable.ToList(); + results.Count.Should().Be(3); + results[0].Key.Should().Be("A"); + results[0].Value.Should().Be("a"); + results[1].Key.Should().Be("B"); + results[1].Value.Should().Be("b"); + results[2].Key.Should().Be("C"); + results[2].Value.Should().Be("c"); + } + + public class C + { + public int Id { get; set; } + public string Name { get; set; } + + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] + public Dictionary DictionaryWithArrayOfArraysRepresentation { get; set; } = new Dictionary(); + + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] + public Dictionary DictionaryWithArrayOfDocumentsRepresentation { get; set; } = new Dictionary(); + + [BsonDictionaryOptions(DictionaryRepresentation.Document)] + public Dictionary DictionaryWithDocumentRepresentation { get; set; } = new Dictionary(); + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, Name = "TestName", @@ -199,7 +199,7 @@ public sealed class ClassFixture : MongoCollectionFixture DictionaryWithArrayOfDocumentsRepresentation = new Dictionary { { "A", "a" }, { "B", "b" }, { "C", "c" } }, DictionaryWithDocumentRepresentation = new Dictionary { { "A", "a" }, { "B", "b" }, { "C", "c" } }, } - ]; + ]; + } } } -} diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/UnionMethodToPipelineTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/UnionMethodToPipelineTranslatorTests.cs index c39746bdd8d..a2e355ca5f7 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/UnionMethodToPipelineTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/UnionMethodToPipelineTranslatorTests.cs @@ -21,7 +21,7 @@ namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators { - public class UnionMethodToPipelineTranslatorTests: Linq3IntegrationTest + public class UnionMethodToPipelineTranslatorTests : Linq3IntegrationTest { private readonly IMongoCollection _firstCollection; private readonly IMongoCollection _secondCollection; diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/MongoQueryableTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/MongoQueryableTests.cs index 3fbbc0031b4..27419ce32f9 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/MongoQueryableTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/MongoQueryableTests.cs @@ -552,8 +552,8 @@ group p by p.A into g "{ $project: { Key: '$_id', FirstB: '$__agg0', _id: 0 } }"); query = from p in CreateQuery() - group p by p.A into g - select new { g.Key, FirstB = g.Select(x => x.B).First() }; + group p by p.A into g + select new { g.Key, FirstB = g.Select(x => x.B).First() }; Assert(query, 2, diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateGroupTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateGroupTranslatorTests.cs index 4d66b9fa0f1..817c5777c24 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateGroupTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateGroupTranslatorTests.cs @@ -170,7 +170,7 @@ public void Should_translate_median_with_embedded_projector() { RequireServer.Check().Supports(Feature.MedianOperator); - var result = Group(x => x.A, g => new { Result = g.Median(x=> x.C.E.F) }); + var result = Group(x => x.A, g => new { Result = g.Median(x => x.C.E.F) }); AssertStages( result.Stages, diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateProjectTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateProjectTranslatorTests.cs index 2ab1bdeab4a..de3000e558c 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateProjectTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateProjectTranslatorTests.cs @@ -1401,7 +1401,7 @@ public void Should_translate_strLenCP() { RequireServer.Check(); - var result = Project(x => new { Result = x.A.Length } ); + var result = Project(x => new { Result = x.A.Length }); result.Projection.Should().Be("{ Result: { \"$strLenCP\": \"$A\" }, _id: 0 }"); diff --git a/tests/MongoDB.Driver.Tests/MongoClientSettingsTests.cs b/tests/MongoDB.Driver.Tests/MongoClientSettingsTests.cs index 741c83448ca..d66bd7e703e 100644 --- a/tests/MongoDB.Driver.Tests/MongoClientSettingsTests.cs +++ b/tests/MongoDB.Driver.Tests/MongoClientSettingsTests.cs @@ -274,13 +274,13 @@ public void TestCompressors() } [Theory] - [InlineData(new[] {CompressorType.Snappy}, "Compressors=[snappy]")] - [InlineData(new[] {CompressorType.Zlib}, "Compressors=[zlib]")] - [InlineData(new[] {CompressorType.ZStandard}, "Compressors=[zstd]")] - [InlineData(new[] {CompressorType.ZStandard, CompressorType.Snappy, CompressorType.Zlib}, "Compressors=[zstd,snappy,zlib]")] + [InlineData(new[] { CompressorType.Snappy }, "Compressors=[snappy]")] + [InlineData(new[] { CompressorType.Zlib }, "Compressors=[zlib]")] + [InlineData(new[] { CompressorType.ZStandard }, "Compressors=[zstd]")] + [InlineData(new[] { CompressorType.ZStandard, CompressorType.Snappy, CompressorType.Zlib }, "Compressors=[zstd,snappy,zlib]")] public void Compressors_ToString_outputs_correct_compressors(CompressorType[] compressors, string expectedConnectionString) { - var settings = new MongoClientSettings {Compressors = compressors.Select(x => new CompressorConfiguration(x)).ToList()}; + var settings = new MongoClientSettings { Compressors = compressors.Select(x => new CompressorConfiguration(x)).ToList() }; var result = settings.ToString(); @@ -899,7 +899,7 @@ public void TestLoadBalanced() settings.Freeze(); settings.LoadBalanced.Should().Be(loadBalanaced); - Record.Exception(() => { settings.LoadBalanced= loadBalanaced; }).Should().BeOfType(); + Record.Exception(() => { settings.LoadBalanced = loadBalanaced; }).Should().BeOfType(); } [Fact] @@ -1534,7 +1534,7 @@ public void TestSrvServiceName() [Theory] [ParameterAttributeData] - public void TestSrvMaxHosts([Values(0, 1, 5)]int srvMaxHosts) + public void TestSrvMaxHosts([Values(0, 1, 5)] int srvMaxHosts) { var subject = new MongoClientSettings { Scheme = ConnectionStringScheme.MongoDBPlusSrv }; subject.SrvMaxHosts.Should().Be(0); diff --git a/tests/MongoDB.Driver.Tests/MongoUrlBuilderTests.cs b/tests/MongoDB.Driver.Tests/MongoUrlBuilderTests.cs index e8bab892ba5..5d42bbadb52 100644 --- a/tests/MongoDB.Driver.Tests/MongoUrlBuilderTests.cs +++ b/tests/MongoDB.Driver.Tests/MongoUrlBuilderTests.cs @@ -350,7 +350,7 @@ public void TestCompressorProperties() { var subject = new MongoUrlBuilder { Server = _localhost }; - var zlibCompressor = new CompressorConfiguration(CompressorType.Zlib) { Properties = {{ "Level", 1 }} }; + var zlibCompressor = new CompressorConfiguration(CompressorType.Zlib) { Properties = { { "Level", 1 } } }; subject.Compressors = new[] { zlibCompressor }; var connectionString = subject.ToString(); @@ -717,7 +717,8 @@ public void TestMaxConnectionIdleTime(int? ms, string formatString, string[] val { var maxConnectionIdleTime = (ms == null) ? (TimeSpan?)null : TimeSpan.FromMilliseconds(ms.Value); var built = new MongoUrlBuilder { Server = _localhost }; - if (maxConnectionIdleTime != null) { built.MaxConnectionIdleTime = maxConnectionIdleTime.Value; }; + if (maxConnectionIdleTime != null) { built.MaxConnectionIdleTime = maxConnectionIdleTime.Value; } + ; var canonicalConnectionString = string.Format(formatString, values[0]); foreach (var builder in EnumerateBuiltAndParsedBuilders(built, formatString, values)) diff --git a/tests/MongoDB.Driver.Tests/MongoUrlTests.cs b/tests/MongoDB.Driver.Tests/MongoUrlTests.cs index 317cb188c04..a6200efb790 100644 --- a/tests/MongoDB.Driver.Tests/MongoUrlTests.cs +++ b/tests/MongoDB.Driver.Tests/MongoUrlTests.cs @@ -313,7 +313,7 @@ public void TestAll() [Theory] [ParameterAttributeData] - public void TestDirectConnection([Values(false, true, null)]bool? directConnection) + public void TestDirectConnection([Values(false, true, null)] bool? directConnection) { var directConnectionString = directConnection.HasValue ? $"?directConnection={directConnection.Value}" : string.Empty; var connectionString = $"mongodb://localhost/{directConnectionString}"; diff --git a/tests/MongoDB.Driver.Tests/OfTypeDiscriminatorConventionTests.cs b/tests/MongoDB.Driver.Tests/OfTypeDiscriminatorConventionTests.cs index 6419b18558f..49f1ad25355 100644 --- a/tests/MongoDB.Driver.Tests/OfTypeDiscriminatorConventionTests.cs +++ b/tests/MongoDB.Driver.Tests/OfTypeDiscriminatorConventionTests.cs @@ -210,4 +210,4 @@ protected override void InitializeFixture() PersonCollection = CreateCollection("personCollection"); } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/OfTypeMongoCollectionTests.cs b/tests/MongoDB.Driver.Tests/OfTypeMongoCollectionTests.cs index 22eeaa446c7..b89f33ffa31 100644 --- a/tests/MongoDB.Driver.Tests/OfTypeMongoCollectionTests.cs +++ b/tests/MongoDB.Driver.Tests/OfTypeMongoCollectionTests.cs @@ -969,7 +969,7 @@ public class CHierarchical : BHierarchical public int PropC; } - public class UpdateTestCases : IValueGenerator + public class UpdateTestCases : IValueGenerator { public object[] GenerateValues() => new object[] { diff --git a/tests/MongoDB.Driver.Tests/OfTypeSerializerTests.cs b/tests/MongoDB.Driver.Tests/OfTypeSerializerTests.cs index 7dc3c6a234e..115d791acd6 100644 --- a/tests/MongoDB.Driver.Tests/OfTypeSerializerTests.cs +++ b/tests/MongoDB.Driver.Tests/OfTypeSerializerTests.cs @@ -60,7 +60,7 @@ public void Equals_self_should_return_true() public void Equals_with_equal_fields_should_return_true() { var x = new OfTypeSerializer(__derivedDocumentSerializer1); - var y= new OfTypeSerializer(__derivedDocumentSerializer1); + var y = new OfTypeSerializer(__derivedDocumentSerializer1); var result = x.Equals(y); diff --git a/tests/MongoDB.Driver.Tests/PipelineDefinitionBuilderTests.cs b/tests/MongoDB.Driver.Tests/PipelineDefinitionBuilderTests.cs index bbca8de282f..71b903ed92e 100644 --- a/tests/MongoDB.Driver.Tests/PipelineDefinitionBuilderTests.cs +++ b/tests/MongoDB.Driver.Tests/PipelineDefinitionBuilderTests.cs @@ -913,14 +913,14 @@ private class MovieWithPlot public string Synopsis { get; set; } public int Year { get; set; } public NestedPlot Plot { get; set; } - public float[] NonNestedEmbedding { get; set; } + public float[] NonNestedEmbedding { get; set; } } private class NestedPlot { public bool Synced { get; set; } - public int Rating { get; set; } - public float[] PlotEmbedding { get; set; } + public int Rating { get; set; } + public float[] PlotEmbedding { get; set; } } [Theory] diff --git a/tests/MongoDB.Driver.Tests/PipelineStageDefinitionBuilderTests.cs b/tests/MongoDB.Driver.Tests/PipelineStageDefinitionBuilderTests.cs index 972d2a65d98..b0026318a34 100644 --- a/tests/MongoDB.Driver.Tests/PipelineStageDefinitionBuilderTests.cs +++ b/tests/MongoDB.Driver.Tests/PipelineStageDefinitionBuilderTests.cs @@ -643,7 +643,7 @@ public void RankFusion_with_incorrect_params_should_throw_expected_exception() Assert.Throws(() => { - PipelineStageDefinitionBuilder.RankFusion(new PipelineDefinition[]{null}); + PipelineStageDefinitionBuilder.RankFusion(new PipelineDefinition[] { null }); }); Assert.Throws(() => diff --git a/tests/MongoDB.Driver.Tests/Samples/AggregationSample.cs b/tests/MongoDB.Driver.Tests/Samples/AggregationSample.cs index 54dc53dfc90..29eb20b8b93 100644 --- a/tests/MongoDB.Driver.Tests/Samples/AggregationSample.cs +++ b/tests/MongoDB.Driver.Tests/Samples/AggregationSample.cs @@ -104,9 +104,9 @@ public void States_with_pops_over_20000_queryable_syntax() var collection = database.GetCollection(__collection.CollectionNamespace.CollectionName); var queryable = from z in collection.AsQueryable() - group z by z.State into g - where g.Sum(x => x.Population) > 20000 - select new { State = g.Key, TotalPopulation = g.Sum(x => x.Population) }; + group z by z.State into g + where g.Sum(x => x.Population) > 20000 + select new { State = g.Key, TotalPopulation = g.Sum(x => x.Population) }; var stages = Linq3TestHelpers.Translate(collection, queryable); var expectedStages = diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchIndexManagmentTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchIndexManagmentTests.cs index ba5a9eed6e1..df92b2c1d31 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchIndexManagmentTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchIndexManagmentTests.cs @@ -317,7 +317,9 @@ public async Task Can_create_Atlas_vector_index_for_all_options_using_typed_API( var indexModel = new CreateVectorSearchIndexModel( e => e.Floats, indexName, VectorSimilarity.Cosine, dimensions: 2) { - HnswMaxEdges = 18, HnswNumEdgeCandidates = 102, Quantization = VectorQuantization.Scalar + HnswMaxEdges = 18, + HnswNumEdgeCandidates = 102, + Quantization = VectorQuantization.Scalar }; var collection = _database.GetCollection(_collection.CollectionNamespace.CollectionName); diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index db3a05f010e..86de481e75b 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -425,7 +425,7 @@ public void EqualsGuid() var testGuid = Guid.Parse("b52af144-bc97-454f-a578-418a64fa95bf"); var result = GetExtraTestsCollection().Aggregate() - .Search(Builders.Search.Equals(c => c.TestGuid, testGuid)) + .Search(Builders.Search.Equals(c => c.TestGuid, testGuid)) .Single(); result.Name.Should().Be("test6"); @@ -435,7 +435,7 @@ public void EqualsGuid() public void EqualsNull() { var result = GetExtraTestsCollection().Aggregate() - .Search(Builders.Search.Equals(c => c.TestString, null)) + .Search(Builders.Search.Equals(c => c.TestString, null)) .Single(); result.Name.Should().Be("testNull"); @@ -579,7 +579,7 @@ public void In() .Aggregate() .Search( Builders.Search.In(x => x.Runtime, new[] { 31, 231 }), - new() { Sort = Builders.Sort.Descending(x => x.Runtime)}) + new() { Sort = Builders.Sort.Descending(x => x.Runtime) }) .Limit(10) .ToList(); @@ -610,7 +610,7 @@ public void InGuid() }; var result = GetExtraTestsCollection().Aggregate() - .Search(Builders.Search.In(c => c.TestGuid, testGuids)) + .Search(Builders.Search.In(c => c.TestGuid, testGuids)) .Limit(10) .ToList(); @@ -989,7 +989,7 @@ public void SearchSequenceToken() .ToList(); baseSearchResults.Count.Should().Be(limitVal); - baseSearchResults.ForEach( m => m.PaginationToken.Should().NotBeNullOrEmpty()); + baseSearchResults.ForEach(m => m.PaginationToken.Should().NotBeNullOrEmpty()); baseSearchResults[0].Title.Should().Be(titles[0]); baseSearchResults[1].Title.Should().Be(titles[1]); baseSearchResults[2].Title.Should().Be(titles[2]); @@ -1007,7 +1007,7 @@ public void SearchSequenceToken() // Only two flower-titled docs remain after the 2nd base result. searchAfterResults.Count.Should().Be(2); - searchAfterResults.ForEach( m => m.PaginationToken.Should().NotBeNullOrEmpty()); + searchAfterResults.ForEach(m => m.PaginationToken.Should().NotBeNullOrEmpty()); searchAfterResults[0].Title.Should().Be(titles[2]); searchAfterResults[1].Title.Should().Be(titles[3]); @@ -1024,7 +1024,7 @@ public void SearchSequenceToken() // We only get the first 3 elements of the base search searchBeforeResults.Count.Should().Be(3); - searchBeforeResults.ForEach( m => m.PaginationToken.Should().NotBeNullOrEmpty()); + searchBeforeResults.ForEach(m => m.PaginationToken.Should().NotBeNullOrEmpty()); // With searchBefore the results are reversed searchBeforeResults[0].Title.Should().Be(titles[2]); searchBeforeResults[1].Title.Should().Be(titles[1]); @@ -1221,7 +1221,7 @@ public void TextMatchCriteria() var result = GetMoviesCollection().Aggregate() .Search( - Builders.Search.Text("plot", "attire", new SearchTextOptions { Synonyms = "attireSynonyms", MatchCriteria = MatchCriteria.Any}), + Builders.Search.Text("plot", "attire", new SearchTextOptions { Synonyms = "attireSynonyms", MatchCriteria = MatchCriteria.Any }), indexName: "synonyms-tests") .Project(Builders.Projection.Include("Title").Exclude("_id")) .Limit(5) diff --git a/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs b/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs index 4b109d40f29..f0d15ea918c 100644 --- a/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs @@ -1144,7 +1144,7 @@ public void Phrase() "{ phrase: { query: 'foo', path: 'x', score: { constant: { value: 1 } } } }"); AssertRendered( - subject.Phrase("x", "foo", new SearchPhraseOptions { Score = scoreBuilder.Constant(1), Slop = 5}), + subject.Phrase("x", "foo", new SearchPhraseOptions { Score = scoreBuilder.Constant(1), Slop = 5 }), "{ phrase: { query: 'foo', slop: 5, path: 'x', score: { constant: { value: 1 } } } }"); } @@ -1342,11 +1342,11 @@ public void Range_should_use_correct_serializers_when_using_attributes_and_expre var subjectTyped = CreateSubject(); AssertRendered( - subjectTyped.Range(t => t.DefaultLong, new SearchRange(testLong, null, false, false )), + subjectTyped.Range(t => t.DefaultLong, new SearchRange(testLong, null, false, false)), """{"range" :{ "gt" : 23, "path" : "DefaultLong" }}"""); AssertRendered( - subjectTyped.Range(t => t.StringLong, new SearchRange(testLong, null, false, false )), + subjectTyped.Range(t => t.StringLong, new SearchRange(testLong, null, false, false)), """{"range":{ "gt" : "23", "path" : "StringLong" }}"""); } @@ -1357,11 +1357,11 @@ public void Range_should_use_correct_serializers_when_using_attributes_and_strin var subjectTyped = CreateSubject(); AssertRendered( - subjectTyped.Range("DefaultLong", new SearchRange(testLong, null, false, false )), + subjectTyped.Range("DefaultLong", new SearchRange(testLong, null, false, false)), """{"range" :{ "gt" : 23, "path" : "DefaultLong" }}"""); AssertRendered( - subjectTyped.Range("StringLong", new SearchRange(testLong, null, false, false )), + subjectTyped.Range("StringLong", new SearchRange(testLong, null, false, false)), """{"range":{ "gt" : "23", "path" : "StringLong" }}"""); } @@ -1374,7 +1374,7 @@ public void Range_should_use_correct_serializers_when_using_serializer_registry( var subjectTyped = CreateSubject(); AssertRendered( - subjectTyped.Range(t => t.DefaultLong, new SearchRange(testLong, null, false, false )), + subjectTyped.Range(t => t.DefaultLong, new SearchRange(testLong, null, false, false)), """{"range":{ "gt" : "23", "path" : "DefaultLong" }}"""); } @@ -1516,7 +1516,7 @@ public void Text() "{ text: { query: ['foo', 'bar'], synonyms: 'testSynonyms', path: ['x', 'y'] } }"); AssertRendered( - subject.Text(new[] { "x", "y" }, new[] { "foo", "bar" }, new SearchTextOptions{ MatchCriteria = MatchCriteria.Any }), + subject.Text(new[] { "x", "y" }, new[] { "foo", "bar" }, new SearchTextOptions { MatchCriteria = MatchCriteria.Any }), "{ text: { query: ['foo', 'bar'], matchCriteria: 'any', path: ['x', 'y'] } }"); AssertRendered( @@ -1540,7 +1540,7 @@ public void Text() "{ text: { query: 'foo', synonyms: 'testSynonyms', path: 'x', score: { constant: { value: 1 } } } }"); AssertRendered( - subject.Text("x", "foo", new SearchTextOptions {Score = scoreBuilder.Constant(1), MatchCriteria = MatchCriteria.All}), + subject.Text("x", "foo", new SearchTextOptions { Score = scoreBuilder.Constant(1), MatchCriteria = MatchCriteria.All }), "{ text: { query: 'foo', matchCriteria: 'all', path: 'x', score: { constant: { value: 1 } } } }"); } @@ -1564,7 +1564,7 @@ public void Text_typed() subject.Text(x => x.FirstName, "foo"), "{ text: { query: 'foo', path: 'fn' } }"); AssertRendered( - subject.Text(x => x.FirstName, "foo", new SearchTextOptions { MatchCriteria = MatchCriteria.All}), + subject.Text(x => x.FirstName, "foo", new SearchTextOptions { MatchCriteria = MatchCriteria.All }), "{ text: { query: 'foo', matchCriteria: 'all', path: 'fn' } }"); AssertRendered( subject.Text("FirstName", "foo"), diff --git a/tests/MongoDB.Driver.Tests/Search/VectorSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/VectorSearchTests.cs index e329f337a8a..a6aec6fa40f 100644 --- a/tests/MongoDB.Driver.Tests/Search/VectorSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/VectorSearchTests.cs @@ -116,7 +116,7 @@ public void VectorSearchExact() "When Trumpets Fade" }; - var vector = new [] { -0.006954097,-0.009932499,-0.001311474,-0.021280076,-0.014608995,-0.008227668,-0.013274779,-0.0069271433,-0.009521453,-0.030943038,0.017304381,0.015094165,-0.010397454,0.010943269,0.012230316,0.025943095,0.02583528,0.001368751,0.009777515,-0.016024074,-0.013989056,0.00685639,0.030242238,-0.023881124,-0.011057823,-0.0056906347,-0.00055929273,-0.03199424,0.0072168973,-0.023166848,0.0033490178,-0.024069803,-0.023557678,-0.020862292,0.007452744,-0.019002475,0.007850314,-0.032856762,-0.012951332,0.003005356,-0.003739849,0.010053792,0.019541552,0.007702067,-0.035498243,-0.00918453,-0.0143529335,0.000249955,-0.011866439,0.019703276,0.0076481593,0.025161434,-0.015714103,-0.0076818517,-0.023180325,-0.0032883717,-0.02315337,0.015188503,0.031347346,-0.008739791,0.01454161,0.014824626,-0.025107525,0.0012558816,-0.012803086,-0.013146748,-0.01652272,0.01283004,-0.019352876,-0.010444623,0.04706145,0.030754361,0.008820653,0.011657547,0.014878534,-0.010181823,0.00041673204,-0.009103668,-0.0055255424,0.00579845,0.024110233,-0.020404076,-0.0066272817,-0.005299804,0.019649368,0.007729021,-0.0066845585,0.025592696,0.00575465,-0.014824626,0.00033334352,-0.008591545,0.004164372,0.028085928,-0.020875769,-0.00448108,-0.009258653,0.02535011,-0.0025538788,-0.059082873,-0.0074055744,0.005950066,-0.014164257,-0.016185796,-0.015768012,-0.01309284,0.0030222023,0.0028436328,0.0037095258,-0.0068462817,-0.010963485,0.018988999,0.010929792,-0.03967609,0.016994413,-0.023503771,-0.0037903874,-0.012075332,-0.005923112,-0.01902943,0.017978229,-0.005993866,0.024015894,-0.017722167,0.010875884,0.0153637035,-0.04045775,-0.0016568204,-0.0074190516,0.0011084777,0.033018485,0.021536138,0.025794849,-0.019622413,-0.041724585,0.014743765,-0.011111731,0.0065666353,-0.019851523,-0.035174794,0.007270805,0.02698082,-0.010929792,-0.020148015,-0.009689915,0.032182917,0.015700627,0.013786903,-0.0021647324,-0.0063644815,0.027317744,0.004403588,0.03158993,-0.0039116796,0.02029626,0.04191326,-0.0050504804,0.008416344,-0.0034602026,0.010485054,-0.0030996946,-0.0212666,0.0043934803,-0.016765304,-0.00039441086,0.025538787,0.008483729,0.017479582,-0.0061454815,-0.018220814,-0.0025589326,0.0102829,-0.045498125,0.029784022,0.017169613,0.020592753,0.012445947,0.021630477,-0.031050853,-0.011327362,-0.024689741,0.0048988652,0.022129124,0.0114621315,-0.026091343,0.015067211,0.004723665,0.017722167,0.014608995,-0.016805734,0.0042250184,0.027843343,0.03264113,0.007034959,-0.6852751,-0.019986292,0.003827449,0.0032462562,0.006115158,-0.001972686,0.001937309,0.015956689,-0.010437884,0.00803899,-0.01401601,-0.00026869634,-0.033207163,-0.00623982,-0.0048449575,-0.013193917,-0.00426208,-0.013207395,-0.014379887,0.017991705,0.0007264909,0.023517247,-0.00725059,0.0071832053,-0.003466941,-0.0072842822,0.0028234175,-0.02460888,0.0044608647,-0.008746529,-0.025713988,0.012499855,0.004882019,0.010525485,0.05250613,-0.003387764,-0.021212691,0.026549557,0.034123596,0.014325979,-0.0080592055,-0.012189886,-0.005970281,0.0115093,0.0021731553,0.033557564,0.020929677,-0.02130703,0.022991648,-0.03123953,0.0102829,-0.0067721587,0.008510683,0.010013361,0.031320393,0.010646777,0.015215457,-0.019797614,0.0022186402,-0.0010351969,0.0015523742,0.021630477,0.00751339,0.0062162355,-0.016468812,0.018840753,-0.02544445,0.030943038,0.008295052,-0.005700743,-0.0033557562,0.020053675,-0.012722225,-0.016778782,0.025511835,0.025538787,0.022802971,-0.017708689,-0.009615792,-0.00733819,0.0049224496,-0.021590047,-0.021158785,0.022034785,0.046872772,-0.021064445,-0.024811033,0.0043429416,-0.006169066,-0.0044406494,-0.003357441,0.006445343,-0.01801866,-0.0082074525,0.0037802798,0.02258734,0.0018598167,-0.0101548685,0.020134538,-0.008214191,-0.0004830638,0.00421828,0.0048719114,0.0087869605,-0.008335483,0.023503771,-0.030161375,0.0055929273,0.054069456,-0.010006622,0.018975522,0.015956689,-0.018530782,0.003669095,0.014662903,-0.023126416,0.011300408,0.021563092,-0.00106552,-0.03269504,0.020282784,-0.023665493,0.025242295,-0.01801866,-0.008537637,-0.00083472754,0.02130703,-0.008780221,0.0080592055,-0.0012971548,0.014838103,0.0056704194,0.015794965,0.001546478,0.013072625,0.0057310658,0.011711455,-0.020997062,0.010289638,0.0041070953,-0.025592696,0.012661578,-0.013436502,0.013348902,0.014312503,-0.023894602,-0.018517306,-0.0105928695,-0.02140137,0.0076885903,0.03220987,-0.0042283875,-0.04649542,-0.000022110593,0.00013803327,-0.0046293265,-0.0036286642,-0.028598052,-0.0042856648,-0.029406667,0.026765188,0.0027711943,-0.0059298505,-0.00311991,0.016293611,-0.027182974,-0.011623855,0.0030508407,-0.0035747564,-0.018032135,0.03045787,0.0011337469,-0.004780942,0.012055117,-0.0081333285,0.02908322,-0.008092898,-0.0015944897,0.014716811,0.014325979,-0.0037061565,-0.0074325283,-0.01854426,-0.0070821284,-0.003598341,-0.01718309,-0.0108826235,0.014959396,-0.019366352,0.017722167,0.009528192,0.022439092,-0.01630709,-0.003625295,-0.00413068,-0.007311236,-0.008503945,-0.006024189,0.038867474,0.030943038,0.015956689,0.007196682,0.013699302,0.0025471402,0.026792143,-0.031832516,-0.018867707,-0.03897529,0.04679191,0.00421828,0.01634752,-0.004120572,-0.009696653,-0.011414962,0.011980994,0.045659848,-0.010080745,-0.0045720492,-0.020794908,-0.0030205175,-0.00896216,-0.0071427743,0.006559897,0.0045147724,-0.032991532,0.0059332196,0.0033153256,0.00426208,0.0063779587,-0.025943095,-0.021495707,-0.008268098,-0.002429217,0.0102829,-0.0048786495,0.003584864,0.004737142,-0.029244944,0.027169496,0.010599608,-0.008517422,-0.0016652435,0.023544202,-0.022398662,0.010202038,0.0029211252,0.021185739,-0.01708875,-0.03396187,0.025121003,-0.009838161,0.015633242,-0.015525427,0.003743218,0.0044676033,-0.021819154,-0.006802482,-0.023126416,0.028112883,0.03045787,0.015255888,-0.008685883,-0.010943269,-0.0039386335,-0.0014950972,-0.009043022,-0.0023264554,-0.0028975406,-0.0021377786,0.002860479,-0.0010166661,-0.01173167,0.03040396,-0.028005067,-0.00509765,-0.008463514,0.019959338,-0.012533547,-0.012782871,-0.0055558654,0.004807896,-0.018800322,0.005582819,0.017991705,-0.005505327,-0.008382652,0.0011404854,-0.0035073718,-0.017587397,0.012890686,-0.0015363704,-0.000308706,0.011603639,-0.0042452337,-0.027129065,-0.0086387135,0.023786787,-0.024352817,-0.015175027,0.017546967,0.0064318664,0.0100874845,-0.008605022,-0.006529574,0.014703333,-0.0010318276,-0.012290963,-0.014622472,-0.008382652,-0.000661212,0.0044170646,0.009386684,-0.0030660022,0.0033102715,-0.007095605,0.007978344,-0.016980935,-0.0040262337,0.022344755,0.0077357595,0.0063341586,-0.016482288,-0.028220698,-0.026899958,0.08291009,0.014002534,0.00075428706,0.013018717,0.0013485356,-0.0223178,-0.016697919,-0.018584691,0.0057378043,0.007924437,0.0032850024,-0.01735829,0.029730113,0.021684386,-0.008382652,0.017021365,0.0030811639,-0.008025514,0.0043564187,-0.000044694985,-0.0038375566,-0.012924379,-0.012230316,0.0345279,-0.014689857,-0.019406782,0.008780221,0.0092923455,-0.01555238,-0.01920463,-0.01827472,-0.00305421,-0.017573921,0.016320566,0.02548488,0.02105097,0.012823301,0.03431227,0.026589988,-0.025606172,0.007755975,0.0019693167,0.0096494835,-0.034069687,0.0067721587,0.0004190484,0.005508696,0.033207163,-0.0011792317,-0.012648102,0.022829924,0.015821919,-0.035956457,-0.038732704,-0.020740999,0.0063880663,-0.010471577,-0.006933882,0.005936589,0.015889304,-0.00852416,-0.031455163,0.009305822,0.0051178653,-0.027452512,-0.015700627,-0.017762598,-0.005869204,-0.0065531586,-0.011879916,-0.008220929,-0.0053503425,-0.0026920172,-0.00038830412,0.019959338,-0.010444623,-0.00047548304,-0.015040257,0.0008330429,0.008005298,-0.0075336057,-0.02117226,-0.027250359,-0.018962044,-0.006138743,0.014918964,-0.014757241,-0.013867764,0.0006961678,0.01726395,-0.0039352644,0.005724327,0.019878477,0.009494499,0.0071832053,-0.0023652017,0.004865173,0.029784022,0.002390471,0.0005854043,0.00034387235,0.0053975116,-0.011650808,0.005218942,0.007136036,-0.0091440985,0.005879312,0.028193744,-0.024662787,-0.0029447097,0.009636007,-0.029730113,0.00025206077,0.006745205,0.011522777,0.02035017,0.026131773,0.029972699,0.008012037,-0.012466162,0.012459424,-0.01836906,0.0051515577,0.022196509,-0.015970165,0.0037465873,-0.008396129,-0.009494499,-0.0036657257,0.011219546,-0.01823429,0.013524102,0.015134595,0.020269306,-0.0028891175,0.008456775,0.0051650344,0.011131947,-0.0038948336,-0.010909577,-0.010485054,-0.026859527,-0.005475004,-0.0036589873,0.0034602026,-0.026253065,-0.010350284,0.0137734255,0.0030828484,0.012526809,-0.026131773,-0.02363854,0.00024321652,-0.015956689,-0.0042991415,-0.027762482,-0.012782871,-0.016940504,0.01256724,0.03598341,0.026387835,0.0013763318,0.0041946955,0.0017520012,-0.007755975,-0.011179116,0.003537695,0.011522777,-0.035929505,0.021037493,0.041859355,0.034770485,-0.012769394,0.0059534353,0.02851719,0.017749121,-0.011017392,0.0059568044,-0.02105097,-0.011233023,0.0095079765,-0.0019002475,-0.006472297,-0.00826136,-0.011495824,-0.024056325,0.00628362,0.0028689022,0.0050808038,0.00632742,0.020228876,-0.0029767177,0.0327759,-0.016859643,0.0006439447,-0.01516155,0.015889304,0.0032765793,-0.0017570552,0.016509242,0.0076481593,0.0033254332,-0.012513332,-0.0073718824,-0.012237055,0.025997004,-0.0052122036,-0.0007530236,-0.01739872,-0.020188445,-0.0005908793,-0.011212808,0.008840868,-0.015741058,0.0034197718,-0.0033456485,-0.010262684,0.010080745,-0.016751828,-0.04415043,0.010202038,0.0058557275,0.023369001,0.009238438,0.04029603,0.009743823,-0.006802482,-0.01502678,0.01634752,-0.018301675,0.011313885,0.030080514,0.009501237,0.000942543,-0.007755975,-0.015242411,0.003898203,-0.017236996,-0.026172204,0.02394851,0.0065834816,0.021617,0.0054514194,-0.039487414,-0.021549616,0.018813798,-0.025848757,0.0026566405,-0.011199331,-0.024635833,-0.01129367,0.010181823,-0.033638425,0.033072393,-0.008537637,-0.02597005,0.010444623,-0.037169382,-0.0003693522,0.008793699,-0.006647497,0.014716811,-0.026023958,-0.011455393,0.0012853625,-0.0063072047,-0.01103087,-0.0034736795,-0.010390716,0.021913493,-0.021509185,0.0022085323,-0.003756695,0.009656223,0.016549673,0.0022186402,-0.020687092,-0.029056268,-0.00065447355,-0.0035309563,0.009305822,0.007958129,-0.0086387135,-0.02035017,-0.029298851,-0.007479698,-0.0205658,-0.0051178653,-0.003770172,-0.02394851,-0.020174969,0.010053792,-0.014325979,0.014811149,-0.0015481627,-0.0060073426,-0.0028116251,0.04091597,-0.026873004,0.00038851472,0.0037769105,0.017344812,-0.003067687,0.023099463,0.0015094165,-0.030296145,0.045012955,-0.035147842,-0.0067553124,0.0090025915,0.0063408967,0.020538846,-0.0011295355,0.0006153062,0.03870575,0.03840926,0.007486436,-0.040619474,-0.0059466967,0.033934917,0.018813798,0.026037434,0.0026195787,-0.010424407,0.011960777,-0.0032277254,0.007924437,0.011617116,-0.028328514,-0.024622357,0.0014639319,0.025147956,-0.00003919366,-0.008800437,-0.0345279,0.009757299,-0.003044102,0.023786787,0.008989114,-0.018207336,-0.0035612795,0.0025185018,-0.00079050637,-0.00048643304,0.0041778493,-0.00927213,-0.014285549,-0.018705983,-0.024150664,-0.021509185,-0.0032193023,0.028220698,-0.005720958,0.00070711784,-0.016953982,-0.0071629896,-0.02702125,0.0040093875,0.00628362,-0.0021411476,0.029110175,0.018220814,0.0071562515,0.022924263,0.0076144673,-0.002565671,0.0020771322,0.004016126,-0.007836836,0.0016509243,0.005485112,0.0061050504,-0.018988999,0.0060713585,-0.0017823244,0.0054413117,-0.0059837583,-0.0060342965,0.013348902,-0.0223178,-0.01300524,-0.013261302,-0.0058995276,0.030377006,-0.002319717,-0.02948753,0.0110982545,0.000072175295,-0.006657605,-0.031131715,0.00733819,-0.0033186947,-0.02649565,0.0060983123,0.011441916,-0.014555087,0.007291021,-0.017735643,0.03654944,0.024622357,0.0003013358,0.02227737,0.0105457,0.025026664,-0.0013965472,-0.012836779,-0.017803028,0.0021849477,0.025997004,0.00009791834,0.007048436,-0.00032555216,0.026131773,-0.025053618,0.01361844,-0.023517247,-0.0023230864,-0.014892011,0.016239705,0.022021309,-0.016967459,0.019056384,0.0047539882,0.0029598714,-0.0013519048,-0.0045585725,0.0015439511,0.021509185,-0.0050909114,0.029999653,0.00074712746,-0.011354316,-0.0037735412,0.0031805562,-0.0055962964,0.019298967,0.18652076,-0.010640038,0.0029514483,0.018962044,-0.0013190547,0.011852963,0.020444507,-0.004720296,0.0021344093,-0.0016542935,-0.008005298,0.013854287,0.0020181707,0.007210159,-0.0037162642,-0.0023129785,-0.03415055,-0.03202119,-0.023665493,0.012621148,0.00927213,-0.006630651,-0.007958129,-0.009379946,0.026172204,-0.006947359,-0.008679145,-0.0073516667,0.01739872,0.0014209741,-0.000361982,0.012142717,-0.0030036713,0.0080592055,-0.021873062,-0.0064116507,0.008227668,-0.028598052,0.0013156856,0.018476875,-0.014231641,0.010929792,0.0066373893,0.03840926,0.015565857,0.009777515,-0.0049628806,0.006920405,0.019528076,0.030646546,-0.028948452,-0.008335483,0.012412256,0.040942922,0.016482288,0.022021309,0.0041946955,0.0058759428,-0.011219546,-0.022021309,-0.016401427,0.020660138,-0.02632045,0.023355525,-0.018759891,0.014299026,-0.029406667,0.0076346826,0.019891953,-0.021387892,-0.0071629896,-0.014110349,-0.026684327,-0.004797788,-0.015606288,-0.006570005,0.034986116,0.006738466,-0.009838161,0.0011303778,-0.010538962,-0.03444704,0.00685639,-0.003888095,-0.009494499,-0.013800379,0.017236996,0.017614352,-0.017546967,0.017614352,0.0024612248,-0.0006982736,-0.008800437,0.0016677704,-0.004666388,-0.0050605885,0.018975522,0.009602315,-0.0034416718,-0.01401601,-0.018247766,-0.00032576272,0.005114496,0.009016068,-0.009609053,-0.0049662497,-0.001726732,0.0019339399,-0.010774808,-0.004016126,-0.0065127276,-0.018759891,0.0020063785,-0.0052661113,-0.0073449286,0.0017671628,-0.034905255,-0.014218165,0.004235126,-0.019649368,0.00010865777,-0.025727466,0.030781314,-0.00861176,-0.016158843,-0.016617058,-0.01454161,-0.0020333321,0.002092294,-0.032533314,0.006206128,-0.029433621,0.004663019,-0.023625063,-0.021199215,0.0073988363,0.007715544,0.00680922,-0.01103087,0.012270748,0.012614409,-0.034420088,-0.003898203,0.015848873,-0.0030828484,-0.0054244655,0.030107468,0.002491548,-0.009993146,-0.014824626,-0.026266541,-0.000074912794,-0.0048719114,-0.012277486,0.014770718,-0.021428322,-0.03506698,-0.013086102,-0.0028571098,0.024554972,-0.03439313,-0.010902839,0.04474342,-0.017196566,0.0026819096,0.00081240636,-0.17476887,0.004710188,0.024231525,-0.00033229063,0.025902664,0.027762482,0.008268098,0.00016561887,0.00027080212,0.0032934255,0.011799055,0.004161003,-0.037519783,0.007243851,-0.0018901399,-0.00799856,-0.024460632,0.008295052,-0.010821977,0.0101548685,0.017681736,0.0082748365,-0.008840868,-0.01722352,0.013793641,0.015983643,0.003409664,0.041589815,-0.010896101,0.0017722166,-0.03282981,-0.0031249637,0.02359811,0.01058613,-0.0003004935,-0.0016248127,-0.027924204,-0.016360996,-0.0048516956,0.014905488,0.0036724643,0.009063237,0.030781314,-0.023854172,-0.013706041,0.0202154,0.011340839,-0.013604964,0.013692563,-0.005879312,0.0024157402,0.0071764668,-0.01630709,0.0032850024,0.003343964,-0.00404308,0.012095547,-0.009898807,0.004764096,-0.0030744253,-0.031428207,-0.015821919,-0.0012407202,-0.024447156,-0.011718193,-0.013658872,-0.011542993,-0.0046832343,-0.0051347115,0.0032277254,0.004464234,-0.002718971,-0.0057613887,-0.016953982,0.01419121,0.0064891432,-0.012668317,0.0038914643,-0.0018193859,-0.004652911,-0.022910787,0.026953865,0.012890686,-0.009993146,-0.0041407878,-0.0024629096,-0.009541669,0.020687092,-0.015175027,-0.022735586,0.01485158,-0.029945744,-0.020377122,-0.010714161,0.008160283,0.010714161,-0.022439092,0.010330069,-0.016563151,-0.012836779,0.017439151,0.014258595,-0.029891837,0.00896216,0.03506698,0.005936589,0.02548488,0.0067283586,0.035821687,0.0056569427,0.005993866,0.028490236,0.011320624,0.021792201,0.012904163,0.025377065,0.007742498,0.01634752,0.016590104,0.01792432,0.04517468,0.0029935637,-0.019689798,0.0025892558,-0.0055524963,-0.0068867127,-0.10786937,-0.030484822,0.008146806,0.025916142,-0.0038375566,0.014918964,-0.0076481593,-0.003224356,-0.0068833437,0.010559177,-0.0007584986,-0.020242354,-0.021738293,-0.007884006,0.05703438,0.0015296319,-0.008706098,-0.01331521,-0.0153637035,0.03862489,-0.010437884,0.015121119,-0.0012070278,-0.007553821,-0.0088543445,-0.0060511427,-0.01349041,0.018220814,-0.018557737,-0.011987732,-0.012358348,-0.0053503425,-0.000028559516,-0.020148015,-0.011866439,-0.004289034,-0.010896101,-0.012412256,0.011482347,-0.0310239,0.01813995,0.03827449,-0.009406899,-0.022991648,0.009838161,-0.02262777,0.023678971,0.013375856,-0.009171053,-0.020094106,-0.01753349,-0.025188388,-0.03291067,0.0043463106,0.009689915,-0.00725059,0.0070147435,0.0063948045,-0.016940504,0.032991532,0.000852416,-0.002139463,-0.028948452,0.014689857,-0.0056434656,0.014299026,-0.013827333,-0.007958129,0.024864942,-0.0134836715,-0.018422967,0.013908194,-0.021037493,0.004336203,-0.03911006,-0.012627886,-0.019002475,0.0013670664,0.0411316,-0.009514715,-0.031455163,-0.020377122,0.0021647324,-0.01906986,0.027843343,0.018854229,-0.0076616365,0.0032614178,-0.000111395275,-0.010693946,-0.003945372,0.022209985,0.040349938,-0.03870575,0.008692621,0.02043103,0.0026044173,-0.019460691,-0.0032614178,0.010040315,-0.025026664,-0.0015102588,-0.047142312,0.043665264,-0.0054985886,-0.007243851,-0.0024831248,0.00084441405,0.025956573,-0.010889362,-0.00733819,0.018759891,-0.011866439,0.014959396,-0.008578068,0.0027206559,-0.025067095,-0.012499855,0.023180325,0.014865057,0.012452686,-0.0034905255,0.0030727407,-0.0048752804,0.028840637,0.01718309,-0.010444623,-0.020498415,-0.018921614,0.012392039,-0.0086387135,-0.0219674,0.024285434,-0.019083338,-0.013086102,0.01801866,0.02029626,-0.025471402,-0.011482347,0.0011126893,0.015754534,0.04846305,-0.026118295,-0.020336691,0.017075274,-0.007850314,0.014177733,0.030862177,0.007958129,0.018881183,0.013375856,0.001256724,0.006981051,0.028705867,-0.0033405947,-0.010309854,-0.020511892,-0.008254621,0.03695375,0.0015549011,0.024730172,0.0038375566,0.025740942,0.024528017,0.005171773,0.00013319,0.009588838,-0.0029733484,-0.004454126,-0.01199447,-0.012135978,-0.02830156,0.007958129,0.006859759,0.009110407,-0.005505327,-0.0067519434,0.005225681,0.011772101,0.014218165,-0.024878418,0.008955422,0.00900933,0.015094165,-0.038867474,0.018503828,0.012243793,0.012843517,-0.020727523,0.008193975,-0.013935149,0.014838103,0.012695271,0.0004902234,0.005950066,0.015929734,-0.006994528,0.021374416,-0.0093597295,-0.009440592,0.017749121,0.004908973,0.0036926796,-0.005458158,-0.00799856,-0.015646718,-0.008517422,0.0074729593,-0.012991764,-0.0061623277,-0.00944733,0.0032529947,0.013261302,-0.003827449,0.0026212635,0.0037769105,-0.0029143868,0.0013325317,0.0024797556,-0.005124604,-0.03989172,0.019568507,0.0100874845,0.016280135,-0.0003554541,-0.025565742,0.012560502,-0.010491792,0.008631975,-0.00904976,-0.00016856696,0.006010712,0.010781546,-0.0020670246,-0.021873062,-0.011859701,-0.00040346567,0.008665668,0.016199274,0.04204803,-0.036091227,0.032102056,0.02043103,0.008402867,0.013766687,-0.020201921,0.0054682656,-0.0037027872,-0.01221684,0.0030036713,-0.027573805,0.0054076193,0.001863186,-0.006357743,-0.029137129,-0.0096697,0.007675113,-0.0153637035,-0.014878534,0.0060612503,0.001300524,0.030484822,0.003800495,0.018908137,0.01840949,-0.00082461984,-0.030808268,0.014918964,-0.013254563,-0.0036050796,-0.009319299,-0.011920347,-0.0059062657,-0.020714046,-0.0051347115,0.02737165,0.005198727,-0.0059601734,-0.027519897,0.026967343,0.0007357563,0.010431146,0.017654782,-0.019797614,-0.039137013,0.033099346,0.0023129785,-0.011017392,-0.0032816331,-0.020848814 }; + var vector = new[] { -0.006954097, -0.009932499, -0.001311474, -0.021280076, -0.014608995, -0.008227668, -0.013274779, -0.0069271433, -0.009521453, -0.030943038, 0.017304381, 0.015094165, -0.010397454, 0.010943269, 0.012230316, 0.025943095, 0.02583528, 0.001368751, 0.009777515, -0.016024074, -0.013989056, 0.00685639, 0.030242238, -0.023881124, -0.011057823, -0.0056906347, -0.00055929273, -0.03199424, 0.0072168973, -0.023166848, 0.0033490178, -0.024069803, -0.023557678, -0.020862292, 0.007452744, -0.019002475, 0.007850314, -0.032856762, -0.012951332, 0.003005356, -0.003739849, 0.010053792, 0.019541552, 0.007702067, -0.035498243, -0.00918453, -0.0143529335, 0.000249955, -0.011866439, 0.019703276, 0.0076481593, 0.025161434, -0.015714103, -0.0076818517, -0.023180325, -0.0032883717, -0.02315337, 0.015188503, 0.031347346, -0.008739791, 0.01454161, 0.014824626, -0.025107525, 0.0012558816, -0.012803086, -0.013146748, -0.01652272, 0.01283004, -0.019352876, -0.010444623, 0.04706145, 0.030754361, 0.008820653, 0.011657547, 0.014878534, -0.010181823, 0.00041673204, -0.009103668, -0.0055255424, 0.00579845, 0.024110233, -0.020404076, -0.0066272817, -0.005299804, 0.019649368, 0.007729021, -0.0066845585, 0.025592696, 0.00575465, -0.014824626, 0.00033334352, -0.008591545, 0.004164372, 0.028085928, -0.020875769, -0.00448108, -0.009258653, 0.02535011, -0.0025538788, -0.059082873, -0.0074055744, 0.005950066, -0.014164257, -0.016185796, -0.015768012, -0.01309284, 0.0030222023, 0.0028436328, 0.0037095258, -0.0068462817, -0.010963485, 0.018988999, 0.010929792, -0.03967609, 0.016994413, -0.023503771, -0.0037903874, -0.012075332, -0.005923112, -0.01902943, 0.017978229, -0.005993866, 0.024015894, -0.017722167, 0.010875884, 0.0153637035, -0.04045775, -0.0016568204, -0.0074190516, 0.0011084777, 0.033018485, 0.021536138, 0.025794849, -0.019622413, -0.041724585, 0.014743765, -0.011111731, 0.0065666353, -0.019851523, -0.035174794, 0.007270805, 0.02698082, -0.010929792, -0.020148015, -0.009689915, 0.032182917, 0.015700627, 0.013786903, -0.0021647324, -0.0063644815, 0.027317744, 0.004403588, 0.03158993, -0.0039116796, 0.02029626, 0.04191326, -0.0050504804, 0.008416344, -0.0034602026, 0.010485054, -0.0030996946, -0.0212666, 0.0043934803, -0.016765304, -0.00039441086, 0.025538787, 0.008483729, 0.017479582, -0.0061454815, -0.018220814, -0.0025589326, 0.0102829, -0.045498125, 0.029784022, 0.017169613, 0.020592753, 0.012445947, 0.021630477, -0.031050853, -0.011327362, -0.024689741, 0.0048988652, 0.022129124, 0.0114621315, -0.026091343, 0.015067211, 0.004723665, 0.017722167, 0.014608995, -0.016805734, 0.0042250184, 0.027843343, 0.03264113, 0.007034959, -0.6852751, -0.019986292, 0.003827449, 0.0032462562, 0.006115158, -0.001972686, 0.001937309, 0.015956689, -0.010437884, 0.00803899, -0.01401601, -0.00026869634, -0.033207163, -0.00623982, -0.0048449575, -0.013193917, -0.00426208, -0.013207395, -0.014379887, 0.017991705, 0.0007264909, 0.023517247, -0.00725059, 0.0071832053, -0.003466941, -0.0072842822, 0.0028234175, -0.02460888, 0.0044608647, -0.008746529, -0.025713988, 0.012499855, 0.004882019, 0.010525485, 0.05250613, -0.003387764, -0.021212691, 0.026549557, 0.034123596, 0.014325979, -0.0080592055, -0.012189886, -0.005970281, 0.0115093, 0.0021731553, 0.033557564, 0.020929677, -0.02130703, 0.022991648, -0.03123953, 0.0102829, -0.0067721587, 0.008510683, 0.010013361, 0.031320393, 0.010646777, 0.015215457, -0.019797614, 0.0022186402, -0.0010351969, 0.0015523742, 0.021630477, 0.00751339, 0.0062162355, -0.016468812, 0.018840753, -0.02544445, 0.030943038, 0.008295052, -0.005700743, -0.0033557562, 0.020053675, -0.012722225, -0.016778782, 0.025511835, 0.025538787, 0.022802971, -0.017708689, -0.009615792, -0.00733819, 0.0049224496, -0.021590047, -0.021158785, 0.022034785, 0.046872772, -0.021064445, -0.024811033, 0.0043429416, -0.006169066, -0.0044406494, -0.003357441, 0.006445343, -0.01801866, -0.0082074525, 0.0037802798, 0.02258734, 0.0018598167, -0.0101548685, 0.020134538, -0.008214191, -0.0004830638, 0.00421828, 0.0048719114, 0.0087869605, -0.008335483, 0.023503771, -0.030161375, 0.0055929273, 0.054069456, -0.010006622, 0.018975522, 0.015956689, -0.018530782, 0.003669095, 0.014662903, -0.023126416, 0.011300408, 0.021563092, -0.00106552, -0.03269504, 0.020282784, -0.023665493, 0.025242295, -0.01801866, -0.008537637, -0.00083472754, 0.02130703, -0.008780221, 0.0080592055, -0.0012971548, 0.014838103, 0.0056704194, 0.015794965, 0.001546478, 0.013072625, 0.0057310658, 0.011711455, -0.020997062, 0.010289638, 0.0041070953, -0.025592696, 0.012661578, -0.013436502, 0.013348902, 0.014312503, -0.023894602, -0.018517306, -0.0105928695, -0.02140137, 0.0076885903, 0.03220987, -0.0042283875, -0.04649542, -0.000022110593, 0.00013803327, -0.0046293265, -0.0036286642, -0.028598052, -0.0042856648, -0.029406667, 0.026765188, 0.0027711943, -0.0059298505, -0.00311991, 0.016293611, -0.027182974, -0.011623855, 0.0030508407, -0.0035747564, -0.018032135, 0.03045787, 0.0011337469, -0.004780942, 0.012055117, -0.0081333285, 0.02908322, -0.008092898, -0.0015944897, 0.014716811, 0.014325979, -0.0037061565, -0.0074325283, -0.01854426, -0.0070821284, -0.003598341, -0.01718309, -0.0108826235, 0.014959396, -0.019366352, 0.017722167, 0.009528192, 0.022439092, -0.01630709, -0.003625295, -0.00413068, -0.007311236, -0.008503945, -0.006024189, 0.038867474, 0.030943038, 0.015956689, 0.007196682, 0.013699302, 0.0025471402, 0.026792143, -0.031832516, -0.018867707, -0.03897529, 0.04679191, 0.00421828, 0.01634752, -0.004120572, -0.009696653, -0.011414962, 0.011980994, 0.045659848, -0.010080745, -0.0045720492, -0.020794908, -0.0030205175, -0.00896216, -0.0071427743, 0.006559897, 0.0045147724, -0.032991532, 0.0059332196, 0.0033153256, 0.00426208, 0.0063779587, -0.025943095, -0.021495707, -0.008268098, -0.002429217, 0.0102829, -0.0048786495, 0.003584864, 0.004737142, -0.029244944, 0.027169496, 0.010599608, -0.008517422, -0.0016652435, 0.023544202, -0.022398662, 0.010202038, 0.0029211252, 0.021185739, -0.01708875, -0.03396187, 0.025121003, -0.009838161, 0.015633242, -0.015525427, 0.003743218, 0.0044676033, -0.021819154, -0.006802482, -0.023126416, 0.028112883, 0.03045787, 0.015255888, -0.008685883, -0.010943269, -0.0039386335, -0.0014950972, -0.009043022, -0.0023264554, -0.0028975406, -0.0021377786, 0.002860479, -0.0010166661, -0.01173167, 0.03040396, -0.028005067, -0.00509765, -0.008463514, 0.019959338, -0.012533547, -0.012782871, -0.0055558654, 0.004807896, -0.018800322, 0.005582819, 0.017991705, -0.005505327, -0.008382652, 0.0011404854, -0.0035073718, -0.017587397, 0.012890686, -0.0015363704, -0.000308706, 0.011603639, -0.0042452337, -0.027129065, -0.0086387135, 0.023786787, -0.024352817, -0.015175027, 0.017546967, 0.0064318664, 0.0100874845, -0.008605022, -0.006529574, 0.014703333, -0.0010318276, -0.012290963, -0.014622472, -0.008382652, -0.000661212, 0.0044170646, 0.009386684, -0.0030660022, 0.0033102715, -0.007095605, 0.007978344, -0.016980935, -0.0040262337, 0.022344755, 0.0077357595, 0.0063341586, -0.016482288, -0.028220698, -0.026899958, 0.08291009, 0.014002534, 0.00075428706, 0.013018717, 0.0013485356, -0.0223178, -0.016697919, -0.018584691, 0.0057378043, 0.007924437, 0.0032850024, -0.01735829, 0.029730113, 0.021684386, -0.008382652, 0.017021365, 0.0030811639, -0.008025514, 0.0043564187, -0.000044694985, -0.0038375566, -0.012924379, -0.012230316, 0.0345279, -0.014689857, -0.019406782, 0.008780221, 0.0092923455, -0.01555238, -0.01920463, -0.01827472, -0.00305421, -0.017573921, 0.016320566, 0.02548488, 0.02105097, 0.012823301, 0.03431227, 0.026589988, -0.025606172, 0.007755975, 0.0019693167, 0.0096494835, -0.034069687, 0.0067721587, 0.0004190484, 0.005508696, 0.033207163, -0.0011792317, -0.012648102, 0.022829924, 0.015821919, -0.035956457, -0.038732704, -0.020740999, 0.0063880663, -0.010471577, -0.006933882, 0.005936589, 0.015889304, -0.00852416, -0.031455163, 0.009305822, 0.0051178653, -0.027452512, -0.015700627, -0.017762598, -0.005869204, -0.0065531586, -0.011879916, -0.008220929, -0.0053503425, -0.0026920172, -0.00038830412, 0.019959338, -0.010444623, -0.00047548304, -0.015040257, 0.0008330429, 0.008005298, -0.0075336057, -0.02117226, -0.027250359, -0.018962044, -0.006138743, 0.014918964, -0.014757241, -0.013867764, 0.0006961678, 0.01726395, -0.0039352644, 0.005724327, 0.019878477, 0.009494499, 0.0071832053, -0.0023652017, 0.004865173, 0.029784022, 0.002390471, 0.0005854043, 0.00034387235, 0.0053975116, -0.011650808, 0.005218942, 0.007136036, -0.0091440985, 0.005879312, 0.028193744, -0.024662787, -0.0029447097, 0.009636007, -0.029730113, 0.00025206077, 0.006745205, 0.011522777, 0.02035017, 0.026131773, 0.029972699, 0.008012037, -0.012466162, 0.012459424, -0.01836906, 0.0051515577, 0.022196509, -0.015970165, 0.0037465873, -0.008396129, -0.009494499, -0.0036657257, 0.011219546, -0.01823429, 0.013524102, 0.015134595, 0.020269306, -0.0028891175, 0.008456775, 0.0051650344, 0.011131947, -0.0038948336, -0.010909577, -0.010485054, -0.026859527, -0.005475004, -0.0036589873, 0.0034602026, -0.026253065, -0.010350284, 0.0137734255, 0.0030828484, 0.012526809, -0.026131773, -0.02363854, 0.00024321652, -0.015956689, -0.0042991415, -0.027762482, -0.012782871, -0.016940504, 0.01256724, 0.03598341, 0.026387835, 0.0013763318, 0.0041946955, 0.0017520012, -0.007755975, -0.011179116, 0.003537695, 0.011522777, -0.035929505, 0.021037493, 0.041859355, 0.034770485, -0.012769394, 0.0059534353, 0.02851719, 0.017749121, -0.011017392, 0.0059568044, -0.02105097, -0.011233023, 0.0095079765, -0.0019002475, -0.006472297, -0.00826136, -0.011495824, -0.024056325, 0.00628362, 0.0028689022, 0.0050808038, 0.00632742, 0.020228876, -0.0029767177, 0.0327759, -0.016859643, 0.0006439447, -0.01516155, 0.015889304, 0.0032765793, -0.0017570552, 0.016509242, 0.0076481593, 0.0033254332, -0.012513332, -0.0073718824, -0.012237055, 0.025997004, -0.0052122036, -0.0007530236, -0.01739872, -0.020188445, -0.0005908793, -0.011212808, 0.008840868, -0.015741058, 0.0034197718, -0.0033456485, -0.010262684, 0.010080745, -0.016751828, -0.04415043, 0.010202038, 0.0058557275, 0.023369001, 0.009238438, 0.04029603, 0.009743823, -0.006802482, -0.01502678, 0.01634752, -0.018301675, 0.011313885, 0.030080514, 0.009501237, 0.000942543, -0.007755975, -0.015242411, 0.003898203, -0.017236996, -0.026172204, 0.02394851, 0.0065834816, 0.021617, 0.0054514194, -0.039487414, -0.021549616, 0.018813798, -0.025848757, 0.0026566405, -0.011199331, -0.024635833, -0.01129367, 0.010181823, -0.033638425, 0.033072393, -0.008537637, -0.02597005, 0.010444623, -0.037169382, -0.0003693522, 0.008793699, -0.006647497, 0.014716811, -0.026023958, -0.011455393, 0.0012853625, -0.0063072047, -0.01103087, -0.0034736795, -0.010390716, 0.021913493, -0.021509185, 0.0022085323, -0.003756695, 0.009656223, 0.016549673, 0.0022186402, -0.020687092, -0.029056268, -0.00065447355, -0.0035309563, 0.009305822, 0.007958129, -0.0086387135, -0.02035017, -0.029298851, -0.007479698, -0.0205658, -0.0051178653, -0.003770172, -0.02394851, -0.020174969, 0.010053792, -0.014325979, 0.014811149, -0.0015481627, -0.0060073426, -0.0028116251, 0.04091597, -0.026873004, 0.00038851472, 0.0037769105, 0.017344812, -0.003067687, 0.023099463, 0.0015094165, -0.030296145, 0.045012955, -0.035147842, -0.0067553124, 0.0090025915, 0.0063408967, 0.020538846, -0.0011295355, 0.0006153062, 0.03870575, 0.03840926, 0.007486436, -0.040619474, -0.0059466967, 0.033934917, 0.018813798, 0.026037434, 0.0026195787, -0.010424407, 0.011960777, -0.0032277254, 0.007924437, 0.011617116, -0.028328514, -0.024622357, 0.0014639319, 0.025147956, -0.00003919366, -0.008800437, -0.0345279, 0.009757299, -0.003044102, 0.023786787, 0.008989114, -0.018207336, -0.0035612795, 0.0025185018, -0.00079050637, -0.00048643304, 0.0041778493, -0.00927213, -0.014285549, -0.018705983, -0.024150664, -0.021509185, -0.0032193023, 0.028220698, -0.005720958, 0.00070711784, -0.016953982, -0.0071629896, -0.02702125, 0.0040093875, 0.00628362, -0.0021411476, 0.029110175, 0.018220814, 0.0071562515, 0.022924263, 0.0076144673, -0.002565671, 0.0020771322, 0.004016126, -0.007836836, 0.0016509243, 0.005485112, 0.0061050504, -0.018988999, 0.0060713585, -0.0017823244, 0.0054413117, -0.0059837583, -0.0060342965, 0.013348902, -0.0223178, -0.01300524, -0.013261302, -0.0058995276, 0.030377006, -0.002319717, -0.02948753, 0.0110982545, 0.000072175295, -0.006657605, -0.031131715, 0.00733819, -0.0033186947, -0.02649565, 0.0060983123, 0.011441916, -0.014555087, 0.007291021, -0.017735643, 0.03654944, 0.024622357, 0.0003013358, 0.02227737, 0.0105457, 0.025026664, -0.0013965472, -0.012836779, -0.017803028, 0.0021849477, 0.025997004, 0.00009791834, 0.007048436, -0.00032555216, 0.026131773, -0.025053618, 0.01361844, -0.023517247, -0.0023230864, -0.014892011, 0.016239705, 0.022021309, -0.016967459, 0.019056384, 0.0047539882, 0.0029598714, -0.0013519048, -0.0045585725, 0.0015439511, 0.021509185, -0.0050909114, 0.029999653, 0.00074712746, -0.011354316, -0.0037735412, 0.0031805562, -0.0055962964, 0.019298967, 0.18652076, -0.010640038, 0.0029514483, 0.018962044, -0.0013190547, 0.011852963, 0.020444507, -0.004720296, 0.0021344093, -0.0016542935, -0.008005298, 0.013854287, 0.0020181707, 0.007210159, -0.0037162642, -0.0023129785, -0.03415055, -0.03202119, -0.023665493, 0.012621148, 0.00927213, -0.006630651, -0.007958129, -0.009379946, 0.026172204, -0.006947359, -0.008679145, -0.0073516667, 0.01739872, 0.0014209741, -0.000361982, 0.012142717, -0.0030036713, 0.0080592055, -0.021873062, -0.0064116507, 0.008227668, -0.028598052, 0.0013156856, 0.018476875, -0.014231641, 0.010929792, 0.0066373893, 0.03840926, 0.015565857, 0.009777515, -0.0049628806, 0.006920405, 0.019528076, 0.030646546, -0.028948452, -0.008335483, 0.012412256, 0.040942922, 0.016482288, 0.022021309, 0.0041946955, 0.0058759428, -0.011219546, -0.022021309, -0.016401427, 0.020660138, -0.02632045, 0.023355525, -0.018759891, 0.014299026, -0.029406667, 0.0076346826, 0.019891953, -0.021387892, -0.0071629896, -0.014110349, -0.026684327, -0.004797788, -0.015606288, -0.006570005, 0.034986116, 0.006738466, -0.009838161, 0.0011303778, -0.010538962, -0.03444704, 0.00685639, -0.003888095, -0.009494499, -0.013800379, 0.017236996, 0.017614352, -0.017546967, 0.017614352, 0.0024612248, -0.0006982736, -0.008800437, 0.0016677704, -0.004666388, -0.0050605885, 0.018975522, 0.009602315, -0.0034416718, -0.01401601, -0.018247766, -0.00032576272, 0.005114496, 0.009016068, -0.009609053, -0.0049662497, -0.001726732, 0.0019339399, -0.010774808, -0.004016126, -0.0065127276, -0.018759891, 0.0020063785, -0.0052661113, -0.0073449286, 0.0017671628, -0.034905255, -0.014218165, 0.004235126, -0.019649368, 0.00010865777, -0.025727466, 0.030781314, -0.00861176, -0.016158843, -0.016617058, -0.01454161, -0.0020333321, 0.002092294, -0.032533314, 0.006206128, -0.029433621, 0.004663019, -0.023625063, -0.021199215, 0.0073988363, 0.007715544, 0.00680922, -0.01103087, 0.012270748, 0.012614409, -0.034420088, -0.003898203, 0.015848873, -0.0030828484, -0.0054244655, 0.030107468, 0.002491548, -0.009993146, -0.014824626, -0.026266541, -0.000074912794, -0.0048719114, -0.012277486, 0.014770718, -0.021428322, -0.03506698, -0.013086102, -0.0028571098, 0.024554972, -0.03439313, -0.010902839, 0.04474342, -0.017196566, 0.0026819096, 0.00081240636, -0.17476887, 0.004710188, 0.024231525, -0.00033229063, 0.025902664, 0.027762482, 0.008268098, 0.00016561887, 0.00027080212, 0.0032934255, 0.011799055, 0.004161003, -0.037519783, 0.007243851, -0.0018901399, -0.00799856, -0.024460632, 0.008295052, -0.010821977, 0.0101548685, 0.017681736, 0.0082748365, -0.008840868, -0.01722352, 0.013793641, 0.015983643, 0.003409664, 0.041589815, -0.010896101, 0.0017722166, -0.03282981, -0.0031249637, 0.02359811, 0.01058613, -0.0003004935, -0.0016248127, -0.027924204, -0.016360996, -0.0048516956, 0.014905488, 0.0036724643, 0.009063237, 0.030781314, -0.023854172, -0.013706041, 0.0202154, 0.011340839, -0.013604964, 0.013692563, -0.005879312, 0.0024157402, 0.0071764668, -0.01630709, 0.0032850024, 0.003343964, -0.00404308, 0.012095547, -0.009898807, 0.004764096, -0.0030744253, -0.031428207, -0.015821919, -0.0012407202, -0.024447156, -0.011718193, -0.013658872, -0.011542993, -0.0046832343, -0.0051347115, 0.0032277254, 0.004464234, -0.002718971, -0.0057613887, -0.016953982, 0.01419121, 0.0064891432, -0.012668317, 0.0038914643, -0.0018193859, -0.004652911, -0.022910787, 0.026953865, 0.012890686, -0.009993146, -0.0041407878, -0.0024629096, -0.009541669, 0.020687092, -0.015175027, -0.022735586, 0.01485158, -0.029945744, -0.020377122, -0.010714161, 0.008160283, 0.010714161, -0.022439092, 0.010330069, -0.016563151, -0.012836779, 0.017439151, 0.014258595, -0.029891837, 0.00896216, 0.03506698, 0.005936589, 0.02548488, 0.0067283586, 0.035821687, 0.0056569427, 0.005993866, 0.028490236, 0.011320624, 0.021792201, 0.012904163, 0.025377065, 0.007742498, 0.01634752, 0.016590104, 0.01792432, 0.04517468, 0.0029935637, -0.019689798, 0.0025892558, -0.0055524963, -0.0068867127, -0.10786937, -0.030484822, 0.008146806, 0.025916142, -0.0038375566, 0.014918964, -0.0076481593, -0.003224356, -0.0068833437, 0.010559177, -0.0007584986, -0.020242354, -0.021738293, -0.007884006, 0.05703438, 0.0015296319, -0.008706098, -0.01331521, -0.0153637035, 0.03862489, -0.010437884, 0.015121119, -0.0012070278, -0.007553821, -0.0088543445, -0.0060511427, -0.01349041, 0.018220814, -0.018557737, -0.011987732, -0.012358348, -0.0053503425, -0.000028559516, -0.020148015, -0.011866439, -0.004289034, -0.010896101, -0.012412256, 0.011482347, -0.0310239, 0.01813995, 0.03827449, -0.009406899, -0.022991648, 0.009838161, -0.02262777, 0.023678971, 0.013375856, -0.009171053, -0.020094106, -0.01753349, -0.025188388, -0.03291067, 0.0043463106, 0.009689915, -0.00725059, 0.0070147435, 0.0063948045, -0.016940504, 0.032991532, 0.000852416, -0.002139463, -0.028948452, 0.014689857, -0.0056434656, 0.014299026, -0.013827333, -0.007958129, 0.024864942, -0.0134836715, -0.018422967, 0.013908194, -0.021037493, 0.004336203, -0.03911006, -0.012627886, -0.019002475, 0.0013670664, 0.0411316, -0.009514715, -0.031455163, -0.020377122, 0.0021647324, -0.01906986, 0.027843343, 0.018854229, -0.0076616365, 0.0032614178, -0.000111395275, -0.010693946, -0.003945372, 0.022209985, 0.040349938, -0.03870575, 0.008692621, 0.02043103, 0.0026044173, -0.019460691, -0.0032614178, 0.010040315, -0.025026664, -0.0015102588, -0.047142312, 0.043665264, -0.0054985886, -0.007243851, -0.0024831248, 0.00084441405, 0.025956573, -0.010889362, -0.00733819, 0.018759891, -0.011866439, 0.014959396, -0.008578068, 0.0027206559, -0.025067095, -0.012499855, 0.023180325, 0.014865057, 0.012452686, -0.0034905255, 0.0030727407, -0.0048752804, 0.028840637, 0.01718309, -0.010444623, -0.020498415, -0.018921614, 0.012392039, -0.0086387135, -0.0219674, 0.024285434, -0.019083338, -0.013086102, 0.01801866, 0.02029626, -0.025471402, -0.011482347, 0.0011126893, 0.015754534, 0.04846305, -0.026118295, -0.020336691, 0.017075274, -0.007850314, 0.014177733, 0.030862177, 0.007958129, 0.018881183, 0.013375856, 0.001256724, 0.006981051, 0.028705867, -0.0033405947, -0.010309854, -0.020511892, -0.008254621, 0.03695375, 0.0015549011, 0.024730172, 0.0038375566, 0.025740942, 0.024528017, 0.005171773, 0.00013319, 0.009588838, -0.0029733484, -0.004454126, -0.01199447, -0.012135978, -0.02830156, 0.007958129, 0.006859759, 0.009110407, -0.005505327, -0.0067519434, 0.005225681, 0.011772101, 0.014218165, -0.024878418, 0.008955422, 0.00900933, 0.015094165, -0.038867474, 0.018503828, 0.012243793, 0.012843517, -0.020727523, 0.008193975, -0.013935149, 0.014838103, 0.012695271, 0.0004902234, 0.005950066, 0.015929734, -0.006994528, 0.021374416, -0.0093597295, -0.009440592, 0.017749121, 0.004908973, 0.0036926796, -0.005458158, -0.00799856, -0.015646718, -0.008517422, 0.0074729593, -0.012991764, -0.0061623277, -0.00944733, 0.0032529947, 0.013261302, -0.003827449, 0.0026212635, 0.0037769105, -0.0029143868, 0.0013325317, 0.0024797556, -0.005124604, -0.03989172, 0.019568507, 0.0100874845, 0.016280135, -0.0003554541, -0.025565742, 0.012560502, -0.010491792, 0.008631975, -0.00904976, -0.00016856696, 0.006010712, 0.010781546, -0.0020670246, -0.021873062, -0.011859701, -0.00040346567, 0.008665668, 0.016199274, 0.04204803, -0.036091227, 0.032102056, 0.02043103, 0.008402867, 0.013766687, -0.020201921, 0.0054682656, -0.0037027872, -0.01221684, 0.0030036713, -0.027573805, 0.0054076193, 0.001863186, -0.006357743, -0.029137129, -0.0096697, 0.007675113, -0.0153637035, -0.014878534, 0.0060612503, 0.001300524, 0.030484822, 0.003800495, 0.018908137, 0.01840949, -0.00082461984, -0.030808268, 0.014918964, -0.013254563, -0.0036050796, -0.009319299, -0.011920347, -0.0059062657, -0.020714046, -0.0051347115, 0.02737165, 0.005198727, -0.0059601734, -0.027519897, 0.026967343, 0.0007357563, 0.010431146, 0.017654782, -0.019797614, -0.039137013, 0.033099346, 0.0023129785, -0.011017392, -0.0032816331, -0.020848814 }; var options = new VectorSearchOptions { @@ -1215,10 +1215,10 @@ public class NestedPlot public string Plot { get; set; } [BsonElement("rating")] - public int Rating { get; set; } + public int Rating { get; set; } [BsonElement("plot-embedding")] - public float[] PlotEmbedding { get; set; } + public float[] PlotEmbedding { get; set; } } private static string GetRandomName() => $"test_{Guid.NewGuid():N}"; diff --git a/tests/MongoDB.Driver.Tests/Specifications/UnifiedTestSpecRunner.cs b/tests/MongoDB.Driver.Tests/Specifications/UnifiedTestSpecRunner.cs index a1c82cb4f8c..5da19ac0723 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/UnifiedTestSpecRunner.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/UnifiedTestSpecRunner.cs @@ -200,7 +200,7 @@ public void LoadBalancers(JsonDrivenTestCase testCase) .SkipWhen(SupportedOperatingSystem.MacOS); #endif - Run(testCase); + Run(testCase); } [UnifiedTestsTheory("mongodb_handshake.tests.unified")] diff --git a/tests/MongoDB.Driver.Tests/Specifications/auth/OidcAuthenticationProseTests.cs b/tests/MongoDB.Driver.Tests/Specifications/auth/OidcAuthenticationProseTests.cs index fc281d59a30..31607eb0adf 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/auth/OidcAuthenticationProseTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/auth/OidcAuthenticationProseTests.cs @@ -62,7 +62,7 @@ public OidcAuthenticationProseTests(ITestOutputHelper output) : base(output) // https://github.com/mongodb/specifications/blob/44176c1b633819b5a070e05148a989d0c79d406d/source/auth/tests/mongodb-oidc.md?plain=1#L47 [Theory] [ParameterAttributeData] - public async Task Callback_authentication_callback_called_during_authentication([Values(false, true)]bool async) + public async Task Callback_authentication_callback_called_during_authentication([Values(false, true)] bool async) { EnsureOidcIsConfigured(); @@ -85,7 +85,7 @@ public async Task Callback_authentication_callback_called_during_authentication( // https://github.com/mongodb/specifications/blob/44176c1b633819b5a070e05148a989d0c79d406d/source/auth/tests/mongodb-oidc.md?plain=1#L54 [Theory] [ParameterAttributeData] - public async Task Callback_authentication_callback_called_once_for_multiple_connections([Values(false, true)]bool async) + public async Task Callback_authentication_callback_called_once_for_multiple_connections([Values(false, true)] bool async) { EnsureOidcIsConfigured(); diff --git a/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/EncryptionTestHelper.cs b/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/EncryptionTestHelper.cs index 5a8051ee642..48a3d88be7a 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/EncryptionTestHelper.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/EncryptionTestHelper.cs @@ -34,7 +34,7 @@ public static class EncryptionTestHelper private static readonly string __allKmsProviderNames = CreateKmsProviderFilter("aws", "aws:name1", "aws:name2", "local", "local:name1", "local:name2", "azure", "azure:name1", "gcp", "gcp:name1", "kmip", "kmip:name1"); - private static readonly ConcurrentDictionary> __kmsProviders = new(); + private static readonly ConcurrentDictionary> __kmsProviders = new(); private const string KmsProviderFilterDelimiter = ";"; private static readonly string __defaultMongocryptdPath = Environment.GetEnvironmentVariable("MONGODB_BINARIES") ?? ""; private static readonly Lazy<(bool IsValid, SemanticVersion Version)> __defaultCsfleSetupState = new(IsDefaultCsfleSetupValid, isThreadSafe: true); @@ -260,7 +260,7 @@ public static SslSettings CreateTlsOptionsIfAllowed( var password = Environment.GetEnvironmentVariable("MONGO_X509_CLIENT_CERTIFICATE_PASSWORD"); var clientCertificate = X509CertificateLoader.LoadPkcs12FromFile(Ensure.IsNotNull(certificateFilename, nameof(certificateFilename)), Ensure.IsNotNull(password, nameof(password))); - return new SslSettings { ClientCertificates = [ clientCertificate ] }; + return new SslSettings { ClientCertificates = [clientCertificate] }; } return null; diff --git a/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs b/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs index d3611204092..a734591d378 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs @@ -48,8 +48,8 @@ using Xunit; using Xunit.Abstractions; using Xunit.Sdk; -using OperatingSystemHelper = MongoDB.Driver.Core.Misc.OperatingSystemHelper; -using OperatingSystemPlatform = MongoDB.Driver.Core.Misc.OperatingSystemPlatform; +using OperatingSystemHelper = MongoDB.Driver.Core.Misc.OperatingSystemHelper; +using OperatingSystemPlatform = MongoDB.Driver.Core.Misc.OperatingSystemPlatform; using Reflector = MongoDB.Bson.TestHelpers.Reflector; namespace MongoDB.Driver.Tests.Specifications.client_side_encryption.prose_tests @@ -136,7 +136,7 @@ void RunTestCase(int testCase) exception .Should().BeOfType().Which.InnerException - .Should().BeOfType().Which.Message.Should().Contain("There are no encrypted fields defined for the collection.") ; + .Should().BeOfType().Which.Message.Should().Contain("There are no encrypted fields defined for the collection."); } break; case 3: // Case 3: Invalid ``keyId`` @@ -149,7 +149,7 @@ void RunTestCase(int testCase) .Should().BeOfType().Which.Message.Should().Contain("BSON field 'create.encryptedFields.fields.keyId' is the wrong type 'bool', expected type 'binData'"); } break; - case 4: // Case 4: Insert encrypted value + case 4: // Case 4: Insert encrypted value { var createCollectionOptions = new CreateCollectionOptions { EncryptedFields = encryptedFields }; var collection = CreateEncryptedCollection(client, clientEncryption, __collCollectionNamespace, createCollectionOptions, kmsProvider, async, out var effectiveEncryptedFields); @@ -1792,7 +1792,7 @@ void AssertTlsWithoutClientCertOnWindows(Exception exception) { try { - AssertInnerEncryptionException(exception,"The message received was unexpected or badly formatted"); + AssertInnerEncryptionException(exception, "The message received was unexpected or badly formatted"); } catch (XunitException) // assertation failed { @@ -2501,7 +2501,7 @@ public void TestLookup() { "$project": { "_id": 0 } } ] """; - var expectedResult1 ="""{"csfle" : "csfle", "matched" : [ {"no_schema" : "no_schema"} ]}"""; + var expectedResult1 = """{"csfle" : "csfle", "matched" : [ {"no_schema" : "no_schema"} ]}"""; RunTestCase(csfleNamespace, pipeline1, expectedResult1); // Case 2: db.qe joins db.no_schema @@ -2519,7 +2519,7 @@ public void TestLookup() {"$project" : {"_id" : 0, "__safeContent__" : 0}} ] """; - var expectedResult2 ="""{"qe" : "qe", "matched" : [ {"no_schema" : "no_schema"} ]}"""; + var expectedResult2 = """{"qe" : "qe", "matched" : [ {"no_schema" : "no_schema"} ]}"""; RunTestCase(qeNamespace, pipeline2, expectedResult2); // Case 3: db.no_schema joins db.csfle @@ -2536,7 +2536,7 @@ public void TestLookup() {"$project" : {"_id" : 0}} ] """; - var expectedResult3 ="""{"no_schema" : "no_schema", "matched" : [ {"csfle" : "csfle"} ]}"""; + var expectedResult3 = """{"no_schema" : "no_schema", "matched" : [ {"csfle" : "csfle"} ]}"""; RunTestCase(noSchemaNamespace, pipeline3, expectedResult3); // Case 4: db.no_schema joins db.qe @@ -2553,7 +2553,7 @@ public void TestLookup() {"$project" : {"_id" : 0}} ] """; - var expectedResult4 ="""{"no_schema" : "no_schema", "matched" : [ {"qe" : "qe"} ]}"""; + var expectedResult4 = """{"no_schema" : "no_schema", "matched" : [ {"qe" : "qe"} ]}"""; RunTestCase(noSchemaNamespace, pipeline4, expectedResult4); // Case 5: db.csfle joins db.csfle2 @@ -2570,7 +2570,7 @@ public void TestLookup() {"$project" : {"_id" : 0}} ] """; - var expectedResult5 ="""{"csfle" : "csfle", "matched" : [ {"csfle2" : "csfle2"} ]}"""; + var expectedResult5 = """{"csfle" : "csfle", "matched" : [ {"csfle2" : "csfle2"} ]}"""; RunTestCase(csfleNamespace, pipeline5, expectedResult5); // Case 6: db.qe joins db.qe2 @@ -2587,7 +2587,7 @@ public void TestLookup() {"$project" : {"_id" : 0, "__safeContent__" : 0}} ] """; - var expectedResult6 ="""{"qe" : "qe", "matched" : [ {"qe2" : "qe2"} ]}"""; + var expectedResult6 = """{"qe" : "qe", "matched" : [ {"qe2" : "qe2"} ]}"""; RunTestCase(qeNamespace, pipeline6, expectedResult6); // Case 7: db.no_schema joins db.no_schema2 @@ -2604,7 +2604,7 @@ public void TestLookup() {"$project" : {"_id" : 0}} ] """; - var expectedResult7 ="""{"no_schema" : "no_schema", "matched" : [ {"no_schema2" : "no_schema2"} ]}"""; + var expectedResult7 = """{"no_schema" : "no_schema", "matched" : [ {"no_schema2" : "no_schema2"} ]}"""; RunTestCase(noSchemaNamespace, pipeline7, expectedResult7); // Case 8: db.csfle joins db.qe @@ -2919,223 +2919,223 @@ void RunTestCase( switch (testCase) { case 1: // can find a document by prefix - { - var encryptedFoo = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: prefixQueryType, stringOptions: new StringOptions( - true, - true, - new PrefixOptions(10, 2))), - "foo", - async); - - var filter = CreateFindFilter("$encStrStartsWith", "encryptedText", encryptedFoo); - - var findResult = Find(prefixSuffixCollection, filter, async).Single(); - findResult["encryptedText"].AsString.Should().Be("foobarbaz"); - break; - } + { + var encryptedFoo = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: prefixQueryType, stringOptions: new StringOptions( + true, + true, + new PrefixOptions(10, 2))), + "foo", + async); + + var filter = CreateFindFilter("$encStrStartsWith", "encryptedText", encryptedFoo); + + var findResult = Find(prefixSuffixCollection, filter, async).Single(); + findResult["encryptedText"].AsString.Should().Be("foobarbaz"); + break; + } case 2: // can find a document by suffix - { - var encryptedBaz = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: suffixQueryType, stringOptions: new StringOptions( - true, - true, - suffixOptions: new SuffixOptions(10, 2))), - "baz", - async); - - var filter = CreateFindFilter("$encStrEndsWith", "encryptedText", encryptedBaz); - - var findResult = Find(prefixSuffixCollection, filter, async).Single(); - findResult["encryptedText"].AsString.Should().Be("foobarbaz"); - break; - } + { + var encryptedBaz = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: suffixQueryType, stringOptions: new StringOptions( + true, + true, + suffixOptions: new SuffixOptions(10, 2))), + "baz", + async); + + var filter = CreateFindFilter("$encStrEndsWith", "encryptedText", encryptedBaz); + + var findResult = Find(prefixSuffixCollection, filter, async).Single(); + findResult["encryptedText"].AsString.Should().Be("foobarbaz"); + break; + } case 3: // assert no document found by prefix - { - var encryptedBaz = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: prefixQueryType, stringOptions: new StringOptions( - true, - true, - new PrefixOptions(10, 2))), - "baz", - async); - - var filter = CreateFindFilter("$encStrStartsWith", "encryptedText", encryptedBaz); - - var findResult = Find(prefixSuffixCollection, filter, async).ToList(); - findResult.Should().BeEmpty(); - break; - } + { + var encryptedBaz = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: prefixQueryType, stringOptions: new StringOptions( + true, + true, + new PrefixOptions(10, 2))), + "baz", + async); + + var filter = CreateFindFilter("$encStrStartsWith", "encryptedText", encryptedBaz); + + var findResult = Find(prefixSuffixCollection, filter, async).ToList(); + findResult.Should().BeEmpty(); + break; + } case 4: // assert no document found by suffix - { - var encryptedFoo = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: suffixQueryType, stringOptions: new StringOptions( - true, - true, - suffixOptions: new SuffixOptions(10, 2))), - "foo", - async); - - var filter = CreateFindFilter("$encStrEndsWith", "encryptedText", encryptedFoo); - - var findResult = Find(prefixSuffixCollection, filter, async).ToList(); - findResult.Should().BeEmpty(); - break; - } + { + var encryptedFoo = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: suffixQueryType, stringOptions: new StringOptions( + true, + true, + suffixOptions: new SuffixOptions(10, 2))), + "foo", + async); + + var filter = CreateFindFilter("$encStrEndsWith", "encryptedText", encryptedFoo); + + var findResult = Find(prefixSuffixCollection, filter, async).ToList(); + findResult.Should().BeEmpty(); + break; + } case 5: // can find a document by substring - { - var encryptedBar = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: substringQueryType, stringOptions: new StringOptions( - true, - true, - substringOptions: new SubstringOptions(10, 6, 2))), - "bar", - async); - - var filter = CreateFindFilter("$encStrContains", "encryptedText", encryptedBar); - - var findResult = Find(substringCollection, filter, async).Single(); - findResult["encryptedText"].AsString.Should().Be("foobarbaz"); - break; - } + { + var encryptedBar = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: substringQueryType, stringOptions: new StringOptions( + true, + true, + substringOptions: new SubstringOptions(10, 6, 2))), + "bar", + async); + + var filter = CreateFindFilter("$encStrContains", "encryptedText", encryptedBar); + + var findResult = Find(substringCollection, filter, async).Single(); + findResult["encryptedText"].AsString.Should().Be("foobarbaz"); + break; + } case 6: // assert no document found by substring - { - var encryptedQux = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: substringQueryType, stringOptions: new StringOptions( - true, - true, - substringOptions: new SubstringOptions(10, 6, 2))), - "qux", - async); - - var filter = CreateFindFilter("$encStrContains", "encryptedText", encryptedQux); - - var findResult = Find(substringCollection, filter, async).ToList(); - findResult.Should().BeEmpty(); - break; - } - case 7: // assert contentionFactor is required - { - var exception = Record.Exception(() => { - ExplicitEncrypt( + var encryptedQux = ExplicitEncrypt( clientEncryption, - encryptOptions.With(contentionFactor: null, queryType: "prefix", stringOptions: new StringOptions( + encryptOptions.With(queryType: substringQueryType, stringOptions: new StringOptions( true, true, - new PrefixOptions(10, 2))), - "foo", + substringOptions: new SubstringOptions(10, 6, 2))), + "qux", async); - }); - exception.Should().BeOfType() - .Which.Message.Should().Contain("contention factor is required for string algorithm"); - break; - } + var filter = CreateFindFilter("$encStrContains", "encryptedText", encryptedQux); + + var findResult = Find(substringCollection, filter, async).ToList(); + findResult.Should().BeEmpty(); + break; + } + case 7: // assert contentionFactor is required + { + var exception = Record.Exception(() => + { + ExplicitEncrypt( + clientEncryption, + encryptOptions.With(contentionFactor: null, queryType: "prefix", stringOptions: new StringOptions( + true, + true, + new PrefixOptions(10, 2))), + "foo", + async); + }); + + exception.Should().BeOfType() + .Which.Message.Should().Contain("contention factor is required for string algorithm"); + break; + } case 8: // can find an auto-encrypted case indexed document by prefix and suffix - { - Insert(prefixSuffixCiDiCollectionAuto, async, new BsonDocument("encryptedText", "BingQiLin")); - - var encryptedBing = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: "prefix", stringOptions: new StringOptions( - false, - false, - new PrefixOptions(10, 2))), - "bing", - async); - - var prefixFilter = CreateFindFilter("$encStrStartsWith", "encryptedText", encryptedBing); - var prefixResult = Find(prefixSuffixCiDiCollectionExplicit, prefixFilter, async).Single(); - prefixResult["encryptedText"].AsString.Should().Be("BingQiLin"); - - var encryptedLin = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: "suffix", stringOptions: new StringOptions( - false, - false, - suffixOptions: new SuffixOptions(10, 2))), - "lin", - async); - - var suffixFilter = CreateFindFilter("$encStrEndsWith", "encryptedText", encryptedLin); - var suffixResult = Find(prefixSuffixCiDiCollectionExplicit, suffixFilter, async).Single(); - suffixResult["encryptedText"].AsString.Should().Be("BingQiLin"); - break; - } + { + Insert(prefixSuffixCiDiCollectionAuto, async, new BsonDocument("encryptedText", "BingQiLin")); + + var encryptedBing = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: "prefix", stringOptions: new StringOptions( + false, + false, + new PrefixOptions(10, 2))), + "bing", + async); + + var prefixFilter = CreateFindFilter("$encStrStartsWith", "encryptedText", encryptedBing); + var prefixResult = Find(prefixSuffixCiDiCollectionExplicit, prefixFilter, async).Single(); + prefixResult["encryptedText"].AsString.Should().Be("BingQiLin"); + + var encryptedLin = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: "suffix", stringOptions: new StringOptions( + false, + false, + suffixOptions: new SuffixOptions(10, 2))), + "lin", + async); + + var suffixFilter = CreateFindFilter("$encStrEndsWith", "encryptedText", encryptedLin); + var suffixResult = Find(prefixSuffixCiDiCollectionExplicit, suffixFilter, async).Single(); + suffixResult["encryptedText"].AsString.Should().Be("BingQiLin"); + break; + } case 9: // can find an auto-encrypted diacritic-insensitively indexed document by prefix and suffix - { - Insert(prefixSuffixCiDiCollectionAuto, async, new BsonDocument("encryptedText", "cafébarbäz")); - - var encryptedCafe = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: "prefix", stringOptions: new StringOptions( - false, - false, - new PrefixOptions(10, 2))), - "cafe", - async); - - var prefixFilter = CreateFindFilter("$encStrStartsWith", "encryptedText", encryptedCafe); - var prefixResult = Find(prefixSuffixCiDiCollectionExplicit, prefixFilter, async).Single(); - prefixResult["encryptedText"].AsString.Should().Be("cafébarbäz"); - - var encryptedBaz = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: "suffix", stringOptions: new StringOptions( - false, - false, - suffixOptions: new SuffixOptions(10, 2))), - "baz", - async); - - var suffixFilter = CreateFindFilter("$encStrEndsWith", "encryptedText", encryptedBaz); - var suffixResult = Find(prefixSuffixCiDiCollectionExplicit, suffixFilter, async).Single(); - suffixResult["encryptedText"].AsString.Should().Be("cafébarbäz"); - break; - } + { + Insert(prefixSuffixCiDiCollectionAuto, async, new BsonDocument("encryptedText", "cafébarbäz")); + + var encryptedCafe = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: "prefix", stringOptions: new StringOptions( + false, + false, + new PrefixOptions(10, 2))), + "cafe", + async); + + var prefixFilter = CreateFindFilter("$encStrStartsWith", "encryptedText", encryptedCafe); + var prefixResult = Find(prefixSuffixCiDiCollectionExplicit, prefixFilter, async).Single(); + prefixResult["encryptedText"].AsString.Should().Be("cafébarbäz"); + + var encryptedBaz = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: "suffix", stringOptions: new StringOptions( + false, + false, + suffixOptions: new SuffixOptions(10, 2))), + "baz", + async); + + var suffixFilter = CreateFindFilter("$encStrEndsWith", "encryptedText", encryptedBaz); + var suffixResult = Find(prefixSuffixCiDiCollectionExplicit, suffixFilter, async).Single(); + suffixResult["encryptedText"].AsString.Should().Be("cafébarbäz"); + break; + } case 10: // can find an auto-encrypted case-insensitively indexed document by substring - { - Insert(substringCiDiCollectionAuto, async, new BsonDocument("encryptedText", "FooBarBaz")); - - var encryptedBar = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: "substring", stringOptions: new StringOptions( - false, - false, - substringOptions: new SubstringOptions(10, 6, 2))), - "bar", - async); - - var filter = CreateFindFilter("$encStrContains", "encryptedText", encryptedBar); - var findResult = Find(substringCiDiCollectionExplicit, filter, async).Single(); - findResult["encryptedText"].AsString.Should().Be("FooBarBaz"); - break; - } + { + Insert(substringCiDiCollectionAuto, async, new BsonDocument("encryptedText", "FooBarBaz")); + + var encryptedBar = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: "substring", stringOptions: new StringOptions( + false, + false, + substringOptions: new SubstringOptions(10, 6, 2))), + "bar", + async); + + var filter = CreateFindFilter("$encStrContains", "encryptedText", encryptedBar); + var findResult = Find(substringCiDiCollectionExplicit, filter, async).Single(); + findResult["encryptedText"].AsString.Should().Be("FooBarBaz"); + break; + } case 11: // can find an auto-encrypted diacritic-insensitively indexed document by substring - { - Insert(substringCiDiCollectionAuto, async, new BsonDocument("encryptedText", "foocafébaz")); - - var encryptedCafe = ExplicitEncrypt( - clientEncryption, - encryptOptions.With(queryType: "substring", stringOptions: new StringOptions( - false, - false, - substringOptions: new SubstringOptions(10, 6, 2))), - "cafe", - async); - - var filter = CreateFindFilter("$encStrContains", "encryptedText", encryptedCafe); - var findResult = Find(substringCiDiCollectionExplicit, filter, async).Single(); - findResult["encryptedText"].AsString.Should().Be("foocafébaz"); - break; - } + { + Insert(substringCiDiCollectionAuto, async, new BsonDocument("encryptedText", "foocafébaz")); + + var encryptedCafe = ExplicitEncrypt( + clientEncryption, + encryptOptions.With(queryType: "substring", stringOptions: new StringOptions( + false, + false, + substringOptions: new SubstringOptions(10, 6, 2))), + "cafe", + async); + + var filter = CreateFindFilter("$encStrContains", "encryptedText", encryptedCafe); + var findResult = Find(substringCiDiCollectionExplicit, filter, async).Single(); + findResult["encryptedText"].AsString.Should().Be("foocafébaz"); + break; + } default: throw new Exception($"Unexpected test case {testCase}."); } } @@ -3161,7 +3161,7 @@ BsonDocument CreateFindFilter(string operation, string fieldName, BsonValue encr void DropAndCreateCollection(IMongoClient client, CollectionNamespace collectionNamespace, BsonDocument encryptedFields) { - var db = client.GetDatabase(collectionNamespace.DatabaseNamespace.DatabaseName, new MongoDatabaseSettings{ WriteConcern = WriteConcern.WMajority }); + var db = client.GetDatabase(collectionNamespace.DatabaseNamespace.DatabaseName, new MongoDatabaseSettings { WriteConcern = WriteConcern.WMajority }); db.DropCollection(collectionNamespace.CollectionName, new DropCollectionOptions { EncryptedFields = encryptedFields }); db.CreateCollection(collectionNamespace.CollectionName, new CreateCollectionOptions { EncryptedFields = encryptedFields }); } @@ -3414,7 +3414,7 @@ private MongoClientSettings ConfigureClientEncryptedSettings( var clientEncryptedSettings = CreateMongoClientSettings( - keyVaultNamespace: keyVaultCollectionNamespace ??__keyVaultCollectionNamespace, + keyVaultNamespace: keyVaultCollectionNamespace ?? __keyVaultCollectionNamespace, schemaMapDocument: schemaMap, kmsProviders: kmsProviders, externalKeyVaultClient: externalKeyVaultClient, diff --git a/tests/MongoDB.Driver.Tests/Specifications/crud/prose-tests/CrudProseTests.cs b/tests/MongoDB.Driver.Tests/Specifications/crud/prose-tests/CrudProseTests.cs index 16490af7506..a1da9868707 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/crud/prose-tests/CrudProseTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/crud/prose-tests/CrudProseTests.cs @@ -152,13 +152,13 @@ BsonDocument GetExpectedWriteErrorDetails(ObjectId objectId) // https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L68C8-L68C104 [Theory] [ParameterAttributeData] - public async Task MongoClient_bulkWrite_splits_batches_on_maxWriteBatchSize([Values(true, false)]bool async) + public async Task MongoClient_bulkWrite_splits_batches_on_maxWriteBatchSize([Values(true, false)] bool async) { RequireServer.Check().Supports(Feature.ClientBulkWrite); var maxBatchCount = DriverTestConfiguration.GetConnectionDescription().MaxBatchCount; var models = Enumerable .Range(0, maxBatchCount + 1) - .Select(_ => new BulkWriteInsertOneModel("db.coll", new BsonDocument{ { "a", "b" } })) + .Select(_ => new BulkWriteInsertOneModel("db.coll", new BsonDocument { { "a", "b" } })) .ToArray(); var eventCapturer = new EventCapturer().Capture(e => e.CommandName == "bulkWrite"); @@ -176,7 +176,7 @@ public async Task MongoClient_bulkWrite_splits_batches_on_maxWriteBatchSize([Val // https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L96 [Theory] [ParameterAttributeData] - public async Task MongoClient_bulkWrite_splits_batches_on_maxMessageSizeBytes([Values(true, false)]bool async) + public async Task MongoClient_bulkWrite_splits_batches_on_maxMessageSizeBytes([Values(true, false)] bool async) { RequireServer.Check().Supports(Feature.ClientBulkWrite); var connectionDescription = DriverTestConfiguration.GetConnectionDescription(); @@ -204,7 +204,7 @@ public async Task MongoClient_bulkWrite_splits_batches_on_maxMessageSizeBytes([V // https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L136 [Theory] [ParameterAttributeData] - public async Task MongoClient_bulkWrite_collects_WriteConcernError_across_batches([Values(true, false)]bool async) + public async Task MongoClient_bulkWrite_collects_WriteConcernError_across_batches([Values(true, false)] bool async) { RequireServer.Check().Supports(Feature.ClientBulkWrite); var maxBatchCount = DriverTestConfiguration.GetConnectionDescription().MaxBatchCount; @@ -222,7 +222,7 @@ public async Task MongoClient_bulkWrite_collects_WriteConcernError_across_batche }"; var models = Enumerable .Range(0, maxBatchCount + 1) - .Select(_ => new BulkWriteInsertOneModel("db.coll", new BsonDocument{ { "a", "b" } })) + .Select(_ => new BulkWriteInsertOneModel("db.coll", new BsonDocument { { "a", "b" } })) .ToArray(); var eventCapturer = new EventCapturer().Capture(e => e.CommandName == "bulkWrite"); @@ -467,7 +467,7 @@ public async Task MongoClient_bulkWrite_handles_getMore_error([Values(true, fals // https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L602 [Theory] [ParameterAttributeData] - public async Task MongoClient_bulkWrite_throws_if_no_operations_can_be_added_big_document([Values(true, false)]bool async) + public async Task MongoClient_bulkWrite_throws_if_no_operations_can_be_added_big_document([Values(true, false)] bool async) { RequireServer.Check().Supports(Feature.ClientBulkWrite); var maxMessageSize = DriverTestConfiguration.GetConnectionDescription().MaxMessageSize; @@ -494,7 +494,7 @@ public async Task MongoClient_bulkWrite_throws_if_no_operations_can_be_added_big // https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L602 [Theory] [ParameterAttributeData] - public async Task MongoClient_bulkWrite_throws_if_no_operations_can_be_added_big_namespace([Values(true, false)]bool async) + public async Task MongoClient_bulkWrite_throws_if_no_operations_can_be_added_big_namespace([Values(true, false)] bool async) { RequireServer.Check().Supports(Feature.ClientBulkWrite); var maxMessageSize = DriverTestConfiguration.GetConnectionDescription().MaxMessageSize; @@ -521,7 +521,7 @@ public async Task MongoClient_bulkWrite_throws_if_no_operations_can_be_added_big // https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L647 [Theory] [ParameterAttributeData] - public async Task MongoClient_bulkWrite_throws_if_auto_encryption_configured([Values(true, false)]bool async) + public async Task MongoClient_bulkWrite_throws_if_auto_encryption_configured([Values(true, false)] bool async) { RequireServer.Check().Supports(Feature.ClientBulkWrite); diff --git a/tests/MongoDB.Driver.Tests/Specifications/initial-dns-seedlist-discovery/prose-tests/SrvPartsTests.cs b/tests/MongoDB.Driver.Tests/Specifications/initial-dns-seedlist-discovery/prose-tests/SrvPartsTests.cs index f93e7095d4f..9a629d1b6bd 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/initial-dns-seedlist-discovery/prose-tests/SrvPartsTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/initial-dns-seedlist-discovery/prose-tests/SrvPartsTests.cs @@ -98,4 +98,4 @@ public Task> ResolveTxtRecordsAsync(string domainName, Cancellat } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsProseTests.cs b/tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsProseTests.cs index 06e3d8ad541..5b04eeeb68e 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsProseTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsProseTests.cs @@ -106,7 +106,7 @@ await ThreadingUtilities.ExecuteTasksOnNewThreads(2, async __ => eventsWaitTimeout); eventCapturer.Events.OfType().Count().Should().Be(3); - eventCapturer.Events.OfType().Count().Should().Be(1); + eventCapturer.Events.OfType().Count().Should().Be(1); eventCapturer.Events.OfType().Count().Should().Be(2); eventCapturer.Events.OfType().Count().Should().Be(1); eventCapturer.Events.OfType().Count().Should().Be(3); diff --git a/tests/MongoDB.Driver.Tests/Specifications/retryable-writes/prose-tests/PoolClearRetryability.cs b/tests/MongoDB.Driver.Tests/Specifications/retryable-writes/prose-tests/PoolClearRetryability.cs index e9705e12a1b..75788b83c72 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/retryable-writes/prose-tests/PoolClearRetryability.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/retryable-writes/prose-tests/PoolClearRetryability.cs @@ -98,7 +98,7 @@ await ThreadingUtilities.ExecuteTasksOnNewThreads(2, async _ => { ThreadingUtilities.ExecuteOnNewThreads(2, _ => { - collection.InsertOne(new BsonDocument("x", 1)); + collection.InsertOne(new BsonDocument("x", 1)); }); } diff --git a/tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/prose-tests/ServerDiscoveryProseTests.cs b/tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/prose-tests/ServerDiscoveryProseTests.cs index 2af27327a0d..d50f9fed912 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/prose-tests/ServerDiscoveryProseTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/prose-tests/ServerDiscoveryProseTests.cs @@ -104,7 +104,7 @@ public void Topology_secondary_discovery_with_directConnection_false_should_work // https://github.com/mongodb/specifications/blob/a8d34be0df234365600a9269af5a463f581562fd/source/server-discovery-and-monitoring/server-discovery-and-monitoring-tests.md?plain=1#L176 [Theory] [ParameterAttributeData] - public async Task Connection_Pool_Backpressure([Values(true, false)]bool async) + public async Task Connection_Pool_Backpressure([Values(true, false)] bool async) { RequireServer.Check().VersionGreaterThanOrEqualTo("7.0.23"); #if MACOS diff --git a/tests/MongoDB.Driver.Tests/Specifications/server-selection/InWindowTestRunner.cs b/tests/MongoDB.Driver.Tests/Specifications/server-selection/InWindowTestRunner.cs index cece28fc354..bc0c516c7c0 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/server-selection/InWindowTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/server-selection/InWindowTestRunner.cs @@ -46,7 +46,7 @@ private sealed class OperationsCount private sealed class Outcome { public double tolerance { get; set; } - public IDictionary expected_frequencies { get; set; } + public IDictionary expected_frequencies { get; set; } } private sealed class TestData @@ -57,7 +57,7 @@ private sealed class TestData public string description { get; set; } public int iterations { get; set; } - public OperationsCount[] mocked_topology_state { get; set;} + public OperationsCount[] mocked_topology_state { get; set; } public Outcome outcome { get; set; } } diff --git a/tests/MongoDB.Driver.Tests/Specifications/server-selection/ServerSelectionTestHelpers.cs b/tests/MongoDB.Driver.Tests/Specifications/server-selection/ServerSelectionTestHelpers.cs index b52b1834278..7d099e02e8d 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/server-selection/ServerSelectionTestHelpers.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/server-selection/ServerSelectionTestHelpers.cs @@ -38,16 +38,16 @@ private enum ClusterTypeTest private enum ServerTypeTest { - RSPrimary = ServerType.ReplicaSetPrimary, - RSSecondary = ServerType.ReplicaSetSecondary, - RSArbiter = ServerType.ReplicaSetArbiter, - RSGhost = ServerType.ReplicaSetGhost, - RSOther = ServerType.ReplicaSetOther, - Mongos = ServerType.ShardRouter, - Standalone = ServerType.Standalone, - Unknown = ServerType.Unknown, - PossiblePrimary = ServerType.Unknown, - LoadBalancer = ServerType.LoadBalanced + RSPrimary = ServerType.ReplicaSetPrimary, + RSSecondary = ServerType.ReplicaSetSecondary, + RSArbiter = ServerType.ReplicaSetArbiter, + RSGhost = ServerType.ReplicaSetGhost, + RSOther = ServerType.ReplicaSetOther, + Mongos = ServerType.ShardRouter, + Standalone = ServerType.Standalone, + Unknown = ServerType.Unknown, + PossiblePrimary = ServerType.Unknown, + LoadBalancer = ServerType.LoadBalanced } public enum ServerTagTest diff --git a/tests/MongoDB.Driver.Tests/Specifications/sessions/SessionsProseTests.cs b/tests/MongoDB.Driver.Tests/Specifications/sessions/SessionsProseTests.cs index 34e019e7b6b..a8bfd174d38 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/sessions/SessionsProseTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/sessions/SessionsProseTests.cs @@ -121,7 +121,7 @@ public async Task Ensure_implicit_session_is_ignored_if_connection_does_not_supp [Theory] [ParameterAttributeData] - public async Task Ensure_server_session_are_allocated_only_on_connection_checkout([Values(true, false)]bool async) + public async Task Ensure_server_session_are_allocated_only_on_connection_checkout([Values(true, false)] bool async) { var eventCapturer = new EventCapturer() .Capture(); diff --git a/tests/MongoDB.Driver.Tests/Specifications/socks5-support/Socks5SupportProseTests.cs b/tests/MongoDB.Driver.Tests/Specifications/socks5-support/Socks5SupportProseTests.cs index 1f79d06f74c..ee9ccbbb2ca 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/socks5-support/Socks5SupportProseTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/socks5-support/Socks5SupportProseTests.cs @@ -62,9 +62,9 @@ public static IEnumerable GetTestCombinations() return (from tc in testCases - from useTls in new[] { true, false } - from isAsync in new[] { true, false } - select new { tc.ConnectionString, tc.ExpectedResult, useTls, isAsync }) + from useTls in new[] { true, false } + from isAsync in new[] { true, false } + select new { tc.ConnectionString, tc.ExpectedResult, useTls, isAsync }) .Select((x, i) => new object[] { $"{i}_{(x.useTls ? "Tls" : "NoTls")}_{(x.isAsync ? "Async" : "Sync")}", @@ -98,7 +98,7 @@ public async Task TestConnectionStrings(string id, string connectionString, bool { //Convert the hosts to a format that can be used in the connection string (host:port), and join them into a string. actualHosts = CoreTestConfiguration.ConnectionString.Hosts.Select(h => h.GetHostAndPort()).ToList(); - var stringHosts = string.Join(",", actualHosts.Select( h => $"{h.Host}:{h.Port}")); + var stringHosts = string.Join(",", actualHosts.Select(h => $"{h.Host}:{h.Port}")); connectionString = connectionString.Replace("", stringHosts); } @@ -151,4 +151,4 @@ private static void AssertEventListContainsCorrectEndpoints(List<(string Host, i Assert.DoesNotContain(endPointsSeen, proxyHosts.Contains); Assert.Contains(endPointsSeen, hosts.Contains); } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionsProseTests.cs b/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionsProseTests.cs index 7a8f8cb2b2c..3fa7725ed49 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionsProseTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionsProseTests.cs @@ -68,4 +68,4 @@ public async Task Ensure_write_concern_is_not_inherited_from_collection_object_i collection.Find(new BsonDocument("n", 1)).First().Should().NotBeNull().And.Subject["n"].AsInt32.Should().Be(1); } } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/SslSettingsTests.cs b/tests/MongoDB.Driver.Tests/SslSettingsTests.cs index c610964578b..65ab10f06d6 100644 --- a/tests/MongoDB.Driver.Tests/SslSettingsTests.cs +++ b/tests/MongoDB.Driver.Tests/SslSettingsTests.cs @@ -70,7 +70,7 @@ public void TestClientCertificates() Assert.Equal(null, settings.ClientCertificates); var certificateFileName = GetTestCertificateFileName(); - var clientCertificates = new[] { X509CertificateLoader.LoadPkcs12FromFile(certificateFileName, "password"), X509CertificateLoader.LoadPkcs12FromFile(certificateFileName, "password") }; + var clientCertificates = new[] { X509CertificateLoader.LoadPkcs12FromFile(certificateFileName, "password"), X509CertificateLoader.LoadPkcs12FromFile(certificateFileName, "password") }; settings.ClientCertificates = clientCertificates; Assert.True(clientCertificates.SequenceEqual(settings.ClientCertificates)); @@ -103,7 +103,7 @@ public void TestClone() var settings = new SslSettings { CheckCertificateRevocation = false, - ClientCertificates = [ X509CertificateLoader.LoadPkcs12FromFile(certificateFileName, "password") ], + ClientCertificates = [X509CertificateLoader.LoadPkcs12FromFile(certificateFileName, "password")], ClientCertificateSelectionCallback = ClientCertificateSelectionCallback, EnabledSslProtocols = SslProtocols.Tls12, ServerCertificateValidationCallback = ServerCertificateValidationCallback @@ -137,7 +137,7 @@ public void TestEquals() clone = settings.Clone(); var certificateFileName = GetTestCertificateFileName(); - clone.ClientCertificates = [ X509CertificateLoader.LoadPkcs12FromFile(certificateFileName, "password") ]; + clone.ClientCertificates = [X509CertificateLoader.LoadPkcs12FromFile(certificateFileName, "password")]; Assert.NotEqual(settings, clone); Assert.NotEqual(clone, settings); diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedErrorMatcher.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedErrorMatcher.cs index dce082711f1..8ebeaae3729 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedErrorMatcher.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedErrorMatcher.cs @@ -141,8 +141,8 @@ private void AssertExpectResult(Exception actualException, BsonDocument expected switch (actualException) { case MongoBulkWriteException bulkWriteException: - actualResult = UnifiedBulkWriteOperationResultConverter.Convert(bulkWriteException.Result); - break; + actualResult = UnifiedBulkWriteOperationResultConverter.Convert(bulkWriteException.Result); + break; case ClientBulkWriteException clientBulkWriteException: actualResult = UnifiedClientBulkWriteOperation.ConvertClientBulkWriteResult(clientBulkWriteException.PartialResult); diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedEventMatcher.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedEventMatcher.cs index f1a08b5bda0..aa6c5d55e5f 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedEventMatcher.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedEventMatcher.cs @@ -441,7 +441,8 @@ private void AssertTopologyType(string topologyType, ClusterDescription clusterD break; default: throw new Exception($"Unexpected topology type: {topologyType}."); - }; + } + ; } private string GetAssertionErrorMessage(List actualEvents, BsonArray expectedEventsDocuments) diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedAppendMetadataOperation.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedAppendMetadataOperation.cs index 7f0800b71fc..037f776cac7 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedAppendMetadataOperation.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedAppendMetadataOperation.cs @@ -96,4 +96,4 @@ public UnifiedAppendMetadataOperation Build(string targetClientId, BsonDocument return new(client, new LibraryInfo(name, version, platform)); } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedBulkWriteOperation.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedBulkWriteOperation.cs index 44c0ff7fc15..26835c7bdf3 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedBulkWriteOperation.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedBulkWriteOperation.cs @@ -315,7 +315,7 @@ private WriteModel ParseWriteModel(BsonDocument modelItem) return new DeleteManyModel(filter) { - Collation = collation, + Collation = collation, Hint = hint }; } @@ -325,7 +325,7 @@ private WriteModel ParseWriteModel(BsonDocument modelItem) return new DeleteOneModel(filter) { - Collation = collation, + Collation = collation, Hint = hint }; } @@ -354,7 +354,7 @@ private WriteModel ParseWriteModel(BsonDocument modelItem) return new UpdateManyModel(filter, update) { ArrayFilters = arrayFilters, - Collation = collation, + Collation = collation, Hint = hint, IsUpsert = isUpsert }; @@ -366,7 +366,7 @@ private WriteModel ParseWriteModel(BsonDocument modelItem) return new UpdateOneModel(filter, update) { ArrayFilters = arrayFilters, - Collation = collation, + Collation = collation, Hint = hint, IsUpsert = isUpsert, Sort = sort diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedGetSnapshotTimeOperation.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedGetSnapshotTimeOperation.cs index 0f1b29b228a..c9170268533 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedGetSnapshotTimeOperation.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedGetSnapshotTimeOperation.cs @@ -65,4 +65,4 @@ public UnifiedGetSnapshotTimeOperation Build(string targetSessionId, BsonDocumen var session = _entityMap.Sessions[targetSessionId]; return new UnifiedGetSnapshotTimeOperation(session); } -} \ No newline at end of file +} diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedRewrapManyDataKeyOperation.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedRewrapManyDataKeyOperation.cs index 1b2b2b16452..940e240d918 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedRewrapManyDataKeyOperation.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedRewrapManyDataKeyOperation.cs @@ -116,7 +116,8 @@ public UnifiedRewrapManyDataKeyOperation Build(string targetSessionId, BsonDocum case "provider": provider = option.Value.AsString; break; case "masterKey": masterKey = option.Value.AsBsonDocument; break; default: throw new FormatException($"Invalid {nameof(RewrapManyDataKeyOptions)} option argument name: '{option.Name}'."); - }; + } + ; } break; default: diff --git a/tests/MongoDB.Driver.Tests/X509Tests.cs b/tests/MongoDB.Driver.Tests/X509Tests.cs index 1d8ad839690..11bdf71edee 100644 --- a/tests/MongoDB.Driver.Tests/X509Tests.cs +++ b/tests/MongoDB.Driver.Tests/X509Tests.cs @@ -70,7 +70,7 @@ public void Authentication_fails_with_MONGODB_X509_mechanism_when_user_is_not_in private void AssertAuthenticationSucceeds(MongoClientSettings settings) { using var client = DriverTestConfiguration.CreateMongoClient(settings); - _ = client.ListDatabaseNames().ToList(); + _ = client.ListDatabaseNames().ToList(); } private void AssertAuthenticationFails(MongoClientSettings settings, string innerExceptionMessage = null) diff --git a/tests/MongoDB.TestHelpers/XunitExtensions/TimeoutEnforcing/UnobservedExceptionTestDiscoverer.cs b/tests/MongoDB.TestHelpers/XunitExtensions/TimeoutEnforcing/UnobservedExceptionTestDiscoverer.cs index b2daa83c3af..410c13d239c 100644 --- a/tests/MongoDB.TestHelpers/XunitExtensions/TimeoutEnforcing/UnobservedExceptionTestDiscoverer.cs +++ b/tests/MongoDB.TestHelpers/XunitExtensions/TimeoutEnforcing/UnobservedExceptionTestDiscoverer.cs @@ -23,8 +23,8 @@ namespace MongoDB.TestHelpers.XunitExtensions.TimeoutEnforcing; [XunitTestCaseDiscoverer("MongoDB.TestHelpers.XunitExtensions.TimeoutEnforcing.UnobservedExceptionTestDiscoverer", "MongoDB.TestHelpers")] -public class UnobservedExceptionTrackingFactAttribute: FactAttribute -{} +public class UnobservedExceptionTrackingFactAttribute : FactAttribute +{ } public class UnobservedExceptionTestDiscoverer : IXunitTestCaseDiscoverer { diff --git a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/ArrayMethodTests.cs b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/ArrayMethodTests.cs index 0af354d7405..8883768db97 100644 --- a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/ArrayMethodTests.cs +++ b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/ArrayMethodTests.cs @@ -58,7 +58,7 @@ private void RunTestCase(Action> testCase) { var collection = database.GetCollection("test"); - collection.InsertMany(new[] { new Model { Id = 1, Array = new[] {1, 2, 3} } }); + collection.InsertMany(new[] { new Model { Id = 1, Array = new[] { 1, 2, 3 } } }); testCase(collection); } diff --git a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LibmongocryptTests.cs b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LibmongocryptTests.cs index 4c2abc5c046..0aab076d304 100644 --- a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LibmongocryptTests.cs +++ b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LibmongocryptTests.cs @@ -44,7 +44,7 @@ public LibmongocryptTests(ITestOutputHelper output) [Fact] public void Explicit_encryption_with_libmongocrypt_package_works() { - var categories = new[] {("LogLevel:MongoDB.Client", "Trace")}; + var categories = new[] { ("LogLevel:MongoDB.Client", "Trace") }; using (var logsTracer = new LogsTraceListener()) { diff --git a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LoggingTests.cs b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LoggingTests.cs index ea538bc9621..e648a45eabb 100644 --- a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LoggingTests.cs +++ b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LoggingTests.cs @@ -45,7 +45,7 @@ public void MongoClient_should_log_only_configured_categories(string categoryNam if (categoryName != null) { - categories = new[] { ("LogLevel:Default", "Error"), ($"LogLevel:{categoryName}", "Trace")}; + categories = new[] { ("LogLevel:Default", "Error"), ($"LogLevel:{categoryName}", "Trace") }; expectedLogs = expectedLogs.Where(l => l.Category == categoryName).ToArray(); }