public void CurrentPath_ForeshoreProfileCollectionHasPathSet_ReturnsExpectedPath() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); const string expectedFilePath = "some/path"; var foreshoreProfiles = new ForeshoreProfileCollection(); foreshoreProfiles.AddRange(new[] { new TestForeshoreProfile() }, expectedFilePath); var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); using (var plugin = new RiskeerPlugin()) { UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call string currentFilePath = updateInfo.CurrentPath(context); // Assert Assert.AreEqual(expectedFilePath, currentFilePath); mocks.VerifyAll(); } }
public void ForeColor_CollectionHasElements_ReturnControlText() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); var collection = new ForeshoreProfileCollection(); collection.AddRange(new[] { new TestForeshoreProfile() }, "path"); var context = new ForeshoreProfilesContext(collection, failureMechanism, assessmentSection); // Call Color color = info.ForeColor(context); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); mocks.ReplayAll(); }
public void IsEnabled_SourcePathNotSet_ReturnFalse() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); var foreshoreProfiles = new ForeshoreProfileCollection(); var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); using (var plugin = new RiskeerPlugin()) { UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call bool isEnabled = updateInfo.IsEnabled(context); // Assert Assert.IsFalse(isEnabled); } mocks.VerifyAll(); }
public void IsEnabled_ReferenceLineWithoutGeometry_ReturnFalse() { // Setup var mocks = new MockRepository(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); var assessmentSection = mocks.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); mocks.ReplayAll(); var foreshoreProfiles = new ForeshoreProfileCollection(); var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); using (var plugin = new RiskeerPlugin()) { ImportInfo importInfo = GetImportInfo(plugin); // Call bool isEnabled = importInfo.IsEnabled(context); // Assert Assert.IsFalse(isEnabled); } mocks.VerifyAll(); }
public void UpdateForeshoreProfilesWithImportedData_WithCurrentCollectionNotEmptyAndImportedCollectionHasProfilesWithSameId_ThrowsUpdateException() { // Setup var foreshoreProfiles = new ForeshoreProfileCollection(); var originalForeshoreProfiles = new[] { new TestForeshoreProfile("name 1", "different ID") }; foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath); const string duplicateId = "duplicate ID"; var importedForeshoreProfiles = new[] { new TestForeshoreProfile("Name A", duplicateId), new TestForeshoreProfile("Name B", duplicateId) }; var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles); // Call void Call() => strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles, sourceFilePath); // Assert var exception = Assert.Throws <UpdateDataException>(Call); const string expectedMessage = "Geïmporteerde data moet unieke elementen bevatten."; Assert.AreEqual(expectedMessage, exception.Message); CollectionAssert.AreEqual(originalForeshoreProfiles, foreshoreProfiles); }
public void UpdateForeshoreProfilesWithImportedData_ForeshoreProfilePropertiesChanged_UpdateRelevantProperties( ForeshoreProfile readForeshoreProfile) { // Setup var profileToBeUpdated = new TestForeshoreProfile(); var targetCollection = new ForeshoreProfileCollection(); targetCollection.AddRange(new[] { profileToBeUpdated }, sourceFilePath); var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), targetCollection); // Call strategy.UpdateForeshoreProfilesWithImportedData(new[] { readForeshoreProfile }, sourceFilePath); // Assert Assert.AreEqual(1, targetCollection.Count); Assert.AreSame(profileToBeUpdated, targetCollection[0]); AssertForeshoreProfile(readForeshoreProfile, profileToBeUpdated); }
public void Import_FromFileWithUnmatchableId_FalseAndLogError() { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "IpflWithUnmatchableId", "Voorlanden_12-2_UnmatchableId.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var foreshoreProfiles = new ForeshoreProfileCollection(); var assessmentSection = mockRepository.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(referenceLine); var messageProvider = mockRepository.Stub <IImporterMessageProvider>(); var strategy = mockRepository.StrictMock <IForeshoreProfileUpdateDataStrategy>(); mockRepository.ReplayAll(); var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath, strategy, messageProvider); // Call var importResult = true; Action call = () => importResult = foreshoreProfilesImporter.Import(); // Assert TestHelper.AssertLogMessages(call, messages => { string[] messageArray = messages.ToArray(); const string expectedMessage = "Kan geen geldige gegevens vinden voor voorlandprofiellocatie met ID 'unmatchable'."; Assert.AreEqual(expectedMessage, messageArray[0]); }); Assert.IsFalse(importResult); }
public void UpdateForeshoreProfilesWithImportedData_CurrentCollectionEmptyImportedCollectionContainDuplicateIDs_ThrowUpdateException() { // Setup var foreshoreProfiles = new ForeshoreProfileCollection(); const string duplicateId = "duplicate ID"; var importedForeshoreProfiles = new[] { new TestForeshoreProfile("Name A", duplicateId), new TestForeshoreProfile("Name B", duplicateId) }; var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles); // Call void Call() => strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles, sourceFilePath); // Assert var exception = Assert.Throws <UpdateDataException>(Call); const string expectedMessage = "Geïmporteerde data moet unieke elementen bevatten."; Assert.AreEqual(expectedMessage, exception.Message); CollectionAssert.IsEmpty(foreshoreProfiles); }
public void CreateFileImporter_Always_ReturnFileImporter() { // Setup var mocks = new MockRepository(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); var assessmentSection = mocks.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); mocks.ReplayAll(); var foreshoreProfiles = new ForeshoreProfileCollection(); var importTarget = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); using (var plugin = new RiskeerPlugin()) { UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call IFileImporter importer = updateInfo.CreateFileImporter(importTarget, "test"); // Assert Assert.IsInstanceOf <ProfilesImporter <ForeshoreProfileCollection> >(importer); } mocks.VerifyAll(); }
public void UpdateForeshoreProfilesWithImportedData_CollectionAndImportedCollectionNotEmpty_ReplaceCurrentWithImportedData() { // Setup var foreshoreProfiles = new ForeshoreProfileCollection(); foreshoreProfiles.AddRange(new[] { new TestForeshoreProfile("Profile 1", "ID 1") }, sourceFilePath); var strategy = new ForeshoreProfileReplaceDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles); var importedForeshoreProfiles = new[] { new TestForeshoreProfile("Profile 2", "ID 2") }; // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles, sourceFilePath); // Assert CollectionAssert.AreEqual(importedForeshoreProfiles, foreshoreProfiles); CollectionAssert.AreEqual(new IObservable[] { foreshoreProfiles }, affectedObjects); }
public void UpdateForeshoreProfilesWithImportedData_MultipleCalculationsWithOutputAndProfile_UpdatesCalculationWithUpdatedProfile() { // Setup var affectedProfile = new TestForeshoreProfile("Name", "Updated ID"); TestCalculationWithForeshoreProfile affectedCalculation = TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile); ForeshoreProfile profileToUpdateFrom = DeepCloneAndModify(affectedProfile); const string unaffectedProfileId = "Unaffected ID"; const string unaffectedProfileName = "Name"; var unaffectedProfile = new TestForeshoreProfile(unaffectedProfileName, unaffectedProfileId); TestCalculationWithForeshoreProfile unaffectedCalculation = TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(unaffectedProfile); var foreshoreProfiles = new ForeshoreProfileCollection(); TestForeshoreProfile[] originalForeshoreProfiles = { affectedProfile, unaffectedProfile }; foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath); var failureMechanism = new TestCalculatableFailureMechanism(new[] { affectedCalculation, unaffectedCalculation }); var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(new[] { new TestForeshoreProfile(unaffectedProfileName, unaffectedProfileId), profileToUpdateFrom }, sourceFilePath); // Assert Assert.IsTrue(unaffectedCalculation.HasOutput); Assert.AreSame(unaffectedProfile, unaffectedCalculation.InputParameters.ForeshoreProfile); Assert.IsFalse(affectedCalculation.HasOutput); Assert.AreSame(affectedProfile, affectedCalculation.InputParameters.ForeshoreProfile); CollectionAssert.AreEquivalent(originalForeshoreProfiles, foreshoreProfiles); CollectionAssert.AreEquivalent(new IObservable[] { affectedCalculation, affectedCalculation.InputParameters, affectedProfile, foreshoreProfiles }, affectedObjects); }
/// <summary> /// Initializes a new instance of the <see cref="StabilityStoneCoverFailureMechanism"/> class. /// </summary> public StabilityStoneCoverFailureMechanism() : base(Resources.StabilityStoneCoverFailureMechanism_DisplayName, Resources.StabilityStoneCoverFailureMechanism_Code) { CalculationsGroup = new CalculationGroup { Name = RiskeerCommonDataResources.HydraulicBoundaryConditions_DisplayName }; GeneralInput = new GeneralStabilityStoneCoverWaveConditionsInput(); ForeshoreProfiles = new ForeshoreProfileCollection(); CalculationsInputComments = new Comment(); }
public void UpdateForeshoreProfilesWithImportedData_CalculationWithOutputAndForeshoreProfileUpdatedWithProfileWithoutGeometry_UpdatesCalculation() { // Setup const string id = "profile ID"; IEnumerable <Point2D> geometry = new[] { new Point2D(1, 2), new Point2D(3, 4) }; var affectedProfile = new TestForeshoreProfile(id, geometry); TestCalculationWithForeshoreProfile affectedCalculation = TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile); affectedCalculation.InputParameters.UseForeshore = true; var profileToUpdateFrom = new TestForeshoreProfile(id, Enumerable.Empty <Point2D>()); var foreshoreProfiles = new ForeshoreProfileCollection(); TestForeshoreProfile[] originalForeshoreProfiles = { affectedProfile }; foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath); var failureMechanism = new TestCalculatableFailureMechanism(new[] { affectedCalculation }); var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(new[] { profileToUpdateFrom }, sourceFilePath); // Assert Assert.IsFalse(affectedCalculation.HasOutput); Assert.IsFalse(affectedCalculation.InputParameters.UseForeshore); AssertForeshoreProfile(affectedProfile, profileToUpdateFrom); CollectionAssert.AreEquivalent(new IObservable[] { affectedCalculation, affectedCalculation.InputParameters, affectedProfile, foreshoreProfiles }, affectedObjects); }
public void UpdateForeshoreProfilesWithImportedData_WithCurrentCollectionAndImportedCollectionHasPartialOverlap_UpdatesTargetDataCollection() { // Setup var commonName = "Name"; var foreshoreProfileToBeUpdated = new TestForeshoreProfile(commonName, "Updated ID"); var foreshoreProfileToBeRemoved = new TestForeshoreProfile(commonName, "Removed ID"); var foreshoreProfiles = new ForeshoreProfileCollection(); foreshoreProfiles.AddRange(new[] { foreshoreProfileToBeUpdated, foreshoreProfileToBeRemoved }, sourceFilePath); ForeshoreProfile foreshoreProfileToUpdateFrom = DeepCloneAndModify(foreshoreProfileToBeUpdated); var foreshoreProfileToBeAdded = new TestForeshoreProfile(commonName, "Added ID"); ForeshoreProfile[] importedForeshoreProfiles = { foreshoreProfileToUpdateFrom, foreshoreProfileToBeAdded }; var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles, sourceFilePath); // Assert Assert.AreEqual(2, foreshoreProfiles.Count); CollectionAssert.AreEqual(new[] { foreshoreProfileToBeUpdated, foreshoreProfileToBeAdded }, foreshoreProfiles); ForeshoreProfile updatedForeshoreProfile = foreshoreProfiles[0]; Assert.AreSame(foreshoreProfileToBeUpdated, updatedForeshoreProfile); AssertForeshoreProfile(foreshoreProfileToUpdateFrom, updatedForeshoreProfile); ForeshoreProfile addedForeshoreProfile = foreshoreProfiles[1]; Assert.AreSame(foreshoreProfileToBeAdded, addedForeshoreProfile); AssertForeshoreProfile(foreshoreProfileToBeAdded, addedForeshoreProfile); CollectionAssert.AreEquivalent(new IObservable[] { foreshoreProfileToBeUpdated, foreshoreProfiles }, affectedObjects); }
private static void AddEntitiesForForeshoreProfiles( ForeshoreProfileCollection foreshoreProfiles, FailureMechanismEntity entity, PersistenceRegistry registry) { for (var i = 0; i < foreshoreProfiles.Count; i++) { ForeshoreProfileEntity foreshoreProfileEntity = foreshoreProfiles[i].Create(registry, i); entity.ForeshoreProfileEntities.Add(foreshoreProfileEntity); } }
/// <summary> /// Initializes a new instance of the <see cref="GrassCoverErosionOutwardsFailureMechanism"/> class. /// </summary> public GrassCoverErosionOutwardsFailureMechanism() : base(Resources.GrassCoverErosionOutwardsFailureMechanism_DisplayName, Resources.GrassCoverErosionOutwardsFailureMechanism_Code) { GeneralInput = new GeneralGrassCoverErosionOutwardsInput(); CalculationsGroup = new CalculationGroup { Name = RiskeerCommonDataResources.HydraulicBoundaryConditions_DisplayName }; ForeshoreProfiles = new ForeshoreProfileCollection(); CalculationsInputComments = new Comment(); }
/// <summary> /// Creates a new instance of the <see cref="HeightStructuresFailureMechanism"/> class. /// </summary> public HeightStructuresFailureMechanism() : base(Resources.HeightStructuresFailureMechanism_DisplayName, Resources.HeightStructuresFailureMechanism_Code) { CalculationsGroup = new CalculationGroup { Name = RiskeerCommonDataResources.FailureMechanism_Calculations_DisplayName }; GeneralInput = new GeneralHeightStructuresInput(); HeightStructures = new StructureCollection <HeightStructure>(); ForeshoreProfiles = new ForeshoreProfileCollection(); CalculationsInputComments = new Comment(); }
/// <summary> /// Initializes a new instance of the <see cref="WaveImpactAsphaltCoverFailureMechanism"/> class. /// </summary> public WaveImpactAsphaltCoverFailureMechanism() : base(Resources.WaveImpactAsphaltCoverFailureMechanism_DisplayName, Resources.WaveImpactAsphaltCoverFailureMechanism_Code) { CalculationsGroup = new CalculationGroup { Name = RiskeerCommonDataResources.HydraulicBoundaryConditions_DisplayName }; ForeshoreProfiles = new ForeshoreProfileCollection(); GeneralInput = new GeneralWaveConditionsInput(1.0, 0.0, 0.0); GeneralWaveImpactAsphaltCoverInput = new GeneralWaveImpactAsphaltCoverInput(); CalculationsInputComments = new Comment(); }
public void UpdateForeshoreProfilesWithImportedData_CalculationsWithForeshoreProfilesAndOutput_CalculationUpdatedAndReturnsAffectedData() { // Setup var foreshoreProfile = new TestForeshoreProfile(); TestCalculationWithForeshoreProfile calculationWithForeshoreProfileAndOutput = TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(foreshoreProfile); TestCalculationWithForeshoreProfile calculationWithForeshoreProfile = TestCalculationWithForeshoreProfile.CreateCalculationWithoutOutput(foreshoreProfile); TestCalculationWithForeshoreProfile calculationWithoutForeshoreProfile = TestCalculationWithForeshoreProfile.CreateDefaultCalculation(); var failureMechanism = new TestCalculatableFailureMechanism(new[] { calculationWithForeshoreProfileAndOutput, calculationWithForeshoreProfile, calculationWithoutForeshoreProfile }); var foreshoreProfiles = new ForeshoreProfileCollection(); foreshoreProfiles.AddRange(new[] { foreshoreProfile }, sourceFilePath); TestCalculationWithForeshoreProfile[] calculationsWithForeshoreProfile = { calculationWithForeshoreProfileAndOutput, calculationWithForeshoreProfile }; var strategy = new ForeshoreProfileReplaceDataStrategy(failureMechanism, foreshoreProfiles); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(Enumerable.Empty <ForeshoreProfile>(), sourceFilePath); // Assert CollectionAssert.IsEmpty(foreshoreProfiles); Assert.IsFalse(calculationWithForeshoreProfileAndOutput.HasOutput); Assert.IsTrue(calculationsWithForeshoreProfile.All(calc => calc.InputParameters.ForeshoreProfile == null)); IEnumerable <IObservable> expectedAffectedObjects = calculationsWithForeshoreProfile.Select(calc => calc.InputParameters) .Concat(new IObservable[] { foreshoreProfiles, calculationWithForeshoreProfileAndOutput }); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); }
public void UpdateForeshoreProfilesWithImportedData_SourceFilePathNull_ThrowsArgumentNullException() { // Setup var foreshoreProfileCollection = new ForeshoreProfileCollection(); var strategy = new ForeshoreProfileReplaceDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfileCollection); // Call void Call() => strategy.UpdateForeshoreProfilesWithImportedData(Enumerable.Empty <ForeshoreProfile>(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("sourceFilePath", exception.ParamName); }
public void Import_ReuseOfCanceledImportToValidTargetWithValidFile_TrueAndLogMessagesAndFiveForeshoreProfiles() { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var assessmentSection = mockRepository.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(referenceLine); var foreshoreProfiles = new ForeshoreProfileCollection(); var strategy = mockRepository.StrictMock <IForeshoreProfileUpdateDataStrategy>(); strategy.Expect(strat => strat.UpdateForeshoreProfilesWithImportedData(null, null)) .IgnoreArguments() .WhenCalled(invocation => { Assert.AreSame(filePath, invocation.Arguments[1]); var readForeshoreProfiles = (IEnumerable <ForeshoreProfile>)invocation.Arguments[0]; { Assert.AreEqual(5, readForeshoreProfiles.Count()); } }); var messageProvider = mockRepository.Stub <IImporterMessageProvider>(); mockRepository.ReplayAll(); var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath, strategy, messageProvider); foreshoreProfilesImporter.SetProgressChanged((description, step, steps) => foreshoreProfilesImporter.Cancel()); // Precondition bool importResult = foreshoreProfilesImporter.Import(); Assert.IsFalse(importResult); CollectionAssert.IsEmpty(foreshoreProfiles); foreshoreProfilesImporter.SetProgressChanged(null); // Call importResult = foreshoreProfilesImporter.Import(); // Assert Assert.IsTrue(importResult); }
public void Import_ThreeInvalidForeshoreProfileDefinitions_TrueAndLogWarning() { // Setup string fileDirectory = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "NoDamsAndNoForeshoreGeometries")); string filePath = Path.Combine(fileDirectory, "Voorlanden 12-2.shp"); var foreshoreProfiles = new ForeshoreProfileCollection(); var strategy = mockRepository.StrictMock <IForeshoreProfileUpdateDataStrategy>(); strategy.Expect(strat => strat.UpdateForeshoreProfilesWithImportedData(null, null)) .IgnoreArguments() .WhenCalled(invocation => { Assert.AreSame(filePath, invocation.Arguments[1]); var readForeshoreProfiles = (IEnumerable <ForeshoreProfile>)invocation.Arguments[0]; Assert.AreEqual(5, readForeshoreProfiles.Count()); }); var messageProvider = mockRepository.Stub <IImporterMessageProvider>(); mockRepository.ReplayAll(); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath, strategy, messageProvider); // Call var importResult = false; Action call = () => importResult = foreshoreProfilesImporter.Import(); // Assert Tuple <string, LogLevelConstant>[] expectedMessages = { Tuple.Create( $"Profielgegevens definiëren geen dam en geen voorlandgeometrie. Bestand '{Path.Combine(fileDirectory, "profiel001NoForeshoreNoDam.prfl")}' wordt overgeslagen.", LogLevelConstant.Warn), Tuple.Create( $"Profielgegevens definiëren geen geldige voorlandgeometrie. De voorlandgeometrie moet bestaan uit 0 of tenminste 2 punten. Bestand '{Path.Combine(fileDirectory, "profiel002ForeshoreOnePointNoDam.prfl")}' wordt overgeslagen.", LogLevelConstant.Warn), Tuple.Create( $"Profielgegevens definiëren geen geldige voorlandgeometrie. De voorlandgeometrie moet bestaan uit 0 of tenminste 2 punten. Bestand '{Path.Combine(fileDirectory, "profiel003ForeshoreOnePointWithDam.prfl")}' wordt overgeslagen.", LogLevelConstant.Warn) }; TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages, 4); Assert.IsTrue(importResult); }
public void Constructor_WithData_ReturnExpectedValues() { // Setup const string someFilePath = "location/to/a/file"; var collection = new ForeshoreProfileCollection(); collection.AddRange(Enumerable.Empty <ForeshoreProfile>(), someFilePath); // Call var properties = new ForeshoreProfileCollectionProperties(collection); // Assert Assert.IsInstanceOf <ObjectProperties <ForeshoreProfileCollection> >(properties); Assert.AreSame(collection, properties.Data); Assert.AreEqual(someFilePath, properties.SourcePath); }
public void ParameteredConstructor_ExpectedValues() { // Setup var messageProvider = mockRepository.Stub <IImporterMessageProvider>(); var strategy = mockRepository.Stub <IForeshoreProfileUpdateDataStrategy>(); mockRepository.ReplayAll(); var importTarget = new ForeshoreProfileCollection(); var referenceLine = new ReferenceLine(); // Call var importer = new ForeshoreProfilesImporter(importTarget, referenceLine, "", strategy, messageProvider); // Assert Assert.IsInstanceOf <ProfilesImporter <ForeshoreProfileCollection> >(importer); }
public void Import_CancelOfImportWhileReadingProfileLocations_CancelsImportAndLogs() { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var assessmentSection = mockRepository.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(referenceLine); const string cancelledLogMessage = "Operation cancelled"; var messageProvider = mockRepository.StrictMock <IImporterMessageProvider>(); messageProvider.Expect(mp => mp.GetCancelledLogMessageText("Voorlandprofielen")).Return(cancelledLogMessage); var strategy = mockRepository.StrictMock <IForeshoreProfileUpdateDataStrategy>(); mockRepository.ReplayAll(); var foreshoreProfiles = new ForeshoreProfileCollection(); var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath, strategy, messageProvider); foreshoreProfilesImporter.SetProgressChanged((description, step, steps) => { if (description.Contains("Inlezen van profiellocaties uit een shapebestand.")) { foreshoreProfilesImporter.Cancel(); } }); var importResult = true; // Call Action call = () => importResult = foreshoreProfilesImporter.Import(); // Assert Tuple <string, LogLevelConstant> expectedLogMessage = Tuple.Create(cancelledLogMessage, LogLevelConstant.Info); TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage, 1); Assert.IsFalse(importResult); }
public void DoPostImport_AfterImport_ObserversNotified() { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); var observableA = mockRepository.StrictMock <IObservable>(); observableA.Expect(o => o.NotifyObservers()); var observableB = mockRepository.StrictMock <IObservable>(); observableB.Expect(o => o.NotifyObservers()); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var assessmentSection = mockRepository.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(referenceLine); var strategy = mockRepository.StrictMock <IForeshoreProfileUpdateDataStrategy>(); var foreshoreProfiles = new ForeshoreProfileCollection(); strategy.Expect(strat => strat.UpdateForeshoreProfilesWithImportedData(null, null)) .IgnoreArguments() .Return(new[] { observableA, observableB }); var messageProvider = mockRepository.Stub <IImporterMessageProvider>(); mockRepository.ReplayAll(); var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath, strategy, messageProvider); foreshoreProfilesImporter.Import(); // Call foreshoreProfilesImporter.DoPostImport(); // Assert // Assertions are handled in the TearDown }
public void UpdateForeshoreProfilesWithImportedData_MultipleCalculationsWithSameReference_OnlyReturnsDistinctCalculations() { // Setup var affectedProfile = new TestForeshoreProfile("Name", "Updated ID"); TestCalculationWithForeshoreProfile affectedCalculation = TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile); ForeshoreProfile profileToUpdateFrom = DeepCloneAndModify(affectedProfile); TestCalculationWithForeshoreProfile calculationSameReference = affectedCalculation; var foreshoreProfiles = new ForeshoreProfileCollection(); TestForeshoreProfile[] originalForeshoreProfiles = { affectedProfile }; foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath); var failureMechanism = new TestCalculatableFailureMechanism(new[] { affectedCalculation, calculationSameReference }); var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(new[] { profileToUpdateFrom }, sourceFilePath); // Assert CollectionAssert.AreEquivalent(new IObservable[] { affectedCalculation, affectedCalculation.InputParameters, affectedProfile, foreshoreProfiles }, affectedObjects); }
public void ForeColor_CollectionIsEmpty_ReturnGrayText() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); var emptyCollection = new ForeshoreProfileCollection(); var context = new ForeshoreProfilesContext(emptyCollection, failureMechanism, assessmentSection); // Call Color color = info.ForeColor(context); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); mocks.ReplayAll(); }
public void UpdateForeshoreProfilesWithImportedData_DifferentSourcePath_UpdatesSourcePathOfDataCollection() { // Setup var foreshoreProfiles = new ForeshoreProfileCollection(); var strategy = new ForeshoreProfileReplaceDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles); const string newForeshoreProfilesPath = "new/path"; // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(Enumerable.Empty <ForeshoreProfile>(), newForeshoreProfilesPath); // Assert Assert.AreEqual(newForeshoreProfilesPath, foreshoreProfiles.SourcePath); CollectionAssert.AreEqual(new IObservable[] { foreshoreProfiles }, affectedObjects); }
public void UpdateForeshoreProfilesWithImportedData_SupportedFailureMechanism_CalculationUpdatedAndReturnsAffectedData( ICalculatableFailureMechanism failureMechanism, ForeshoreProfileCollection foreshoreProfiles) { // Setup ICalculation <ICalculationInput>[] calculationsWithForeshoreProfiles = failureMechanism.Calculations .Cast <ICalculation <ICalculationInput> >() .Where(calc => ((IHasForeshoreProfile)calc.InputParameters).ForeshoreProfile != null) .ToArray(); ICalculation <ICalculationInput>[] calculationsWithOutput = calculationsWithForeshoreProfiles.Where(calc => calc.HasOutput) .ToArray(); // Precondition CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfiles); CollectionAssert.IsNotEmpty(calculationsWithOutput); var strategy = new ForeshoreProfileReplaceDataStrategy(failureMechanism, foreshoreProfiles); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(Enumerable.Empty <ForeshoreProfile>(), sourceFilePath); // Assert Assert.IsFalse(calculationsWithOutput.All(calc => calc.HasOutput)); Assert.IsTrue(calculationsWithForeshoreProfiles.All(calc => ((IHasForeshoreProfile)calc.InputParameters) .ForeshoreProfile == null)); CollectionAssert.IsEmpty(foreshoreProfiles); IEnumerable <IObservable> expectedAffectedObjects = calculationsWithForeshoreProfiles.Select(calc => calc.InputParameters) .Concat(new IObservable[] { foreshoreProfiles } .Concat(calculationsWithOutput)); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); }