public void Test_SubGrid_SetAbsoluteLevel() { ISubGrid subgrid = null; SubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>()); subgrid = new SubGrid(tree, null, 2); // create a node to be a chile of the root node // Test setting level for unattached subgrid (even though we set it in the constructor above subgrid.SetAbsoluteLevel(3); Assert.Equal(3, subgrid.Level); // Add subgrid to the root (which will set it's parent and prevent the level from // being changed and will throw an exception) try { tree.Root.SetSubGrid(0, 0, subgrid); Assert.True(false, "Calling SetSubGrid with an invalid/non-null level did not throw an exception"); } catch (Exception) { // As expected } // Restore Level to the correct value of 2, then assign it into the root subgrid subgrid.SetAbsoluteLevel(2); tree.Root.SetSubGrid(0, 0, subgrid); // Now test the level cannot be changed with root as its parent try { subgrid.SetAbsoluteLevel(2); Assert.True(false, "Setting absolute level for node with a parent did not raise an exception"); } catch (Exception) { // As expected` } }