public void TearDown() { Criteria criteria1 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "MyShape"); Shape shape = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <Shape>( criteria1); if (shape != null) { shape.MarkForDelete(); shape.Save(); } criteria1 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "Circle"); Criteria criteria2 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "CircleChanged"); Criteria criteria = new Criteria(criteria1, Criteria.LogicalOp.Or, criteria2); CircleNoPrimaryKey circle = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <CircleNoPrimaryKey>( criteria); if (circle != null) { circle.MarkForDelete(); circle.Save(); } criteria1 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "FilledCircle"); criteria2 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "FilledCircleChanged"); criteria = new Criteria(criteria1, Criteria.LogicalOp.Or, criteria2); FilledCircleNoPrimaryKey filledCircle = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <FilledCircleNoPrimaryKey>( criteria); if (filledCircle == null) { return; } filledCircle.MarkForDelete(); filledCircle.Save(); }
public void TestDatabaseReadWrite() { // Test inserting & selecting Shape shape = new Shape { ShapeName = "MyShape" }; shape.Save(); BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>(); shapes.LoadAll(); Assert.AreEqual(1, shapes.Count); BusinessObjectCollection <CircleNoPrimaryKey> circles = new BusinessObjectCollection <CircleNoPrimaryKey>(); circles.LoadAll(); Assert.AreEqual(0, circles.Count); BusinessObjectCollection <FilledCircleNoPrimaryKey> filledCircles = new BusinessObjectCollection <FilledCircleNoPrimaryKey>(); filledCircles.LoadAll(); Assert.AreEqual(0, filledCircles.Count); CircleNoPrimaryKey circle = new CircleNoPrimaryKey { Radius = 5, ShapeName = "Circle" }; circle.Save(); FixtureEnvironment.ClearBusinessObjectManager(); shapes.LoadAll("ShapeName"); Assert.AreEqual(2, shapes.Count); Assert.AreEqual("Circle", shapes[0].ShapeName); Assert.AreEqual("MyShape", shapes[1].ShapeName); FixtureEnvironment.ClearBusinessObjectManager(); circles.LoadAll(); Assert.AreEqual(1, circles.Count); Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID); Assert.AreEqual(5, circles[0].Radius); Assert.AreEqual("Circle", circles[0].ShapeName); FilledCircleNoPrimaryKey filledCircle = new FilledCircleNoPrimaryKey { Colour = 3, Radius = 7, ShapeName = "FilledCircle" }; filledCircle.Save(); FixtureEnvironment.ClearBusinessObjectManager(); shapes.LoadAll("ShapeName"); Assert.AreEqual(3, shapes.Count); Assert.AreEqual("Circle", shapes[0].ShapeName); Assert.AreEqual("FilledCircle", shapes[1].ShapeName); Assert.AreEqual("MyShape", shapes[2].ShapeName); Assert.That(shapes[0], Is.InstanceOf(typeof(CircleNoPrimaryKey))); Assert.That(shapes[1], Is.InstanceOf(typeof(FilledCircleNoPrimaryKey))); Assert.That(shapes[2], Is.InstanceOf(typeof(Shape))); circles.LoadAll("ShapeName"); Assert.AreEqual(2, circles.Count); Assert.AreEqual(circles[1].ShapeID, shapes[1].ShapeID); Assert.AreEqual(7, circles[1].Radius); Assert.AreEqual("FilledCircle", circles[1].ShapeName); filledCircles.LoadAll(); Assert.AreEqual(1, filledCircles.Count); Assert.AreEqual(filledCircles[0].ShapeID, shapes[1].ShapeID); Assert.AreEqual(7, filledCircles[0].Radius); Assert.AreEqual("FilledCircle", filledCircles[0].ShapeName); Assert.AreEqual(3, filledCircles[0].Colour); // Test updating shape.ShapeName = "MyShapeChanged"; shape.Save(); circle.ShapeName = "CircleChanged"; circle.Radius = 10; circle.Save(); filledCircle.ShapeName = "FilledCircleChanged"; filledCircle.Radius = 12; filledCircle.Colour = 4; filledCircle.Save(); shapes.LoadAll("ShapeName"); Assert.AreEqual("CircleChanged", shapes[0].ShapeName); Assert.AreEqual("FilledCircleChanged", shapes[1].ShapeName); Assert.AreEqual("MyShapeChanged", shapes[2].ShapeName); circles.LoadAll("ShapeName"); Assert.AreEqual(10, circles[0].Radius); Assert.AreEqual(12, circles[1].Radius); Assert.AreEqual("CircleChanged", circles[0].ShapeName); Assert.AreEqual("FilledCircleChanged", circles[1].ShapeName); filledCircles.LoadAll(); Assert.AreEqual(4, filledCircles[0].Colour); Assert.AreEqual(12, filledCircles[0].Radius); Assert.AreEqual("FilledCircleChanged", filledCircles[0].ShapeName); // Test deleting shape.MarkForDelete(); shape.Save(); circle.MarkForDelete(); circle.Save(); filledCircle.MarkForDelete(); filledCircle.Save(); shapes.LoadAll(); Assert.AreEqual(0, shapes.Count); Assert.AreEqual(0, shapes.PersistedBusinessObjects.Count); Assert.AreEqual(0, shapes.CreatedBusinessObjects.Count); circles.LoadAll(); Assert.AreEqual(0, circles.Count); filledCircles.LoadAll(); Assert.AreEqual(0, filledCircles.Count); }
public void TestDatabaseReadWrite() { // Test inserting & selecting Shape shape = new Shape {ShapeName = "MyShape"}; shape.Save(); BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>(); shapes.LoadAll(); Assert.AreEqual(1, shapes.Count); BusinessObjectCollection<CircleNoPrimaryKey> circles = new BusinessObjectCollection<CircleNoPrimaryKey>(); circles.LoadAll(); Assert.AreEqual(0, circles.Count); BusinessObjectCollection<FilledCircleNoPrimaryKey> filledCircles = new BusinessObjectCollection<FilledCircleNoPrimaryKey>(); filledCircles.LoadAll(); Assert.AreEqual(0, filledCircles.Count); CircleNoPrimaryKey circle = new CircleNoPrimaryKey {Radius = 5, ShapeName = "Circle"}; circle.Save(); FixtureEnvironment.ClearBusinessObjectManager(); shapes.LoadAll("ShapeName"); Assert.AreEqual(2, shapes.Count); Assert.AreEqual("Circle", shapes[0].ShapeName); Assert.AreEqual("MyShape", shapes[1].ShapeName); FixtureEnvironment.ClearBusinessObjectManager(); circles.LoadAll(); Assert.AreEqual(1, circles.Count); Assert.AreEqual(circles[0].ShapeID, shapes[0].ShapeID); Assert.AreEqual(5, circles[0].Radius); Assert.AreEqual("Circle", circles[0].ShapeName); FilledCircleNoPrimaryKey filledCircle = new FilledCircleNoPrimaryKey { Colour = 3, Radius = 7, ShapeName = "FilledCircle" }; filledCircle.Save(); FixtureEnvironment.ClearBusinessObjectManager(); shapes.LoadAll("ShapeName"); Assert.AreEqual(3, shapes.Count); Assert.AreEqual("Circle", shapes[0].ShapeName); Assert.AreEqual("FilledCircle", shapes[1].ShapeName); Assert.AreEqual("MyShape", shapes[2].ShapeName); Assert.That(shapes[0], Is.InstanceOf(typeof(CircleNoPrimaryKey))); Assert.That(shapes[1], Is.InstanceOf(typeof(FilledCircleNoPrimaryKey))); Assert.That(shapes[2], Is.InstanceOf(typeof(Shape))); circles.LoadAll("ShapeName"); Assert.AreEqual(2, circles.Count); Assert.AreEqual(circles[1].ShapeID, shapes[1].ShapeID); Assert.AreEqual(7, circles[1].Radius); Assert.AreEqual("FilledCircle", circles[1].ShapeName); filledCircles.LoadAll(); Assert.AreEqual(1, filledCircles.Count); Assert.AreEqual(filledCircles[0].ShapeID, shapes[1].ShapeID); Assert.AreEqual(7, filledCircles[0].Radius); Assert.AreEqual("FilledCircle", filledCircles[0].ShapeName); Assert.AreEqual(3, filledCircles[0].Colour); // Test updating shape.ShapeName = "MyShapeChanged"; shape.Save(); circle.ShapeName = "CircleChanged"; circle.Radius = 10; circle.Save(); filledCircle.ShapeName = "FilledCircleChanged"; filledCircle.Radius = 12; filledCircle.Colour = 4; filledCircle.Save(); shapes.LoadAll("ShapeName"); Assert.AreEqual("CircleChanged", shapes[0].ShapeName); Assert.AreEqual("FilledCircleChanged", shapes[1].ShapeName); Assert.AreEqual("MyShapeChanged", shapes[2].ShapeName); circles.LoadAll("ShapeName"); Assert.AreEqual(10, circles[0].Radius); Assert.AreEqual(12, circles[1].Radius); Assert.AreEqual("CircleChanged", circles[0].ShapeName); Assert.AreEqual("FilledCircleChanged", circles[1].ShapeName); filledCircles.LoadAll(); Assert.AreEqual(4, filledCircles[0].Colour); Assert.AreEqual(12, filledCircles[0].Radius); Assert.AreEqual("FilledCircleChanged", filledCircles[0].ShapeName); // Test deleting shape.MarkForDelete(); shape.Save(); circle.MarkForDelete(); circle.Save(); filledCircle.MarkForDelete(); filledCircle.Save(); shapes.LoadAll(); Assert.AreEqual(0, shapes.Count); Assert.AreEqual(0, shapes.PersistedBusinessObjects.Count); Assert.AreEqual(0, shapes.CreatedBusinessObjects.Count); circles.LoadAll(); Assert.AreEqual(0, circles.Count); filledCircles.LoadAll(); Assert.AreEqual(0, filledCircles.Count); }