public static void TestStateView(int index, Node rootNode) { ControllerTools.ResetExpectedName(); IReadOnlyRootNodeIndex RootIndex = new ReadOnlyRootNodeIndex(rootNode); ReadOnlyController Controller = ReadOnlyController.Create(RootIndex); ReadOnlyControllerView ControllerView = ReadOnlyControllerView.Create(Controller); Assert.That(ControllerView.StateViewTable.ContainsKey(Controller.RootState), $"Views #0"); Assert.That(ControllerView.StateViewTable.Count == Controller.Stats.NodeCount, $"Views #1"); foreach (KeyValuePair <IReadOnlyNodeState, IReadOnlyNodeStateView> Entry in ControllerView.StateViewTable) { IReadOnlyNodeState State = Entry.Key; Assert.That(ControllerView.StateViewTable.ContainsKey(Controller.RootState), $"Views #2, state={State}"); IReadOnlyNodeStateView View = Entry.Value; Assert.That(View.State == State, $"Views #3"); } ReadOnlyControllerView ControllerView2 = ReadOnlyControllerView.Create(Controller); Assert.That(ControllerView2.IsEqual(CompareEqual.New(), ControllerView), $"Views #4"); }
public static void ReadOnlyViews() { ControllerTools.ResetExpectedName(); Main RootNode; IReadOnlyRootNodeIndex RootIndex; RootNode = CreateRoot(ValueGuid0, Imperfections.None); RootIndex = new ReadOnlyRootNodeIndex(RootNode); ReadOnlyController Controller = ReadOnlyController.Create(RootIndex); using (ReadOnlyControllerView ControllerView0 = ReadOnlyControllerView.Create(Controller)) { Assert.That(ControllerView0.Controller == Controller); Assert.That(ControllerView0.RootStateView == ControllerView0.StateViewTable[Controller.RootState]); using (ReadOnlyControllerView ControllerView1 = ReadOnlyControllerView.Create(Controller)) { Assert.That(ControllerView0.IsEqual(CompareEqual.New(), ControllerView0)); Assert.That(CompareEqual.CoverIsEqual(ControllerView0, ControllerView1)); } foreach (KeyValuePair <IReadOnlyBlockState, ReadOnlyBlockStateView> Entry in ControllerView0.BlockStateViewTable) { IReadOnlyBlockState BlockState = Entry.Key; Assert.That(BlockState != null); ReadOnlyBlockStateView BlockStateView = Entry.Value; Assert.That(BlockStateView != null); Assert.That(BlockStateView.ControllerView == ControllerView0); } foreach (KeyValuePair <IReadOnlyNodeState, IReadOnlyNodeStateView> Entry in ControllerView0.StateViewTable) { IReadOnlyNodeState State = Entry.Key; Assert.That(State != null); Assert.That(State.Comment != null); IReadOnlyNodeStateView StateView = Entry.Value; Assert.That(StateView != null); Assert.That(StateView.State == State); IReadOnlyIndex ParentIndex = State.ParentIndex; Assert.That(ParentIndex != null); Assert.That(Controller.Contains(ParentIndex)); Assert.That(StateView.ControllerView == ControllerView0); switch (StateView) { case ReadOnlyPatternStateView AsPatternStateView: Assert.That(AsPatternStateView.State == State); break; case ReadOnlySourceStateView AsSourceStateView: Assert.That(AsSourceStateView.State == State); break; case ReadOnlyPlaceholderNodeStateView AsPlaceholderNodeStateView: Assert.That(AsPlaceholderNodeStateView.State == State); break; case ReadOnlyOptionalNodeStateView AsOptionalNodeStateView: Assert.That(AsOptionalNodeStateView.State == State); break; } } } }