public void CreateMongocryptdClientSettings_should_set_correct_serverSelectionTimeout() { var subject = new MongocryptdFactory(null); var clientSettings = subject.CreateMongocryptdClientSettings(); clientSettings.ServerSelectionTimeout.Should().Be(TimeSpan.FromSeconds(10)); }
public void Mongocryptd_should_be_spawned_with_correct_extra_arguments( string stringExtraOptions, string expectedPath, string expectedArgs, bool shouldBeSpawned) { string emptyLogPath; string platformExtension; #if WINDOWS emptyLogPath = "nul"; platformExtension = ".exe"; #else emptyLogPath = "/dev/null"; platformExtension = ""; #endif stringExtraOptions = stringExtraOptions?.Replace("#logpath#", emptyLogPath); expectedArgs = expectedArgs?.Replace("#logpath#", emptyLogPath); expectedPath = expectedPath?.Replace("#extension#", platformExtension); var bsonDocumentExtraOptions = stringExtraOptions != null ? BsonDocument.Parse(stringExtraOptions) : new BsonDocument(); var extraOptions = bsonDocumentExtraOptions .Elements .ToDictionary(k => k.Name, v => CreateTypedExtraOptions(v.Value)); var subject = new MongocryptdFactory(extraOptions); var result = subject.ShouldMongocryptdBeSpawned(out var path, out var args); result.Should().Be(shouldBeSpawned); path.Should().Be(expectedPath); args.Should().Be(expectedArgs); object CreateTypedExtraOptions(BsonValue value) { if (value.IsBsonArray) { return(value.AsBsonArray); // IEnumerable } else if (value.IsBoolean) { return((bool)value); // bool } else { return((string)value); // string } } }
public void CreateMongocryptdConnectionString_should_create_expected_connection_string(string optionKey, string optionValue, string expectedConnectionString) { var extraOptions = new Dictionary <string, object>(); if (optionKey != null) { extraOptions.Add(optionKey, optionValue); } var subject = new MongocryptdFactory(extraOptions); var connectionString = subject.CreateMongocryptdConnectionString(); connectionString.Should().Be(expectedConnectionString); }
public void Mongocryptd_should_be_spawned_with_correct_extra_arguments( string stringExtraOptions, string expectedPath, string expectedArgs, bool shouldBeSpawned) { var bsonDocumentExtraOptions = stringExtraOptions != null ? BsonDocument.Parse(stringExtraOptions) : new BsonDocument(); var extraOptions = bsonDocumentExtraOptions .Elements .ToDictionary(k => k.Name, v => CreateTypedExtraOptions(v.Value)); var subject = new MongocryptdFactory(extraOptions); var result = subject.ShouldMongocryptdBeSpawned(out var path, out var args); result.Should().Be(shouldBeSpawned); path.Should().Be(expectedPath); args.Should().Be(expectedArgs); object CreateTypedExtraOptions(BsonValue value) { if (value.IsBsonArray) { return(value.AsBsonArray); // IEnumerable } else if (value.IsBoolean) { return((bool)value); // bool } else { return((string)value); // string } } }
public static bool ShouldMongocryptdBeSpawned(this MongocryptdFactory mongocryptdHelper, out string path, out string args) { return((bool)Reflector.Invoke(mongocryptdHelper, nameof(ShouldMongocryptdBeSpawned), out path, out args)); }
public static string CreateMongocryptdConnectionString(this MongocryptdFactory mongocryptdHelper) { return((string)Reflector.Invoke(mongocryptdHelper, nameof(CreateMongocryptdConnectionString))); }
public static MongoClientSettings CreateMongocryptdClientSettings(this MongocryptdFactory mongocryptdHelper) { return((MongoClientSettings)Reflector.Invoke(mongocryptdHelper, nameof(CreateMongocryptdClientSettings))); }