internal static MockBO CreateMockBOWithExtraReadOnlyProp(string newPropName)
 {
     ClassDef newClassDef = new MockBO().ClassDef.Clone();
     PropDef def = new PropDef(newPropName, typeof (string), PropReadWriteRule.ReadOnly, "");
     newClassDef.PropDefcol.Add(def);
     return new MockBO(newClassDef);
 }
示例#2
0
        public void TestCreateRelationship()
        {
            ISingleRelationship rel =
                (ISingleRelationship)mRelationshipDef.CreateRelationship(mMockBo, mMockBo.PropCol);

            Assert.AreEqual(mRelationshipDef.RelationshipName, rel.RelationshipName);
            Assert.IsTrue(mMockBo.GetPropertyValue("MockBOProp1") == null);
            Assert.IsFalse(rel.HasRelatedObject(), "Should be false since props are not defaulted in Mock bo");
            mMockBo.SetPropertyValue("MockBOProp1", mMockBo.GetPropertyValue("MockBOID"));
            mMockBo.Save();
            Assert.IsTrue(rel.HasRelatedObject(), "Should be true since prop MockBOProp1 has been set");

            Assert.AreEqual(mMockBo.GetPropertyValue("MockBOProp1"), mMockBo.GetPropertyValue("MockBOID"));
            MockBO ltempBO = (MockBO)rel.GetRelatedObject();

            Assert.IsFalse(ltempBO == null);
            Assert.AreEqual
                (mMockBo.GetPropertyValue("MockBOID"), ltempBO.GetPropertyValue("MockBOID"),
                "The object returned should be the one with the ID = MockBOID");
            Assert.AreEqual
                (mMockBo.GetPropertyValueString("MockBOProp1"), ltempBO.GetPropertyValueString("MockBOID"),
                "The object returned should be the one with the ID = MockBOID");
            Assert.AreEqual
                (mMockBo.GetPropertyValue("MockBOProp1"), ltempBO.GetPropertyValue("MockBOID"),
                "The object returned should be the one with the ID = MockBOID");
            mMockBo.MarkForDelete();
            mMockBo.Save();
        }
 public void TestAutoIncrementObjNotApplicable()
 {
     MockBO bo = new MockBO();
     InsertStatementGenerator gen = new InsertStatementGenerator(bo, DatabaseConnection.CurrentConnection);
     var statementCol = gen.Generate();
     InsertSqlStatement statement = (InsertSqlStatement)statementCol.First();
     Assert.AreEqual(null, statement.SupportsAutoIncrementingField);
 }
 internal static MockBO CreateMockBOWithExtraNonPersistableProp(string newPropName)
 {
     ClassDef newClassDef = new MockBO().ClassDef.Clone();
     PropDef def = new PropDef(newPropName, typeof (string), PropReadWriteRule.ReadWrite, "")
                       {Persistable = false};
     newClassDef.PropDefcol.Add(def);
     return new MockBO(newClassDef);
 }
 public void TestSqlStatementTableName()
 {
     MockBO bo = new MockBO();
     InsertStatementGenerator gen = new InsertStatementGenerator(bo, DatabaseConnection.CurrentConnection);
     var statementCol = gen.Generate();
     InsertSqlStatement statement = (InsertSqlStatement)statementCol.First();
     Assert.AreEqual("MockBO", statement.TableName);
 }
 public void TestSqlStatementType()
 {
     MockBO bo = new MockBO();
     InsertStatementGenerator gen = new InsertStatementGenerator(bo, DatabaseConnection.CurrentConnection);
     var statementCol = gen.Generate();
     var sqlStatements = statementCol.ToList();
     Assert.AreEqual(1, sqlStatements.Count);
     Assert.AreSame(typeof(InsertSqlStatement), sqlStatements[0].GetType());
     
 }
