Пример #1
0
        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 -------------------------
        }
Пример #2
0
        public void Test_UsingDefaultBusinessObjectLoader()
        {
            //---------------Set up test pack-------------------
            DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory());
            ITransactionCommitter   committer    = dataAccessor.CreateTransactionCommitter();

            MyBO.LoadDefaultClassDef();
            var bo1 = new MyBO();

            committer.AddBusinessObject(bo1);
            committer.CommitTransaction();
            //---------------Execute Test ----------------------
            var loadedBo1 = dataAccessor.BusinessObjectLoader.GetBusinessObject <MyBO>(bo1.ID);

            //---------------Test Result -----------------------
            Assert.AreSame(loadedBo1, bo1);
            //---------------Tear down -------------------------
        }
Пример #3
0
        public void TestCompareThroughRelationship()
        {
            //---------------Set up test pack-------------------
            Car car1 = new Car();

            car1.CarRegNo = "5";
            Car car2 = new Car();

            car2.CarRegNo = "2";

            Engine engine1 = new Engine();

            engine1.CarID    = car1.CarID;
            engine1.EngineNo = "20";

            Engine engine2 = new Engine();

            engine2.CarID    = car2.CarID;
            engine2.EngineNo = "50";

            ITransactionCommitter committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            committer.AddBusinessObject(car1);
            committer.AddBusinessObject(car2);
            committer.AddBusinessObject(engine1);
            committer.AddBusinessObject(engine2);
            committer.CommitTransaction();

            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------
            PropertyComparer <Engine, string> comparer = new PropertyComparer <Engine, string>("CarRegNo");

            comparer.Source = new Source("Car");
            int comparisonResult = comparer.Compare(engine1, engine2);

            //---------------Test Result -----------------------
            Assert.Greater(comparisonResult, 0, "engine1 should be greater as its car's regno is greater");
            //---------------Tear Down -------------------------
        }
Пример #4
0
        public void TestField_Compare_ThroughRelationship()
        {
            //---------------Set up test pack-------------------
            Car car1 = new Car();

            car1.CarRegNo = "5";
            Car car2 = new Car();

            car2.CarRegNo = "2";

            Engine engine1 = new Engine();

            engine1.CarID    = car1.CarID;
            engine1.EngineNo = "20";

            Engine engine2 = new Engine();

            engine2.CarID    = car2.CarID;
            engine2.EngineNo = "50";

            ITransactionCommitter committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            committer.AddBusinessObject(car1);
            committer.AddBusinessObject(car2);
            committer.AddBusinessObject(engine1);
            committer.AddBusinessObject(engine2);
            committer.CommitTransaction();

            OrderCriteriaField orderCriteriaField = OrderCriteriaField.FromString("Engine.Car.CarRegNo");

            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------
            int comparisonResult = orderCriteriaField.Compare(engine1, engine2);

            //---------------Test Result -----------------------
            Assert.Greater(comparisonResult, 0, "engine1 should be greater as its car's regno is greater");
            //---------------Tear Down -------------------------
        }
Пример #5
0
        public void TestCompare_ThroughRelationship()
        {
            //---------------Set up test pack-------------------
            Car car1 = new Car();

            car1.CarRegNo = "2";
            Car car2 = new Car();

            car2.CarRegNo = "2";

            Engine engine1 = new Engine();

            engine1.CarID    = car1.CarID;
            engine1.EngineNo = "20";

            Engine engine2 = new Engine();

            engine2.CarID    = car2.CarID;
            engine2.EngineNo = "50";

            ITransactionCommitter committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            committer.AddBusinessObject(car1);
            committer.AddBusinessObject(car2);
            committer.AddBusinessObject(engine1);
            committer.AddBusinessObject(engine2);
            committer.CommitTransaction();

            IOrderCriteria orderCriteria = QueryBuilder.CreateOrderCriteria(engine1.ClassDef, "Car.CarRegNo, EngineNo");

            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------
            int comparisonResult = orderCriteria.Compare(engine1, engine2);

            //---------------Test Result -----------------------
            Assert.Less(comparisonResult, 0, "engine1 should be less as the car regnos are equal and its engine no is less");
            //---------------Tear Down -------------------------
        }
 /// <summary>
 /// A handler to respond when the "OK" button has been pressed.
 /// All changes are committed to the database and the dialog is closed.
 /// </summary>
 /// <param name="sender">The object that notified of the event</param>
 /// <param name="e">Attached arguments regarding the event</param>
 private void OKButtonHandler(object sender, EventArgs e)
 {
     try
     {
         _panelInfo.ApplyChangesToBusinessObject();
         ITransactionCommitter committer = CreateSaveTransaction();
         committer.CommitTransaction();
         DialogResult = DialogResult.OK;
         if (_postObjectEditAction != null)
         {
             _postObjectEditAction(this._bo, false);
         }
         _panelInfo.BusinessObject = null;
         SafeCloseForm();
     }
     catch (Exception ex)
     {
         log.Error(ExceptionUtilities.GetExceptionString(ex, 0, true));
         GlobalRegistry.UIExceptionNotifier.Notify(ex,
                                                   "There was a problem saving for the following reason(s):",
                                                   "Saving Problem");
     }
 }
 ///<summary>
 /// Commit the transactions to the datasource e.g. the database, file, memory DB
 ///</summary>
 ///<returns></returns>
 public List <Guid> CommitTransaction()
 {
     return(_transactionCommitter != null?_transactionCommitter.CommitTransaction() : new List <Guid>());
 }