public void UpdateDikeProfilesWithImportedData_CollectionAndImportedDataCollectionNotEmpty_ReplacesCurrentWithImportedData() { // Setup DikeProfile targetDikeProfile = DikeProfileTestFactory.CreateDikeProfile("Name A", "Name A ID"); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); failureMechanism.DikeProfiles.AddRange(new[] { targetDikeProfile }, sourceFilePath); DikeProfile readDikeProfile = DikeProfileTestFactory.CreateDikeProfile("Name B", "Name B ID"); var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateDikeProfilesWithImportedData(new[] { readDikeProfile }, sourceFilePath); // Assert CollectionAssert.AreEqual(new[] { failureMechanism.DikeProfiles }, affectedObjects); DikeProfile[] expectedDikeProfiles = { readDikeProfile }; CollectionAssert.AreEqual(expectedDikeProfiles, failureMechanism.DikeProfiles); }
public void Constructor_CreatesNewInstance() { // Call var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); // Assert Assert.IsInstanceOf <ReplaceDataStrategyBase <DikeProfile, GrassCoverErosionInwardsFailureMechanism> >(strategy); Assert.IsInstanceOf <IDikeProfileUpdateDataStrategy>(strategy); }
public void UpdateDikeProfilesWithImportedData_SourceFilePathNull_ThrowsArgumentNullException() { // Setup var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); // Call TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(Enumerable.Empty <DikeProfile>(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("sourceFilePath", exception.ParamName); }
public void UpdateDikeProfilesWithImportedData_ImportedDataCollectionNull_ThrowsArgumentNullException() { // Setup var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); // Call TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(null, string.Empty); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("importedDataCollection", exception.ParamName); }
public void UpdateDikeProfilesWithImportedData_DifferentSourcePath_UpdatesSourcePathOfDataCollection() { // Setup var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); DikeProfileCollection targetCollection = failureMechanism.DikeProfiles; var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism); const string newSourcePath = "some/other/path"; // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateDikeProfilesWithImportedData(Enumerable.Empty <DikeProfile>(), newSourcePath); // Assert Assert.AreEqual(newSourcePath, targetCollection.SourcePath); CollectionAssert.AreEqual(new IObservable[] { targetCollection }, affectedObjects); CollectionAssert.IsEmpty(targetCollection); }
public void UpdateDikeProfilesWithImportedData_CalculationWithOutputAndDikeProfile_CalculationUpdatedAndReturnsAffectedObjects() { // Setup DikeProfile existingDikeProfile = DikeProfileTestFactory.CreateDikeProfile("test", "ID1"); var calculation = new GrassCoverErosionInwardsCalculation { InputParameters = { DikeProfile = existingDikeProfile }, Output = new TestGrassCoverErosionInwardsOutput() }; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); failureMechanism.DikeProfiles.AddRange(new[] { existingDikeProfile }, sourceFilePath); failureMechanism.CalculationsGroup.Children.Add(calculation); var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateDikeProfilesWithImportedData(Enumerable.Empty <DikeProfile>(), sourceFilePath); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.DikeProfile); CollectionAssert.AreEquivalent(new IObservable[] { calculation, calculation.InputParameters, failureMechanism.DikeProfiles }, affectedObjects); }
public void UpdateDikeProfilesWithImportedData_ImportedDataContainsDuplicateIDs_ThrowsUpdateException() { // Setup const string duplicateId = "Duplicate ID it is"; DikeProfile[] importedSurfaceLines = { DikeProfileTestFactory.CreateDikeProfile("Naam A", duplicateId), DikeProfileTestFactory.CreateDikeProfile("Naam B", duplicateId) }; var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); // Call TestDelegate call = () => strategy.UpdateDikeProfilesWithImportedData(importedSurfaceLines, sourceFilePath); // Assert var exception = Assert.Throws <UpdateDataException>(call); string expectedMessage = $"Dijkprofielen moeten een unieke id hebben. Gevonden dubbele elementen: {duplicateId}."; Assert.AreEqual(expectedMessage, exception.Message); }
public void UpdateDikeProfilesWithImportedData_CollectionEmptyAndImportedCollectionNotEmpty_AddsNewDikeProfiles() { // Setup DikeProfile[] importedDikeProfiles = { DikeProfileTestFactory.CreateDikeProfile() }; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateDikeProfilesWithImportedData(importedDikeProfiles, sourceFilePath); // Assert DikeProfileCollection actualCollection = failureMechanism.DikeProfiles; CollectionAssert.AreEqual(importedDikeProfiles, actualCollection); CollectionAssert.AreEqual(new[] { actualCollection }, affectedObjects); }