Example #1
0
        public void GetCollectionCreatesIfNotExists()
        {
            MongoPersist toTest = new MongoPersist(
                new MongoPersistSettings()
            {
                Collection         = "newCollection"
                , ConnectionString = ""
                , DB = "test"
            });

            IPersist asI = (IPersist)toTest;

            MongoProviderMockHelper helper = new MongoProviderMockHelper();

            helper.PrimeDatabase(new List <BsonDocument>()
            {
                new BsonDocument("name", "test")
            });
            //need to prime an empty collection so that the cursor works
            helper.PrimeCollection(new List <BsonDocument>()
            {
            });



            toTest.MongoProvider = helper.MockProvider.Object;

            //this method should call create database
            IMongoCollection <PersistedMessage> result = toTest.GetCollection();


            helper.MockDatabase.Verify(m => m.CreateCollection(It.IsAny <string>()
                                                               , It.IsAny <CreateCollectionOptions>()
                                                               , It.IsAny <System.Threading.CancellationToken>()));
        }