Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -149,7 +149,7 @@ { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + var assessmentSection = new AssessmentSectionStub(); var parent = new CalculationGroup(); var calculation = new StructuresCalculation(); var nodeData = new ClosingStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); @@ -372,7 +372,7 @@ public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateStructureClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestClosingStructure(); var parent = new CalculationGroup(); var calculation = new StructuresCalculation @@ -418,7 +418,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructureClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestClosingStructure(); var parent = new CalculationGroup(); var calculation = new StructuresCalculation @@ -479,7 +479,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructureClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestClosingStructure(); var parent = new CalculationGroup(); var calculation = new StructuresCalculation @@ -609,48 +609,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemPerformCalculationAndValidationDisabledAndTooltipSet() - { - // Setup - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - var assessmentSection = mocks.Stub(); - var parent = new CalculationGroup(); - var calculation = new StructuresCalculation(); - var failureMechanism = new ClosingStructuresFailureMechanism(); - var nodeData = new ClosingStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); - - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - using (var treeViewControl = new TreeViewControl()) - { - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); - mocks.ReplayAll(); - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, - "Be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateIcon, - false); - - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, - "&Valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemPerformCalculationAndValidationEnabled() { // Setup @@ -951,7 +909,7 @@ } [Test] - public void GivenCalculationThatSucceeds_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() + public void GivenValidCalculation_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() { // Given var mainWindow = mocks.Stub(); Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -559,63 +559,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet() - { - // Setup - var group = new CalculationGroup - { - Children = - { - new StructuresCalculation() - } - }; - - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - var nodeData = new ClosingStructuresCalculationGroupContext(group, - null, - failureMechanism, - assessmentSection); - - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - using (var treeViewControl = new TreeViewControl()) - { - gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - gui.Stub(g => g.MainWindow).Return(mocks.Stub()); - mocks.ReplayAll(); - - // Call - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup, - "Alles be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateAllIcon, - false); - - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup, - "Alles &valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateAllIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllAndValidateAllEnabled() { // Setup @@ -850,13 +793,14 @@ CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]); StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[4]); CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[5]); - Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[6]); - CalculationServiceTestHelper.AssertValidationStartMessage(messageList[7]); - CalculationServiceTestHelper.AssertValidationEndMessage(messageList[8]); - CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[9]); - StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[10]); - CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[11]); - Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[12]); + Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[6]); + + Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[7]); + CalculationServiceTestHelper.AssertValidationStartMessage(messageList[8]); + CalculationServiceTestHelper.AssertValidationEndMessage(messageList[9]); + CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[10]); + StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[11]); + CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[12]); Assert.AreEqual("Uitvoeren van berekening 'B' is gelukt.", messageList[13]); }); } @@ -980,7 +924,7 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var group = new CalculationGroup(); var failureMechanism = new ClosingStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new ClosingStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1065,7 +1009,7 @@ }; var failureMechanism = new ClosingStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new ClosingStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1109,7 +1053,7 @@ }; var failureMechanism = new ClosingStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new ClosingStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1154,7 +1098,7 @@ }; var failureMechanism = new ClosingStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new ClosingStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1184,7 +1128,7 @@ public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateStructuresClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestClosingStructure(); var calculation = new StructuresCalculation { @@ -1231,7 +1175,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructuresClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestClosingStructure(); var calculation = new StructuresCalculation { @@ -1292,7 +1236,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructuresClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestClosingStructure(); var calculation = new StructuresCalculation { @@ -1356,7 +1300,7 @@ // Given using (var treeViewControl = new TreeViewControl()) { - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); ClosingStructure structure1 = new TestClosingStructure("Structure 1"); ClosingStructure structure2 = new TestClosingStructure("Structure 2"); @@ -1479,7 +1423,7 @@ // Given using (var treeViewControl = new TreeViewControl()) { - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); const string existingCalculationName = "Closing structure"; ClosingStructure closingStructure = new TestClosingStructure("id", existingCalculationName); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -149,7 +149,7 @@ { // Setup var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var assessmentSection = mocks.Stub(); + var assessmentSection = new AssessmentSectionStub(); var parent = new CalculationGroup(); var calculation = new GrassCoverErosionInwardsCalculation(); var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, parent, failureMechanism, assessmentSection); @@ -375,7 +375,7 @@ public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateDikeProfileClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); var parent = new CalculationGroup(); var calculation = new GrassCoverErosionInwardsCalculation @@ -424,7 +424,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateDikeProfileClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); var parent = new CalculationGroup(); var calculation = new GrassCoverErosionInwardsCalculation @@ -487,7 +487,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateDikeProfileClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); var parent = new CalculationGroup(); @@ -612,44 +612,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemPerformCalculationDisabledAndTooltipSet() - { - // Setup - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - var assessmentSection = mocks.Stub(); - var parent = new CalculationGroup(); - var calculation = new GrassCoverErosionInwardsCalculation(); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, parent, failureMechanism, assessmentSection); - - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - using (var treeViewControl = new TreeViewControl()) - { - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - mocks.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, - "Be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemPerformCalculationEnabled() { // Setup @@ -750,44 +712,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemValidateCalculationDisabledAndTooltipSet() - { - // Setup - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - var assessmentSection = mocks.Stub(); - var parent = new CalculationGroup(); - var calculation = new GrassCoverErosionInwardsCalculation(); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, parent, failureMechanism, assessmentSection); - - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - using (var treeViewControl = new TreeViewControl()) - { - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - mocks.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, - "&Valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemValidateCalculationEnabled() { // Setup @@ -825,7 +749,7 @@ } [Test] - public void GivenCalculationThatSucceeds_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() + public void GivenValidCalculation_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() { // Given var mainWindow = mocks.DynamicMock(); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -333,6 +333,7 @@ // Call info.ContextMenuStrip(groupContext, parentGroupContext, treeViewControl); } + // Assert // Assert expectancies are called in TearDown() } @@ -534,7 +535,7 @@ }; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, null, failureMechanism, @@ -579,7 +580,7 @@ }; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, null, failureMechanism, @@ -625,7 +626,7 @@ }; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, null, failureMechanism, @@ -694,7 +695,7 @@ group.Children.Add(emptyChildGroup); group.Children.Add(calculation2); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, null, @@ -768,7 +769,7 @@ group.Children.Add(emptyChildGroup); group.Children.Add(calculation2); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, null, @@ -860,7 +861,7 @@ group.Children.Add(emptyChildGroup); group.Children.Add(calculation2); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, null, @@ -960,56 +961,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAllDisabledAndTooltipSet() - { - // Setup - var group = new CalculationGroup - { - Children = - { - new GrassCoverErosionInwardsCalculation() - } - }; - - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation()); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, - null, - failureMechanism, - assessmentSection); - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - using (var treeViewControl = new TreeViewControl()) - { - gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - - mocks.ReplayAll(); - - // Call - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup, - "Alles be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateAllIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllEnabled() { // Setup @@ -1167,56 +1118,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemValidateAllDisabledAndTooltipSet() - { - // Setup - var group = new CalculationGroup - { - Children = - { - new GrassCoverErosionInwardsCalculation() - } - }; - - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation()); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, - null, - failureMechanism, - assessmentSection); - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - using (var treeViewControl = new TreeViewControl()) - { - gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - - mocks.ReplayAll(); - - // Call - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup, - "Alles &valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateAllIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemValidateAllEnabled() { // Setup @@ -1480,13 +1381,14 @@ CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]); StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", messageList[4]); CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[5]); - Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[6]); - CalculationServiceTestHelper.AssertValidationStartMessage(messageList[7]); - CalculationServiceTestHelper.AssertValidationEndMessage(messageList[8]); - CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[9]); - StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", messageList[10]); - CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[11]); - Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[12]); + Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[6]); + + Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[7]); + CalculationServiceTestHelper.AssertValidationStartMessage(messageList[8]); + CalculationServiceTestHelper.AssertValidationEndMessage(messageList[9]); + CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[10]); + StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", messageList[11]); + CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[12]); Assert.AreEqual("Uitvoeren van berekening 'B' is gelukt.", messageList[13]); }); } @@ -1547,7 +1449,7 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var group = new CalculationGroup(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, null, failureMechanism, @@ -1591,9 +1493,8 @@ public void GivenCalculationsViewGenerateScenariosButtonClicked_WhenDikeProfileSelectedAndDialogClosed_ThenCalculationsAddedWithProfileAssigned() { // Given + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); - var assessmentSection = mocks.Stub(); - DikeProfile dikeProfile1 = DikeProfileTestFactory.CreateDikeProfile("Dike profile 1", "id1"); DikeProfile dikeProfile2 = DikeProfileTestFactory.CreateDikeProfile("Dike profile 2", "id2"); @@ -1719,9 +1620,8 @@ public void GivenScenariosWithExistingCalculationWithSameName_WhenOkButtonClickedAndDialogClosed_ThenCalculationWithUniqueNameAdded() { // Given + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); - var assessmentSection = mocks.Stub(); - const string existingCalculationName = "Dike profile"; DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(existingCalculationName); Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -72,7 +72,7 @@ public void SetUp() { mockRepository = new MockRepository(); - assessmentSection = mockRepository.StrictMock(); + assessmentSection = mockRepository.Stub(); } [Test] Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -148,7 +148,7 @@ { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + var assessmentSection = new AssessmentSectionStub(); var parent = new CalculationGroup(); var calculation = new StructuresCalculation(); var nodeData = new HeightStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); @@ -386,7 +386,7 @@ public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateStructureClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestHeightStructure(); var parent = new CalculationGroup(); var calculation = new StructuresCalculation @@ -435,7 +435,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructureClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestHeightStructure(); var parent = new CalculationGroup(); var calculation = new StructuresCalculation @@ -498,7 +498,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructureClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestHeightStructure(); var parent = new CalculationGroup(); var calculation = new StructuresCalculation @@ -624,45 +624,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemPerformCalculationDisabledAndTooltipSet() - { - // Setup - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - var failureMechanism = new HeightStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); - var parent = new CalculationGroup(); - var calculation = new StructuresCalculation(); - var nodeData = new HeightStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); - - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - using (var treeViewControl = new TreeViewControl()) - { - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); - mocks.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, - "Be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemPerformCalculationEnabled() { // Setup @@ -766,45 +727,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemValidateCalculationDisabledAndTooltipSet() - { - // Setup - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - var assessmentSection = mocks.Stub(); - var parent = new CalculationGroup(); - var calculation = new StructuresCalculation(); - var failureMechanism = new HeightStructuresFailureMechanism(); - var nodeData = new HeightStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); - - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - using (var treeViewControl = new TreeViewControl()) - { - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); - mocks.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, - "&Valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemValidateCalculationEnabled() { // Setup @@ -978,7 +900,7 @@ var calculationInputObserver = mocks.StrictMock(); calculationInputObserver.Expect(o => o.UpdateObserver()); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new HeightStructuresFailureMechanism(); var foreshoreProfileInput = new TestForeshoreProfile(true); @@ -1107,7 +1029,7 @@ } [Test] - public void GivenCalculationThatSucceeds_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() + public void GivenValidCalculation_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() { // Given var mainWindow = mocks.DynamicMock(); Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -550,57 +550,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAllDisabledAndTooltipSet() - { - // Setup - var group = new CalculationGroup - { - Children = - { - new StructuresCalculation() - } - }; - - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - - var failureMechanism = new HeightStructuresFailureMechanism(); - failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - var nodeData = new HeightStructuresCalculationGroupContext(group, - null, - failureMechanism, - assessmentSection); - - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - using (var treeViewControl = new TreeViewControl()) - { - gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); - gui.Stub(g => g.MainWindow).Return(mocks.Stub()); - mocks.ReplayAll(); - - // Call - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup, - "Alles be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateAllIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllEnabled() { // Setup @@ -740,57 +689,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemValidateAllDisabledAndTooltipSet() - { - // Setup - var group = new CalculationGroup - { - Children = - { - new StructuresCalculation() - } - }; - - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - - var failureMechanism = new HeightStructuresFailureMechanism(); - failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - var nodeData = new HeightStructuresCalculationGroupContext(group, - null, - failureMechanism, - assessmentSection); - - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - using (var treeViewControl = new TreeViewControl()) - { - gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); - gui.Stub(g => g.MainWindow).Return(mocks.Stub()); - mocks.ReplayAll(); - - // Call - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup, - "Alles &valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateAllIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemValidateAllEnabled() { // Setup @@ -1019,13 +917,14 @@ CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]); StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[4]); CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[5]); - Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[6]); - CalculationServiceTestHelper.AssertValidationStartMessage(messageList[7]); - CalculationServiceTestHelper.AssertValidationEndMessage(messageList[8]); - CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[9]); - StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[10]); - CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[11]); - Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[12]); + Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[6]); + + Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[7]); + CalculationServiceTestHelper.AssertValidationStartMessage(messageList[8]); + CalculationServiceTestHelper.AssertValidationEndMessage(messageList[9]); + CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[10]); + StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[11]); + CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[12]); Assert.AreEqual("Uitvoeren van berekening 'B' is gelukt.", messageList[13]); }); } @@ -1149,7 +1048,7 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var group = new CalculationGroup(); var failureMechanism = new HeightStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new HeightStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1234,7 +1133,7 @@ }; var failureMechanism = new HeightStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new HeightStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1278,7 +1177,7 @@ }; var failureMechanism = new HeightStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new HeightStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1323,7 +1222,7 @@ }; var failureMechanism = new HeightStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new HeightStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1353,7 +1252,7 @@ public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateStructuresClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestHeightStructure(); var calculation = new StructuresCalculation { @@ -1400,7 +1299,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructuresClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestHeightStructure(); var calculation = new StructuresCalculation { @@ -1461,7 +1360,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructuresClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestHeightStructure(); var calculation = new StructuresCalculation { @@ -1525,7 +1424,7 @@ // Given using (var treeViewControl = new TreeViewControl()) { - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); HeightStructure structure1 = new TestHeightStructure("Structure Id", "Structure 1"); @@ -1594,7 +1493,7 @@ // Given using (var treeViewControl = new TreeViewControl()) { - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.HeightStructures.AddRange( @@ -1646,7 +1545,7 @@ // Given using (var treeViewControl = new TreeViewControl()) { - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); const string existingCalculationName = "Height structure"; HeightStructure heightStructure = new TestHeightStructure("heightStructureId", existingCalculationName); @@ -1785,7 +1684,7 @@ { // Setup var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new HeightStructuresFailureMechanism(); var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -556,63 +556,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet() - { - // Setup - using (var treeViewControl = new TreeViewControl()) - { - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - var assessmentSection = new AssessmentSectionStub(); - var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); - - assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] - { - hydraulicBoundaryLocation - }, true); - - var group = new CalculationGroup - { - Children = - { - MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation) - } - }; - - var nodeData = new MacroStabilityInwardsCalculationGroupContext(group, - null, - Enumerable.Empty(), - Enumerable.Empty(), - failureMechanism, - assessmentSection); - - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - mocks.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, failureMechanism, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndexRootGroup, - "Alles be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateAllIcon, - false); - - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndexRootGroup, - "Alles &valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateAllIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllAndValidateAllEnabled() { // Setup @@ -876,13 +819,13 @@ hydraulicBoundaryLocation }, true); - MacroStabilityInwardsCalculationScenario validCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation); - validCalculation.Name = "A"; - MacroStabilityInwardsCalculationScenario invalidCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput(); - invalidCalculation.Name = "B"; + MacroStabilityInwardsCalculationScenario calculationA = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation); + calculationA.Name = "A"; + MacroStabilityInwardsCalculationScenario calculationB = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation); + calculationB.Name = "B"; var childGroup = new CalculationGroup(); - childGroup.Children.Add(validCalculation); + childGroup.Children.Add(calculationA); var emptyChildGroup = new CalculationGroup(); @@ -891,7 +834,7 @@ group.Children.Add(childGroup); group.Children.Add(emptyChildGroup); - group.Children.Add(invalidCalculation); + group.Children.Add(calculationB); var failureMechanism = new TestMacroStabilityInwardsFailureMechanism(); var nodeData = new MacroStabilityInwardsCalculationGroupContext(group, @@ -916,6 +859,7 @@ plugin.Gui = gui; + using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { DialogBoxHandler = (name, wnd) => @@ -924,11 +868,29 @@ }; // Call - contextMenu.Items[contextMenuCalculateAllIndexNestedGroup].PerformClick(); + Action call = () => contextMenu.Items[contextMenuCalculateAllIndexNestedGroup].PerformClick(); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(12, msgs.Length); + Assert.AreEqual("Uitvoeren van berekening 'A' is gestart.", msgs[0]); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[4]); + Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", msgs[5]); + + Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", msgs[6]); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[7]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[8]); + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[9]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[10]); + Assert.AreEqual("Uitvoeren van berekening 'B' is gelukt.", msgs[11]); + }); } } - - // Assert } [Test] @@ -1124,7 +1086,7 @@ new Point3D(5.0, -5.0, 0.0) }); - var surfaceLines = new[] + MacroStabilityInwardsSurfaceLine[] surfaceLines = { surfaceLine1, surfaceLine2 @@ -1233,7 +1195,7 @@ new Point3D(5.0, -5.0, 0.0) }); - var surfaceLines = new[] + MacroStabilityInwardsSurfaceLine[] surfaceLines = { surfaceLine1, surfaceLine2 Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -221,50 +221,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAndValidateDisabledAndTooltipSet() - { - // Setup - using (var treeViewControl = new TreeViewControl()) - { - var calculation = new MacroStabilityInwardsCalculationScenario(); - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - var assessmentSection = mocks.Stub(); - var nodeData = new MacroStabilityInwardsCalculationScenarioContext(calculation, - new CalculationGroup(), - Enumerable.Empty(), - Enumerable.Empty(), - failureMechanism, - assessmentSection); - - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - mocks.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - - TestHelper.AssertContextMenuStripContainsItem(contextMenu, - contextMenuValidateIndex, - "&Valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateIcon, - false); - - TestHelper.AssertContextMenuStripContainsItem(contextMenu, - contextMenuCalculateIndex, - "Be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAndValidateEnabled() { // Setup Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -570,63 +570,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet() - { - // Setup - using (var treeViewControl = new TreeViewControl()) - { - var pipingFailureMechanism = new PipingFailureMechanism(); - var assessmentSection = new AssessmentSectionStub(); - var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); - - assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] - { - hydraulicBoundaryLocation - }, true); - - var group = new CalculationGroup - { - Children = - { - PipingCalculationScenarioTestFactory.CreatePipingCalculationScenarioWithValidInput(hydraulicBoundaryLocation) - } - }; - - var nodeData = new PipingCalculationGroupContext(group, - null, - Enumerable.Empty(), - Enumerable.Empty(), - pipingFailureMechanism, - assessmentSection); - - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - mocks.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, pipingFailureMechanism, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndexRootGroup, - "Alles be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateAllIcon, - false); - - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndexRootGroup, - "Alles &valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateAllIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllAndValidateAllEnabled() { // Setup @@ -1064,13 +1007,13 @@ hydraulicBoundaryLocation }, true); - PipingCalculationScenario validCalculation = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenarioWithValidInput(hydraulicBoundaryLocation); - validCalculation.Name = "A"; - PipingCalculationScenario invalidCalculation = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenarioWithInvalidInput(); - invalidCalculation.Name = "B"; + PipingCalculationScenario calculationA = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenarioWithValidInput(hydraulicBoundaryLocation); + calculationA.Name = "A"; + PipingCalculationScenario calculationB = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenarioWithValidInput(hydraulicBoundaryLocation); + calculationB.Name = "B"; var childGroup = new CalculationGroup(); - childGroup.Children.Add(validCalculation); + childGroup.Children.Add(calculationA); var emptyChildGroup = new CalculationGroup(); @@ -1079,7 +1022,7 @@ group.Children.Add(childGroup); group.Children.Add(emptyChildGroup); - group.Children.Add(invalidCalculation); + group.Children.Add(calculationB); var nodeData = new PipingCalculationGroupContext(group, parentGroup, @@ -1111,11 +1054,29 @@ }; // Call - contextMenu.Items[contextMenuCalculateAllIndexNestedGroup].PerformClick(); + Action call = () => contextMenu.Items[contextMenuCalculateAllIndexNestedGroup].PerformClick(); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(12, msgs.Length); + Assert.AreEqual("Uitvoeren van berekening 'A' is gestart.", msgs[0]); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[4]); + Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", msgs[5]); + + Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", msgs[6]); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[7]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[8]); + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[9]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[10]); + Assert.AreEqual("Uitvoeren van berekening 'B' is gelukt.", msgs[11]); + }); } } - - // Assert } [Test] @@ -1310,7 +1271,7 @@ new Point3D(5.0, -5.0, 0.0) }); - var surfaceLines = new[] + PipingSurfaceLine[] surfaceLines = { surfaceLine1, surfaceLine2 @@ -1424,7 +1385,7 @@ new Point3D(5.0, -5.0, 0.0) }); - var surfaceLines = new[] + PipingSurfaceLine[] surfaceLines = { surfaceLine1, surfaceLine2 Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -256,50 +256,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAndValidateDisabledAndTooltipSet() - { - // Setup - using (var treeViewControl = new TreeViewControl()) - { - var calculation = new PipingCalculationScenario(new GeneralPipingInput()); - var pipingFailureMechanism = new PipingFailureMechanism(); - var assessmentSection = mocks.Stub(); - var nodeData = new PipingCalculationScenarioContext(calculation, - new CalculationGroup(), - Enumerable.Empty(), - Enumerable.Empty(), - pipingFailureMechanism, - assessmentSection); - - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - mocks.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - - TestHelper.AssertContextMenuStripContainsItem(contextMenu, - contextMenuValidateIndex, - "&Valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateIcon, - false); - - TestHelper.AssertContextMenuStripContainsItem(contextMenu, - contextMenuCalculateIndex, - "Be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAndValidateEnabled() { // Setup Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -147,7 +147,7 @@ { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + var assessmentSection = new AssessmentSectionStub(); var parent = new CalculationGroup(); var calculation = new StructuresCalculation(); var nodeData = new StabilityPointStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); @@ -588,51 +588,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemPerformCalculationAndValidationDisabledAndTooltipSet() - { - // Setup - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - var assessmentSection = mocks.Stub(); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var parent = new CalculationGroup(); - var calculation = new StructuresCalculation(); - var nodeData = new StabilityPointStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); - - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - using (var treeViewControl = new TreeViewControl()) - { - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); - mocks.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, - "Be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateIcon, - false); - - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, - "&Valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemPerformCalculationAndValidationEnabled() { // Setup @@ -940,7 +895,7 @@ } [Test] - public void GivenCalculationThatSucceeds_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() + public void GivenValidCalculation_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() { // Given var mainWindow = mocks.Stub(); Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rea7fd6455177ea93f8419e6a29fc00d1d3167359 -rb7c9234daf5a52422362a7cb3fa1f46a86df63bb --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision ea7fd6455177ea93f8419e6a29fc00d1d3167359) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -428,63 +428,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet() - { - // Setup - var group = new CalculationGroup - { - Children = - { - new StructuresCalculation() - } - }; - - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase - { - FilePath = validFilePath, - Version = "1.0" - }); - - var nodeData = new StabilityPointStructuresCalculationGroupContext(group, - null, - failureMechanism, - assessmentSection); - - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - using (var treeViewControl = new TreeViewControl()) - { - gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); - gui.Stub(g => g.MainWindow).Return(mocks.Stub()); - mocks.ReplayAll(); - - // Call - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup, - "Alles be&rekenen", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.CalculateAllIcon, - false); - - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup, - "Alles &valideren", - "De bijdrage van dit toetsspoor is nul.", - RingtoetsCommonFormsResources.ValidateAllIcon, - false); - } - } - } - - [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllAndValidateAllEnabled() { // Setup @@ -712,7 +655,7 @@ } }; - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new StabilityPointStructuresFailureMechanism(); var nodeData = new StabilityPointStructuresCalculationGroupContext(group, null, @@ -751,7 +694,7 @@ } }; - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new StabilityPointStructuresFailureMechanism(); var nodeData = new StabilityPointStructuresCalculationGroupContext(group, null, @@ -791,7 +734,7 @@ } }; - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new StabilityPointStructuresFailureMechanism(); var nodeData = new StabilityPointStructuresCalculationGroupContext(group, null, @@ -820,7 +763,7 @@ public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateStructuresClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestStabilityPointStructure(); var calculation1Observer = mocks.StrictMock(); @@ -902,7 +845,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructuresClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestStabilityPointStructure(); var calculation1Observer = mocks.StrictMock(); @@ -990,7 +933,7 @@ public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructuresClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified() { // Given - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var structure = new TestStabilityPointStructure(); var calculation1Observer = mocks.StrictMock(); @@ -1083,7 +1026,7 @@ public void ContextMenuStrip_CalculationGroupWithCalculationWithForeshoreProfileAndInputOutOfSync_ContextMenuItemUpdateForeshoreProfilesEnabledAndToolTipSet() { // Setup - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new StabilityPointStructuresFailureMechanism(); var calculation = new StructuresCalculation { @@ -1136,7 +1079,7 @@ var calculationInputObserver = mocks.StrictMock(); calculationInputObserver.Expect(o => o.UpdateObserver()); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var failureMechanism = new StabilityPointStructuresFailureMechanism(); var calculation = new StructuresCalculation @@ -1190,7 +1133,7 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var group = new CalculationGroup(); var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new StabilityPointStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1237,7 +1180,7 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var group = new CalculationGroup(); var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var nodeData = new StabilityPointStructuresCalculationGroupContext(group, null, failureMechanism, @@ -1359,13 +1302,14 @@ CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]); StringAssert.StartsWith("Puntconstructies berekening is uitgevoerd op de tijdelijke locatie", messageList[4]); CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[5]); - Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[6]); - CalculationServiceTestHelper.AssertValidationStartMessage(messageList[7]); - CalculationServiceTestHelper.AssertValidationEndMessage(messageList[8]); - CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[9]); - StringAssert.StartsWith("Puntconstructies berekening is uitgevoerd op de tijdelijke locatie", messageList[10]); - CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[11]); - Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[12]); + Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[6]); + + Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[7]); + CalculationServiceTestHelper.AssertValidationStartMessage(messageList[8]); + CalculationServiceTestHelper.AssertValidationEndMessage(messageList[9]); + CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[10]); + StringAssert.StartsWith("Puntconstructies berekening is uitgevoerd op de tijdelijke locatie", messageList[11]); + CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[12]); Assert.AreEqual("Uitvoeren van berekening 'B' is gelukt.", messageList[13]); }); } @@ -1446,7 +1390,7 @@ // Given using (var treeViewControl = new TreeViewControl()) { - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); StabilityPointStructure structure1 = new TestStabilityPointStructure("id structure1"); StabilityPointStructure structure2 = new TestStabilityPointStructure("id structure2"); @@ -1518,7 +1462,7 @@ // Given using (var treeViewControl = new TreeViewControl()) { - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); StabilityPointStructure structure1 = new TestStabilityPointStructure("id structure1"); StabilityPointStructure structure2 = new TestStabilityPointStructure("id structure2"); @@ -1573,7 +1517,7 @@ // Given using (var treeViewControl = new TreeViewControl()) { - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); const string existingCalculationName = "StabilityPoint structure"; StabilityPointStructure stabilityPointStructure = new TestStabilityPointStructure("id", existingCalculationName); @@ -1676,7 +1620,7 @@ { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var assessmentSection = mocks.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); var nodeData = new StabilityPointStructuresCalculationGroupContext(group, Index: Ringtoets/Storage/src/Ringtoets.Storage.Core/Read/FailureMechanismEntityReadExtensions.cs =================================================================== diff -u --- Ringtoets/Storage/src/Ringtoets.Storage.Core/Read/FailureMechanismEntityReadExtensions.cs (revision 0) +++ Ringtoets/Storage/src/Ringtoets.Storage.Core/Read/FailureMechanismEntityReadExtensions.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,1121 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base.Data; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.DuneErosion.Data; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.HeightStructures.Data; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.Piping.Data; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.Read.ClosingStructures; +using Ringtoets.Storage.Core.Read.DuneErosion; +using Ringtoets.Storage.Core.Read.GrassCoverErosionInwards; +using Ringtoets.Storage.Core.Read.GrassCoverErosionOutwards; +using Ringtoets.Storage.Core.Read.HeightStructures; +using Ringtoets.Storage.Core.Read.MacroStabilityInwards; +using Ringtoets.Storage.Core.Read.MacroStabilityOutwards; +using Ringtoets.Storage.Core.Read.Piping; +using Ringtoets.Storage.Core.Read.PipingStructure; +using Ringtoets.Storage.Core.Read.StabilityPointStructures; +using Ringtoets.Storage.Core.Read.StabilityStoneCover; +using Ringtoets.Storage.Core.Read.WaveImpactAsphaltCover; +using Ringtoets.WaveImpactAsphaltCover.Data; + +namespace Ringtoets.Storage.Core.Read +{ + /// + /// This class defines extension methods for read operations for a based on the + /// . + /// + internal static class FailureMechanismEntityReadExtensions + { + /// + /// Read the and use the information to update a . + /// + /// The to read into a . + /// The target of the read operation. + /// The object keeping track of read operations. + internal static void ReadCommonFailureMechanismProperties(this FailureMechanismEntity entity, + IFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + failureMechanism.IsRelevant = Convert.ToBoolean(entity.IsRelevant); + failureMechanism.InputComments.Body = entity.InputComments; + failureMechanism.OutputComments.Body = entity.OutputComments; + failureMechanism.NotRelevantComments.Body = entity.NotRelevantComments; + + entity.ReadFailureMechanismSections(failureMechanism, collector); + } + + private static void ReadFailureMechanismSections(this FailureMechanismEntity entity, + IFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + FailureMechanismSection[] readFailureMechanismSections = entity.FailureMechanismSectionEntities + .Select(failureMechanismSectionEntity => + failureMechanismSectionEntity.Read(collector)) + .ToArray(); + failureMechanism.AddSections(readFailureMechanismSections); + } + + private static void ReadForeshoreProfiles(this FailureMechanismEntity entity, + ForeshoreProfileCollection foreshoreProfiles, + string foreshoreProfileSourcePath, + ReadConversionCollector collector) + { + if (foreshoreProfileSourcePath != null) + { + foreshoreProfiles.AddRange(entity.ForeshoreProfileEntities + .OrderBy(fpe => fpe.Order) + .Select(foreshoreProfileEntity => foreshoreProfileEntity.Read(collector)) + .ToArray(), + foreshoreProfileSourcePath); + } + } + + #region Piping + + /// + /// Read the and use the information to update a . + /// + /// The to read into a . + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when any input parameter is null. + /// Thrown when expected table entries cannot be found. + internal static void ReadAsPipingFailureMechanism(this FailureMechanismEntity entity, + PipingFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (collector == null) + { + throw new ArgumentNullException(nameof(collector)); + } + + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + + PipingFailureMechanismMetaEntity metaEntity = entity.PipingFailureMechanismMetaEntities.Single(); + metaEntity.ReadProbabilityAssessmentInput(failureMechanism.PipingProbabilityAssessmentInput); + metaEntity.ReadGeneralPipingInput(failureMechanism.GeneralInput); + + string stochasticSoilModelCollectionSourcePath = metaEntity.StochasticSoilModelCollectionSourcePath; + if (stochasticSoilModelCollectionSourcePath != null) + { + failureMechanism.StochasticSoilModels.AddRange(entity.StochasticSoilModelEntities + .OrderBy(ssm => ssm.Order) + .Select(e => e.ReadAsPipingStochasticSoilModel(collector)) + .ToArray(), + stochasticSoilModelCollectionSourcePath); + } + + string surfaceLineCollectionSourcePath = metaEntity.SurfaceLineCollectionSourcePath; + if (surfaceLineCollectionSourcePath != null) + { + failureMechanism.SurfaceLines.AddRange(entity.SurfaceLineEntities + .OrderBy(sl => sl.Order) + .Select(e => e.ReadAsPipingSurfaceLine(collector)) + .ToArray(), + surfaceLineCollectionSourcePath); + } + + entity.ReadPipingMechanismSectionResults(failureMechanism, collector); + + ReadPipingRootCalculationGroup(entity.CalculationGroupEntity, failureMechanism.CalculationsGroup, + failureMechanism.GeneralInput, collector); + } + + private static void ReadPipingMechanismSectionResults(this FailureMechanismEntity entity, + PipingFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (PipingSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.PipingSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + PipingFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + private static void ReadPipingRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, + GeneralPipingInput generalPipingInput, + ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsPipingCalculationGroup(collector, generalPipingInput); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + + #endregion + + #region Grass Cover Erosion Inwards + + /// + /// Read the and use the information to update a . + /// + /// The to read into a . + /// The target of the read operation. + /// The object keeping track of read operations. + internal static void ReadAsGrassCoverErosionInwardsFailureMechanism(this FailureMechanismEntity entity, + GrassCoverErosionInwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadGeneralGrassCoverErosionInwardsCalculationInput(failureMechanism.GeneralInput); + entity.ReadDikeProfiles(failureMechanism.DikeProfiles, collector); + ReadGrassCoverErosionInwardsRootCalculationGroup(entity.CalculationGroupEntity, failureMechanism.CalculationsGroup, collector); + entity.ReadGrassCoverErosionInwardsMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadGeneralGrassCoverErosionInwardsCalculationInput(this FailureMechanismEntity entity, + GeneralGrassCoverErosionInwardsInput input) + { + entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single().Read(input); + } + + private static void ReadDikeProfiles(this FailureMechanismEntity entity, DikeProfileCollection dikeProfiles, ReadConversionCollector collector) + { + if (entity.DikeProfileEntities.Any()) + { + GrassCoverErosionInwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single(); + string sourcePath = metaEntity.DikeProfileCollectionSourcePath; + + dikeProfiles.AddRange(entity.DikeProfileEntities + .OrderBy(dp => dp.Order) + .Select(dp => dp.Read(collector)) + .ToArray(), + sourcePath); + } + } + + private static void ReadGrassCoverErosionInwardsMechanismSectionResults(this FailureMechanismEntity entity, + GrassCoverErosionInwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (GrassCoverErosionInwardsSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverErosionInwardsSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + GrassCoverErosionInwardsFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result, collector); + } + } + + private static void ReadGrassCoverErosionInwardsRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, + ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsGrassCoverErosionInwardsCalculationGroup(collector); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + + #endregion + + #region Height Structures + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when expected table entries could not be found.> + internal static void ReadAsHeightStructuresFailureMechanism(this FailureMechanismEntity entity, + HeightStructuresFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + HeightStructuresFailureMechanismMetaEntity metaEntity = entity.HeightStructuresFailureMechanismMetaEntities.Single(); + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadHeightStructuresMechanismSectionResults(failureMechanism, collector); + entity.ReadForeshoreProfiles(failureMechanism.ForeshoreProfiles, metaEntity.ForeshoreProfileCollectionSourcePath, collector); + entity.ReadHeightStructures(failureMechanism.HeightStructures, metaEntity.HeightStructureCollectionSourcePath, collector); + entity.ReadGeneralInput(failureMechanism.GeneralInput); + ReadHeightStructuresRootCalculationGroup(entity.CalculationGroupEntity, failureMechanism.CalculationsGroup, collector); + } + + private static void ReadHeightStructuresMechanismSectionResults(this FailureMechanismEntity entity, + HeightStructuresFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (HeightStructuresSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.HeightStructuresSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + HeightStructuresFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result, collector); + } + } + + private static void ReadHeightStructures(this FailureMechanismEntity entity, + StructureCollection heightStructures, + string sourcePath, + ReadConversionCollector collector) + { + if (sourcePath != null) + { + heightStructures.AddRange(entity.HeightStructureEntities + .OrderBy(fpe => fpe.Order) + .Select(structureEntity => structureEntity.Read(collector)) + .ToArray(), + sourcePath); + } + } + + private static void ReadGeneralInput(this FailureMechanismEntity entity, GeneralHeightStructuresInput generalInput) + { + GeneralHeightStructuresInput generalHeightStructuresInput = entity.HeightStructuresFailureMechanismMetaEntities.First().Read(); + generalInput.N = generalHeightStructuresInput.N; + } + + private static void ReadHeightStructuresRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, + ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsHeightStructuresCalculationGroup(collector); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + + #endregion + + #region Strength Stability Lengthwise Construction + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + internal static void ReadAsStrengthStabilityLengthwiseConstructionFailureMechanism(this FailureMechanismEntity entity, + StrengthStabilityLengthwiseConstructionFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadStrengthStabilityLengthwiseConstructionMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadStrengthStabilityLengthwiseConstructionMechanismSectionResults(this FailureMechanismEntity entity, + StrengthStabilityLengthwiseConstructionFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (StrengthStabilityLengthwiseConstructionSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.StrengthStabilityLengthwiseConstructionSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + #endregion + + #region Technical Innovation + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + internal static void ReadAsTechnicalInnovationFailureMechanism(this FailureMechanismEntity entity, + TechnicalInnovationFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadTechnicalInnovationMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadTechnicalInnovationMechanismSectionResults(this FailureMechanismEntity entity, + TechnicalInnovationFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (TechnicalInnovationSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.TechnicalInnovationSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + TechnicalInnovationFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + #endregion + + #region Water Pressure Asphalt + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + internal static void ReadAsWaterPressureAsphaltCoverFailureMechanism(this FailureMechanismEntity entity, + WaterPressureAsphaltCoverFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadWaterPressureAsphaltCoverMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadWaterPressureAsphaltCoverMechanismSectionResults(this FailureMechanismEntity entity, + WaterPressureAsphaltCoverFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (WaterPressureAsphaltCoverSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.WaterPressureAsphaltCoverSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + WaterPressureAsphaltCoverFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + #endregion + + #region Closing Structures + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when expected table entries cannot be found. + internal static void ReadAsClosingStructuresFailureMechanism(this FailureMechanismEntity entity, + ClosingStructuresFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadClosingStructuresMechanismSectionResults(failureMechanism, collector); + + ClosingStructuresFailureMechanismMetaEntity metaEntity = entity.ClosingStructuresFailureMechanismMetaEntities.Single(); + + entity.ReadForeshoreProfiles(failureMechanism.ForeshoreProfiles, + metaEntity.ForeshoreProfileCollectionSourcePath, + collector); + entity.ReadClosingStructures(failureMechanism.ClosingStructures, + metaEntity.ClosingStructureCollectionSourcePath, collector); + + entity.ReadGeneralInput(failureMechanism.GeneralInput); + ReadClosingStructuresRootCalculationGroup(entity.CalculationGroupEntity, failureMechanism.CalculationsGroup, collector); + } + + private static void ReadClosingStructuresMechanismSectionResults(this FailureMechanismEntity entity, + ClosingStructuresFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (ClosingStructuresSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.ClosingStructuresSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + ClosingStructuresFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result, collector); + } + } + + private static void ReadGeneralInput(this FailureMechanismEntity entity, GeneralClosingStructuresInput generalInput) + { + GeneralClosingStructuresInput generalClosingStructuresInput = entity.ClosingStructuresFailureMechanismMetaEntities.First().Read(); + generalInput.N2A = generalClosingStructuresInput.N2A; + } + + private static void ReadClosingStructures(this FailureMechanismEntity entity, + StructureCollection closingStructures, + string sourcePath, + ReadConversionCollector collector) + { + if (sourcePath != null) + { + closingStructures.AddRange(entity.ClosingStructureEntities + .OrderBy(fpe => fpe.Order) + .Select(structureEntity => structureEntity.Read(collector)) + .ToArray(), + sourcePath); + } + } + + private static void ReadClosingStructuresRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, + ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsClosingStructuresCalculationGroup(collector); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + + #endregion + + #region MacroStability Inwards + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when any input parameter is null. + /// Thrown when expected table entries could not be found. + internal static void ReadAsMacroStabilityInwardsFailureMechanism(this FailureMechanismEntity entity, + MacroStabilityInwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (collector == null) + { + throw new ArgumentNullException(nameof(collector)); + } + + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + + MacroStabilityInwardsFailureMechanismMetaEntity metaEntity = entity.MacroStabilityInwardsFailureMechanismMetaEntities.Single(); + metaEntity.ReadProbabilityAssessmentInput(failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput); + + string stochasticSoilModelCollectionSourcePath = metaEntity.StochasticSoilModelCollectionSourcePath; + if (stochasticSoilModelCollectionSourcePath != null) + { + failureMechanism.StochasticSoilModels.AddRange(entity.StochasticSoilModelEntities + .OrderBy(ssm => ssm.Order) + .Select(e => e.ReadAsMacroStabilityInwardsStochasticSoilModel(collector)) + .ToArray(), + stochasticSoilModelCollectionSourcePath); + } + + string surfaceLineCollectionSourcePath = metaEntity.SurfaceLineCollectionSourcePath; + if (surfaceLineCollectionSourcePath != null) + { + failureMechanism.SurfaceLines.AddRange(entity.SurfaceLineEntities + .OrderBy(sl => sl.Order) + .Select(e => e.ReadAsMacroStabilityInwardsSurfaceLine(collector)) + .ToArray(), + surfaceLineCollectionSourcePath); + } + + entity.ReadMacroStabilityInwardsMechanismSectionResults(failureMechanism, collector); + ReadMacroStabilityInwardsRootCalculationGroup(entity.CalculationGroupEntity, failureMechanism.CalculationsGroup, collector); + } + + private static void ReadMacroStabilityInwardsMechanismSectionResults(this FailureMechanismEntity entity, + MacroStabilityInwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (MacroStabilityInwardsSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.MacroStabilityInwardsSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + MacroStabilityInwardsFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + private static void ReadMacroStabilityInwardsRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, + ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsMacroStabilityInwardsCalculationGroup(collector); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + + #endregion + + #region MacroStability Outwards + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when any input parameter is null. + internal static void ReadAsMacroStabilityOutwardsFailureMechanism(this FailureMechanismEntity entity, + MacroStabilityOutwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (collector == null) + { + throw new ArgumentNullException(nameof(collector)); + } + + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadMacroStabilityOutwardsMechanismSectionResults(failureMechanism, collector); + MacroStabilityOutwardsFailureMechanismMetaEntity metaEntity = entity.MacroStabilityOutwardsFailureMechanismMetaEntities.Single(); + metaEntity.ReadProbabilityAssessmentInput(failureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput); + } + + private static void ReadMacroStabilityOutwardsMechanismSectionResults(this FailureMechanismEntity entity, + MacroStabilityOutwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (MacroStabilityOutwardsSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.MacroStabilityOutwardsSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + MacroStabilityOutwardsFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + #endregion + + #region Wave Impact Asphalt Cover + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when the expected table entries could not be found. + internal static void ReadAsWaveImpactAsphaltCoverFailureMechanism(this FailureMechanismEntity entity, + WaveImpactAsphaltCoverFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadWaveImpactAsphaltCoverMechanismSectionResults(failureMechanism, collector); + + WaveImpactAsphaltCoverFailureMechanismMetaEntity metaEntity = entity.WaveImpactAsphaltCoverFailureMechanismMetaEntities.Single(); + entity.ReadForeshoreProfiles(failureMechanism.ForeshoreProfiles, metaEntity.ForeshoreProfileCollectionSourcePath, collector); + + ReadWaveImpactAsphaltCoverRootCalculationGroup(entity.CalculationGroupEntity, failureMechanism.WaveConditionsCalculationGroup, collector); + entity.ReadGeneralInput(failureMechanism.GeneralWaveImpactAsphaltCoverInput); + } + + private static void ReadWaveImpactAsphaltCoverMechanismSectionResults(this FailureMechanismEntity entity, + WaveImpactAsphaltCoverFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (WaveImpactAsphaltCoverSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.WaveImpactAsphaltCoverSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + WaveImpactAsphaltCoverFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + private static void ReadWaveImpactAsphaltCoverRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, + ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsWaveImpactAsphaltCoverWaveConditionsCalculationGroup(collector); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + + private static void ReadGeneralInput(this FailureMechanismEntity entity, GeneralWaveImpactAsphaltCoverInput generalInput) + { + GeneralWaveImpactAsphaltCoverInput generalWaveImpactAsphaltCoverInput = entity.WaveImpactAsphaltCoverFailureMechanismMetaEntities.First().Read(); + generalInput.DeltaL = generalWaveImpactAsphaltCoverInput.DeltaL; + } + + #endregion + + #region Grass Cover Erosion Outwards + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when expected table entries could not be found. + internal static void ReadAsGrassCoverErosionOutwardsFailureMechanism(this FailureMechanismEntity entity, + GrassCoverErosionOutwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadGeneralGrassCoverErosionOutwardsCalculationInput(failureMechanism.GeneralInput); + entity.ReadGrassCoverErosionOutwardsMechanismSectionResults(failureMechanism, collector); + + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + ReadForeshoreProfiles(entity, + failureMechanism.ForeshoreProfiles, + metaEntity.ForeshoreProfileCollectionSourcePath, + collector); + + entity.ReadHydraulicBoundaryLocationCalculations(failureMechanism, collector); + + ReadGrassCoverErosionOutwardsWaveConditionsRootCalculationGroup(entity.CalculationGroupEntity, failureMechanism.WaveConditionsCalculationGroup, collector); + } + + private static void ReadGeneralGrassCoverErosionOutwardsCalculationInput(this FailureMechanismEntity entity, + GeneralGrassCoverErosionOutwardsInput input) + { + GetGrassCoverErosionOutwardsFailureMechanismMetaEntity(entity).Read(input); + } + + private static void ReadGrassCoverErosionOutwardsMechanismSectionResults(this FailureMechanismEntity entity, + GrassCoverErosionOutwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (GrassCoverErosionOutwardsSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverErosionOutwardsSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + GrassCoverErosionOutwardsFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + private static void ReadHydraulicBoundaryLocationCalculations(this FailureMechanismEntity entity, + GrassCoverErosionOutwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = GetGrassCoverErosionOutwardsFailureMechanismMetaEntity(entity); + + metaEntity.HydraulicLocationCalculationCollectionEntity5.Read(failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm, + collector); + metaEntity.HydraulicLocationCalculationCollectionEntity4.Read(failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm, + collector); + metaEntity.HydraulicLocationCalculationCollectionEntity3.Read(failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm, + collector); + + metaEntity.HydraulicLocationCalculationCollectionEntity2.Read(failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm, + collector); + metaEntity.HydraulicLocationCalculationCollectionEntity1.Read(failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm, + collector); + metaEntity.HydraulicLocationCalculationCollectionEntity.Read(failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm, + collector); + } + + private static void ReadGrassCoverErosionOutwardsWaveConditionsRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsGrassCoverErosionOutwardsWaveConditionsCalculationGroup(collector); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + + private static GrassCoverErosionOutwardsFailureMechanismMetaEntity GetGrassCoverErosionOutwardsFailureMechanismMetaEntity(FailureMechanismEntity entity) + { + return entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + } + + #endregion + + #region Grass Cover Slip Off Inwards + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + internal static void ReadAsGrassCoverSlipOffInwardsFailureMechanism(this FailureMechanismEntity entity, + GrassCoverSlipOffInwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadGrassCoverSlipOffInwardsMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadGrassCoverSlipOffInwardsMechanismSectionResults(this FailureMechanismEntity entity, + GrassCoverSlipOffInwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (GrassCoverSlipOffInwardsSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverSlipOffInwardsSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + GrassCoverSlipOffInwardsFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + #endregion + + #region Grass Cover Slip Off Outwards + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + internal static void ReadAsGrassCoverSlipOffOutwardsFailureMechanism(this FailureMechanismEntity entity, + GrassCoverSlipOffOutwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadGrassCoverSlipOffOutwardsMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadGrassCoverSlipOffOutwardsMechanismSectionResults(this FailureMechanismEntity entity, + GrassCoverSlipOffOutwardsFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (GrassCoverSlipOffOutwardsSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverSlipOffOutwardsSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + GrassCoverSlipOffOutwardsFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + #endregion + + #region Microstability + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + internal static void ReadAsMicrostabilityFailureMechanism(this FailureMechanismEntity entity, + MicrostabilityFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadMicrostabilityMechanismSectionResults(failureMechanism, collector); + } + + private static void ReadMicrostabilityMechanismSectionResults(this FailureMechanismEntity entity, + MicrostabilityFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (MicrostabilitySectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.MicrostabilitySectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + MicrostabilityFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + #endregion + + #region Piping Structure + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when any input parameter is null. + internal static void ReadAsPipingStructureFailureMechanism(this FailureMechanismEntity entity, + PipingStructureFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (collector == null) + { + throw new ArgumentNullException(nameof(collector)); + } + + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadPipingStructureMechanismSectionResults(failureMechanism, collector); + + failureMechanism.N = (RoundedDouble) entity.PipingStructureFailureMechanismMetaEntities.Single().N; + } + + private static void ReadPipingStructureMechanismSectionResults(this FailureMechanismEntity entity, + PipingStructureFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (PipingStructureSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.PipingStructureSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + PipingStructureFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + #endregion + + #region Dune Erosion + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + internal static void ReadAsDuneErosionFailureMechanism(this FailureMechanismEntity entity, + DuneErosionFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadDuneErosionMechanismSectionResults(failureMechanism, collector); + entity.ReadGeneralDuneErosionInput(failureMechanism.GeneralInput); + entity.ReadDuneLocations(failureMechanism, collector); + entity.ReadDuneLocationCalculations(failureMechanism, collector); + } + + private static void ReadGeneralDuneErosionInput(this FailureMechanismEntity entity, GeneralDuneErosionInput input) + { + GetDuneErosionFailureMechanismMetaEntity(entity).Read(input); + } + + private static void ReadDuneErosionMechanismSectionResults(this FailureMechanismEntity entity, + DuneErosionFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (DuneErosionSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.DuneErosionSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + DuneErosionFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + private static void ReadDuneLocations(this FailureMechanismEntity entity, + DuneErosionFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + failureMechanism.SetDuneLocations(entity.DuneLocationEntities + .OrderBy(location => location.Order) + .Select(location => location.Read(collector)) + .ToArray()); + } + + private static void ReadDuneLocationCalculations(this FailureMechanismEntity entity, + DuneErosionFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + DuneErosionFailureMechanismMetaEntity metaEntity = GetDuneErosionFailureMechanismMetaEntity(entity); + + metaEntity.DuneLocationCalculationCollectionEntity4.Read(failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm, collector); + metaEntity.DuneLocationCalculationCollectionEntity3.Read(failureMechanism.CalculationsForMechanismSpecificSignalingNorm, collector); + metaEntity.DuneLocationCalculationCollectionEntity2.Read(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm, collector); + metaEntity.DuneLocationCalculationCollectionEntity1.Read(failureMechanism.CalculationsForLowerLimitNorm, collector); + metaEntity.DuneLocationCalculationCollectionEntity.Read(failureMechanism.CalculationsForFactorizedLowerLimitNorm, collector); + } + + private static DuneErosionFailureMechanismMetaEntity GetDuneErosionFailureMechanismMetaEntity(FailureMechanismEntity entity) + { + return entity.DuneErosionFailureMechanismMetaEntities.Single(); + } + + #endregion + + #region Stability Stone Cover + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when expected table entries cannot be found. + internal static void ReadAsStabilityStoneCoverFailureMechanism(this FailureMechanismEntity entity, + StabilityStoneCoverFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadStabilityStoneCoverMechanismSectionResults(failureMechanism, collector); + + StabilityStoneCoverFailureMechanismMetaEntity metaEntity = + entity.StabilityStoneCoverFailureMechanismMetaEntities.Single(); + ReadForeshoreProfiles(entity, + failureMechanism.ForeshoreProfiles, + metaEntity.ForeshoreProfileCollectionSourcePath, + collector); + + ReadStabilityStoneCoverWaveConditionsRootCalculationGroup(entity.CalculationGroupEntity, + failureMechanism.WaveConditionsCalculationGroup, + collector); + entity.ReadGeneralInput(failureMechanism.GeneralInput); + } + + private static void ReadStabilityStoneCoverMechanismSectionResults(this FailureMechanismEntity entity, + StabilityStoneCoverFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (StabilityStoneCoverSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.StabilityStoneCoverSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + StabilityStoneCoverFailureMechanismSectionResult result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result); + } + } + + private static void ReadStabilityStoneCoverWaveConditionsRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, + ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsStabilityStoneCoverWaveConditionsCalculationGroup(collector); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + + private static void ReadGeneralInput(this FailureMechanismEntity entity, GeneralStabilityStoneCoverWaveConditionsInput generalInput) + { + GeneralStabilityStoneCoverWaveConditionsInput generalStabilityPointStructuresInput = entity.StabilityStoneCoverFailureMechanismMetaEntities.First().Read(); + generalInput.N = generalStabilityPointStructuresInput.N; + } + + #endregion + + #region Stability Point Structures + + /// + /// Read the and use the information to update a . + /// + /// The to create for. + /// The target of the read operation. + /// The object keeping track of read operations. + /// Thrown when expected table entries cannot be found. + internal static void ReadAsStabilityPointStructuresFailureMechanism(this FailureMechanismEntity entity, + StabilityPointStructuresFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + entity.ReadStabilityPointStructuresMechanismSectionResults(failureMechanism, collector); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = + entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + entity.ReadForeshoreProfiles(failureMechanism.ForeshoreProfiles, + metaEntity.ForeshoreProfileCollectionSourcePath, + collector); + + entity.ReadStabilityPointStructures(failureMechanism.StabilityPointStructures, + metaEntity.StabilityPointStructureCollectionSourcePath, + collector); + entity.ReadGeneralInput(failureMechanism.GeneralInput); + ReadStabilityPointStructuresRootCalculationGroup(entity.CalculationGroupEntity, failureMechanism.CalculationsGroup, collector); + } + + private static void ReadStabilityPointStructuresMechanismSectionResults(this FailureMechanismEntity entity, + StabilityPointStructuresFailureMechanism failureMechanism, + ReadConversionCollector collector) + { + foreach (StabilityPointStructuresSectionResultEntity sectionResultEntity in entity.FailureMechanismSectionEntities.SelectMany(fms => fms.StabilityPointStructuresSectionResultEntities)) + { + FailureMechanismSection failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity); + StabilityPointStructuresFailureMechanismSectionResult result = failureMechanism.SectionResults + .Single(sr => ReferenceEquals(sr.Section, failureMechanismSection)); + + sectionResultEntity.Read(result, collector); + } + } + + private static void ReadStabilityPointStructures(this FailureMechanismEntity entity, + StructureCollection stabilityPointStructures, + string sourcePath, + ReadConversionCollector collector) + { + if (sourcePath != null) + { + stabilityPointStructures.AddRange(entity.StabilityPointStructureEntities + .OrderBy(fpe => fpe.Order) + .Select(structureEntity => structureEntity.Read(collector)) + .ToArray(), + sourcePath); + } + } + + private static void ReadGeneralInput(this FailureMechanismEntity entity, GeneralStabilityPointStructuresInput generalInput) + { + GeneralStabilityPointStructuresInput generalStabilityPointStructuresInput = entity.StabilityPointStructuresFailureMechanismMetaEntities.First().Read(); + generalInput.N = generalStabilityPointStructuresInput.N; + } + + private static void ReadStabilityPointStructuresRootCalculationGroup(CalculationGroupEntity rootCalculationGroupEntity, + CalculationGroup targetRootCalculationGroup, + ReadConversionCollector collector) + { + CalculationGroup rootCalculationGroup = rootCalculationGroupEntity.ReadAsStabilityPointStructuresCalculationGroup(collector); + foreach (ICalculationBase calculationBase in rootCalculationGroup.Children) + { + targetRootCalculationGroup.Children.Add(calculationBase); + } + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/ClosingStructures/ClosingStructuresFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,278 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.ClosingStructures; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.TestUtil; + +namespace Ringtoets.Storage.Core.Test.Create.ClosingStructures +{ + [TestFixture] + public class ClosingStructuresFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N2A = new Random().Next(0, 40) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.ReliabilityClosingOfStructure, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + ClosingStructuresFailureMechanismMetaEntity metaEntity = entity.ClosingStructuresFailureMechanismMetaEntities.Single(); + Assert.AreEqual(failureMechanism.GeneralInput.N2A, metaEntity.N2A); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + Assert.IsNull(metaEntity.ClosingStructureCollectionSourcePath); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + const string originalForeshoreProfilesSourcePath = "foreshoreProfiles/file/path"; + const string originalStructuresSourcePath = "structures/file/path"; + var failureMechanism = new ClosingStructuresFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + failureMechanism.ForeshoreProfiles.AddRange(Enumerable.Empty(), originalForeshoreProfilesSourcePath); + failureMechanism.ClosingStructures.AddRange(Enumerable.Empty(), originalStructuresSourcePath); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + ClosingStructuresFailureMechanismMetaEntity metaEntity = entity.ClosingStructuresFailureMechanismMetaEntities.First(); + Assert.AreNotSame(originalForeshoreProfilesSourcePath, metaEntity.ForeshoreProfileCollectionSourcePath, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(originalForeshoreProfilesSourcePath, metaEntity.ForeshoreProfileCollectionSourcePath); + Assert.AreNotSame(originalStructuresSourcePath, metaEntity.ClosingStructureCollectionSourcePath, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(originalStructuresSourcePath, metaEntity.ClosingStructureCollectionSourcePath); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.ClosingStructuresSectionResultEntities).Count()); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfileEntitiesCreated() + { + // Setup + var profile = new TestForeshoreProfile(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + const string filePath = "some/file/path/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + profile + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(profile)); + + ClosingStructuresFailureMechanismMetaEntity metaEntity = + entity.ClosingStructuresFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + Assert.AreNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + Assert.AreEqual(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithClosingStructures_ClosingStructureEntitiesCreated() + { + // Setup + ClosingStructure structure = new TestClosingStructure(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + var path = "some path"; + failureMechanism.ClosingStructures.AddRange(new[] + { + structure + }, path); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.ClosingStructureEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(structure)); + + ClosingStructuresFailureMechanismMetaEntity metaEntity = + entity.ClosingStructuresFailureMechanismMetaEntities.Single(); + string entitySourcePath = metaEntity.ClosingStructureCollectionSourcePath; + Assert.AreEqual(path, entitySourcePath); + Assert.AreNotSame(path, entitySourcePath); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities() + { + // Setup + StructuresCalculation calculation = new TestClosingStructuresCalculation(); + calculation.InputParameters.Structure = null; + calculation.InputParameters.HydraulicBoundaryLocation = null; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(1, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity = childGroupEntities[0]; + Assert.AreEqual("A", childGroupEntity.Name); + Assert.AreEqual(0, childGroupEntity.Order); + + ClosingStructuresCalculationEntity[] calculationEntities = entity.CalculationGroupEntity.ClosingStructuresCalculationEntities + .OrderBy(ce => ce.Order) + .ToArray(); + ClosingStructuresCalculationEntity calculationEntity = calculationEntities[0]; + Assert.AreEqual("Nieuwe berekening", calculationEntity.Name); + Assert.AreEqual(1, calculationEntity.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/DuneErosion/DuneErosionFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,279 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.DuneErosion; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.TestUtil; + +namespace Ringtoets.Storage.Core.Test.Create.DuneErosion +{ + [TestFixture] + public class DuneErosionFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new DuneErosionFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet() + { + // Setup + var random = new Random(21); + var failureMechanism = new DuneErosionFailureMechanism + { + IsRelevant = random.NextBoolean(), + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = random.NextRoundedDouble(1, 20) + } + }; + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.DuneErosion, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(failureMechanism.IsRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + DuneErosionFailureMechanismMetaEntity metaEntity = entity.DuneErosionFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.GeneralInput.N, metaEntity.N, failureMechanism.GeneralInput.N.GetAccuracy()); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new DuneErosionFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new DuneErosionFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new DuneErosionFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.DuneErosionSectionResultEntities).Count()); + } + + [Test] + public void Create_WithoutDuneLocations_ReturnsEntityWithoutDuneLocations() + { + // Setup + var failureMechanism = new DuneErosionFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + CollectionAssert.IsEmpty(entity.DuneLocationEntities); + + DuneErosionFailureMechanismMetaEntity metaEntity = entity.DuneErosionFailureMechanismMetaEntities.Single(); + AssertDuneLocationCalculationCollectionEntities(failureMechanism, registry, metaEntity); + } + + [Test] + public void Create_WithDuneLocations_ReturnsEntityWithDuneLocations() + { + // Setup + var duneLocation = new TestDuneLocation(); + var failureMechanism = new DuneErosionFailureMechanism(); + failureMechanism.SetDuneLocations(new[] + { + duneLocation + }); + SetDuneLocationCalculationOutput(failureMechanism); + + var duneLocationEntity = new DuneLocationEntity(); + var registry = new PersistenceRegistry(); + registry.Register(duneLocationEntity, duneLocation); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + DuneLocationEntity actualDuneLocationEntity = entity.DuneLocationEntities.Single(); + Assert.AreSame(duneLocationEntity, actualDuneLocationEntity); + + DuneErosionFailureMechanismMetaEntity metaEntity = entity.DuneErosionFailureMechanismMetaEntities.Single(); + AssertDuneLocationCalculationCollectionEntities(failureMechanism, registry, metaEntity); + } + + private static void AssertDuneLocationCalculationCollectionEntities(DuneErosionFailureMechanism failureMechanism, + PersistenceRegistry registry, + DuneErosionFailureMechanismMetaEntity metaEntity) + { + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForFactorizedLowerLimitNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity); + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForLowerLimitNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity1); + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity2); + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForMechanismSpecificSignalingNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity3); + AssertDuneLocationCalculationCollectionEntity(failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm, + registry, + metaEntity.DuneLocationCalculationCollectionEntity4); + } + + private static void SetDuneLocationCalculationOutput(DuneErosionFailureMechanism failureMechanism) + { + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm, 1); + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForMechanismSpecificSignalingNorm, 2); + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm, 3); + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForLowerLimitNorm, 4); + SetDuneLocationCalculationOutput(failureMechanism.CalculationsForFactorizedLowerLimitNorm, 5); + } + + private static void SetDuneLocationCalculationOutput(IEnumerable calculations, + int seed) + { + var random = new Random(seed); + foreach (DuneLocationCalculation calculation in calculations) + { + calculation.Output = random.NextBoolean() + ? new TestDuneLocationCalculationOutput() + : null; + } + } + + private static void AssertDuneLocationCalculationCollectionEntity(IEnumerable expectedCalculations, + PersistenceRegistry registry, + DuneLocationCalculationCollectionEntity actualCollectionEntity) + { + Assert.IsNotNull(actualCollectionEntity); + ICollection duneLocationCalculationEntities = actualCollectionEntity.DuneLocationCalculationEntities; + Assert.AreEqual(expectedCalculations.Count(), duneLocationCalculationEntities.Count); + + var i = 0; + foreach (DuneLocationCalculationEntity duneLocationCalculationEntity in duneLocationCalculationEntities) + { + DuneLocationCalculation expectedDuneLocationCalculation = expectedCalculations.ElementAt(i); + DuneLocation expectedDuneLocation = expectedDuneLocationCalculation.DuneLocation; + Assert.AreSame(registry.Get(expectedDuneLocation), duneLocationCalculationEntity.DuneLocationEntity); + + DuneLocationCalculationOutputEntity actualOutput = duneLocationCalculationEntity.DuneLocationCalculationOutputEntities.SingleOrDefault(); + if (expectedDuneLocationCalculation.Output != null) + { + Assert.IsNotNull(actualOutput); + } + else + { + Assert.IsNull(actualOutput); + } + + i++; + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/FailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/FailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/FailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,121 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.TestUtil; + +namespace Ringtoets.Storage.Core.Test.Create +{ + [TestFixture] + public class FailureMechanismCreateExtensionsTest + { + [Test] + public void AddEntitiesForFailureMechanismSections_WithoutCollector_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.AddEntitiesForFailureMechanismSections(null, new FailureMechanismEntity()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void AddEntitiesForFailureMechanismSections_WithoutEntity_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.AddEntitiesForFailureMechanismSections(new PersistenceRegistry(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void AddEntitiesForFailureMechanismSections_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + var failureMechanismEntity = new FailureMechanismEntity(); + + // Call + failureMechanism.AddEntitiesForFailureMechanismSections(new PersistenceRegistry(), failureMechanismEntity); + + // Assert + CollectionAssert.IsEmpty(failureMechanismEntity.FailureMechanismSectionEntities); + } + + [Test] + public void AddEntitiesForFailureMechanismSections_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var failureMechanismEntity = new FailureMechanismEntity(); + + // Call + failureMechanism.AddEntitiesForFailureMechanismSections(new PersistenceRegistry(), failureMechanismEntity); + + // Assert + Assert.AreEqual(1, failureMechanismEntity.FailureMechanismSectionEntities.Count); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + IFailureMechanism failureMechanism = new TestFailureMechanism("a", "cool"); + failureMechanism.InputComments.Body = originalInput; + failureMechanism.OutputComments.Body = originalOutput; + failureMechanism.NotRelevantComments.Body = originalNotRelevantText; + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(FailureMechanismType.DuneErosion, registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionInwards/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,240 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.GrassCoverErosionInwards; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.TestUtil; + +namespace Ringtoets.Storage.Core.Test.Create.GrassCoverErosionInwards +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random().NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.GrassRevetmentTopErosionAndInwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + Assert.AreEqual(1, entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Count); + GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity = entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.GeneralInput.N, generalInputEntity.N); + Assert.IsNull(generalInputEntity.DikeProfileCollectionSourcePath); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverErosionInwardsSectionResultEntities).Count()); + } + + [Test] + public void Create_WithoutDikeProfiles_EmptyDikeProfileEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + CollectionAssert.IsEmpty(entity.DikeProfileEntities); + } + + [Test] + public void Create_WithDikeProfiles_AddDikeProfileEntities() + { + // Setup + const string sourcePath = "some/path/to/my/dikeprofiles"; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.DikeProfiles.AddRange(new[] + { + DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id1"), + DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id2") + }, sourcePath); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreEqual(2, entity.DikeProfileEntities.Count); + + GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity = + entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(sourcePath, generalInputEntity.DikeProfileCollectionSourcePath); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual("A", childGroupEntities[0].Name); + Assert.AreEqual(0, childGroupEntities[0].Order); + Assert.AreEqual("B", childGroupEntities[1].Name); + Assert.AreEqual(1, childGroupEntities[1].Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverErosionOutwards/GrassCoverErosionOutwardsFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,353 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.GrassCoverErosionOutwards; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.TestUtil; + +namespace Ringtoets.Storage.Core.Test.Create.GrassCoverErosionOutwards +{ + [TestFixture] + public class GrassCoverErosionOutwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random(39).NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.GrassRevetmentErosionOutwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + Assert.AreEqual(1, entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Count); + GrassCoverErosionOutwardsFailureMechanismMetaEntity generalInputEntity = entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.GeneralInput.N, generalInputEntity.N); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverErosionOutwardsSectionResultEntities).Count()); + } + + [Test] + public void Create_WithoutForeshoreProfiles_EmptyForeshoreProfilesEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.ForeshoreProfileEntities); + + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfilesEntitiesCreated() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + [TestCase(true, TestName = "Create_WithCalculationGroup_ReturnFMEntityWithCalculationGroupEntities(true)")] + [TestCase(false, TestName = "Create_WithCalculationGroup_ReturnFMEntityWithCalculationGroupEntities(false)")] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.WaveConditionsCalculationGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual("A", childGroupEntities[0].Name); + Assert.AreEqual(0, childGroupEntities[0].Order); + Assert.AreEqual("B", childGroupEntities[1].Name); + Assert.AreEqual(1, childGroupEntities[1].Order); + } + + [Test] + public void Create_WithoutHydraulicBoundaryLocationCalculations_ReturnsFailureMechanismWithoutHydraulicLocationCalculationEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + + AssertHydraulicLocationCalculationCollectionEntities(failureMechanism, registry, metaEntity); + } + + [Test] + public void Create_WithHydraulicBoundaryLocationCalculations_ReturnsFailureMechanismWithHydraulicLocationCalculationEntities() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "A", 0, 0); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation + }); + SetHydraulicBoundaryLocationCalculationInputsOfFailureMechanism(failureMechanism); + + var registry = new PersistenceRegistry(); + registry.Register(new HydraulicLocationEntity(), hydraulicBoundaryLocation); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + GrassCoverErosionOutwardsFailureMechanismMetaEntity metaEntity = + entity.GrassCoverErosionOutwardsFailureMechanismMetaEntities.Single(); + + AssertHydraulicLocationCalculationCollectionEntities(failureMechanism, registry, metaEntity); + } + + private static void AssertHydraulicLocationCalculationCollectionEntities(GrassCoverErosionOutwardsFailureMechanism expectedFailureMechanism, + PersistenceRegistry registry, + GrassCoverErosionOutwardsFailureMechanismMetaEntity actualEntity) + { + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity); + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity1); + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity2); + + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity3); + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity4); + AssertHydraulicLocationCalculationCollectionEntity(expectedFailureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm, + registry, + actualEntity.HydraulicLocationCalculationCollectionEntity5); + } + + private static void SetHydraulicBoundaryLocationCalculationInputsOfFailureMechanism(GrassCoverErosionOutwardsFailureMechanism failureMechanism) + { + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm, 1); + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm, 2); + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm, 3); + + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm, 4); + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm, 5); + SetHydraulicBoundaryLocationCalculationInputs(failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm, 6); + } + + private static void SetHydraulicBoundaryLocationCalculationInputs(IEnumerable calculations, + int seed) + { + var random = new Random(seed); + foreach (HydraulicBoundaryLocationCalculation calculation in calculations) + { + calculation.InputParameters.ShouldIllustrationPointsBeCalculated = random.NextBoolean(); + } + } + + private static void AssertHydraulicLocationCalculationCollectionEntity(IEnumerable expectedCalculations, + PersistenceRegistry registry, + HydraulicLocationCalculationCollectionEntity actualCollectionEntity) + { + Assert.IsNotNull(actualCollectionEntity); + + HydraulicBoundaryLocationCalculation[] expectedCalculationsArray = expectedCalculations.ToArray(); + ICollection hydraulicLocationCalculationEntities = actualCollectionEntity.HydraulicLocationCalculationEntities; + Assert.AreEqual(expectedCalculationsArray.Length, hydraulicLocationCalculationEntities.Count); + + var i = 0; + foreach (HydraulicLocationCalculationEntity actualCalculationEntity in hydraulicLocationCalculationEntities) + { + HydraulicBoundaryLocationCalculation expectedCalculation = expectedCalculationsArray[i]; + HydraulicBoundaryLocation expectedLocation = expectedCalculation.HydraulicBoundaryLocation; + Assert.AreSame(registry.Get(expectedLocation), actualCalculationEntity.HydraulicLocationEntity); + + Assert.AreEqual(Convert.ToByte(expectedCalculation.InputParameters.ShouldIllustrationPointsBeCalculated), + actualCalculationEntity.ShouldIllustrationPointsBeCalculated); + i++; + } + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffInwards/GrassCoverSlipOffInwardsFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,153 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.GrassCoverSlipOffInwards; +using Ringtoets.Storage.Core.DbContext; + +namespace Ringtoets.Storage.Core.Test.Create.GrassCoverSlipOffInwards +{ + [TestFixture] + public class GrassCoverSlipOffInwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.GrassRevetmentSlidingInwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new GrassCoverSlipOffInwardsFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverSlipOffInwardsSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/GrassCoverSlipOffOutwards/GrassCoverSlipOffOutwardsFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,153 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.GrassCoverSlipOffOutwards; +using Ringtoets.Storage.Core.DbContext; + +namespace Ringtoets.Storage.Core.Test.Create.GrassCoverSlipOffOutwards +{ + [TestFixture] + public class GrassCoverSlipOffOutwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.GrassRevetmentSlidingOutwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.GrassCoverSlipOffOutwardsSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/HeightStructures/HeightStructuresFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,323 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.HeightStructures; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.TestUtil; + +namespace Ringtoets.Storage.Core.Test.Create.HeightStructures +{ + [TestFixture] + public class HeightStructuresFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random().NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.StructureHeight, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + HeightStructuresFailureMechanismMetaEntity metaEntity = entity.HeightStructuresFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.GeneralInput.N, metaEntity.N); + Assert.IsNull(metaEntity.HeightStructureCollectionSourcePath); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + const string originalSourcePath = "some output path"; + var failureMechanism = new HeightStructuresFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + failureMechanism.HeightStructures.AddRange(Enumerable.Empty(), originalSourcePath); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + HeightStructuresFailureMechanismMetaEntity metaEntity = entity.HeightStructuresFailureMechanismMetaEntities.First(); + Assert.AreEqual(originalSourcePath, metaEntity.HeightStructureCollectionSourcePath); + Assert.AreNotSame(originalSourcePath, metaEntity.HeightStructureCollectionSourcePath, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.HeightStructuresSectionResultEntities).Count()); + } + + [Test] + public void Create_WithoutForeshoreProfiles_EmptyForeshoreProfilesEntities() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.ForeshoreProfileEntities); + + HeightStructuresFailureMechanismMetaEntity metaEntity = + entity.HeightStructuresFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfileEntitiesCreated() + { + // Setup + var profile = new TestForeshoreProfile(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + profile + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(profile)); + + HeightStructuresFailureMechanismMetaEntity metaEntity = + entity.HeightStructuresFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + Assert.AreNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + Assert.AreEqual(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithoutHeightStructures_EmptyHeightStructureEntities() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(0, entity.HeightStructureEntities.Count); + + HeightStructuresFailureMechanismMetaEntity metaEntity = + entity.HeightStructuresFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.HeightStructureCollectionSourcePath); + } + + [Test] + public void Create_WithoutHeightStructuresWithSourcePath_EmptyHeightStructureEntitiesWithSourcePath() + { + // Setup + const string originalSourcePath = "some output path"; + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.HeightStructures.AddRange(Enumerable.Empty(), originalSourcePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(0, entity.HeightStructureEntities.Count); + + HeightStructuresFailureMechanismMetaEntity metaEntity = + entity.HeightStructuresFailureMechanismMetaEntities.Single(); + Assert.AreEqual(originalSourcePath, metaEntity.HeightStructureCollectionSourcePath); + } + + [Test] + public void Create_WithHeightStructures_HeightStructureEntitiesCreated() + { + // Setup + HeightStructure structure = new TestHeightStructure(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + const string filePath = "some/path/to/structures"; + failureMechanism.HeightStructures.AddRange(new[] + { + structure + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.HeightStructureEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(structure)); + + HeightStructuresFailureMechanismMetaEntity metaEntity = + entity.HeightStructuresFailureMechanismMetaEntities.Single(); + string metaEntityHeightStructureCollectionSourcePath = metaEntity.HeightStructureCollectionSourcePath; + Assert.AreNotSame(filePath, metaEntityHeightStructureCollectionSourcePath); + Assert.AreEqual(filePath, metaEntityHeightStructureCollectionSourcePath); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity1 = childGroupEntities[0]; + Assert.AreEqual("A", childGroupEntity1.Name); + Assert.AreEqual(0, childGroupEntity1.Order); + CalculationGroupEntity childGroupEntity2 = childGroupEntities[1]; + Assert.AreEqual("B", childGroupEntity2.Name); + Assert.AreEqual(1, childGroupEntity2.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/MacroStabilityInwards/MacroStabilityInwardsFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,337 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.SoilProfile; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.MacroStabilityInwards; +using Ringtoets.Storage.Core.DbContext; + +namespace Ringtoets.Storage.Core.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Create_WithoutAllPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.MacroStabilityInwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(failureMechanism.IsRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + CollectionAssert.IsEmpty(entity.StochasticSoilModelEntities); + MacroStabilityInwardsFailureMechanismMetaEntity failureMechanismMetaEntity = entity.MacroStabilityInwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A, failureMechanismMetaEntity.A); + Assert.AreEqual(failureMechanism.SurfaceLines.SourcePath, failureMechanismMetaEntity.SurfaceLineCollectionSourcePath); + Assert.AreEqual(failureMechanism.StochasticSoilModels.SourcePath, failureMechanismMetaEntity.StochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_WithPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + var failureMechanism = new MacroStabilityInwardsFailureMechanism + { + IsRelevant = random.NextBoolean(), + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + MacroStabilityInwardsProbabilityAssessmentInput = + { + A = random.NextDouble(), + SectionLength = random.NextDouble() + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.MacroStabilityInwards, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(failureMechanism.IsRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + CollectionAssert.IsEmpty(entity.StochasticSoilModelEntities); + CollectionAssert.IsEmpty(entity.SurfaceLineEntities); + MacroStabilityInwardsFailureMechanismMetaEntity failureMechanismMetaEntity = entity.MacroStabilityInwardsFailureMechanismMetaEntities.First(); + Assert.AreEqual(failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A, failureMechanismMetaEntity.A); + Assert.AreEqual(failureMechanism.SurfaceLines.SourcePath, failureMechanismMetaEntity.SurfaceLineCollectionSourcePath); + Assert.AreEqual(failureMechanism.StochasticSoilModels.SourcePath, failureMechanismMetaEntity.StochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism + { + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithStochasticSoilModels_ReturnsFailureMechanismEntityWithStochasticSoilModelEntities() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + MacroStabilityInwardsStochasticSoilModelCollection stochasticSoilModels = failureMechanism.StochasticSoilModels; + + stochasticSoilModels.AddRange(new[] + { + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("name"), + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("name2") + }, "some/path/to/file"); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stochasticSoilModels.Count, entity.StochasticSoilModelEntities.Count); + for (var i = 0; i < stochasticSoilModels.Count; i++) + { + AssertStochasticSoilModel(stochasticSoilModels[i], + entity.StochasticSoilModelEntities.ElementAt(i)); + } + + string stochasticSoilModelCollectionSourcePath = entity.MacroStabilityInwardsFailureMechanismMetaEntities + .Single() + .StochasticSoilModelCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(stochasticSoilModels.SourcePath, stochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_WithSurfaceLines_ReturnFailureMechanismEntityWithSurfaceLineEntities() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + MacroStabilityInwardsSurfaceLineCollection surfaceLines = failureMechanism.SurfaceLines; + + surfaceLines.AddRange(new[] + { + CreateSurfaceLine(new Random(31)) + }, "path"); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(surfaceLines.Count, entity.SurfaceLineEntities.Count); + for (var i = 0; i < surfaceLines.Count; i++) + { + AssertSurfaceLine(surfaceLines[i], entity.SurfaceLineEntities.ElementAt(i)); + } + + string surfaceLineCollectionSourcePath = entity.MacroStabilityInwardsFailureMechanismMetaEntities + .Single() + .SurfaceLineCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(surfaceLines.SourcePath, surfaceLineCollectionSourcePath); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNotNull(entity); + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var testFailureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + failureMechanism.AddSectionResult(testFailureMechanismSection); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.MacroStabilityInwardsSectionResultEntities).Count()); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismWithCalculationGroupEntities() + { + // Setup + var calculationGroup = new CalculationGroup(); + var calculation = new MacroStabilityInwardsCalculationScenario(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(1, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity = childGroupEntities[0]; + Assert.AreEqual(calculationGroup.Name, childGroupEntity.Name); + Assert.AreEqual(0, childGroupEntity.Order); + + MacroStabilityInwardsCalculationEntity[] calculationEntities = entity.CalculationGroupEntity.MacroStabilityInwardsCalculationEntities + .OrderBy(ce => ce.Order) + .ToArray(); + Assert.AreEqual(1, calculationEntities.Length); + MacroStabilityInwardsCalculationEntity calculationEntity = calculationEntities[0]; + Assert.AreEqual(calculation.Name, calculationEntity.Name); + Assert.AreEqual(1, calculationEntity.Order); + } + + private static void AssertSurfaceLine(MacroStabilityInwardsSurfaceLine surfaceLine, SurfaceLineEntity entity) + { + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + + Assert.AreEqual(0, entity.PipingCharacteristicPointEntities.Count); + Assert.AreEqual(12, entity.MacroStabilityInwardsCharacteristicPointEntities.Count); + } + + private MacroStabilityInwardsSurfaceLine CreateSurfaceLine(Random random) + { + var surfaceLine = new MacroStabilityInwardsSurfaceLine(nameof(MacroStabilityInwardsSurfaceLine)) + { + ReferenceLineIntersectionWorldPoint = new Point2D(random.NextDouble(), random.NextDouble()) + }; + + var geometryPoints = new Point3D[12]; + for (var i = 0; i < geometryPoints.Length; i++) + { + geometryPoints[i] = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); + } + + surfaceLine.SetGeometry(geometryPoints); + + surfaceLine.SetDitchPolderSideAt(geometryPoints[1]); + surfaceLine.SetBottomDitchPolderSideAt(geometryPoints[2]); + surfaceLine.SetBottomDitchDikeSideAt(geometryPoints[3]); + surfaceLine.SetDitchDikeSideAt(geometryPoints[4]); + surfaceLine.SetDikeTopAtPolderAt(geometryPoints[5]); + surfaceLine.SetDikeTopAtRiverAt(geometryPoints[6]); + surfaceLine.SetShoulderBaseInsideAt(geometryPoints[7]); + surfaceLine.SetShoulderTopInsideAt(geometryPoints[8]); + surfaceLine.SetDikeToeAtRiverAt(geometryPoints[9]); + surfaceLine.SetDikeToeAtPolderAt(geometryPoints[10]); + surfaceLine.SetSurfaceLevelInsideAt(geometryPoints[11]); + surfaceLine.SetSurfaceLevelOutsideAt(geometryPoints[0]); + + return surfaceLine; + } + + private static void AssertStochasticSoilModel(MacroStabilityInwardsStochasticSoilModel model, StochasticSoilModelEntity entity) + { + Assert.AreEqual(model.Name, entity.Name); + Assert.AreEqual(model.StochasticSoilProfiles.Count(), entity.MacroStabilityInwardsStochasticSoilProfileEntities.Count); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Microstability/MicrostabilityFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,153 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.Microstability; +using Ringtoets.Storage.Core.DbContext; + +namespace Ringtoets.Storage.Core.Test.Create.Microstability +{ + [TestFixture] + public class MicrostabilityFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new MicrostabilityFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new MicrostabilityFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.Microstability, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new MicrostabilityFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new MicrostabilityFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new MicrostabilityFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.MicrostabilitySectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/Piping/PipingFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,296 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.SoilProfile; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.Primitives; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.Piping; +using Ringtoets.Storage.Core.DbContext; + +namespace Ringtoets.Storage.Core.Test.Create.Piping +{ + [TestFixture] + public class PipingFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + var failureMechanism = new PipingFailureMechanism + { + IsRelevant = random.NextBoolean(), + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + PipingProbabilityAssessmentInput = + { + A = random.NextDouble() + }, + GeneralInput = + { + WaterVolumetricWeight = random.NextRoundedDouble(0, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.Piping, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(failureMechanism.IsRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + CollectionAssert.IsEmpty(entity.StochasticSoilModelEntities); + CollectionAssert.IsEmpty(entity.SurfaceLineEntities); + + PipingFailureMechanismMetaEntity failureMechanismMetaEntity = entity.PipingFailureMechanismMetaEntities.ToArray()[0]; + Assert.AreEqual(failureMechanism.PipingProbabilityAssessmentInput.A, failureMechanismMetaEntity.A); + Assert.AreEqual(failureMechanism.GeneralInput.WaterVolumetricWeight.Value, failureMechanismMetaEntity.WaterVolumetricWeight); + Assert.AreEqual(failureMechanism.SurfaceLines.SourcePath, failureMechanismMetaEntity.SurfaceLineCollectionSourcePath); + Assert.AreEqual(failureMechanism.StochasticSoilModels.SourcePath, failureMechanismMetaEntity.StochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + var failureMechanism = new PipingFailureMechanism + { + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InputComments.Body, entity.InputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.OutputComments.Body, entity.OutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithStochasticSoilModels_ReturnsFailureMechanismEntityWithStochasticSoilModelEntities() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + PipingStochasticSoilModelCollection stochasticSoilModels = failureMechanism.StochasticSoilModels; + + stochasticSoilModels.AddRange(new[] + { + PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("name"), + PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("name2") + }, "some/path/to/file"); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(stochasticSoilModels.Count, entity.StochasticSoilModelEntities.Count); + for (var i = 0; i < stochasticSoilModels.Count; i++) + { + AssertStochasticSoilModel(stochasticSoilModels[i], + entity.StochasticSoilModelEntities.ElementAt(i)); + } + + string stochasticSoilModelCollectionSourcePath = entity.PipingFailureMechanismMetaEntities + .Single() + .StochasticSoilModelCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(stochasticSoilModels.SourcePath, stochasticSoilModelCollectionSourcePath); + } + + [Test] + public void Create_WithSections_ReturnsWithFailureMechanismSectionEntitiesAndPipingResultEntities() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.PipingSectionResultEntities).Count()); + } + + [Test] + public void Create_WithSurfaceLines_ReturnFailureMechanismEntityWithSurfaceLineEntities() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + PipingSurfaceLineCollection surfaceLines = failureMechanism.SurfaceLines; + + surfaceLines.AddRange(new[] + { + CreateSurfaceLine(new Random(31)) + }, "path"); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(surfaceLines.Count, entity.SurfaceLineEntities.Count); + for (var i = 0; i < surfaceLines.Count; i++) + { + AssertSurfaceLine(surfaceLines[i], entity.SurfaceLineEntities.ElementAt(i)); + } + + string surfaceLineCollectionSourcePath = entity.PipingFailureMechanismMetaEntities + .Single() + .SurfaceLineCollectionSourcePath; + TestHelper.AssertAreEqualButNotSame(surfaceLines.SourcePath, surfaceLineCollectionSourcePath); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities() + { + // Setup + var calculationGroup = new CalculationGroup(); + var calculation = new PipingCalculationScenario(new GeneralPipingInput()); + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(1, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity = childGroupEntities[0]; + Assert.AreEqual(calculationGroup.Name, childGroupEntity.Name); + Assert.AreEqual(0, childGroupEntity.Order); + + PipingCalculationEntity[] calculationEntities = entity.CalculationGroupEntity.PipingCalculationEntities + .OrderBy(ce => ce.Order) + .ToArray(); + Assert.AreEqual(1, calculationEntities.Length); + PipingCalculationEntity calculationEntity = calculationEntities[0]; + Assert.AreEqual(calculation.Name, calculationEntity.Name); + Assert.AreEqual(1, calculationEntity.Order); + } + + private static void AssertSurfaceLine(PipingSurfaceLine surfaceLine, SurfaceLineEntity entity) + { + Assert.AreEqual(surfaceLine.Name, entity.Name); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.X, entity.ReferenceLineIntersectionX); + Assert.AreEqual(surfaceLine.ReferenceLineIntersectionWorldPoint.Y, entity.ReferenceLineIntersectionY); + + Assert.AreEqual(6, entity.PipingCharacteristicPointEntities.Count); + CollectionAssert.IsEmpty(entity.MacroStabilityInwardsCharacteristicPointEntities); + } + + private static void AssertStochasticSoilModel(PipingStochasticSoilModel model, StochasticSoilModelEntity entity) + { + Assert.AreEqual(model.Name, entity.Name); + Assert.AreEqual(model.StochasticSoilProfiles.Count(), entity.PipingStochasticSoilProfileEntities.Count); + CollectionAssert.IsEmpty(entity.MacroStabilityInwardsStochasticSoilProfileEntities); + } + + private PipingSurfaceLine CreateSurfaceLine(Random random) + { + var surfaceLine = new PipingSurfaceLine(nameof(PipingSurfaceLine)) + { + ReferenceLineIntersectionWorldPoint = new Point2D(random.NextDouble(), random.NextDouble()) + }; + + var geometryPoints = new Point3D[10]; + for (var i = 0; i < 10; i++) + { + geometryPoints[i] = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); + } + + surfaceLine.SetGeometry(geometryPoints); + + surfaceLine.SetBottomDitchDikeSideAt(geometryPoints[1]); + surfaceLine.SetBottomDitchPolderSideAt(geometryPoints[2]); + surfaceLine.SetDikeToeAtPolderAt(geometryPoints[3]); + surfaceLine.SetDikeToeAtRiverAt(geometryPoints[4]); + surfaceLine.SetDitchDikeSideAt(geometryPoints[5]); + surfaceLine.SetDitchPolderSideAt(geometryPoints[7]); + + return surfaceLine; + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/PipingStructure/PipingStructureFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,156 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.PipingStructure; +using Ringtoets.Storage.Core.DbContext; + +namespace Ringtoets.Storage.Core.Test.Create.PipingStructure +{ + [TestFixture] + public class PipingStructureFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new PipingStructureFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new PipingStructureFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + N = new Random().NextRoundedDouble(1, 20) + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.PipingAtStructure, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + Assert.AreEqual(failureMechanism.N, entity.PipingStructureFailureMechanismMetaEntities.Single().N); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new PipingStructureFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new PipingStructureFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new PipingStructureFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.PipingStructureSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityPointStructures/StabilityPointStructuresFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,313 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.StabilityPointStructures; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.TestUtil; + +namespace Ringtoets.Storage.Core.Test.Create.StabilityPointStructures +{ + [TestFixture] + public class StabilityPointStructuresFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsExpectedEntity(bool isRelevant) + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random().NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.StabilityPointStructures, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + Assert.AreEqual(failureMechanism.GeneralInput.N, metaEntity.N); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + const string originalForeshoreProfilesSourcePath = "some/foreshoreProfile/sourcePath"; + const string originalStructuresSourcePath = "some/structures/sourcePath"; + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + failureMechanism.ForeshoreProfiles.AddRange(Enumerable.Empty(), + originalForeshoreProfilesSourcePath); + failureMechanism.StabilityPointStructures.AddRange(Enumerable.Empty(), + originalStructuresSourcePath); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + Assert.AreNotSame(originalForeshoreProfilesSourcePath, metaEntity.ForeshoreProfileCollectionSourcePath, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(originalForeshoreProfilesSourcePath, metaEntity.ForeshoreProfileCollectionSourcePath); + + Assert.AreNotSame(originalStructuresSourcePath, metaEntity.StabilityPointStructureCollectionSourcePath, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(originalStructuresSourcePath, metaEntity.StabilityPointStructureCollectionSourcePath); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.StabilityPointStructuresSectionResultEntities).Count()); + } + + [Test] + public void Create_WithoutForeshoreProfiles_EmptyForeshoreProfilesEntities() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.ForeshoreProfileEntities); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = + entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfileEntitiesCreated() + { + // Setup + var profile = new TestForeshoreProfile(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + profile + }, filePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(profile)); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = + entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + Assert.AreNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + Assert.AreEqual(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithoutStabilityPointStructures_EmptyStabilityPointStructuresEntities() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.StabilityPointStructureEntities); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = + entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.StabilityPointStructureCollectionSourcePath); + } + + [Test] + public void Create_WithStabilityPointStructures_StabilityPointStructureEntitiesCreated() + { + // Setup + StabilityPointStructure structure = new TestStabilityPointStructure(); + + const string sourcePath = "path/to/structures"; + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.StabilityPointStructures.AddRange(new[] + { + structure + }, sourcePath); + + var persistenceRegistry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); + + // Assert + Assert.AreEqual(1, entity.StabilityPointStructureEntities.Count); + Assert.IsTrue(persistenceRegistry.Contains(structure)); + + StabilityPointStructuresFailureMechanismMetaEntity metaEntity = + entity.StabilityPointStructuresFailureMechanismMetaEntities.Single(); + Assert.AreEqual(sourcePath, metaEntity.StabilityPointStructureCollectionSourcePath); + } + + [Test] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities() + { + // Setup + StructuresCalculation calculation = new TestStabilityPointStructuresCalculation(); + calculation.InputParameters.Structure = null; + calculation.InputParameters.HydraulicBoundaryLocation = null; + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(1, childGroupEntities.Length); + CalculationGroupEntity childGroupEntity = childGroupEntities[0]; + Assert.AreEqual("A", childGroupEntity.Name); + Assert.AreEqual(0, childGroupEntity.Order); + + StabilityPointStructuresCalculationEntity[] calculationEntities = entity.CalculationGroupEntity.StabilityPointStructuresCalculationEntities + .OrderBy(ce => ce.Order) + .ToArray(); + StabilityPointStructuresCalculationEntity calculationEntity = calculationEntities[0]; + Assert.AreEqual("Nieuwe berekening", calculationEntity.Name); + Assert.AreEqual(1, calculationEntity.Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StabilityStoneCover/StabilityStoneCoverFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,239 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.StabilityStoneCover; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.TestUtil; + +namespace Ringtoets.Storage.Core.Test.Create.StabilityStoneCover +{ + [TestFixture] + public class StabilityStoneCoverFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralInput = + { + N = new Random().NextRoundedDouble(1, 20) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.StabilityStoneRevetment, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + Assert.AreEqual(failureMechanism.GeneralInput.N, entity.StabilityStoneCoverFailureMechanismMetaEntities.Single().N); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new StabilityStoneCoverFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.StabilityStoneCoverSectionResultEntities).Count()); + } + + [Test] + public void Create_WithoutForeshoreProfiles_EmptyForeshoreProfilesEntities() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.ForeshoreProfileEntities); + + StabilityStoneCoverFailureMechanismMetaEntity metaEntity = + entity.StabilityStoneCoverFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfilesEntitiesCreated() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile() + }, + filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + + StabilityStoneCoverFailureMechanismMetaEntity metaEntity = + entity.StabilityStoneCoverFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + Assert.AreNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + Assert.AreEqual(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities(bool isRelevant) + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.WaveConditionsCalculationGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual("A", childGroupEntities[0].Name); + Assert.AreEqual(0, childGroupEntities[0].Order); + Assert.AreEqual("B", childGroupEntities[1].Name); + Assert.AreEqual(1, childGroupEntities[1].Order); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/StrengthStabilityLengthwise/StrengthStabilityLengthwiseConstructionFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,153 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.StrengthStabilityLengthwise; +using Ringtoets.Storage.Core.DbContext; + +namespace Ringtoets.Storage.Core.Test.Create.StrengthStabilityLengthwise +{ + [TestFixture] + public class StrengthStabilityLengthwiseConstructionFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndProperties_ReturnsExpectedEntity(bool isRelevant) + { + // Setup + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.StrengthAndStabilityParallelConstruction, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new StrengthStabilityLengthwiseConstructionFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.StrengthStabilityLengthwiseConstructionSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/TechnicalInnovation/TechnicalInnovationFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,153 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.TechnicalInnovation; +using Ringtoets.Storage.Core.DbContext; + +namespace Ringtoets.Storage.Core.Test.Create.TechnicalInnovation +{ + [TestFixture] + public class TechnicalInnovationFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.TechnicalInnovations, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new TechnicalInnovationFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new TechnicalInnovationFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.TechnicalInnovationSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaterPressureAsphaltCover/WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,153 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.WaterPressureAsphaltCover; +using Ringtoets.Storage.Core.DbContext; + +namespace Ringtoets.Storage.Core.Test.Create.WaterPressureAsphaltCover +{ + [TestFixture] + public class WaterPressureAsphaltCoverFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.WaterOverpressureAsphaltRevetment, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new WaterPressureAsphaltCoverFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.WaterPressureAsphaltCoverSectionResultEntities).Count()); + } + } +} \ No newline at end of file Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Create/WaveImpactAsphaltCover/WaveImpactAsphaltCoverFailureMechanismCreateExtensionsTest.cs (revision b7c9234daf5a52422362a7cb3fa1f46a86df63bb) @@ -0,0 +1,239 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Storage.Core.Create; +using Ringtoets.Storage.Core.Create.WaveImpactAsphaltCover; +using Ringtoets.Storage.Core.DbContext; +using Ringtoets.Storage.Core.TestUtil; +using Ringtoets.WaveImpactAsphaltCover.Data; + +namespace Ringtoets.Storage.Core.Test.Create.WaveImpactAsphaltCover +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailureMechanismCreateExtensionsTest + { + [Test] + public void Create_PersistenceRegistryNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism + { + IsRelevant = isRelevant, + InputComments = + { + Body = "Some input text" + }, + OutputComments = + { + Body = "Some output text" + }, + NotRelevantComments = + { + Body = "Really not relevant" + }, + GeneralWaveImpactAsphaltCoverInput = + { + DeltaL = new Random(39).NextRoundedDouble(0.1, 2000.0) + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short) FailureMechanismType.WaveImpactOnAsphaltRevetment, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + Assert.AreEqual(failureMechanism.GeneralWaveImpactAsphaltCoverInput.DeltaL, + entity.WaveImpactAsphaltCoverFailureMechanismMetaEntities.Single().DeltaL); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + const string originalInput = "Some input text"; + const string originalOutput = "Some output text"; + const string originalNotRelevantText = "Really not relevant"; + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism + { + InputComments = + { + Body = originalInput + }, + OutputComments = + { + Body = originalOutput + }, + NotRelevantComments = + { + Body = originalNotRelevantText + } + }; + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.AreNotSame(originalInput, entity.InputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.InputComments.Body, entity.InputComments); + Assert.AreNotSame(originalOutput, entity.OutputComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.OutputComments.Body, entity.OutputComments); + Assert.AreNotSame(originalNotRelevantText, entity.NotRelevantComments, + "To create stable binary representations/fingerprints, it's really important that strings are not shared."); + Assert.AreEqual(failureMechanism.NotRelevantComments.Body, entity.NotRelevantComments); + } + + [Test] + public void Create_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void Create_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.SelectMany(fms => fms.WaveImpactAsphaltCoverSectionResultEntities).Count()); + } + + [Test] + public void Create_WithoutForeshoreProfiles_EmptyForeshoreProfilesEntities() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + CollectionAssert.IsEmpty(entity.ForeshoreProfileEntities); + + WaveImpactAsphaltCoverFailureMechanismMetaEntity metaEntity = + entity.WaveImpactAsphaltCoverFailureMechanismMetaEntities.Single(); + Assert.IsNull(metaEntity.ForeshoreProfileCollectionSourcePath); + } + + [Test] + public void Create_WithForeshoreProfiles_ForeshoreProfilesEntitiesCreated() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + const string filePath = "some/path/to/foreshoreProfiles"; + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile() + }, filePath); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry()); + + // Assert + Assert.AreEqual(1, entity.ForeshoreProfileEntities.Count); + + WaveImpactAsphaltCoverFailureMechanismMetaEntity metaEntity = + entity.WaveImpactAsphaltCoverFailureMechanismMetaEntities.Single(); + string metaEntityForeshoreProfileCollectionSourcePath = metaEntity.ForeshoreProfileCollectionSourcePath; + Assert.AreNotSame(filePath, metaEntityForeshoreProfileCollectionSourcePath); + Assert.AreEqual(filePath, metaEntityForeshoreProfileCollectionSourcePath); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities(bool isRelevant) + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "A" + }); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(new CalculationGroup + { + Name = "B" + }); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(registry); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual(failureMechanism.WaveConditionsCalculationGroup.Name, entity.CalculationGroupEntity.Name); + Assert.AreEqual(0, entity.CalculationGroupEntity.Order); + + CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1 + .OrderBy(cge => cge.Order) + .ToArray(); + Assert.AreEqual(2, childGroupEntities.Length); + Assert.AreEqual("A", childGroupEntities[0].Name); + Assert.AreEqual(0, childGroupEntities[0].Order); + Assert.AreEqual("B", childGroupEntities[1].Name); + Assert.AreEqual(1, childGroupEntities[1].Order); + } + } +} \ No newline at end of file