An implementation of ITransactionCommitter used as an aggregate transaction committer. It stores a dictionary of IDataAccessor - one for each type, as well as a default. If the business object added is linked to a particular DataAccessor it will be added to that one, otherwise it will be added to the default. Note that only one underlying DataAccessor will be allowed to be used. If you add business objects whose types are linked to different DataAccessors you will get an error. This can be used when you have some objects that are persisted to one database and others to another. See DataAccessorMultiSource
Inheritance: ITransactionCommitter
 public void Test_DefaultDataAccessor_OneObject()
 {
     //---------------Set up test pack-------------------
     DataStoreInMemory dataStore = new DataStoreInMemory();
     IDataAccessor defaultDataAccessor = new DataAccessorInMemory(dataStore);
     MyBO.LoadDefaultClassDef();
     MyBO bo = new MyBO();
     //---------------Execute Test ----------------------
     ITransactionCommitter transactionCommitter = new TransactionCommitterMultiSource(defaultDataAccessor, new Dictionary<Type, IDataAccessor>());
     transactionCommitter.AddBusinessObject(bo);
     transactionCommitter.CommitTransaction();
     //---------------Test Result -----------------------
     Assert.IsNotNull(dataStore.Find<MyBO>(bo.ID));
     //---------------Tear down -------------------------
 }
        public void Test_UsingDataAccessorAssignedForType()
        {
            //---------------Set up test pack-------------------
            IDataAccessor defaultDataAccessor = new DataAccessorInMemory();

            DataStoreInMemory dataStore1 = new DataStoreInMemory();
            DataStoreInMemory dataStore2 = new DataStoreInMemory();
            DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1);
            DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2);
            MyBO.LoadDefaultClassDef();
            MyRelatedBo.LoadClassDef();
            MyBO bo1 = new MyBO();
            MyRelatedBo bo2 = new MyRelatedBo();

            Dictionary<Type, IDataAccessor> dataAccessors = new Dictionary<Type, IDataAccessor>();
            dataAccessors.Add(typeof(MyBO), dataAccessorInMemory1);
            dataAccessors.Add(typeof(MyRelatedBo), dataAccessorInMemory2);

            //---------------Execute Test ----------------------
            ITransactionCommitter transactionCommitter1 = new TransactionCommitterMultiSource(defaultDataAccessor, dataAccessors);
            transactionCommitter1.AddBusinessObject(bo1);
            transactionCommitter1.CommitTransaction();

            ITransactionCommitter transactionCommitter2 = new TransactionCommitterMultiSource(defaultDataAccessor, dataAccessors);
            transactionCommitter2.AddBusinessObject(bo2);
            transactionCommitter2.CommitTransaction();

            //---------------Test Result -----------------------
            Assert.IsNotNull(dataStore1.Find<MyBO>(bo1.ID));
            Assert.IsNull(dataStore2.Find<MyBO>(bo1.ID));

            Assert.IsNotNull(dataStore2.Find<MyRelatedBo>(bo2.ID));
            Assert.IsNull(dataStore1.Find<MyRelatedBo>(bo2.ID));
            //---------------Tear down -------------------------
        }
        public void Test_CommitTransaction_WhenEmpty_ShouldNotCommitOnAnyDataAccessors()
        {
            //---------------Set up test pack-------------------
            IDataAccessor defaultDataAccessor = MockRepository.GenerateStub<IDataAccessor>();
            IDataAccessor alternateDataAccessor = MockRepository.GenerateStub<IDataAccessor>();

            MyBO.LoadDefaultClassDef();
            Dictionary<Type, IDataAccessor> dataAccessors = new Dictionary<Type, IDataAccessor>();
            dataAccessors.Add(typeof(MyBO), alternateDataAccessor);
            ITransactionCommitter transactionCommitter = new TransactionCommitterMultiSource(defaultDataAccessor, dataAccessors);
            //---------------Assert Precondition----------------
            defaultDataAccessor.AssertWasNotCalled(accessor => accessor.CreateTransactionCommitter());
            alternateDataAccessor.AssertWasNotCalled(accessor => accessor.CreateTransactionCommitter());
            //---------------Execute Test ----------------------
            transactionCommitter.CommitTransaction();
            //---------------Test Result -----------------------
            defaultDataAccessor.AssertWasNotCalled(accessor => accessor.CreateTransactionCommitter());
            alternateDataAccessor.AssertWasNotCalled(accessor => accessor.CreateTransactionCommitter());
        }
        public void Test_ShouldThrowError_WhenAddingObjectsOfDifferentTypesWithDifferentDataAccessors()
        {
            //---------------Set up test pack-------------------
            IDataAccessor defaultDataAccessor = new DataAccessorInMemory();

            DataStoreInMemory dataStore1 = new DataStoreInMemory();
            DataStoreInMemory dataStore2 = new DataStoreInMemory();
            DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1);
            DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2);
            MyBO.LoadDefaultClassDef();
            MyRelatedBo.LoadClassDef();
            MyBO bo1 = new MyBO();
            MyRelatedBo bo2 = new MyRelatedBo();

            Dictionary<Type, IDataAccessor> dataAccessors = new Dictionary<Type, IDataAccessor>();
            dataAccessors.Add(typeof(MyBO), dataAccessorInMemory1);
            dataAccessors.Add(typeof(MyRelatedBo), dataAccessorInMemory2);

            //---------------Execute Test ----------------------
            try
            {
                ITransactionCommitter transactionCommitter1 = new TransactionCommitterMultiSource(defaultDataAccessor, dataAccessors);
                transactionCommitter1.AddBusinessObject(bo1);
                transactionCommitter1.AddBusinessObject(bo2);
                transactionCommitter1.CommitTransaction();
                Assert.Fail("Error should have occurred");
            } catch (HabaneroDeveloperException ex)
            //---------------Test Result -----------------------
            {
                Assert.IsNull(dataStore1.Find<MyBO>(bo1.ID));
                Assert.IsNull(dataStore1.Find<MyRelatedBo>(bo2.ID));
                Assert.IsNull(dataStore2.Find<MyBO>(bo1.ID));
                Assert.IsNull(dataStore2.Find<MyRelatedBo>(bo2.ID));

                StringAssert.Contains("MyRelatedBo", ex.DeveloperMessage);
                StringAssert.Contains("was added to a TransactionCommitterMultiSource which has been set up with a different source to this type", ex.DeveloperMessage);

                //correct
            }
            //---------------Tear down -------------------------

        }