public void Test_LoadingFromMultipleSources()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore1 = new DataStoreInMemory();
            DataStoreInMemory dataStore2 = new DataStoreInMemory();

            MyBO.LoadDefaultClassDef();
            TransactionCommitterInMemory committer1 = new TransactionCommitterInMemory(dataStore1);
            var bo1 = new MyBO();
            committer1.AddBusinessObject(bo1);
            committer1.CommitTransaction();

            MyRelatedBo.LoadClassDef();
            TransactionCommitterInMemory committer2 = new TransactionCommitterInMemory(dataStore2);
            var bo2 = new MyRelatedBo();
            committer2.AddBusinessObject(bo2);
            committer2.CommitTransaction();

            DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1);
            DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2);

            //---------------Execute Test ----------------------
            
            //---------------Test Result -----------------------
            DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory());
            dataAccessor.AddDataAccessor(typeof(MyBO), dataAccessorInMemory1);
            dataAccessor.AddDataAccessor(typeof(MyRelatedBo), dataAccessorInMemory2);
            var loadedBo1 = dataAccessor.BusinessObjectLoader.GetBusinessObject<MyBO>(bo1.ID);
            var loadedBo2 = dataAccessor.BusinessObjectLoader.GetBusinessObject<MyRelatedBo>(bo2.ID);
            //---------------Tear down -------------------------

            Assert.AreSame(loadedBo1, bo1);
            Assert.AreSame(loadedBo2, bo2);
        }
