예제 #1
0
        public void Constructor_WithData_ExpectedValues()
        {
            // Setup
            var mocks       = new MockRepository();
            var calculation = mocks.Stub <ICalculation>();

            mocks.ReplayAll();

            // Call
            var view = new TestGeneralResultIllustrationPointView(calculation, GetGeneralResultWithoutTopLevelIllustrationPoints);

            // Assert
            Assert.IsInstanceOf <UserControl>(view);
            Assert.IsInstanceOf <IView>(view);
            Assert.IsInstanceOf <ISelectionProvider>(view);
            Assert.AreSame(calculation, view.Data);
            Assert.AreEqual("GeneralResultIllustrationPointView", view.Name);

            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]);

            CollectionAssert.IsEmpty(splitContainer.Panel2.Controls);

            mocks.VerifyAll();
        }
예제 #2
0
        public void GivenFullyConfiguredView_WhenSelectingCellInRow_ThenSelectionChangedAndPropagatedAccordingly()
        {
            // Given
            var mocks       = new MockRepository();
            var calculation = mocks.Stub <ICalculation>();

            mocks.ReplayAll();

            GeneralResult <TestTopLevelIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints();
            var view = new TestGeneralResultIllustrationPointView(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);

            TestTopLevelIllustrationPoint[] topLevelIllustrationPoints = generalResult.TopLevelIllustrationPoints.ToArray();
            TestTopLevelIllustrationPoint   topLevelIllustrationPoint  = topLevelIllustrationPoints.ElementAt(1);

            Assert.AreSame(topLevelIllustrationPoint, view.Selection);
            mocks.VerifyAll();
        }
예제 #3
0
        public void GivenFullyConfiguredViewWithIllustrationPoints_WhenIllustrationPointsCleared_ThenControlsSyncedAccordingly()
        {
            // Given
            var returnGeneralResult = true;

            var calculation = new TestCalculation();
            GeneralResult <TestTopLevelIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints();

            var view = new TestGeneralResultIllustrationPointView(calculation, () => returnGeneralResult
                                                                                         ? generalResult
                                                                                         : null);

            ShowTestView(view);

            // Precondition
            IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(view);

            AssertIllustrationPointControlItems(generalResult, illustrationPointsControl);

            // When
            returnGeneralResult = false;
            calculation.NotifyObservers();

            // Then
            CollectionAssert.IsEmpty(illustrationPointsControl.Data);
        }
예제 #4
0
        public void Constructor_GeneralResultFuncReturningEmptyData_SelectionNull()
        {
            // Setup
            var mocks       = new MockRepository();
            var calculation = mocks.Stub <ICalculation>();

            mocks.ReplayAll();

            // Call
            var view = new TestGeneralResultIllustrationPointView(calculation, GetGeneralResultWithoutTopLevelIllustrationPoints);

            ShowTestView(view);

            // Assert
            Assert.IsNull(view.Selection);
            mocks.VerifyAll();
        }
예제 #5
0
        public void Constructor_GeneralResultFuncReturningData_SelectionSetToFirstTopLevelIllustrationPoint()
        {
            // Setup
            var mocks       = new MockRepository();
            var calculation = mocks.Stub <ICalculation>();

            mocks.ReplayAll();

            // Call
            GeneralResult <TestTopLevelIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints();
            var view = new TestGeneralResultIllustrationPointView(calculation, () => generalResult);

            ShowTestView(view);

            // Assert
            IEnumerable <TestTopLevelIllustrationPoint> topLevelFaultTreeIllustrationPoints = generalResult.TopLevelIllustrationPoints.ToArray();

            Assert.AreSame(topLevelFaultTreeIllustrationPoints.First(), view.Selection);
            mocks.VerifyAll();
        }
예제 #6
0
        public void Constructor_GeneralResultWithoutIllustrationPoints_DataSetOnIllustrationPointControl()
        {
            // Setup
            var mocks       = new MockRepository();
            var calculation = mocks.Stub <ICalculation>();

            mocks.ReplayAll();

            // Call
            var view = new TestGeneralResultIllustrationPointView(calculation, () => null);

            ShowTestView(view);

            // Assert
            IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(view);

            CollectionAssert.IsEmpty(illustrationPointsControl.Data);

            mocks.VerifyAll();
        }
예제 #7
0
        public void Constructor_GeneralResultWithIllustrationPoints_DataSetOnIllustrationPointControl()
        {
            // Setup
            var mocks       = new MockRepository();
            var calculation = mocks.Stub <ICalculation>();

            mocks.ReplayAll();

            GeneralResult <TestTopLevelIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints();

            // Call
            var view = new TestGeneralResultIllustrationPointView(calculation, () => generalResult);

            ShowTestView(view);

            // Assert
            IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(view);

            AssertIllustrationPointControlItems(generalResult, illustrationPointsControl);

            mocks.VerifyAll();
        }
예제 #8
0
        public void GivenFullyConfiguredView_WhenOutputChangesAndNotifyObserver_ThenSelectionChangedAndPropagated(bool withInitialOutput)
        {
            // Given
            var calculation = new TestCalculation();

            if (withInitialOutput)
            {
                calculation.Output = new object();
            }

            var view = new TestGeneralResultIllustrationPointView(
                calculation, () => withInitialOutput
                                       ? GetGeneralResultWithTwoTopLevelIllustrationPoints()
                                       : null);

            ShowTestView(view);

            var selectionChangedCount = 0;

            view.SelectionChanged += (sender, args) => selectionChangedCount++;

            // When
            calculation.Output = withInitialOutput ? null : new object();
            calculation.NotifyObservers();

            // Then
            Assert.AreEqual(1, selectionChangedCount);
            if (withInitialOutput)
            {
                Assert.IsNotNull(view.Selection);
            }
            else
            {
                Assert.IsNull(view.Selection);
            }
        }
예제 #9
0
 private void ShowTestView(TestGeneralResultIllustrationPointView view)
 {
     testForm.Controls.Add(view);
     testForm.Show();
 }
예제 #10
0
 private static IllustrationPointsControl GetIllustrationPointsControl(TestGeneralResultIllustrationPointView view)
 {
     return(TypeUtils.GetField <IllustrationPointsControl>(view, "illustrationPointsControl"));
 }