示例#7
0
 private static MockBO GetMockBO(out RelationshipDef mRelationshipDef, out RelKeyDef mRelKeyDef)
 {
     MockBO _mMockBO= new MockBO();
     IPropDefCol mPropDefCol = _mMockBO.PropDefCol;
     mRelKeyDef = new RelKeyDef();
     IPropDef propDef = mPropDefCol["MockBOProp1"];
     RelPropDef lRelPropDef = new RelPropDef(propDef, "MockBOID");
     mRelKeyDef.Add(lRelPropDef);
     mRelationshipDef = new SingleRelationshipDef("Relation1", typeof(MockBO), mRelKeyDef, false,
                                                  DeleteParentAction.Prevent);
     return _mMockBO;
 }
        public void init()
        {
            this.SetupDBConnection();

            mMockBo = new MockBO();
            mPropDefCol = mMockBo.PropDefCol;

            mRelKeyDef = new RelKeyDef();
            IPropDef propDef = mPropDefCol["MockBOProp1"];

            RelPropDef lRelPropDef = new RelPropDef(propDef, "MockBOID");
            mRelKeyDef.Add(lRelPropDef);

            mRelationshipDef = new SingleRelationshipDef
                ("Relation1", typeof (MockBO), mRelKeyDef, false, DeleteParentAction.Prevent);
            //DatabaseConnection.CurrentConnection.ConnectionString = MyDBConnection.GetConnectionString();
        }
