public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenSpecificFailureMechanismRemovedAndNotified_ThenAttachedObserverNotNotified()
        {
            // Given
            var failureMechanismToRemove        = new SpecificFailureMechanism();
            AssessmentSection assessmentSection = CreateAssessmentSection();

            assessmentSection.SpecificFailureMechanisms.AddRange(new[]
            {
                failureMechanismToRemove,
                new SpecificFailureMechanism()
            });

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

                assessmentSection.SpecificFailureMechanisms.Remove(failureMechanismToRemove);
                assessmentSection.SpecificFailureMechanisms.NotifyObservers();

                resultObserver.Attach(observer);

                // When
                failureMechanismToRemove.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
        public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenSpecificFailureMechanismInCollectionNotified_ThenAttachedObserverNotified()
        {
            // Given
            var specificFailureMechanism = new SpecificFailureMechanism();

            AssessmentSection assessmentSection = CreateAssessmentSection();

            assessmentSection.SpecificFailureMechanisms.Add(specificFailureMechanism);

            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
                specificFailureMechanism.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
Пример #3
0
        public void GivenFormWithAssemblyResultTotalView_WhenSpecificFailureMechanismNotifiesObservers_ThenRefreshButtonEnabledAndWarningSet()
        {
            // Given
            var failureMechanism = new SpecificFailureMechanism();
            AssessmentSection assessmentSection = CreateAssessmentSection();

            assessmentSection.SpecificFailureMechanisms.Add(failureMechanism);

            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
                failureMechanism.NotifyObservers();

                // Then
                Assert.IsTrue(buttonTester.Properties.Enabled);
                Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));
            }
        }
        public void GivenViewWithSpecificFailureMechanismData_WhenFailureMechanismNameUpdatedAndNotified_ThenMapDataUpdatedAndObserversNotified()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            var assessmentSection = new AssessmentSectionStub();
            var failureMechanism  = new SpecificFailureMechanism();

            SpecificFailureMechanismView view    = CreateView(failureMechanism, assessmentSection);
            MapDataCollection            mapData = view.Map.Data;

            mapData.Attach(observer);

            // Precondition
            Assert.AreEqual(failureMechanism.Name, mapData.Name);

            // When
            const string newFailureMechanismName = "New Failure Mechanism Name";

            failureMechanism.Name = newFailureMechanismName;
            failureMechanism.NotifyObservers();

            // Then
            Assert.AreEqual(newFailureMechanismName, mapData.Name);
            mocks.VerifyAll();
        }
        public void GivenViewWithFailureMechanismSectionData_WhenFailureMechanismsUpdatedAndNotified_ThenMapDataUpdatedAndObserversNotified()
        {
            // Given
            var assessmentSection = new AssessmentSectionStub();
            var failureMechanism  = new SpecificFailureMechanism();

            SpecificFailureMechanismView view = CreateView(failureMechanism, assessmentSection);

            IEnumerable <MapData> mapDataCollection  = view.Map.Data.Collection;
            IEnumerable <MapData> sectionsCollection = ((MapDataCollection)mapDataCollection.ElementAt(sectionsCollectionIndex)).Collection;
            var sectionMapData       = (MapLineData)sectionsCollection.ElementAt(sectionsIndex);
            var sectionStartsMapData = (MapPointData)sectionsCollection.ElementAt(sectionsStartPointIndex);
            var sectionsEndsMapData  = (MapPointData)sectionsCollection.ElementAt(sectionsEndPointIndex);

            var mocks = new MockRepository();

            IObserver[] observers = AttachMapDataObservers(mocks, mapDataCollection);
            observers[sectionsCollectionIndex + sectionsIndex].Expect(obs => obs.UpdateObserver());
            observers[sectionsCollectionIndex + sectionsStartPointIndex].Expect(obs => obs.UpdateObserver());
            observers[sectionsCollectionIndex + sectionsEndPointIndex].Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            // When
            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                new FailureMechanismSection(string.Empty, new[]
                {
                    new Point2D(1, 2),
                    new Point2D(1, 2)
                })
            });
            failureMechanism.NotifyObservers();

            // Then
            MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionMapData);
            MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionStartsMapData);
            MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsEndsMapData);
            mocks.VerifyAll();
        }