public void TestLoad_SingleTableInheritance()
        {
            //---------------Set up test pack-------------------
            CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            CircleNoPrimaryKey circle = CircleNoPrimaryKey.CreateSavedCircle();

            //---------------Execute Test ----------------------
            CircleNoPrimaryKey loadedCircle =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <CircleNoPrimaryKey>(circle.ID);

            //---------------Test Result -----------------------

            Assert.AreSame(circle, loadedCircle);
        }
        public void Test_GetBusinessObjectCollection_NonGeneric_LoadOfSubTypeDoesntLoadSuperTypedObjects()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            Shape     shape    = Shape.CreateSavedShape();
            Criteria  criteria = Criteria.FromPrimaryKey(shape.ID);

            //---------------Execute Test ----------------------
            IBusinessObjectCollection loadedCircles =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection(classDef, criteria);

            //---------------Test Result -----------------------
            Assert.AreEqual(0, loadedCircles.Count);
            Assert.IsInstanceOf(typeof(BusinessObjectCollection <CircleNoPrimaryKey>), loadedCircles);
        }
        public void TestLoad_SingleTableInheritance_LoadingBaseType_ShouldLoadAllSubTypes()
        {
            //---------------Set up test pack-------------------
            CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            Shape shape = Shape.CreateSavedShape();
            CircleNoPrimaryKey circle = CircleNoPrimaryKey.CreateSavedCircle();

            //---------------Execute Test ----------------------
            BusinessObjectCollection <Shape> loadedShapes =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <Shape>("");

            //---------------Test Result -----------------------

            Assert.AreEqual(2, loadedShapes.Count);
        }
Exemple #4
0
        public void TestPrepareDiscriminatorCriteria()
        {
            //---------------Set up test pack-------------------
            IClassDef   circleClassDef = CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            SelectQuery selectQuery    = (SelectQuery)QueryBuilder.CreateSelectQuery(circleClassDef);
            Criteria    discCriteria   = selectQuery.DiscriminatorCriteria;

            //---------------Execute Test ----------------------
            QueryBuilder.PrepareDiscriminatorCriteria(circleClassDef, discCriteria);
            //---------------Test Result -----------------------
            Assert.AreEqual("ShapeType_field", discCriteria.Field.PropertyName);
            Assert.AreEqual("ShapeType_field", discCriteria.Field.FieldName);
            Assert.AreEqual("Shape", discCriteria.Field.Source.Name);
            Assert.AreEqual("Shape_table", discCriteria.Field.Source.EntityName);
        }
Exemple #5
0
        public void TestGetBusinessObject_ReturnsSubType_Fresh()
        {
            //---------------Set up test pack-------------------
            SetupDataAccessor();

            CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            CircleNoPrimaryKey circle = CircleNoPrimaryKey.CreateSavedCircle();

            FixtureEnvironment.ClearBusinessObjectManager();

            //---------------Execute Test ----------------------
            Shape loadedShape = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <Shape>(circle.ID);

            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof(CircleNoPrimaryKey), loadedShape);
        }
Exemple #6
0
        public void TestLoad_SingleTableInheritance_Fresh()
        {
            //---------------Set up test pack-------------------
            CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            CircleNoPrimaryKey circle = CircleNoPrimaryKey.CreateSavedCircle();

            //---------------Execute Test ----------------------
            FixtureEnvironment.ClearBusinessObjectManager();
            CircleNoPrimaryKey loadedCircle =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <CircleNoPrimaryKey>(circle.ID);

            //---------------Test Result -----------------------
            Assert.AreNotSame(loadedCircle, circle);
            Assert.AreEqual(circle.Radius, loadedCircle.Radius);
            Assert.AreEqual(circle.ShapeName, loadedCircle.ShapeName);
        }
        public void Test_GetBusinessObjectCollection_Generic_LoadOfSubTypeDoesntLoadSuperTypedObjects_Fresh()
        {
            //---------------Set up test pack-------------------
            CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            Shape    shape    = Shape.CreateSavedShape();
            Criteria criteria = Criteria.FromPrimaryKey(shape.ID);

            FixtureEnvironment.ClearBusinessObjectManager();

            //---------------Execute Test ----------------------
            BusinessObjectCollection <CircleNoPrimaryKey> loadedCircles =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <CircleNoPrimaryKey>
                    (criteria);

            //---------------Test Result -----------------------
            Assert.AreEqual(0, loadedCircles.Count);
        }
Exemple #8
0
        public void TestSingleTableInheritance_Fields()
        {
            //---------------Set up test pack-------------------
            IClassDef circleClassDef = CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            ISelectQuery selectQuery = QueryBuilder.CreateSelectQuery(circleClassDef);

            //---------------Test Result -----------------------
            Assert.AreEqual(4, selectQuery.Fields.Count);
            Assert.IsTrue(selectQuery.Fields.ContainsKey("ShapeID"));
            Assert.IsTrue(selectQuery.Fields.ContainsKey("ShapeName"));
            Assert.IsTrue(selectQuery.Fields.ContainsKey("Radius"));
            Assert.IsTrue(selectQuery.Fields.ContainsKey("ShapeType_field"));
            Assert.AreEqual("Shape_table", selectQuery.Source.EntityName);
        }
        public void Test_GetBusinessObjectCollection_Generic_ReturnsSubType_NonFresh()
        {
            //---------------Set up test pack-------------------
            CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            CircleNoPrimaryKey circle   = CircleNoPrimaryKey.CreateSavedCircle();
            Criteria           criteria = Criteria.FromPrimaryKey(circle.ID);

            //---------------Execute Test ----------------------
            BusinessObjectCollection <Shape> loadedShapes =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <Shape>(criteria);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedShapes.Count);
            Shape loadedShape = loadedShapes[0];

            Assert.IsInstanceOf(typeof(CircleNoPrimaryKey), loadedShape);
            Assert.AreSame(circle, loadedShape);
        }
