public void TestSeriesDocumentFormat() { GlobalOptions options = MongoDbPopulatorTestHelper.GetNewMongoDbPopulatorOptions(); options.MongoDbPopulatorOptions.MongoDbFlushTime = int.MaxValue; string collectionName = MongoDbPopulatorTestHelper.GetCollectionNameForTest("TestSeriesDocumentFormat"); var testAdapter = new MongoDbAdapter("TestSeriesDocumentFormat", options.MongoDatabases.DicomStoreOptions, collectionName); var callbackUsed = false; Action <Exception> exceptionCallback = (exception) => { callbackUsed = true; }; var processor = new SeriesMessageProcessor(options.MongoDbPopulatorOptions, testAdapter, 1, exceptionCallback) { Model = Mock.Of <IModel>() }; // Max queue size set to 1 so will immediately process this processor.AddToWriteQueue(_helper.TestSeriesMessage, new MessageHeader(), 1); Assert.False(callbackUsed); Assert.True(processor.AckCount == 1); IMongoCollection <BsonDocument> collection = _helper.TestDatabase.GetCollection <BsonDocument>(collectionName); Assert.True(collection.CountDocuments(new BsonDocument()) == 1); BsonDocument document = collection.Find(_ => true).ToList()[0]; Validate(_helper.TestSeriesMessage, document); }
public void TestErrorHandling() { _helper.Globals.MongoDbPopulatorOptions.FailedWriteLimit = 1; var mockAdapter = new Mock <IMongoDbAdapter>(); mockAdapter .Setup(x => x.WriteMany(It.IsAny <IList <BsonDocument> >(), It.IsAny <string>())) .Returns(WriteResult.Failure); var processor = new SeriesMessageProcessor(_helper.Globals.MongoDbPopulatorOptions, mockAdapter.Object, 1, delegate { }) { Model = Mock.Of <IModel>() }; Assert.Throws <ApplicationException>(() => processor.AddToWriteQueue(_helper.TestSeriesMessage, new MessageHeader(), 1)); }