예제 #2
0
 public void SetupTest()
 {
     ClassDef.ClassDefs.Clear();
     DataStoreInMemory dataStore = new DataStoreInMemory();
     DataAccessorInMemory dataAccessor = new DataAccessorInMemory(dataStore);
     BORegistry.DataAccessor = dataAccessor;
 }
 public void Test_ClearDeadThreads()
 {
     //---------------Set up test pack-------------------
     const int BarrierTimeout = 10000;
     var dataAccessorMain = new DataAccessorInMemory();
     var dataAccessor = new DataAccessorThreadSplitter(dataAccessorMain);
     var expectedDataAccessorForThread = new DataAccessorInMemory();
     using (var entryBarrier = new Barrier(2))
     using (var exitBarrier = new Barrier(2))
     {
         var thread = new Thread(() =>
         {
             dataAccessor.AddDataAccessorForThread(expectedDataAccessorForThread);
             entryBarrier.SignalAndWait(BarrierTimeout);
             exitBarrier.SignalAndWait(BarrierTimeout);
         });
         thread.Start();
         entryBarrier.SignalAndWait(BarrierTimeout);
         //---------------Assert preconditions---------------
         Assert.AreSame(expectedDataAccessorForThread, dataAccessor.GetDataAccessorForThread(thread));
         //---------------Execute Test ----------------------
         exitBarrier.SignalAndWait(BarrierTimeout);
         thread.Join();
         dataAccessor.ClearDeadThreads();
         //---------------Test Result -----------------------
         var exception = Assert.Throws<HabaneroDeveloperException>(() => dataAccessor.GetDataAccessorForThread(thread));
         StringAssert.Contains("Data accessor for thread does not exist", exception.Message);
     }
 }
 public void Test_WithThread()
 {
     //---------------Set up test pack-------------------
     const int BarrierTimeout = 10000;
     var dataAccessorMain = new DataAccessorInMemory();
     var dataAccessor = new DataAccessorThreadSplitter(dataAccessorMain);
     var expectedDataAccessorForThread = new DataAccessorInMemory();
     using (var entryBarrier = new Barrier(2))
     using (var exitBarrier = new Barrier(2))
     {
         var thread = new Thread(() =>
         {
             dataAccessor.AddDataAccessorForThread(expectedDataAccessorForThread);
             entryBarrier.SignalAndWait(BarrierTimeout);
             exitBarrier.SignalAndWait(BarrierTimeout);
         });
         thread.Start();
         entryBarrier.SignalAndWait(BarrierTimeout);
         //---------------Execute Test ----------------------
         var dataAccessorForThread = dataAccessor.GetDataAccessorForThread(thread);
         exitBarrier.SignalAndWait(BarrierTimeout);
         //---------------Test Result -----------------------
         Assert.AreSame(expectedDataAccessorForThread, dataAccessorForThread);
     }
 }
 public void Test_StandardConstructor_CreatesADataStore()
 {
     //---------------Set up test pack-------------------
     //---------------Execute Test ----------------------
     DataAccessorInMemory dataAccessorInMemory = new DataAccessorInMemory();
     //---------------Test Result -----------------------
     Assert.IsNotNull(dataAccessorInMemory.DataStoreInMemory);
 }
 public void Test_UsesBusinessObjectLoaderInMemory()
 {
     //---------------Set up test pack-------------------
     
     //---------------Execute Test ----------------------
     DataAccessorInMemory dataAccessorInMemory = new DataAccessorInMemory();
     //---------------Test Result -----------------------
     Assert.IsInstanceOf(typeof(BusinessObjectLoaderInMemory), dataAccessorInMemory.BusinessObjectLoader);
 }
 public void Test_Constructor_UsesPassedInDataStore()
 {
     //---------------Set up test pack-------------------
     DataStoreInMemory dataStore = MockRepository.GenerateMock<DataStoreInMemory>();
     //---------------Execute Test ----------------------
     DataAccessorInMemory dataAccessorInMemory = new DataAccessorInMemory(dataStore);
     //---------------Test Result -----------------------
     Assert.AreSame(dataStore, dataAccessorInMemory.DataStoreInMemory);
 }
 public void TestFixtureSetup()
 {
     //Code that is executed before any test is run in this class. If multiple tests
     // are executed then it will still only be called once.
     ClassDef.ClassDefs.Clear();
     _dataStore = new DataStoreInMemory();
     _dataAccessor = new DataAccessorInMemory(_dataStore);
     BORegistry.DataAccessor = _dataAccessor;
     ContactPersonTestBO.LoadDefaultClassDef();
 }
 public void Test_UsesTransactionCommitterInMemory()
 {
     //---------------Set up test pack-------------------
     
     //---------------Execute Test ----------------------
     DataAccessorInMemory dataAccessorInMemory = new DataAccessorInMemory();
     //---------------Test Result -----------------------
     Assert.IsInstanceOf(typeof(TransactionCommitterInMemory), dataAccessorInMemory.CreateTransactionCommitter());
     //---------------Tear down -------------------------
 }
 public void SetupTest()
 {
     //Runs every time that any testmethod is executed
     //base.SetupTest();
     ClassDef.ClassDefs.Clear();
     _dataStore = new DataStoreInMemory();
     _dataAccessor = new DataAccessorInMemory(_dataStore);
     BORegistry.DataAccessor = _dataAccessor;
     ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
     OrganisationTestBO.LoadDefaultClassDef();
 }
 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_WithThread()
 {
     //---------------Set up test pack-------------------
     var dataAccessorMain = new DataAccessorInMemory();
     var dataAccessor = new DataAccessorThreadSplitter(dataAccessorMain);
     var expectedDataAccessorForThread = new DataAccessorInMemory();
     var thread = new Thread(() =>
                                 {
                                     dataAccessor.AddDataAccessorForThread(expectedDataAccessorForThread);
                                     Thread.Sleep(1000);
                                 });
     thread.Start();
     Thread.Sleep(500);
     //---------------Execute Test ----------------------
     var dataAccessorForThread = dataAccessor.GetDataAccessorForThread(thread);
     //---------------Test Result -----------------------
     Assert.AreSame(expectedDataAccessorForThread, dataAccessorForThread);
 }
 public void Test_ClearDeadThreads()
 {
     //---------------Set up test pack-------------------
     var dataAccessorMain = new DataAccessorInMemory();
     var dataAccessor = new DataAccessorThreadSplitter(dataAccessorMain);
     var expectedDataAccessorForThread = new DataAccessorInMemory();
     var thread = new Thread(() => dataAccessor.AddDataAccessorForThread(expectedDataAccessorForThread));
     thread.Start();
     thread.Join();
     //---------------Assert preconditions---------------
     Assert.AreSame(expectedDataAccessorForThread, dataAccessor.GetDataAccessorForThread(thread));
     //---------------Execute Test ----------------------
     dataAccessor.ClearDeadThreads();
     //---------------Test Result -----------------------
     try
     {
         Assert.IsNull(dataAccessor.GetDataAccessorForThread(thread));
         Assert.Fail("An exception should be thrown");
     } catch (HabaneroDeveloperException ex)
     {
         StringAssert.Contains("Data accessor for thread does not exist", ex.Message);
     }
 }
        public void Test_SavingToMultipleSources()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore1 = new DataStoreInMemory();
            DataStoreInMemory dataStore2 = new DataStoreInMemory();

            DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1);
            DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2);

            DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory());
            dataAccessor.AddDataAccessor(typeof(MyBO), dataAccessorInMemory1);
            dataAccessor.AddDataAccessor(typeof(MyRelatedBo), dataAccessorInMemory2);
            MyBO.LoadDefaultClassDef();
            MyRelatedBo.LoadClassDef();
            var bo1 = new MyBO();
            var bo2 = new MyRelatedBo();
            //---------------Execute Test ----------------------
            ITransactionCommitter committer1 = dataAccessor.CreateTransactionCommitter();
            committer1.AddBusinessObject(bo1);
            committer1.CommitTransaction();

            ITransactionCommitter committer2 = dataAccessor.CreateTransactionCommitter();
            committer2.AddBusinessObject(bo2);
            committer2.CommitTransaction();

            //---------------Test Result -----------------------
            Assert.IsNotNull(dataStore1.Find<MyBO>(bo1.ID));
            Assert.IsNotNull(dataStore2.Find<MyRelatedBo>(bo2.ID));
            //---------------Tear down -------------------------

        }
        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 -------------------------

        }
예제 #16
0
 public void TestDataAccessorInMemoryConstructor()
 {
     //---------------Set up test pack-------------------
     
     //---------------Execute Test ----------------------
     IDataAccessor dataAccessor = new DataAccessorInMemory();
     //---------------Test Result -----------------------
     Assert.IsInstanceOf(typeof(BusinessObjectLoaderInMemory), dataAccessor.BusinessObjectLoader);
     //---------------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 -------------------------
        }