Exemple #1
0
        public void DoPostImportUpdates_CancelingImport_DoNotNotifyObserversAndNotDoPostReplacementUpdates()
        {
            // Setup
            string        path          = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, "traject_10-2.shp");
            ReferenceLine referenceLine = ReferenceLineTestFactory.CreateReferenceLineWithGeometry();

            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            var handler  = mocks.StrictMock <IReferenceLineUpdateHandler>();
            var importer = new ReferenceLineImporter(referenceLine, handler, path);

            handler.Expect(h => h.ConfirmUpdate())
            .WhenCalled(invocation => importer.Cancel())
            .Return(true);

            mocks.ReplayAll();

            referenceLine.Attach(observer);

            // Precondition
            Assert.IsFalse(importer.Import());

            // Call
            importer.DoPostImport();

            // Assert
            mocks.VerifyAll(); // Expect no NotifyObserver calls
        }
Exemple #2
0
        public void DoPostImportUpdates_ReuseImporterWithReferenceLineAndAnswerDialogToContinue_NotifyObserversOfTargetAndClearedObjects()
        {
            // Setup
            string path          = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp"));
            var    referenceLine = new ReferenceLine();

            var mocks = new MockRepository();
            var referenceLineObserver = mocks.Stub <IObserver>();

            referenceLineObserver.Expect(o => o.UpdateObserver());

            var observable1 = mocks.StrictMock <IObservable>();

            observable1.Expect(o => o.NotifyObservers());
            var observable2 = mocks.StrictMock <IObservable>();

            observable2.Expect(o => o.NotifyObservers());

            var handler = mocks.Stub <IReferenceLineUpdateHandler>();

            handler.Expect(h => h.Update(Arg <ReferenceLine> .Is.Same(referenceLine),
                                         Arg <ReferenceLine> .Is.NotNull))
            .Return(new[]
            {
                observable1,
                observable2
            });
            handler.Expect(h => h.DoPostUpdateActions());

            mocks.ReplayAll();

            referenceLine.Attach(referenceLineObserver);

            var importer = new ReferenceLineImporter(referenceLine, handler, path);

            importer.SetProgressChanged((description, step, steps) => importer.Cancel());

            // Precondition
            Assert.IsFalse(importer.Import());

            importer.SetProgressChanged(null);
            Assert.IsTrue(importer.Import());

            // Call
            importer.DoPostImport();

            // Assert
            mocks.VerifyAll(); // Expect NotifyObservers on cleared calculations
        }