示例#9
0
        public void init()
        {
            this.SetupDBConnection();

            mMockBo     = new MockBO();
            mPropDefCol = mMockBo.PropDefCol;

            mRelKeyDef = new RelKeyDef();
            IPropDef propDef = mPropDefCol["MockBOProp1"];

            RelPropDef lRelPropDef = new RelPropDef(propDef, "MockBOID");

            mRelKeyDef.Add(lRelPropDef);

            mRelationshipDef = new SingleRelationshipDef
                                   ("Relation1", typeof(MockBO), mRelKeyDef, false, DeleteParentAction.Prevent);
            //DatabaseConnection.CurrentConnection.ConnectionString = MyDBConnection.GetConnectionString();
        }
        public void init()
        {
            BORegistry.DataAccessor = new DataAccessorInMemory();
            _fakeBO = new MockBO();
            _propDefCol = _fakeBO.PropDefCol;

            _RelKeyDef = new RelKeyDef();
            IPropDef propDef = _propDefCol["MockBOID"];

            RelPropDef relPropDef = new RelPropDef(propDef, "MockBOProp1");
            _RelKeyDef.Add(relPropDef);

            _multipleRelationshipDef = new MultipleRelationshipDef("Relation1", typeof(MockBO),
                                                       _RelKeyDef, false, "",
                                                       DeleteParentAction.DeleteRelated);


            _singleRelationshipDef = new SingleRelationshipDef("Single", typeof(MockBO),
                                                       _RelKeyDef, false,
                                                       DeleteParentAction.DeleteRelated);
        }
        public void init()
        {
            _mockBo = new MockBO();
            _propDefCol = _mockBo.PropDefCol;

            _RelKeyDef = new RelKeyDef();
            IPropDef propDef = _propDefCol["MockBOID"];

            RelPropDef relPropDef = new RelPropDef(propDef, "MockBOProp1");
            _RelKeyDef.Add(relPropDef);

            _multipleRelationshipDef = new MultipleRelationshipDef("Relation1", typeof(MockBO),
                                                       _RelKeyDef, false, "",
                                                       DeleteParentAction.DeleteRelated);


            _singleRelationshipDef = new SingleRelationshipDef("Single", typeof(MockBO),
                                                       _RelKeyDef, false,
                                                       DeleteParentAction.DeleteRelated);
            DatabaseConnection.CurrentConnection.ConnectionString = MyDBConnection.GetConnectionString();
        }
        public void CommitTransaction_WhenBoHasStringPropWithLengthGreaterThanDbField_ShouldRollbackConcurrencyStrategy_FixBugBug_2136()
        {
            //---------------Set up test pack-------------------
            TransactionCommitter committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            var temp = new NumberGeneratorPessimisticLockingImpl("tmp");
            temp.CallReleaseLocks();
            var pessimisticLocking = new NumberGeneratorPessimisticLockingImpl("tmp");

            var mockBO = new MockBO
                             {
                                 // force a database write exception as MockBOProp2 only allows varchar(50)
                                 MockBOProp2 = RandomValueGen.GetRandomString(51, 55)
                             };
            committer.AddBusinessObject(mockBO);
            pessimisticLocking.AddToTransaction(committer);
            var nextNumber = pessimisticLocking.NextNumber();
            //---------------Assert Precondition----------------
            Assert.IsTrue(pessimisticLocking.BoSequenceNumber.Status.IsDirty);
            Assert.IsFalse(pessimisticLocking.BoSequenceNumber.Props["Locked"].IsDirty);
            Assert.Greater(nextNumber, 0);
            Assert.Greater(mockBO.MockBOProp2.Length, 50);
            //---------------Execute Test ----------------------
            try
            {
                committer.CommitTransaction();
                //---------------Test Result -----------------------
                Assert.Fail("Expected to throw an DatabaseWriteException");
            }
            catch (DatabaseWriteException ex)
            {
                StringAssert.Contains("There was an error writing to the database", ex.Message);
            }

            //---------------Test Result -----------------------
            Assert.AreEqual(nextNumber, pessimisticLocking.NextNumber());


        }
 private static MockBO CreateSavedMockBO()
 {
     MockBO fakeBO = new MockBO();
     fakeBO.Save();
     return fakeBO;
 }
 public void TestPersistSimpleCreatedBO_DoesNotFailInTransactionCommitter()
 {
     //---------------Set up test pack-------------------
     MockBO fakeBO = new MockBO();
     Guid mockBOProp1 = Guid.NewGuid();
     fakeBO.MockBOProp1 = mockBOProp1;
     
     TransactionCommitter committerDB = new TransactionCommitterStub();
     committerDB.AddBusinessObject(fakeBO);
     fakeBO.MarkForDelete();
     //---------------Assert Preconditions---------------
     Assert.AreEqual(1, committerDB.OriginalTransactions.Count);
     Assert.IsTrue(fakeBO.Status.IsNew);
     Assert.IsTrue(fakeBO.Status.IsDeleted);
     //---------------Execute Test ----------------------
     committerDB.CommitTransaction();
     //---------------Test Result -----------------------
     Assert.IsTrue(fakeBO.Status.IsNew);
     Assert.IsTrue(fakeBO.Status.IsDeleted);
 }
 private static MockBO CreateSavedMockBO()
 {
     MockBO mockBo = new MockBO();
     mockBo.Save();
     return mockBo;
 }
        public void TestPersistSimpleBO_Insert()
        {
            //---------------Set up test pack-------------------
            MockBO mockBo = new MockBO();
            TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committerDB.AddTransaction(new TransactionalBusinessObjectDB(mockBo, committerDB.DatabaseConnection));

            //---------------Execute Test ----------------------
            committerDB.CommitTransaction();

            //---------------Test Result -----------------------
            TransactionCommitterTestHelper.AssertBOStateIsValidAfterInsert_Updated(mockBo);
//            BOLoader.Instance.Refresh(mockBo);
            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(mockBo);
            //MockBO savedMockBO =
            //    BOLoader.Instance.GetBusinessObject<MockBO>("MockBOID = '" + mockBo.MockBOID.ToString("B") + "'");
            Criteria criteria = new Criteria("MockBOID", Criteria.ComparisonOp.Equals, mockBo.MockBOID);
            MockBO savedMockBO = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<MockBO>(criteria);
            Assert.AreSame(mockBo, savedMockBO);
        }
        public void TestPersistSimpleBO_NewDelete()
        {
            //---------------Set up test pack-------------------
            MockBO mockBo = new MockBO();
            TransactionCommitterInMemory inMemoryCommitter = new TransactionCommitterInMemory(new DataStoreInMemory());
            inMemoryCommitter.AddBusinessObject(mockBo);
            inMemoryCommitter.CommitTransaction();

            TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            mockBo.MarkForDelete();
            committerDB.AddTransaction(new TransactionalBusinessObjectDB(mockBo, committerDB.DatabaseConnection));

            //---------------Execute Test ----------------------
            committerDB.CommitTransaction();

            //---------------Test Result -----------------------
            BOTestUtils.AssertBOStateIsValidAfterDelete(mockBo);
            AssertMockBONotInDatabase(mockBo.MockBOID);
        }