Пример #1
0
        protected override void SetUp()
        {
            var database = MongoTestHelper.GetMongoDatabase();

            database.DropCollection(nameof(MyIdempotentSaga));

            _sagaStorage = new MongoDbSagaStorage(database, new ConsoleLoggerFactory(colored: false));
            _sagaStorage.Initialize();
        }
        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!");
        }