// Copyright (C) Stichting Deltares 2018. 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 System.Windows.Forms;
using Core.Common.Base;
using Core.Common.Base.Geometry;
using Core.Components.Gis.Data;
using Core.Components.Gis.Features;
using Core.Components.Gis.Forms;
using Core.Components.Gis.Geometries;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Forms.TestUtil;
using Ringtoets.Common.Forms.Views;
using Ringtoets.WaveImpactAsphaltCover.Data;
using Ringtoets.WaveImpactAsphaltCover.Forms.Views;
namespace Ringtoets.WaveImpactAsphaltCover.Forms.Test.Views
{
[TestFixture]
public class WaveImpactAsphaltCoverFailureMechanismViewTest
{
private const int referenceLineIndex = 0;
private const int sectionsIndex = 1;
private const int sectionsStartPointIndex = 2;
private const int sectionsEndPointIndex = 3;
private const int hydraulicBoundaryLocationsIndex = 4;
private const int foreshoreProfilesIndex = 5;
private const int calculationsIndex = 6;
[Test]
public void Constructor_FailureMechanismNull_ThrowsArgumentNullException()
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
// Call
TestDelegate call = () => new WaveImpactAsphaltCoverFailureMechanismView(null, assessmentSection);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("failureMechanism", exception.ParamName);
mocks.VerifyAll();
}
[Test]
public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException()
{
// Call
TestDelegate call = () => new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), null);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("assessmentSection", exception.ParamName);
}
[Test]
public void Constructor_ExpectedValues()
{
// Setup
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
var assessmentSection = new AssessmentSectionStub();
// Call
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection))
{
// Assert
Assert.IsInstanceOf(view);
Assert.IsInstanceOf(view);
Assert.IsNull(view.Data);
Assert.AreSame(failureMechanism, view.FailureMechanism);
Assert.AreSame(assessmentSection, view.AssessmentSection);
Assert.AreEqual(1, view.Controls.Count);
Assert.IsInstanceOf(view.Controls[0]);
Assert.AreSame(view.Map, ((RingtoetsMapControl) view.Controls[0]).MapControl);
Assert.AreEqual(DockStyle.Fill, ((Control) view.Map).Dock);
AssertEmptyMapData(view.Map.Data);
}
}
[Test]
public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet()
{
// Setup
IAssessmentSection assessmentSection = new AssessmentSectionStub();
// Call
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection))
{
// Assert
MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData);
}
}
[Test]
public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData()
{
// Setup
var calculationA = new WaveImpactAsphaltCoverWaveConditionsCalculation
{
InputParameters =
{
ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)),
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
};
var calculationB = new WaveImpactAsphaltCoverWaveConditionsCalculation
{
InputParameters =
{
ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5)),
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
};
var geometryPoints = new[]
{
new Point2D(0.0, 0.0),
new Point2D(2.0, 0.0),
new Point2D(4.0, 4.0),
new Point2D(6.0, 4.0)
};
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
FailureMechanismTestHelper.SetSections(failureMechanism, new[]
{
new FailureMechanismSection("A", geometryPoints.Take(2)),
new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2)),
new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2))
});
var profile1 = new TestForeshoreProfile("profile1 ID", new[]
{
new Point2D(0, 0),
new Point2D(1, 1)
});
var profile2 = new TestForeshoreProfile("profile2 ID", new[]
{
new Point2D(2, 2),
new Point2D(3, 3)
});
failureMechanism.ForeshoreProfiles.AddRange(new[]
{
profile1,
profile2
}, "path");
failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationA);
failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationB);
var referenceLine = new ReferenceLine();
referenceLine.SetGeometry(new[]
{
new Point2D(1.0, 2.0),
new Point2D(2.0, 1.0)
});
var assessmentSection = new AssessmentSectionStub
{
ReferenceLine = referenceLine
};
assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
{
new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)
});
// Call
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
// Assert
MapDataCollection mapData = map.Data;
Assert.IsInstanceOf(mapData);
List mapDataList = mapData.Collection.ToList();
Assert.AreEqual(7, mapDataList.Count);
MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]);
MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, mapDataList[sectionsIndex]);
MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, mapDataList[sectionsStartPointIndex]);
MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, mapDataList[sectionsEndPointIndex]);
MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapDataList[hydraulicBoundaryLocationsIndex]);
MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, mapDataList[foreshoreProfilesIndex]);
AssertCalculationsMapData(failureMechanism.Calculations.Cast(),
mapDataList[calculationsIndex]);
}
}
[Test]
public void GivenViewWithHydraulicBoundaryLocationsData_WhenHydraulicBoundaryLocationsUpdatedAndNotified_ThenMapDataUpdated()
{
// Given
var assessmentSection = new AssessmentSectionStub();
assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
{
new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0)
});
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
var mocks = new MockRepository();
IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
observers[hydraulicBoundaryLocationsIndex].Expect(obs => obs.UpdateObserver());
mocks.ReplayAll();
MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex);
// Precondition
MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData);
// When
assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
{
new HydraulicBoundaryLocation(2, "test2", 3.0, 4.0)
});
assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers();
// Then
MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData);
mocks.VerifyAll();
}
}
[Test]
[TestCaseSource(typeof(MapViewTestHelper), nameof(MapViewTestHelper.GetCalculationFuncs))]
public void GivenViewWithHydraulicBoundaryLocationsData_WhenHydraulicBoundaryLocationCalculationUpdatedAndNotified_ThenMapDataUpdated(
Func getCalculationFunc)
{
// Given
var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0);
var assessmentSection = new AssessmentSectionStub();
assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
{
hydraulicBoundaryLocation
});
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
var mocks = new MockRepository();
IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
observers[hydraulicBoundaryLocationsIndex].Expect(obs => obs.UpdateObserver());
mocks.ReplayAll();
MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex);
// Precondition
MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData);
// When
HydraulicBoundaryLocationCalculation calculation = getCalculationFunc(assessmentSection);
calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(new Random(21).NextDouble());
calculation.NotifyObservers();
// Then
MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData);
mocks.ReplayAll();
}
}
[Test]
public void GivenViewWithReferenceLineData_WhenReferenceLineUpdatedAndNotified_ThenMapDataUpdated()
{
// Given
var assessmentSection = new AssessmentSectionStub
{
ReferenceLine = new ReferenceLine()
};
assessmentSection.ReferenceLine.SetGeometry(new[]
{
new Point2D(1.0, 2.0),
new Point2D(2.0, 1.0)
});
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
var mocks = new MockRepository();
IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
observers[referenceLineIndex].Expect(obs => obs.UpdateObserver());
mocks.ReplayAll();
MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex);
// Precondition
MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);
// When
assessmentSection.ReferenceLine.SetGeometry(new[]
{
new Point2D(2.0, 5.0),
new Point2D(4.0, 3.0)
});
assessmentSection.NotifyObservers();
// Then
MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);
mocks.VerifyAll();
}
}
[Test]
public void GivenViewWithFailureMechanismSectionsData_WhenFailureMechanismSectionsUpdatedAndNotified_ThenMapDataUpdated()
{
// Given
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub()))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
var mocks = new MockRepository();
IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
observers[sectionsIndex].Expect(obs => obs.UpdateObserver());
observers[sectionsStartPointIndex].Expect(obs => obs.UpdateObserver());
observers[sectionsEndPointIndex].Expect(obs => obs.UpdateObserver());
mocks.ReplayAll();
var sectionMapData = (MapLineData) map.Data.Collection.ElementAt(sectionsIndex);
var sectionStartsMapData = (MapPointData) map.Data.Collection.ElementAt(sectionsStartPointIndex);
var sectionsEndsMapData = (MapPointData) map.Data.Collection.ElementAt(sectionsEndPointIndex);
// When
FailureMechanismTestHelper.SetSections(failureMechanism, new[]
{
new FailureMechanismSection(string.Empty, new[]
{
new Point2D(1, 2),
new Point2D(1, 2)
})
});
failureMechanism.NotifyObservers();
// Then
MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionMapData);
MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionStartsMapData);
MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsEndsMapData);
mocks.VerifyAll();
}
}
[Test]
public void GivenViewWithForeshoreProfileData_WhenForeshoreProfileUpdatedAndNotified_ThenMapDataUpdated()
{
// Given
var foreshoreProfile = new TestForeshoreProfile("originalProfile ID", new[]
{
new Point2D(0, 0),
new Point2D(1, 1)
});
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
failureMechanism.ForeshoreProfiles.AddRange(new[]
{
foreshoreProfile
}, "path");
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub()))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
var mocks = new MockRepository();
IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
observers[foreshoreProfilesIndex].Expect(obs => obs.UpdateObserver());
mocks.ReplayAll();
MapData foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex);
// Precondition
MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData);
// When
var foreshoreProfileToUpdateFrom = new TestForeshoreProfile("originalProfile ID", new[]
{
new Point2D(2, 2),
new Point2D(3, 3)
});
foreshoreProfile.CopyProperties(foreshoreProfileToUpdateFrom);
foreshoreProfile.NotifyObservers();
// Then
MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData);
mocks.VerifyAll();
}
}
[Test]
public void GivenViewWithForeshoreProfilesData_WhenForeshoreProfilesUpdatedAndNotified_ThenMapDataUpdated()
{
// Given
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
failureMechanism.ForeshoreProfiles.AddRange(new[]
{
new TestForeshoreProfile("originalProfile ID", new[]
{
new Point2D(0, 0),
new Point2D(1, 1)
})
}, "path");
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub()))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
var mocks = new MockRepository();
IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
observers[foreshoreProfilesIndex].Expect(obs => obs.UpdateObserver());
mocks.ReplayAll();
MapData foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex);
// Precondition
MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData);
// When
failureMechanism.ForeshoreProfiles.AddRange(new[]
{
new TestForeshoreProfile("newProfile ID", new[]
{
new Point2D(2, 2),
new Point2D(3, 3)
})
}, "path");
failureMechanism.ForeshoreProfiles.NotifyObservers();
// Then
MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData);
mocks.VerifyAll();
}
}
[Test]
public void GivenViewWithCalculationGroupData_WhenCalculationGroupUpdatedAndNotified_ThenMapDataUpdated()
{
// Given
var calculationA = new WaveImpactAsphaltCoverWaveConditionsCalculation
{
InputParameters =
{
ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)),
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
};
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationA);
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub()))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
var mocks = new MockRepository();
IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
observers[calculationsIndex].Expect(obs => obs.UpdateObserver());
mocks.ReplayAll();
var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex);
// Precondition
AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData);
// When
var calculationB = new WaveImpactAsphaltCoverWaveConditionsCalculation
{
InputParameters =
{
ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5)),
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
};
failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationB);
failureMechanism.WaveConditionsCalculationGroup.NotifyObservers();
// Then
AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData);
mocks.VerifyAll();
}
}
[Test]
public void GivenViewWithCalculationInputData_WhenCalculationInputUpdatedAndNotified_ThenMapDataUpdated()
{
// Given
var calculationA = new WaveImpactAsphaltCoverWaveConditionsCalculation
{
InputParameters =
{
ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)),
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
};
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationA);
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub()))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
var mocks = new MockRepository();
IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
observers[calculationsIndex].Expect(obs => obs.UpdateObserver());
mocks.ReplayAll();
var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex);
// Precondition
AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData);
// When
calculationA.InputParameters.ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5));
calculationA.InputParameters.NotifyObservers();
// Then
AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData);
mocks.VerifyAll();
}
}
[Test]
public void GivenViewWithCalculationData_WhenCalculationUpdatedAndNotified_ThenMapDataUpdated()
{
// Given
var calculationA = new WaveImpactAsphaltCoverWaveConditionsCalculation
{
InputParameters =
{
ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)),
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
};
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationA);
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub()))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
var mocks = new MockRepository();
IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
observers[calculationsIndex].Expect(obs => obs.UpdateObserver());
mocks.ReplayAll();
var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex);
//Precondition
AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData);
// When
calculationA.Name = "new name";
calculationA.NotifyObservers();
// Then
AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData);
mocks.VerifyAll();
}
}
[Test]
public void UpdateObserver_DataUpdated_MapLayersSameOrder()
{
// Setup
const int updatedReferenceLineLayerIndex = referenceLineIndex + 6;
const int updatedSectionsLayerIndex = sectionsIndex - 1;
const int updateSectionStartLayerIndex = sectionsStartPointIndex - 1;
const int updatedSectionEndLayerIndex = sectionsEndPointIndex - 1;
const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryLocationsIndex - 1;
const int updatedForeshoreProfilesLayerIndex = foreshoreProfilesIndex - 1;
const int updatedCalculationsIndex = calculationsIndex - 1;
var assessmentSection = new AssessmentSectionStub();
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection))
{
IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl;
MapDataCollection mapData = map.Data;
var dataToMove = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex);
mapData.Remove(dataToMove);
mapData.Add(dataToMove);
List mapDataList = mapData.Collection.ToList();
// Precondition
var referenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex];
Assert.AreEqual("Referentielijn", referenceLineData.Name);
var sectionsData = (MapLineData) mapDataList[updatedSectionsLayerIndex];
Assert.AreEqual("Vakindeling", sectionsData.Name);
var sectionStartsData = (MapPointData) mapDataList[updateSectionStartLayerIndex];
Assert.AreEqual("Vakindeling (startpunten)", sectionStartsData.Name);
var sectionEndsData = (MapPointData) mapDataList[updatedSectionEndLayerIndex];
Assert.AreEqual("Vakindeling (eindpunten)", sectionEndsData.Name);
var hydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex];
Assert.AreEqual("Hydraulische belastingen", hydraulicLocationsData.Name);
var foreshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex];
Assert.AreEqual("Voorlandprofielen", foreshoreProfilesData.Name);
var calculationsData = (MapLineData) mapDataList[updatedCalculationsIndex];
Assert.AreEqual("Berekeningen", calculationsData.Name);
var points = new List
{
new Point2D(2.0, 5.0),
new Point2D(4.0, 3.0)
};
var referenceLine = new ReferenceLine();
referenceLine.SetGeometry(points);
assessmentSection.ReferenceLine = referenceLine;
// Call
assessmentSection.NotifyObservers();
// Assert
var actualReferenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex];
Assert.AreEqual("Referentielijn", actualReferenceLineData.Name);
var actualSectionsData = (MapLineData) mapDataList[updatedSectionsLayerIndex];
Assert.AreEqual("Vakindeling", actualSectionsData.Name);
var actualSectionStartsData = (MapPointData) mapDataList[updateSectionStartLayerIndex];
Assert.AreEqual("Vakindeling (startpunten)", actualSectionStartsData.Name);
var actualSectionEndsData = (MapPointData) mapDataList[updatedSectionEndLayerIndex];
Assert.AreEqual("Vakindeling (eindpunten)", actualSectionEndsData.Name);
var actualHydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex];
Assert.AreEqual("Hydraulische belastingen", actualHydraulicLocationsData.Name);
var actualForeshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex];
Assert.AreEqual("Voorlandprofielen", actualForeshoreProfilesData.Name);
var actualCalculationsData = (MapLineData) mapDataList[updatedCalculationsIndex];
Assert.AreEqual("Berekeningen", actualCalculationsData.Name);
}
}
private static void AssertCalculationsMapData(IEnumerable calculations, MapData mapData)
{
Assert.IsInstanceOf(mapData);
var calculationsMapData = (MapLineData) mapData;
WaveImpactAsphaltCoverWaveConditionsCalculation[] calculationsArray = calculations.ToArray();
MapFeature[] calculationsFeatures = calculationsMapData.Features.ToArray();
Assert.AreEqual(calculationsArray.Length, calculationsFeatures.Length);
for (var index = 0; index < calculationsArray.Length; index++)
{
MapGeometry[] geometries = calculationsFeatures[index].MapGeometries.ToArray();
Assert.AreEqual(1, geometries.Length);
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = calculationsArray[index];
CollectionAssert.AreEquivalent(new[]
{
calculation.InputParameters.ForeshoreProfile.WorldReferencePoint,
calculation.InputParameters.HydraulicBoundaryLocation.Location
}, geometries[0].PointCollections.First());
}
Assert.AreEqual("Berekeningen", mapData.Name);
}
private static void AssertEmptyMapData(MapDataCollection mapDataCollection)
{
Assert.AreEqual("Dijken en dammen - Golfklappen op asfaltbekleding", mapDataCollection.Name);
List mapDataList = mapDataCollection.Collection.ToList();
Assert.AreEqual(7, mapDataList.Count);
var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex];
var sectionsMapData = (MapLineData) mapDataList[sectionsIndex];
var foreshoreProfilesMapData = (MapLineData) mapDataList[foreshoreProfilesIndex];
var sectionsStartPointMapData = (MapPointData) mapDataList[sectionsStartPointIndex];
var sectionsEndPointMapData = (MapPointData) mapDataList[sectionsEndPointIndex];
var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex];
var calculationsMapData = (MapLineData) mapDataList[calculationsIndex];
CollectionAssert.IsEmpty(referenceLineMapData.Features);
CollectionAssert.IsEmpty(sectionsMapData.Features);
CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features);
CollectionAssert.IsEmpty(sectionsStartPointMapData.Features);
CollectionAssert.IsEmpty(sectionsEndPointMapData.Features);
CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features);
CollectionAssert.IsEmpty(calculationsMapData.Features);
Assert.AreEqual("Referentielijn", referenceLineMapData.Name);
Assert.AreEqual("Vakindeling", sectionsMapData.Name);
Assert.AreEqual("Voorlandprofielen", foreshoreProfilesMapData.Name);
Assert.AreEqual("Vakindeling (startpunten)", sectionsStartPointMapData.Name);
Assert.AreEqual("Vakindeling (eindpunten)", sectionsEndPointMapData.Name);
Assert.AreEqual("Hydraulische belastingen", hydraulicBoundaryLocationsMapData.Name);
Assert.AreEqual("Berekeningen", calculationsMapData.Name);
}
///
/// Attaches mocked observers to all map data components.
///
/// The .
/// The map data collection containing the
/// elements.
/// An array of mocked observers attached to the data in .
private static IObserver[] AttachMapDataObservers(MockRepository mocks, IEnumerable mapData)
{
MapData[] mapDataArray = mapData.ToArray();
var referenceLineMapDataObserver = mocks.StrictMock();
mapDataArray[referenceLineIndex].Attach(referenceLineMapDataObserver);
var sectionsMapDataObserver = mocks.StrictMock();
mapDataArray[sectionsIndex].Attach(sectionsMapDataObserver);
var sectionsStartPointMapDataObserver = mocks.StrictMock();
mapDataArray[sectionsStartPointIndex].Attach(sectionsStartPointMapDataObserver);
var sectionsEndPointMapDataObserver = mocks.StrictMock();
mapDataArray[sectionsEndPointIndex].Attach(sectionsEndPointMapDataObserver);
var hydraulicBoundaryLocationsMapDataObserver = mocks.StrictMock();
mapDataArray[hydraulicBoundaryLocationsIndex].Attach(hydraulicBoundaryLocationsMapDataObserver);
var foreshoreProfilesMapDataObserver = mocks.StrictMock();
mapDataArray[foreshoreProfilesIndex].Attach(foreshoreProfilesMapDataObserver);
var calculationsMapDataObserver = mocks.StrictMock();
mapDataArray[calculationsIndex].Attach(calculationsMapDataObserver);
return new[]
{
referenceLineMapDataObserver,
sectionsMapDataObserver,
sectionsStartPointMapDataObserver,
sectionsEndPointMapDataObserver,
hydraulicBoundaryLocationsMapDataObserver,
foreshoreProfilesMapDataObserver,
calculationsMapDataObserver
};
}
}
}