protected override void SetUp() { var database = MongoTestHelper.GetMongoDatabase(); database.DropCollection(nameof(MyIdempotentSaga)); _sagaStorage = new MongoDbSagaStorage(database, new ConsoleLoggerFactory(colored: false)); _sagaStorage.Initialize(); }
/// <summary> /// Configures Rebus to use MongoDB to store sagas, using the specified collection name resolver function. If the collection name resolver is omitted, /// collection names will be determined by using the <code>Name</code> property of the saga data's <see cref="Type"/> /// </summary> public static void StoreInMongoDb(this StandardConfigurer <ISagaStorage> configurer, IMongoDatabase mongoDatabase, Func <Type, string> collectionNameResolver = null) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (mongoDatabase == null) { throw new ArgumentNullException(nameof(mongoDatabase)); } configurer.Register(c => { var sagaStorage = new MongoDbSagaStorage(mongoDatabase, collectionNameResolver); return(sagaStorage); }); }
/// <summary> /// Configures Rebus to use MongoDB to store sagas, using the specified collection name resolver function. If the collection name resolver is omitted, /// collection names will be determined by using the <code>Name</code> property of the saga data's <see cref="Type"/> /// </summary> public static void StoreInMongoDb(this StandardConfigurer <ISagaStorage> configurer, IMongoDatabase mongoDatabase, Func <Type, string> collectionNameResolver = null, bool automaticallyCreateIndexes = true) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (mongoDatabase == null) { throw new ArgumentNullException(nameof(mongoDatabase)); } configurer.Register(c => { var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var sagaStorage = new MongoDbSagaStorage(mongoDatabase, rebusLoggerFactory, collectionNameResolver, automaticallyCreateIndexes); return(sagaStorage); }); }
public async Task VerifyThatInitializationOnlyOccursOnce() { var database = MongoTestHelper.GetMongoDatabase(); var loggerFactory = new ListLoggerFactory(outputToConsole: true); var storage = new MongoDbSagaStorage(database, loggerFactory); storage.Initialize(); await storage.Insert(new SomeSagaData { Id = Guid.NewGuid() }, Enumerable.Empty <ISagaCorrelationProperty>()); await storage.Insert(new SomeSagaData { Id = Guid.NewGuid() }, Enumerable.Empty <ISagaCorrelationProperty>()); await storage.Insert(new SomeSagaData { Id = Guid.NewGuid() }, Enumerable.Empty <ISagaCorrelationProperty>()); var numberOfInitializations = loggerFactory .Count(line => line.Text.Contains("Initializing index for saga data")); Assert.That(numberOfInitializations, Is.EqualTo(1), "Only expected the collection's indexes to be initialized once!"); }