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 Constructor_SupportedFailureMechanism_CreatesNewInstance() { // Call var strategy = new ForeshoreProfileReplaceDataStrategy(new TestCalculatableFailureMechanism(), new ForeshoreProfileCollection()); // Assert Assert.IsInstanceOf <ReplaceDataStrategyBase <ForeshoreProfile, ICalculatableFailureMechanism> >(strategy); Assert.IsInstanceOf <IForeshoreProfileUpdateDataStrategy>(strategy); }
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 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); }
public void UpdateForeshoreProfilesWithImportedData_ImportedDataContainsDuplicateIDs_ThrowsUpdateException() { // Setup var foreshoreProfiles = new ForeshoreProfileCollection(); var strategy = new ForeshoreProfileReplaceDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles); const string duplicateId = "Just a duplicate ID"; var importedForeshoreProfiles = new[] { new TestForeshoreProfile("Profile 1", duplicateId), new TestForeshoreProfile("Profile 2", duplicateId) }; // Call void Call() => strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles, sourceFilePath); // Assert var exception = Assert.Throws <UpdateDataException>(Call); string expectedMessage = $"Voorlandprofielen moeten een unieke id hebben. Gevonden dubbele elementen: {duplicateId}."; Assert.AreEqual(expectedMessage, exception.Message); }