示例#1
0
        public void GivenFormWithAssemblyResultPerSectionView_WithOrWithoutErrorSetAndObserverNotified_ThenWarningSetWithPadding(bool withError, int expectedPadding)
        {
            // Given
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                new Random(21).NextEnumValue <AssessmentSectionComposition>());

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                AssessmentSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator;
                calculator.ThrowExceptionOnCalculate = withError;

                using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    // Precondition
                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();
                    Button       button       = buttonTester.Properties;
                    Assert.IsFalse(button.Enabled);
                    ErrorProvider errorProvider = GetErrorProvider(view);
                    Assert.AreEqual(withError, !string.IsNullOrEmpty(errorProvider.GetError(button)));
                    ErrorProvider warningProvider = GetWarningProvider(view);
                    Assert.IsEmpty(warningProvider.GetError(button));

                    // When
                    assessmentSection.NotifyObservers();

                    // Then
                    Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));
                    Assert.AreEqual(expectedPadding, warningProvider.GetIconPadding(button));
                }
            }
        }
示例#2
0
        public void GivenFormWithAssemblyResultPerSectionView_WhenCalculationNotifiesObservers_ThenRefreshButtonEnabledAndWarningSet()
        {
            // Given
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                new Random(21).NextEnumValue <AssessmentSectionComposition>());
            var calculation = new TestHeightStructuresCalculationScenario();

            assessmentSection.HeightStructures.CalculationsGroup.Children.Add(calculation);

            using (new AssemblyToolCalculatorFactoryConfig())
                using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    // Precondition
                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();
                    Button       button       = buttonTester.Properties;
                    Assert.IsFalse(button.Enabled);
                    ErrorProvider warningProvider = GetWarningProvider(view);
                    Assert.IsEmpty(warningProvider.GetError(button));

                    // When
                    calculation.NotifyObservers();

                    // Then
                    Assert.IsTrue(buttonTester.Properties.Enabled);
                    Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));
                }
        }
示例#3
0
        public void GivenFormWithAssemblyResultPerSectionView_WhenFailureMechanismNotifiesObservers_ThenRefreshButtonEnabledAndWarningSet()
        {
            // Given
            var random = new Random(21);
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                random.NextEnumValue <AssessmentSectionComposition>());

            using (new AssemblyToolCalculatorFactoryConfig())
                using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    // Precondition
                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();
                    Button       button       = buttonTester.Properties;
                    Assert.IsFalse(button.Enabled);
                    ErrorProvider warningProvider = GetWarningProvider(view);
                    Assert.IsEmpty(warningProvider.GetError(button));

                    // When
                    IFailureMechanism[] failureMechanisms = assessmentSection.GetFailureMechanisms().ToArray();
                    failureMechanisms[random.Next(failureMechanisms.Length)].NotifyObservers();

                    // Then
                    Assert.IsTrue(buttonTester.Properties.Enabled);
                    Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));
                }
        }
示例#4
0
        public void GivenFormWithAssemblyResultPerSectionViewWithOutdatedContent_WhenRefreshingAssemblyResults_ThenRefreshButtonDisabledAndWarningCleared()
        {
            // Given
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                new Random(21).NextEnumValue <AssessmentSectionComposition>());

            using (new AssemblyToolCalculatorFactoryConfig())
                using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    assessmentSection.NotifyObservers();

                    // Precondition
                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();
                    Button       button       = buttonTester.Properties;
                    Assert.IsTrue(button.Enabled);
                    ErrorProvider warningProvider = GetWarningProvider(view);
                    Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));

                    // When
                    buttonTester.Click();

                    // Then
                    Assert.IsFalse(button.Enabled);
                    Assert.IsEmpty(warningProvider.GetError(button));
                }
        }
示例#5
0
        private AssemblyResultPerSectionView ShowAssemblyResultPerSectionView(AssessmentSection assessmentSection)
        {
            var view = new AssemblyResultPerSectionView(assessmentSection);

            testForm.Controls.Add(view);
            testForm.Show();

            return(view);
        }
        public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue()
        {
            // Setup
            var random            = new Random(21);
            var assessmentSection = new AssessmentSection(random.NextEnumValue <AssessmentSectionComposition>());

            using (var view = new AssemblyResultPerSectionView(assessmentSection))
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsTrue(closeForData);
            }
        }
示例#7
0
        public void Constructor_WithAssessmentSection_ExpectedValues()
        {
            // Setup
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                new Random(21).NextEnumValue <AssessmentSectionComposition>());

            // Call
            using (new AssemblyToolCalculatorFactoryConfig())
                using (var view = new AssemblyResultPerSectionView(assessmentSection))
                {
                    testForm.Controls.Add(view);
                    testForm.Show();

                    // Assert
                    Assert.AreEqual(2, view.Controls.Count);

                    var button = (Button)GetRefreshAssemblyResultButtonTester().TheObject;
                    Assert.AreEqual("Resultaten verversen", button.Text);
                    Assert.IsFalse(button.Enabled);

                    ErrorProvider errorProvider = GetErrorProvider(view);
                    TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ErrorIcon.ToBitmap(), errorProvider.Icon.ToBitmap());
                    Assert.AreEqual(ErrorBlinkStyle.NeverBlink, errorProvider.BlinkStyle);
                    Assert.IsEmpty(errorProvider.GetError(button));
                    Assert.AreEqual(4, errorProvider.GetIconPadding(button));

                    ErrorProvider warningProvider = GetWarningProvider(view);
                    TestHelper.AssertImagesAreEqual(CoreGuiResources.warning.ToBitmap(), warningProvider.Icon.ToBitmap());
                    Assert.AreEqual(ErrorBlinkStyle.NeverBlink, warningProvider.BlinkStyle);
                    Assert.IsEmpty(warningProvider.GetError(button));
                    Assert.AreEqual(4, warningProvider.GetIconPadding(button));

                    Assert.IsInstanceOf <IView>(view);
                    Assert.IsInstanceOf <UserControl>(view);
                    Assert.IsNull(view.Data);
                    Assert.AreEqual(new Size(300, 250), view.AutoScrollMinSize);
                    Assert.AreSame(assessmentSection, view.AssessmentSection);
                }
        }
示例#8
0
 private static ErrorProvider GetWarningProvider(AssemblyResultPerSectionView resultControl)
 {
     return(TypeUtils.GetField <ErrorProvider>(resultControl, "warningProvider"));
 }
示例#9
0
 private static ErrorProvider GetErrorProvider(AssemblyResultPerSectionView resultView)
 {
     return(TypeUtils.GetField <ErrorProvider>(resultView, "errorProvider"));
 }