public void GivenAssessmentSectionWithPipingFailureMechanismReplaced_WhenNewPipingScenarioConfigurationsPerFailureMechanismSectionNotified_ThenAssessmentSectionResultObserverNotified()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSection();

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                var newFailureMechanism = new PipingFailureMechanism();
                FailureMechanismTestHelper.SetSections(newFailureMechanism, new[]
                {
                    FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1")
                });

                assessmentSection.Piping = newFailureMechanism;
                assessmentSection.NotifyObservers();

                resultObserver.Attach(observer);

                // When
                newFailureMechanism.ScenarioConfigurationsPerFailureMechanismSection.First().NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
Exemplo n.º 2
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));
                }
            }
        }
        public void GivenAssessmentSectionWithFailureMechanismsReplaced_WhenNewFailureMechanismNotified_ThenAssessmentSectionResultObserverNotified <TFailureMechanism>(
            AssessmentSection assessmentSection, Func <AssessmentSection, TFailureMechanism> getFailureMechanismFunc, Action setNewFailureMechanismAction)
            where TFailureMechanism : IFailureMechanism
        {
            // Given
            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                setNewFailureMechanismAction();
                assessmentSection.NotifyObservers();

                resultObserver.Attach(observer);

                TFailureMechanism newFailureMechanism = getFailureMechanismFunc(assessmentSection);

                // When
                newFailureMechanism.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
Exemplo n.º 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));
                }
        }
Exemplo n.º 5
0
        public void GivenFormWithAssemblyResultPerSectionView_WhenSpecificFailureMechanismRemoved_ThenColumnRemoved()
        {
            // Given
            var random = new Random(21);
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                random.NextEnumValue <AssessmentSectionComposition>());

            using (new AssemblyToolCalculatorFactoryConfig())
                using (ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    // Precondition
                    DataGridView dataGridView = GetDataGridView();

                    DataGridViewColumnCollection dataGridViewColumns = dataGridView.Columns;
                    AssertColumns(dataGridViewColumns, GetExpectedNrOfColumns(assessmentSection), assessmentSection.SpecificFailureMechanisms);

                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();

                    // When
                    SpecificFailureMechanism failureMechanismToRemove = assessmentSection.SpecificFailureMechanisms.First();
                    assessmentSection.SpecificFailureMechanisms.Remove(failureMechanismToRemove);
                    assessmentSection.NotifyObservers();
                    buttonTester.Click();

                    // Then
                    AssertColumns(dataGridViewColumns, GetExpectedNrOfColumns(assessmentSection), assessmentSection.SpecificFailureMechanisms);
                }
        }
        public void UpdateObserver_AssessmentSectionUpdated_MapDataUpdated()
        {
            // Setup
            AssessmentSection assessmentSection = CreateAssessmentSectionWithReferenceLine();

            using (var view = new AssemblyResultPerSectionMapView(assessmentSection))
            {
                IMapControl map = GetMapControl(view);

                var         mocks     = new MockRepository();
                IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
                observers[referenceLineIndex].Expect(obs => obs.UpdateObserver());
                observers[assemblyResultsObserverIndex].Expect(obs => obs.UpdateObserver());
                mocks.ReplayAll();

                var referenceLineMapData = (MapLineData)map.Data.Collection.ElementAt(referenceLineIndex);

                // Precondition
                MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features);
                AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);

                // Call
                assessmentSection.Name = "New name";
                assessmentSection.NotifyObservers();

                // Assert
                MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features);
                mocks.VerifyAll();
            }
        }
        public void GivenViewWithAssemblyResults_WhenAssessmentSectionNotifiesObserver_ThenAssemblyResultsRefreshed()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSectionWithReferenceLine();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                AssessmentSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator;
                calculator.CombinedFailureMechanismSectionAssemblyOutput = new CombinedFailureMechanismSectionAssemblyResultWrapper(
                    new[]
                {
                    CombinedFailureMechanismSectionAssemblyTestFactory.Create(assessmentSection, 10)
                }, AssemblyMethod.BOI3A1, AssemblyMethod.BOI3B1, AssemblyMethod.BOI3C1);

                using (var view = new AssemblyResultPerSectionMapView(assessmentSection))
                {
                    // Precondition
                    MapDataCollection mapData = view.Map.Data;

                    var         mocks     = new MockRepository();
                    IObserver[] observers = AttachMapDataObservers(mocks, mapData.Collection);
                    observers[assemblyResultsObserverIndex].Expect(obs => obs.UpdateObserver());
                    observers[referenceLineIndex].Expect(obs => obs.UpdateObserver());
                    mocks.ReplayAll();

                    IEnumerable <CombinedFailureMechanismSectionAssemblyResult> expectedResults =
                        AssessmentSectionAssemblyFactory.AssembleCombinedPerFailureMechanismSection(assessmentSection);

                    AssertCombinedFailureMechanismSectionAssemblyResultMapData(expectedResults,
                                                                               assessmentSection.ReferenceLine,
                                                                               mapData.Collection.ElementAt(assemblyResultsIndex));

                    // When
                    calculator.CombinedFailureMechanismSectionAssemblyOutput = new CombinedFailureMechanismSectionAssemblyResultWrapper(
                        new[]
                    {
                        CombinedFailureMechanismSectionAssemblyTestFactory.Create(assessmentSection, 20)
                    }, AssemblyMethod.BOI3A1, AssemblyMethod.BOI3B1, AssemblyMethod.BOI3C1);
                    assessmentSection.NotifyObservers();

                    // Then
                    expectedResults = AssessmentSectionAssemblyFactory.AssembleCombinedPerFailureMechanismSection(assessmentSection);
                    AssertCombinedFailureMechanismSectionAssemblyResultMapData(expectedResults,
                                                                               assessmentSection.ReferenceLine,
                                                                               mapData.Collection.ElementAt(assemblyResultsIndex));
                    mocks.VerifyAll();
                }
            }
        }
        public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenAssessmentSectionNotified_ThenAttachedObserverNotified()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSection();

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                resultObserver.Attach(observer);

                // When
                assessmentSection.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
Exemplo n.º 9
0
        public void GivenFormWithAssemblyResultTotalView_WhenAssessmentSectionNotifiesObservers_ThenRefreshButtonEnabledAndWarningSet()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSection();

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

                // When
                assessmentSection.NotifyObservers();

                // Then
                Assert.IsTrue(buttonTester.Properties.Enabled);
                Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));
            }
        }