Exemple #10
0
        public void TestSingleTableInheritance_SubTypeHasDiscriminator()
        {
            //---------------Set up test pack-------------------
            IClassDef circleClassDef = CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            Criteria  expected       = new Criteria("ShapeType_field", Criteria.ComparisonOp.Equals, "CircleNoPrimaryKey");
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            SelectQuery selectQuery = (SelectQuery)QueryBuilder.CreateSelectQuery(circleClassDef);

            //---------------Test Result -----------------------
            Assert.AreEqual(expected, selectQuery.DiscriminatorCriteria);
            Criteria discCriteria = selectQuery.DiscriminatorCriteria;

            Assert.AreEqual("ShapeType_field", discCriteria.Field.PropertyName);
            Assert.AreEqual("ShapeType_field", discCriteria.Field.FieldName);
            Assert.AreEqual("Shape", discCriteria.Field.Source.Name);
            Assert.AreEqual("Shape_table", discCriteria.Field.Source.EntityName);
        }
        public void Test_GetBusinessObjectCollection_NonGeneric_ReturnsSubType_Fresh()
        {
            //---------------Set up test pack-------------------
            CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            CircleNoPrimaryKey circle   = CircleNoPrimaryKey.CreateSavedCircle();
            Criteria           criteria = Criteria.FromPrimaryKey(circle.ID);

            FixtureEnvironment.ClearBusinessObjectManager();

            IClassDef classDef = ClassDef.Get <Shape>();
            //---------------Execute Test ----------------------
            IBusinessObjectCollection loadedShapes =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection(classDef, criteria);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, loadedShapes.Count);
            Assert.IsInstanceOf(typeof(Shape), loadedShapes[0]);
            Shape loadedShape = (Shape)loadedShapes[0];

            Assert.IsInstanceOf(typeof(CircleNoPrimaryKey), loadedShape);
            Assert.IsInstanceOf(typeof(BusinessObjectCollection <Shape>), loadedShapes);
        }
Exemple #12
0
        public void TestSingleTableInheritance_BaseHasDiscriminator()
        {
            //---------------Set up test pack-------------------
            ClassDef  circleClassDef         = (ClassDef)CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            IClassDef shapeClassDef          = circleClassDef.SuperClassClassDef;
            Criteria  expectedShapeCriteria  = new Criteria("ShapeType_field", Criteria.ComparisonOp.Is, "null");
            Criteria  expectedCircleCriteria = new Criteria("ShapeType_field", Criteria.ComparisonOp.Equals, "CircleNoPrimaryKey");
            Criteria  expected = new Criteria(expectedShapeCriteria, Criteria.LogicalOp.Or, expectedCircleCriteria);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            SelectQuery selectQuery = (SelectQuery)QueryBuilder.CreateSelectQuery(shapeClassDef);

            //---------------Test Result -----------------------
            Assert.AreEqual(3, selectQuery.Fields.Count);
            Assert.IsTrue(selectQuery.Fields.ContainsKey("ShapeID"));
            Assert.IsTrue(selectQuery.Fields.ContainsKey("ShapeName"));
            Assert.IsTrue(selectQuery.Fields.ContainsKey("ShapeType_field"));

            Assert.AreEqual(expected, selectQuery.DiscriminatorCriteria);
            Assert.AreEqual("Shape_table", selectQuery.Source.EntityName);
        }
Exemple #13
0
        public void TestLoad_SingleTableInheritance__GetBOAsParent_ThenGetBOAsShape_ThenGetAsCircle_ShouldLoadCircle()
        {
            //---------------Set up test pack-------------------
            CircleNoPrimaryKey.GetClassDefWithSingleInheritance();
            CircleNoPrimaryKey circle = CircleNoPrimaryKey.CreateSavedCircle();

            FixtureEnvironment.ClearBusinessObjectManager();
            //---------------Assert Preconditions---------------
            //---------------Execute Test ----------------------
            Shape circleLoadedAsShape       = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <Shape>("ShapeID = " + circle.ShapeID);
            CircleNoPrimaryKey loadedCircle =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <CircleNoPrimaryKey>(circle.ID);

            //---------------Test Result -----------------------
            Assert.IsNotNull(circleLoadedAsShape);
            Assert.AreEqual(circle.ShapeName, circleLoadedAsShape.ShapeName);

            Assert.IsNotNull(loadedCircle);
            Assert.AreNotSame(loadedCircle, circle);
            Assert.AreSame(loadedCircle, circleLoadedAsShape);
            Assert.AreEqual(circle.Radius, loadedCircle.Radius);
            Assert.AreEqual(circle.ShapeName, loadedCircle.ShapeName);
        }