public void Constructor_WithData_ExpectedValues() { // Setup var mocks = new MockRepository(); var calculation = mocks.Stub <ICalculation>(); mocks.ReplayAll(); // Call using (var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => null)) { // Assert Assert.IsInstanceOf <GeneralResultIllustrationPointView <TopLevelFaultTreeIllustrationPoint> >(view); Assert.AreEqual(1, view.Controls.Count); var splitContainer = view.Controls[0] as SplitContainer; Assert.IsNotNull(splitContainer); Control.ControlCollection splitContainerPanel1Controls = splitContainer.Panel1.Controls; Assert.AreEqual(1, splitContainerPanel1Controls.Count); Assert.IsInstanceOf <IllustrationPointsControl>(splitContainerPanel1Controls[0]); Control.ControlCollection splitContainerPanel2Controls = splitContainer.Panel2.Controls; Assert.AreEqual(1, splitContainerPanel2Controls.Count); Assert.IsInstanceOf <IllustrationPointsFaultTreeControl>(splitContainerPanel2Controls[0]); } mocks.VerifyAll(); }
public void GivenViewWithIllustrationPoints_WhenIllustrationPointsCleared_ThenControlsSyncedAccordingly() { // Given var returnGeneralResult = true; var calculation = new TestCalculation(); GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints(); var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => returnGeneralResult ? generalResult : null); ShowTestView(view); // Precondition IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(view); IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view); AssertIllustrationPointControlItems(generalResult, illustrationPointsControl); Assert.AreSame(generalResult.TopLevelIllustrationPoints.First(), illustrationPointsFaultTreeControl.Data); // When returnGeneralResult = false; calculation.NotifyObservers(); // Then CollectionAssert.IsEmpty(illustrationPointsControl.Data); Assert.IsNull(illustrationPointsFaultTreeControl.Data); }
public void GivenFullyConfiguredView_WhenSelectingFaultTreeIllustrationPointInTree_ThenSelectionChangedAndPropagatedAccordingly(bool sameClosingSituations) { // Given var mocks = new MockRepository(); var calculation = mocks.Stub <ICalculation>(); mocks.ReplayAll(); GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResultFunc = GetGeneralResultWithThreeTopLevelIllustrationPointsWithChildren(sameClosingSituations); var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => generalResultFunc); ShowTestView(view); var selectionChangedCount = 0; view.SelectionChanged += (sender, args) => selectionChangedCount++; IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view); PointedTreeGraph pointedTreeGraph = GetPointedTreeGraph(illustrationPointsFaultTreeControl); // When PointedTreeElementVertex selectedVertex = pointedTreeGraph.Vertices.ElementAt(0); selectedVertex.IsSelected = true; // Then Assert.AreEqual(1, selectionChangedCount); TopLevelFaultTreeIllustrationPoint topLevel = generalResultFunc.TopLevelIllustrationPoints.First(); IllustrationPointNode expectedSelectedNode = topLevel.FaultTreeNodeRoot; var selectedFaultTreeContext = view.Selection as IllustrationPointContext <FaultTreeIllustrationPoint>; Assert.IsNotNull(selectedFaultTreeContext); Assert.AreSame(expectedSelectedNode, selectedFaultTreeContext.IllustrationPointNode); Assert.AreEqual(sameClosingSituations ? string.Empty : topLevel.ClosingSituation, selectedFaultTreeContext.ClosingSituation); Assert.AreEqual(topLevel.WindDirection.Name, selectedFaultTreeContext.WindDirectionName); mocks.VerifyAll(); }
public void Constructor_GeneralResultWithIllustrationPoints_DataSetOnIllustrationPointControl() { // Setup var mocks = new MockRepository(); var calculation = mocks.Stub <ICalculation>(); mocks.ReplayAll(); GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints(); // Call var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => generalResult); ShowTestView(view); // Assert IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(view); AssertIllustrationPointControlItems(generalResult, illustrationPointsControl); mocks.VerifyAll(); }
public void GivenFullyConfiguredView_WhenSelectingCellInRow_ThenSelectionChangedAndPropagatedAccordingly() { // Given var mocks = new MockRepository(); var calculation = mocks.Stub <ICalculation>(); mocks.ReplayAll(); GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints(); var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => generalResult); ShowTestView(view); var selectionChangedCount = 0; view.SelectionChanged += (sender, args) => selectionChangedCount++; DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView"); // When dataGridView.CurrentCell = dataGridView.Rows[1].Cells[0]; EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0)); // Then Assert.AreEqual(1, selectionChangedCount); IEnumerable <TopLevelFaultTreeIllustrationPoint> topLevelFaultTreeIllustrationPoints = generalResult.TopLevelIllustrationPoints.ToArray(); TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint = topLevelFaultTreeIllustrationPoints.ElementAt(1); AssertIllustrationPointSelection(topLevelFaultTreeIllustrationPoint, topLevelFaultTreeIllustrationPoints.Select(ip => ip.ClosingSituation), view.Selection); IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view); Assert.AreSame(topLevelFaultTreeIllustrationPoint, illustrationPointsFaultTreeControl.Data); mocks.VerifyAll(); }
public void GivenViewWithoutIllustrationPoints_WhenIllustrationPointsChangedAndContainingNotSupportedIllustrationPoints_ThenThrowsNotSupportedException() { // Given var calculation = new TestCalculation(); var hasGeneralResult = false; var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => hasGeneralResult ? GetGeneralResultWithTopLevelIllustrationPointsOfNotSupportedType() : null); ShowTestView(view); hasGeneralResult = true; // When void Call() => calculation.NotifyObservers(); // Assert var exception = Assert.Throws <NotSupportedException>(Call); Assert.AreEqual($"IllustrationPointNode of type {nameof(TestIllustrationPoint)} is not supported. " + $"Supported types: {nameof(FaultTreeIllustrationPoint)} and {nameof(SubMechanismIllustrationPoint)}", exception.Message); }
public void Constructor_GeneralResultWithoutIllustrationPoints_DataSetOnIllustrationPointControl() { // Setup var mocks = new MockRepository(); var calculation = mocks.Stub <ICalculation>(); mocks.ReplayAll(); // Call var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => null); ShowTestView(view); // Assert IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(view); CollectionAssert.IsEmpty(illustrationPointsControl.Data); IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view); Assert.IsNull(illustrationPointsFaultTreeControl.Data); mocks.VerifyAll(); }
private void ShowTestView(GeneralResultFaultTreeIllustrationPointView view) { testForm.Controls.Add(view); testForm.Show(); }
private static IllustrationPointsControl GetIllustrationPointsControl(GeneralResultFaultTreeIllustrationPointView view) { return(TypeUtils.GetField <IllustrationPointsControl>(view, "illustrationPointsControl")); }