public void ContextMenuStrip_Always_CallsBuilder()
        {
            // Setup
            var mapData = new TestFeatureBasedMapData();
            FeatureBasedMapDataContext context = GetContext(mapData);
            var builder = mocks.StrictMock <IContextMenuBuilder>();

            using (mocks.Ordered())
            {
                builder.Expect(mb => mb.AddCustomItem(Arg <StrictContextMenuItem> .Is.NotNull)).Return(builder);
                builder.Expect(mb => mb.AddSeparator()).Return(builder);
                builder.Expect(mb => mb.AddDeleteItem()).Return(builder);
                builder.Expect(mb => mb.AddSeparator()).Return(builder);
                builder.Expect(mb => mb.AddPropertiesItem()).Return(builder);
                builder.Expect(mb => mb.Build()).Return(null);
            }

            contextMenuBuilderProvider.Expect(p => p.Get(context, null)).Return(builder);

            mocks.ReplayAll();

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

            // Assert
            // Assert expectancies are called in TearDown()
        }
        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 OnNodeRemoved_WithRemovableDataToRemove_DataRemoved()
        {
            // Setup
            var toRemove = mocks.StrictMultiMock <FeatureBasedMapData>(new[]
            {
                typeof(IRemovable)
            }, "name");
            var otherData = mocks.Stub <MapLineData>("name");

            mocks.ReplayAll();

            var collection = new MapDataCollection("collection");

            collection.Add(toRemove);
            collection.Add(otherData);

            FeatureBasedMapDataContext context = GetContext(toRemove, GetContext(collection));

            // Call
            info.OnNodeRemoved(context, context.ParentMapData);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                otherData
            }, collection.Collection);
        }
        public void Image_WithContext_ReturnExpectedImage(FeatureBasedMapData mapData, Image expectedImage)
        {
            // Setup
            FeatureBasedMapDataContext context = GetContext(mapData);

            // Call
            Image image = info.Image(context);

            // Assert
            TestHelper.AssertImagesAreEqual(expectedImage, image);
        }
        public void Text_WithContext_ReturnsNameFromWrappedMapData()
        {
            // Setup
            FeatureBasedMapDataContext context = GetContext(new TestFeatureBasedMapData());

            // Call
            string text = info.Text(context);

            // Assert
            Assert.AreEqual(context.WrappedData.Name, text);
        }
        public void CanRemove_WithNotRemovableData_ReturnFalse()
        {
            // Setup
            var notRemovable = mocks.StrictMock <FeatureBasedMapData>("name");

            mocks.ReplayAll();

            FeatureBasedMapDataContext context = GetContext(notRemovable);

            // Call
            bool canRemove = info.CanRemove(context, context.ParentMapData);

            // Assert
            Assert.IsFalse(canRemove);
        }
        public void CheckedState_WithContext_ReturnsAccordingToVisibleStateOfMapData(bool isVisible)
        {
            // Setup
            FeatureBasedMapDataContext context = GetContext(new TestFeatureBasedMapData());

            context.WrappedData.IsVisible = isVisible;

            // Call
            TreeNodeCheckedState checkedState = info.CheckedState(context);

            // Assert
            TreeNodeCheckedState expectedCheckedState = isVisible ? TreeNodeCheckedState.Checked : TreeNodeCheckedState.Unchecked;

            Assert.AreEqual(expectedCheckedState, checkedState);
        }
        public void CanRemove_WithoutCollection_ReturnFalse()
        {
            // Setup
            var removable = mocks.StrictMultiMock <FeatureBasedMapData>(new[]
            {
                typeof(IRemovable)
            }, "name");

            mocks.ReplayAll();

            FeatureBasedMapDataContext context = GetContext(removable);

            // Call
            bool canRemove = info.CanRemove(context, null);

            // Assert
            Assert.IsFalse(canRemove);
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            FeatureBasedMapData data = new TestFeatureBasedMapData();
            var collection           = new MapDataCollection("test");

            collection.Add(data);

            var collectionContext = new MapDataCollectionContext(collection, null);

            // Call
            var context = new FeatureBasedMapDataContext(data, collectionContext);

            // Assert
            Assert.IsInstanceOf <MapDataContext>(context);
            Assert.AreSame(data, context.WrappedData);
            Assert.AreSame(collectionContext, context.ParentMapData);
        }
        public void OnNodeChecked_WithContext_SetMapDataVisibilityAndNotifyObservers(bool initialVisibleState)
        {
            // Setup
            var observer = mocks.StrictMock <IObserver>();

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

            FeatureBasedMapDataContext context = GetContext(new TestFeatureBasedMapData());

            context.WrappedData.IsVisible = initialVisibleState;

            context.WrappedData.Attach(observer);

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

            // Assert
            Assert.AreEqual(!initialVisibleState, context.WrappedData.IsVisible);
            mocks.VerifyAll();
        }