Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionTreeNodeInfoTest.cs =================================================================== diff -u -r5ef5e3e186036b4985798236624d86b2801b87d3 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionTreeNodeInfoTest.cs (.../AssessmentSectionTreeNodeInfoTest.cs) (revision 5ef5e3e186036b4985798236624d86b2801b87d3) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionTreeNodeInfoTest.cs (.../AssessmentSectionTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -36,7 +36,6 @@ using Ringtoets.Integration.Data.Placeholders; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Plugin; -using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.PresentationObjects; using RingtoetsIntegrationFormsResources = Ringtoets.Integration.Forms.Properties.Resources; @@ -46,36 +45,32 @@ public class AssessmentSectionTreeNodeInfoTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(IAssessmentSection)); } - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(IAssessmentSection), info.TagType); - Assert.IsNull(info.ForeColor); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(IAssessmentSection), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } } [Test] @@ -89,12 +84,16 @@ mocks.ReplayAll(); - // Call - var text = info.Text(assessmentSection); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(testName, text); + // Call + var text = info.Text(assessmentSection); + // Assert + Assert.AreEqual(testName, text); + } mocks.VerifyAll(); } @@ -106,12 +105,16 @@ mocks.ReplayAll(); - // Call - var image = info.Image(assessmentSection); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsIntegrationFormsResources.AssessmentSectionFolderIcon, image); + // Call + var image = info.Image(assessmentSection); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsIntegrationFormsResources.AssessmentSectionFolderIcon, image); + } mocks.VerifyAll(); } @@ -123,12 +126,16 @@ mocks.ReplayAll(); - // Call - var result = info.EnsureVisibleOnCreate(assessmentSection); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.IsTrue(result); + // Call + var result = info.EnsureVisibleOnCreate(assessmentSection); + // Assert + Assert.IsTrue(result); + } mocks.VerifyAll(); } @@ -149,34 +156,37 @@ assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(failureMechanisms); mocks.ReplayAll(); - // Call - var objects = info.ChildNodeObjects(assessmentSection).ToArray(); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + // Call + var objects = info.ChildNodeObjects(assessmentSection).ToArray(); - // Assert - Assert.AreEqual(6, objects.Length); - var referenceLineContext = (ReferenceLineContext) objects[0]; - Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData); - Assert.AreSame(assessmentSection, referenceLineContext.Parent); + // Assert + Assert.AreEqual(6, objects.Length); + var referenceLineContext = (ReferenceLineContext) objects[0]; + Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData); + Assert.AreSame(assessmentSection, referenceLineContext.Parent); - var contributionContext = (FailureMechanismContributionContext)objects[1]; - Assert.AreSame(contribution, contributionContext.WrappedData); - Assert.AreSame(assessmentSection, contributionContext.Parent); + var contributionContext = (FailureMechanismContributionContext) objects[1]; + Assert.AreSame(contribution, contributionContext.WrappedData); + Assert.AreSame(assessmentSection, contributionContext.Parent); - var context = (HydraulicBoundaryDatabaseContext) objects[2]; - Assert.AreSame(assessmentSection.HydraulicBoundaryDatabase, context.Parent.HydraulicBoundaryDatabase); - Assert.AreSame(assessmentSection, context.Parent); + var context = (HydraulicBoundaryDatabaseContext) objects[2]; + Assert.AreSame(assessmentSection.HydraulicBoundaryDatabase, context.Parent.HydraulicBoundaryDatabase); + Assert.AreSame(assessmentSection, context.Parent); - var commentContext = (CommentContext)objects[3]; - Assert.AreSame(assessmentSection, commentContext.CommentContainer); + var commentContext = (CommentContext)objects[3]; + Assert.AreSame(assessmentSection, commentContext.CommentContainer); - var pipingFailureMechanismContext = (PipingFailureMechanismContext)objects[4]; - Assert.AreSame(failureMechanisms[0], pipingFailureMechanismContext.WrappedData); - Assert.AreSame(assessmentSection, pipingFailureMechanismContext.Parent); + var pipingFailureMechanismContext = (PipingFailureMechanismContext) objects[4]; + Assert.AreSame(failureMechanisms[0], pipingFailureMechanismContext.WrappedData); + Assert.AreSame(assessmentSection, pipingFailureMechanismContext.Parent); - var placeholderFailureMechanismContext = (FailureMechanismPlaceholderContext)objects[5]; - Assert.AreSame(failureMechanisms[1], placeholderFailureMechanismContext.WrappedData); - Assert.AreSame(assessmentSection, placeholderFailureMechanismContext.Parent); - + var placeholderFailureMechanismContext = (FailureMechanismPlaceholderContext) objects[5]; + Assert.AreSame(failureMechanisms[1], placeholderFailureMechanismContext.WrappedData); + Assert.AreSame(assessmentSection, placeholderFailureMechanismContext.Parent); + } mocks.VerifyAll(); } @@ -188,6 +198,8 @@ var treeViewControlMock = mocks.StrictMock(); var menuBuilderMock = mocks.StrictMock(); gui.Expect(g => g.Get(null, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); @@ -205,23 +217,32 @@ mocks.ReplayAll(); - plugin.Gui = gui; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + plugin.Gui = gui; - // Call - info.ContextMenuStrip(null, null, treeViewControlMock); - + // Call + info.ContextMenuStrip(null, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } [Test] public void CanRename_Always_ReturnsTrue() { - // Call - var canRename = info.CanRename(null, null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.IsTrue(canRename); + // Call + var canRename = info.CanRename(null, null); + + // Assert + Assert.IsTrue(canRename); + } } [Test] @@ -233,23 +254,32 @@ mocks.ReplayAll(); - // Call - const string newName = "New Name"; - info.OnNodeRenamed(assessmentSection, newName); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + // Call + const string newName = "New Name"; + info.OnNodeRenamed(assessmentSection, newName); - // Assert - Assert.AreEqual(newName, assessmentSection.Name); + // Assert + Assert.AreEqual(newName, assessmentSection.Name); + } mocks.VerifyAll(); } [Test] public void CanRemove_Always_ReturnsTrue() { - // Call - var canRemove = info.CanRemove(null, null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + // Call + var canRemove = info.CanRemove(null, null); - // Assert - Assert.IsTrue(canRemove); + // Assert + Assert.IsTrue(canRemove); + } } [Test] @@ -267,12 +297,22 @@ project.Items.Add(assessmentSection); project.Attach(observerMock); - // Call - info.OnNodeRemoved(assessmentSection, project); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - CollectionAssert.DoesNotContain(project.Items, assessmentSection); + // Call + info.OnNodeRemoved(assessmentSection, project); + + // Assert + CollectionAssert.DoesNotContain(project.Items, assessmentSection); + } mocks.VerifyAll(); } + + private TreeNodeInfo GetInfo(RingtoetsGuiPlugin guiPlugin) + { + return guiPlugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(IAssessmentSection)); + } } } \ No newline at end of file