public MongoDbUserNotificationRepositoryFixture() { ActivityContextSerializer.Register(); ActivitySpanIdSerializer.Register(); ActivityTraceIdSerializer.Register(); InstantSerializer.Register(); var mongoClient = new MongoClient("mongodb://localhost"); var mongoDatabase = mongoClient.GetDatabase("Notifo_Testing"); var options = new UserNotificationsOptions { MaxItemsPerUser = 100 }; var log = A.Fake <ILogger <MongoDbUserNotificationRepository> >(); Repository = new MongoDbUserNotificationRepository(mongoDatabase, Options.Create(options), log); Repository.InitializeAsync(default).Wait();
static TestUtils() { DefaultOptions.Converters.Add(new JsonReadonlyListConverterFactory()); DefaultOptions.Converters.Add(new JsonReadonlyDictionaryConverterFactory()); DefaultOptions.Converters.Add(new JsonActivityContextConverter()); DefaultOptions.Converters.Add(new JsonActivitySpanIdConverter()); DefaultOptions.Converters.Add(new JsonActivityTraceIdConverter()); ActivityContextSerializer.Register(); ActivitySpanIdSerializer.Register(); ActivityTraceIdSerializer.Register(); BsonSerializer.RegisterGenericSerializerDefinition( typeof(ReadonlyList <>), typeof(ReadonlyListSerializer <>)); BsonSerializer.RegisterGenericSerializerDefinition( typeof(ReadonlyDictionary <,>), typeof(ReadonlyDictionarySerializer <,>)); }
public static void AddMyMongoDb(this IServiceCollection services, IConfiguration config) { ActivityContextSerializer.Register(); ActivitySpanIdSerializer.Register(); ActivityTraceIdSerializer.Register(); DurationSerializer.Register(); InstantSerializer.Register(); LocalDateSerializer.Register(); LocalTimeSerializer.Register(); ConventionRegistry.Register("EnumStringConvention", new ConventionPack { new EnumRepresentationConvention(BsonType.String) }, t => true); ConventionRegistry.Register("IgnoreExtraElements", new ConventionPack { new IgnoreExtraElementsConvention(true) }, t => true); services.ConfigureAndValidate <MongoDbOptions>(config, "storage:mongoDb"); services.AddSingletonAs(c => { var connectionString = c.GetRequiredService <IOptions <MongoDbOptions> >().Value.ConnectionString; return(new MongoClient(connectionString)); }) .As <IMongoClient>(); services.AddSingletonAs(c => { var databaseName = c.GetRequiredService <IOptions <MongoDbOptions> >().Value.DatabaseName; return(c.GetRequiredService <IMongoClient>().GetDatabase(databaseName)); }) .As <IMongoDatabase>(); }