Thursday, September 9, 2010

SelectionContainer tests

Added tests at SelectionContainer to automatically check basic cases. In order to make the tests for this class added Moq as mockup framework.

Because for the OpenCascade related functionality we implemented a GeomUtils library that mostly contains static functions I also had to implement an adapter to this to be able to mock GeomUtils functionality.

Setting up a mock is like the following:

var mock = new Mock();
mock.Setup(geomUtils =>
geomUtils.IdentifySelectedNodes(_document.Root)).Returns(selectedShapes);

then I can check if the selection container behaves correctly:

var selectionContainer = new SelectionContainer(mock.Object) {Document = _document};
selectionContainer.SwitchSelectionMode(OCTopAbs_ShapeEnum.TopAbs_SOLID);
selectionContainer.BuildSelections(new Mouse3DPosition(new Point3D(50, 0 , 50), new OCgp_Ax1(), true, false, false, 150, 150));
Assert.IsTrue(selectionContainer.Entities.Count == 1, "invalid number of solid detected shapes");

Assert.IsTrue(selectionContainer[OCTopAbs_ShapeEnum.TopAbs_SOLID].Count == 1, "invalid number of solid detected shapes");

Assert.IsTrue(selectionContainer[OCTopAbs_ShapeEnum.TopAbs_FACE].Count == 1, "invalid number of face detected shapes");


No comments: