public void AddClientDocumentToCommand_with_ConnectionInitializer_client_document_should_return_expected_result() { var command = HelloHelper.CreateCommand(); var connectionInitializer = new ConnectionInitializer("test", new CompressorConfiguration[0], serverApi: null); var subjectClientDocument = (BsonDocument)Reflector.GetFieldValue(connectionInitializer, "_clientDocument"); var result = HelloHelper.AddClientDocumentToCommand(command, subjectClientDocument); var names = result.Names.ToList(); names.Count.Should().Be(2); names[0].Should().Be("isMaster"); names[1].Should().Be("client"); result[0].Should().Be(1); var clientDocument = result[1].AsBsonDocument; var clientDocumentNames = clientDocument.Names.ToList(); clientDocumentNames.Count.Should().Be(4); clientDocumentNames[0].Should().Be("application"); clientDocumentNames[1].Should().Be("driver"); clientDocumentNames[2].Should().Be("os"); clientDocumentNames[3].Should().Be("platform"); clientDocument["application"]["name"].AsString.Should().Be("test"); clientDocument["driver"]["name"].AsString.Should().Be("mongo-csharp-driver"); clientDocument["driver"]["version"].BsonType.Should().Be(BsonType.String); }
public void CreateCommand_should_return_correct_hello_command(bool useServerApiVersion, bool helloOk, string expectedResult) { var serverApi = useServerApiVersion ? new ServerApi(ServerApiVersion.V1) : null; var command = HelloHelper.CreateCommand(serverApi, helloOk); command.Should().Be(expectedResult); }
private BsonDocument CreateInitialHelloCommand(IReadOnlyList <IAuthenticator> authenticators, bool loadBalanced = false) { var command = HelloHelper.CreateCommand(_serverApi, loadBalanced: loadBalanced); HelloHelper.AddClientDocumentToCommand(command, _clientDocument); HelloHelper.AddCompressorsToCommand(command, _compressors); return(HelloHelper.CustomizeCommand(command, authenticators)); }
private BsonDocument CreateInitialHelloCommand(IReadOnlyList <IAuthenticator> authenticators) { var command = HelloHelper.CreateCommand(); HelloHelper.AddClientDocumentToCommand(command, _clientDocument); HelloHelper.AddCompressorsToCommand(command, _compressors); return(HelloHelper.CustomizeCommand(command, authenticators)); }
public void AddClientDocumentToCommand_with_custom_document_should_return_expected_result( [Values("{ client : { driver : 'dotnet', version : '2.4.0' }, os : { type : 'Windows' } }")] string clientDocumentString) { var clientDocument = BsonDocument.Parse(clientDocumentString); var command = HelloHelper.CreateCommand(); var result = HelloHelper.AddClientDocumentToCommand(command, clientDocument); result.Should().Be($"{{ isMaster : 1, client : {clientDocumentString} }}"); }
public void AddClientDocumentToCommand_with_custom_document_should_return_expected_result( [Values("{ client : { driver : 'dotnet', version : '3.6.0' }, os : { type : 'Windows' } }")] string clientDocumentString) { var clientDocument = BsonDocument.Parse(clientDocumentString); var command = HelloHelper.CreateCommand(null); var result = HelloHelper.AddClientDocumentToCommand(command, clientDocument); result.Should().Be($"{{ {OppressiveLanguageConstants.LegacyHelloCommandName} : 1, helloOk : true, client : {clientDocumentString} }}"); }
public void AddCompressorsToCommand_with_compressors_should_return_expected_result( [Values( new CompressorType[] { }, new [] { CompressorType.Zlib }, new [] { CompressorType.Snappy }, new [] { CompressorType.Zlib, CompressorType.Snappy }, new [] { CompressorType.ZStandard, CompressorType.Snappy })] CompressorType[] compressorsParameters) { var command = HelloHelper.CreateCommand(); var compressors = compressorsParameters .Select(c => new CompressorConfiguration(c)) .ToArray(); var result = HelloHelper.AddCompressorsToCommand(command, compressors); var expectedCompressions = string.Join(",", compressorsParameters.Select(c => $"'{CompressorTypeMapper.ToServerName(c)}'")); result.Should().Be(BsonDocument.Parse($"{{ isMaster : 1, compression: [{expectedCompressions}] }}")); }
public void CreateCommand_without_ServerApi_should_return_legacy_hello_command() { var command = HelloHelper.CreateCommand(null); command.Should().Be($"{{ isMaster : 1 }}"); }
public void CreateCommand_with_ServerApi_should_return_hello_command() { var command = HelloHelper.CreateCommand(new ServerApi(ServerApiVersion.V1)); command.Should().Be($"{{ hello : 1 }}"); }