using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Components.Gis.Features; using Core.Plugins.DotSpatial.Legend; using NUnit.Framework; using Rhino.Mocks; using DotSpatialResources = Core.Plugins.DotSpatial.Properties.Resources; namespace Core.Plugins.DotSpatial.Test.Legend { [TestFixture] public class MapLineDataTreeNodeInfoTest { private MockRepository mocks; private MapLegendView mapLegendView; private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); var contextMenuBuilderProvider = mocks.StrictMock(); var parentWindow = mocks.StrictMock(); mapLegendView = new MapLegendView(contextMenuBuilderProvider, parentWindow); TreeViewControl treeViewControl = TypeUtils.GetField(mapLegendView, "treeViewControl"); Dictionary treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); info = treeNodeInfoLookup[typeof(MapLineData)]; } [TearDown] public void TearDown() { mapLegendView.Dispose(); mocks.VerifyAll(); } [Test] public void Initialized_Always_ExpectedPropertiesSet() { // Setup mocks.ReplayAll(); // Assert Assert.AreEqual(typeof(MapLineData), info.TagType); Assert.IsNull(info.ForeColor); Assert.IsNull(info.ContextMenuStrip); Assert.IsNull(info.EnsureVisibleOnCreate); Assert.IsNull(info.ChildNodeObjects); Assert.IsNull(info.CanRename); Assert.IsNull(info.OnNodeRenamed); Assert.IsNull(info.CanRemove); Assert.IsNull(info.OnNodeRemoved); Assert.IsNull(info.CanDrop); Assert.IsNull(info.CanInsert); Assert.IsNull(info.OnDrop); } [Test] public void Text_Always_ReturnsNameFromMapData() { // Setup var mapLineData = mocks.StrictMock(Enumerable.Empty(), "MapLineData"); mocks.ReplayAll(); // Call var text = info.Text(mapLineData); // Assert Assert.AreEqual(mapLineData.Name, text); } [Test] public void Image_Always_ReturnsImageFromResource() { // Setup mocks.ReplayAll(); // Call var image = info.Image(null); // Assert TestHelper.AssertImagesAreEqual(DotSpatialResources.LineIcon, image); } [Test] public void CanCheck_Always_ReturnsTrue() { // Setup var lineData = mocks.StrictMock(Enumerable.Empty(), "test data"); mocks.ReplayAll(); // Call var canCheck = info.CanCheck(lineData); // Assert Assert.IsTrue(canCheck); } [TestCase(true)] [TestCase(false)] public void IsChecked_Always_ReturnsAccordingToVisibleStateOfLineData(bool isVisible) { // Setup var lineData = mocks.StrictMock(Enumerable.Empty(), "test data"); lineData.IsVisible = isVisible; mocks.ReplayAll(); // Call var canCheck = info.IsChecked(lineData); // Assert Assert.AreEqual(isVisible, canCheck); } [TestCase(true)] [TestCase(false)] public void OnNodeChecked_LineDataNodeWithoutParent_SetsLineDataVisibility(bool initialVisibleState) { // Setup var lineData = mocks.StrictMock(Enumerable.Empty(), "test data"); mocks.ReplayAll(); lineData.IsVisible = initialVisibleState; // Call info.OnNodeChecked(lineData, null); // Assert Assert.AreEqual(!initialVisibleState, lineData.IsVisible); } [TestCase(true)] [TestCase(false)] public void OnNodeChecked_LineDataNodeWithObservableParent_SetsLineDataVisibilityAndNotifiesParentObservers(bool initialVisibleState) { // Setup var observable = mocks.StrictMock(); observable.Expect(o => o.NotifyObservers()); var lineData = mocks.StrictMock(Enumerable.Empty(), "test data"); mocks.ReplayAll(); lineData.IsVisible = initialVisibleState; // Call info.OnNodeChecked(lineData, observable); // Assert Assert.AreEqual(!initialVisibleState, lineData.IsVisible); } [Test] public void CanDrag_Always_ReturnsTrue() { // Setup var lineData = mocks.StrictMock(Enumerable.Empty(), "test data"); mocks.ReplayAll(); // Call var canDrag = info.CanDrag(lineData, null); // Assert Assert.IsTrue(canDrag); } } }