public void OnDrop_MapDataCollectionContextMovedToPositionOutsideRange_ThrowsException(int position)
        {
            // Setup
            var observer = mocks.StrictMock <IObserver>();

            mocks.ReplayAll();

            var mapDataCollection1      = new MapDataCollection("Collection 1");
            var mapDataCollection2      = new MapDataCollection("Collection 2");
            var mapDataCollection3      = new MapDataCollection("Collection 3");
            var parentMapDataCollection = new MapDataCollection("test data");

            parentMapDataCollection.Add(mapDataCollection1);
            parentMapDataCollection.Add(mapDataCollection2);
            parentMapDataCollection.Add(mapDataCollection3);

            parentMapDataCollection.Attach(observer);

            MapDataCollectionContext parentContext = GetContext(parentMapDataCollection);
            MapDataCollectionContext context       = GetContext(mapDataCollection1);

            parentMapDataCollection.Attach(observer);

            using (var treeViewControl = new TreeViewControl())
            {
                // Call
                TestDelegate test = () => info.OnDrop(context, parentContext, parentContext, position, treeViewControl);

                // Assert
                Assert.Throws <ArgumentOutOfRangeException>(test);
            }
        }
        public void OnNodeChecked_WithContext_NotifyObserversOfParentMapDataCollections()
        {
            // Setup
            var collectionObserver = mocks.StrictMock <IObserver>();

            collectionObserver.Expect(o => o.UpdateObserver());
            var parentCollectionObserver = mocks.StrictMock <IObserver>();

            parentCollectionObserver.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var featureBasedMapData     = new TestFeatureBasedMapData();
            var nestedMapDataCollection = new MapDataCollection("nested");

            nestedMapDataCollection.Add(featureBasedMapData);
            var mapDataCollection = new MapDataCollection("test");

            mapDataCollection.Add(nestedMapDataCollection);

            MapDataCollectionContext   rootCollectionContext      = GetContext(mapDataCollection);
            MapDataCollectionContext   nestedCollectionContext    = GetContext(nestedMapDataCollection, rootCollectionContext);
            FeatureBasedMapDataContext featureBasedMapDataContext = GetContext(featureBasedMapData, nestedCollectionContext);

            nestedMapDataCollection.Attach(collectionObserver);
            mapDataCollection.Attach(parentCollectionObserver);

            // Call
            info.OnNodeChecked(featureBasedMapDataContext, null);

            // Assert
            mocks.VerifyAll();
        }
        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 OnDrop_MapDataCollectionContextMovedToPositionInsideRange_SetsNewReverseOrder(int position)
        {
            // Setup
            var observer = mocks.StrictMock <IObserver>();

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

            var mapDataCollection1      = new MapDataCollection("Collection 1");
            var mapDataCollection2      = new MapDataCollection("Collection 2");
            var mapDataCollection3      = new MapDataCollection("Collection 3");
            var parentMapDataCollection = new MapDataCollection("test data");

            parentMapDataCollection.Add(mapDataCollection1);
            parentMapDataCollection.Add(mapDataCollection2);
            parentMapDataCollection.Add(mapDataCollection3);

            MapDataCollectionContext parentContext = GetContext(parentMapDataCollection);
            MapDataCollectionContext context       = GetContext(mapDataCollection1);

            parentMapDataCollection.Attach(observer);

            using (var treeViewControl = new TreeViewControl())
            {
                // Call
                info.OnDrop(context, parentContext, parentContext, position, treeViewControl);

                // Assert
                int reversedIndex = 2 - position;
                Assert.AreSame(context.WrappedData, parentMapDataCollection.Collection.ElementAt(reversedIndex));
            }
        }
        public void OnNodeChecked_WithContext_NotifyObserversOfChangedChildrenOnly(bool initialVisibility, int expectedNotifications)
        {
            // Setup
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver()).Repeat.Times(expectedNotifications);
            mocks.ReplayAll();

            var featureBasedMapData1 = new TestFeatureBasedMapData();
            var featureBasedMapData2 = new TestFeatureBasedMapData
            {
                IsVisible = initialVisibility
            };
            var featureBasedMapData3 = new TestFeatureBasedMapData
            {
                IsVisible = initialVisibility
            };
            var nestedMapDataCollection = new MapDataCollection("nested");

            nestedMapDataCollection.Add(featureBasedMapData1);
            nestedMapDataCollection.Add(featureBasedMapData3);

            var mapDataCollection = new MapDataCollection("test");

            mapDataCollection.Add(nestedMapDataCollection);
            mapDataCollection.Add(featureBasedMapData2);

            MapDataCollectionContext context = GetContext(mapDataCollection);

            nestedMapDataCollection.Attach(observer);
            featureBasedMapData1.Attach(observer);
            featureBasedMapData2.Attach(observer);
            featureBasedMapData3.Attach(observer);

            // Call
            info.OnNodeChecked(context, null);

            // Assert
            mocks.VerifyAll();
        }
        public void DoPostImportUpdates_ImportSuccessful_NotifiesMapDataCollection()
        {
            // Setup
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

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

            string path = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, "Single_Point_with_ID.shp");
            var    mapDataCollection = new MapDataCollection("test");

            mapDataCollection.Attach(observer);
            var importer = new FeatureBasedMapDataImporter(mapDataCollection, path);

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

            // Call
            importer.DoPostImport();

            // Assert
            mocks.VerifyAll();
        }