Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructureContextTreeNodeInfoTest.cs =================================================================== diff -u -r341ddc4bed3bbbae529c1c282d15cc9b593d1e6a -r411592c892cf5e53084fe8a6b8dd9a8c202a6088 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructureContextTreeNodeInfoTest.cs (.../StabilityPointStructureContextTreeNodeInfoTest.cs) (revision 341ddc4bed3bbbae529c1c282d15cc9b593d1e6a) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructureContextTreeNodeInfoTest.cs (.../StabilityPointStructureContextTreeNodeInfoTest.cs) (revision 411592c892cf5e53084fe8a6b8dd9a8c202a6088) @@ -40,44 +40,34 @@ [TestFixture] public class StabilityPointStructureContextTreeNodeInfoTest { - private StabilityPointStructuresPlugin plugin; - private TreeNodeInfo info; - - [SetUp] - public void SetUp() - { - plugin = new StabilityPointStructuresPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(StabilityPointStructureContext)); - } - - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(StabilityPointStructureContext), info.TagType); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.CanRename); - Assert.IsNotNull(info.ChildNodeObjects); - Assert.IsNotNull(info.ContextMenuStrip); - Assert.IsNull(info.EnsureVisibleOnCreate); - Assert.IsNotNull(info.ForeColor); - Assert.IsNotNull(info.Image); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnDrop); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.OnNodeRenamed); - Assert.IsNotNull(info.Text); + // Setup + using (var plugin = new StabilityPointStructuresPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(StabilityPointStructureContext), info.TagType); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.CanRename); + Assert.IsNotNull(info.ChildNodeObjects); + Assert.IsNotNull(info.ContextMenuStrip); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNotNull(info.ForeColor); + Assert.IsNotNull(info.Image); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnDrop); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNotNull(info.Text); + } } [Test] @@ -91,12 +81,17 @@ var context = new StabilityPointStructureContext(new ObservableList(), assessmentSection); - // Call - string text = info.Text(context); + using (var plugin = new StabilityPointStructuresPlugin()) + { + var info = GetInfo(plugin); - // Assert - const string expectedText = "Kunstwerken"; - Assert.AreEqual(expectedText, text); + // Call + string text = info.Text(context); + + // Assert + const string expectedText = "Kunstwerken"; + Assert.AreEqual(expectedText, text); + } mocks.VerifyAll(); } @@ -111,11 +106,16 @@ var context = new StabilityPointStructureContext(new ObservableList(), assessmentSection); - // Call - Image image = info.Image(context); + using (var plugin = new StabilityPointStructuresPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsProperties.GeneralFolderIcon, image); + // Call + Image image = info.Image(context); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsProperties.GeneralFolderIcon, image); + } mocks.VerifyAll(); } @@ -136,12 +136,16 @@ CollectionAssert.IsNotEmpty(structures); var context = new StabilityPointStructureContext(structures, assessmentSection); + using (var plugin = new StabilityPointStructuresPlugin()) + { + var info = GetInfo(plugin); - // Call - Color color = info.ForeColor(context); + // Call + Color color = info.ForeColor(context); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); + } mocks.VerifyAll(); } @@ -162,14 +166,18 @@ }; var context = new StabilityPointStructureContext(closingStructures, assessmentSection); + using (var plugin = new StabilityPointStructuresPlugin()) + { + var info = GetInfo(plugin); - // Call - var children = info.ChildNodeObjects(context); + // Call + var children = info.ChildNodeObjects(context); - // Assert - Assert.AreEqual(2, children.Length); - Assert.AreSame(structure1, children.ElementAt(0)); - Assert.AreSame(structure2, children.ElementAt(1)); + // Assert + Assert.AreEqual(2, children.Length); + Assert.AreSame(structure1, children.ElementAt(0)); + Assert.AreSame(structure2, children.ElementAt(1)); + } mocks.VerifyAll(); } @@ -187,12 +195,16 @@ CollectionAssert.IsEmpty(closingStructures); var context = new StabilityPointStructureContext(closingStructures, assessmentSection); + using (var plugin = new StabilityPointStructuresPlugin()) + { + var info = GetInfo(plugin); - // Call - Color color = info.ForeColor(context); + // Call + Color color = info.ForeColor(context); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); + } mocks.VerifyAll(); } @@ -208,13 +220,15 @@ menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.Build()).Return(null); + using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); gui.Stub(g => g.Get(null, treeViewControl)).Return(menuBuilderMock); mocks.ReplayAll(); plugin.Gui = gui; + var info = GetInfo(plugin); // Call info.ContextMenuStrip(null, null, treeViewControl); @@ -223,6 +237,11 @@ mocks.VerifyAll(); } + private static TreeNodeInfo GetInfo(StabilityPointStructuresPlugin gui) + { + return gui.GetTreeNodeInfos().First(tni => tni.TagType == typeof(StabilityPointStructureContext)); + } + private static StabilityPointStructure CreateStabilityPointStructure() { return new StabilityPointStructure("Name", "Id", new Point2D(1, 2)); Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructureTreeNodeInfoTest.cs =================================================================== diff -u -r341ddc4bed3bbbae529c1c282d15cc9b593d1e6a -r411592c892cf5e53084fe8a6b8dd9a8c202a6088 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructureTreeNodeInfoTest.cs (.../StabilityPointStructureTreeNodeInfoTest.cs) (revision 341ddc4bed3bbbae529c1c282d15cc9b593d1e6a) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructureTreeNodeInfoTest.cs (.../StabilityPointStructureTreeNodeInfoTest.cs) (revision 411592c892cf5e53084fe8a6b8dd9a8c202a6088) @@ -24,7 +24,6 @@ using Core.Common.Controls.TreeView; using Core.Common.TestUtil; using NUnit.Framework; -using Rhino.Mocks; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Plugin; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -34,80 +33,76 @@ [TestFixture] public class StabilityPointStructureTreeNodeInfoTest { - private MockRepository mocks; - private StabilityPointStructuresPlugin plugin; - private TreeNodeInfo info; - - [SetUp] - public void SetUp() - { - mocks = new MockRepository(); - plugin = new StabilityPointStructuresPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(StabilityPointStructure)); - } - - [TearDown] - public void TearDown() - { - plugin.Dispose(); - mocks.VerifyAll(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { // Setup - mocks.ReplayAll(); + using (var plugin = new StabilityPointStructuresPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(typeof(StabilityPointStructure), info.TagType); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.CanRename); - Assert.IsNull(info.ChildNodeObjects); - Assert.IsNull(info.ContextMenuStrip); - Assert.IsNull(info.EnsureVisibleOnCreate); - Assert.IsNull(info.ForeColor); - Assert.IsNotNull(info.Image); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnDrop); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.OnNodeRenamed); - Assert.IsNotNull(info.Text); + // Assert + Assert.AreEqual(typeof(StabilityPointStructure), info.TagType); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.ContextMenuStrip); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.ForeColor); + Assert.IsNotNull(info.Image); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnDrop); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNotNull(info.Text); + } } [Test] public void Text_Always_ReturnNameOfStructure() { // Setup - mocks.ReplayAll(); const string name = "a nice name"; StabilityPointStructure structure = CreateSimpleStabilityPointStructure(name); - // Call - string text = info.Text(structure); + using (var plugin = new StabilityPointStructuresPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(name, text); + // Call + string text = info.Text(structure); + + // Assert + Assert.AreEqual(name, text); + } } [Test] - public void Text_Always_ReturnStructureIcon() + public void Image_Always_ReturnStructureIcon() { // Setup - mocks.ReplayAll(); + using (var plugin = new StabilityPointStructuresPlugin()) + { + var info = GetInfo(plugin); - // Call - var image = info.Image(null); + // Call + var image = info.Image(null); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.StructuresIcon, image); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.StructuresIcon, image); + } } + private static TreeNodeInfo GetInfo(StabilityPointStructuresPlugin gui) + { + return gui.GetTreeNodeInfos().First(tni => tni.TagType == typeof(StabilityPointStructure)); + } + private static StabilityPointStructure CreateSimpleStabilityPointStructure(string name) { return new StabilityPointStructure(name, "1", new Point2D(1, 2));