Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/GeneralResultFaultTreeIllustrationPointViewTest.cs =================================================================== diff -u -r2ee0d42baed610a91cad9f08a8e7bfa3141e6afd -rb6f754b7aaeb3e00f88aac3fcccd96cd412d4d12 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/GeneralResultFaultTreeIllustrationPointViewTest.cs (.../GeneralResultFaultTreeIllustrationPointViewTest.cs) (revision 2ee0d42baed610a91cad9f08a8e7bfa3141e6afd) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/GeneralResultFaultTreeIllustrationPointViewTest.cs (.../GeneralResultFaultTreeIllustrationPointViewTest.cs) (revision b6f754b7aaeb3e00f88aac3fcccd96cd412d4d12) @@ -24,8 +24,8 @@ using System.Linq; using System.Windows.Forms; using Core.Common.Controls.Views; -using Core.Common.TestUtil; using Core.Common.Utils.Reflection; +using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.Calculation; @@ -39,6 +39,20 @@ [TestFixture] public class GeneralResultFaultTreeIllustrationPointViewTest { + private Form testForm; + + [SetUp] + public void Setup() + { + testForm = new Form(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + } + [Test] public void Constructor_GetGeneralResultFuncNull_ThrowsArgumentNullException() { @@ -296,29 +310,26 @@ Enumerable.Empty(), Enumerable.Empty()))); - using (var view = new GeneralResultFaultTreeIllustrationPointView(() => new GeneralResult( - WindDirectionTestFactory.CreateTestWindDirection(), - Enumerable.Empty(), - new List - { - topLevelFaultTreeIllustrationPoint1, - topLevelFaultTreeIllustrationPoint2 - }))) - { - WindowsFormsTestHelper.Show(view); + var view = new GeneralResultFaultTreeIllustrationPointView(() => new GeneralResult( + WindDirectionTestFactory.CreateTestWindDirection(), + Enumerable.Empty(), + new List + { + topLevelFaultTreeIllustrationPoint1, + topLevelFaultTreeIllustrationPoint2 + })); - var selectionChangedCounter = 0; - view.SelectionChanged += (sender, args) => selectionChangedCounter++; + ShowTestView(view); - // Call - view.Data = data; + var selectionChangedCounter = 0; + view.SelectionChanged += (sender, args) => selectionChangedCounter++; - // Assert - Assert.AreNotEqual(0, selectionChangedCounter); - Assert.AreSame(topLevelFaultTreeIllustrationPoint1, view.Selection); - } + // Call + view.Data = data; - WindowsFormsTestHelper.CloseAll(); + // Assert + Assert.AreNotEqual(0, selectionChangedCounter); + Assert.AreSame(topLevelFaultTreeIllustrationPoint1, view.Selection); mocks.VerifyAll(); } @@ -332,32 +343,93 @@ mocks.ReplayAll(); - using (var view = new GeneralResultFaultTreeIllustrationPointView(() => new GeneralResult( - WindDirectionTestFactory.CreateTestWindDirection(), - Enumerable.Empty(), - Enumerable.Empty()))) + var view = new GeneralResultFaultTreeIllustrationPointView(() => new GeneralResult( + WindDirectionTestFactory.CreateTestWindDirection(), + Enumerable.Empty(), + Enumerable.Empty())); + + ShowTestView(view); + + var selectionChangedCounter = 0; + view.SelectionChanged += (sender, args) => selectionChangedCounter++; + + // Call + view.Data = data; + + // Assert + Assert.AreEqual(0, selectionChangedCounter); + Assert.IsNull(view.Selection); + + mocks.VerifyAll(); + } + + [Test] + public void GivenFullyConfiguredView_WhenSelectingCellInRow_SelectionChangePropagatedAccordingly() + { + // Setup + var mocks = new MockRepository(); + var data = mocks.Stub(); + + mocks.ReplayAll(); + + var topLevelFaultTreeIllustrationPoint1 = + new TopLevelFaultTreeIllustrationPoint( + WindDirectionTestFactory.CreateTestWindDirection(), + "Closing situation 1", + new IllustrationPointNode(new FaultTreeIllustrationPoint("Fault tree illustration point", + 1.1, + Enumerable.Empty(), + CombinationType.And))); + + var topLevelFaultTreeIllustrationPoint2 = + new TopLevelFaultTreeIllustrationPoint( + WindDirectionTestFactory.CreateTestWindDirection(), + "Closing situation 2", + new IllustrationPointNode(new SubMechanismIllustrationPoint("Sub mechanism illustration point", + 2.2, + Enumerable.Empty(), + Enumerable.Empty()))); + + var view = new GeneralResultFaultTreeIllustrationPointView(() => new GeneralResult( + WindDirectionTestFactory.CreateTestWindDirection(), + Enumerable.Empty(), + new List + { + topLevelFaultTreeIllustrationPoint1, + topLevelFaultTreeIllustrationPoint2 + })) { - var selectionChangedCounter = 0; - view.SelectionChanged += (sender, args) => selectionChangedCounter++; + Data = data + }; - WindowsFormsTestHelper.Show(view); + ShowTestView(view); - // Call - view.Data = data; + var selectionChangedCounter = 0; + view.SelectionChanged += (sender, args) => selectionChangedCounter++; - // Assert - Assert.AreEqual(0, selectionChangedCounter); - Assert.IsNull(view.Selection); - } + DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView"); - WindowsFormsTestHelper.CloseAll(); + // When + dataGridView.CurrentCell = dataGridView.Rows[1].Cells[0]; + EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0)); + + // Assert + Assert.AreNotEqual(0, selectionChangedCounter); + Assert.AreSame(topLevelFaultTreeIllustrationPoint2, view.Selection); + mocks.VerifyAll(); } private static GeneralResultFaultTreeIllustrationPointView GetValidView() { return new GeneralResultFaultTreeIllustrationPointView(() => new TestGeneralResultFaultTreeIllustrationPoint()); } + + private void ShowTestView(GeneralResultFaultTreeIllustrationPointView view) + { + testForm.Controls.Add(view); + testForm.Show(); + } } } \ No newline at end of file