public void UpdateStructuresWithImportedData_WithCurrentAndImportedDataAreDifferent_ReplacesCurrentWithImportedData() { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); StructureCollection <StabilityPointStructure> targetCollection = failureMechanism.StabilityPointStructures; targetCollection.AddRange(new[] { new TestStabilityPointStructure() }, sourcePath); var importedStructure = new TestStabilityPointStructure("a different id"); var strategy = new StabilityPointStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { importedStructure }, sourcePath); // Assert CollectionAssert.AreEqual(new[] { targetCollection }, affectedObjects); TestStabilityPointStructure[] expectedCollection = { importedStructure }; CollectionAssert.AreEqual(expectedCollection, targetCollection); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedCollectionEmpty_ClearsCollection() { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); StructureCollection <StabilityPointStructure> targetCollection = failureMechanism.StabilityPointStructures; targetCollection.AddRange(new[] { new TestStabilityPointStructure() }, sourcePath); var strategy = new StabilityPointStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <StabilityPointStructure>(), sourcePath); // Assert Assert.AreEqual(sourcePath, targetCollection.SourcePath); CollectionAssert.AreEqual(new[] { targetCollection }, affectedObjects); CollectionAssert.IsEmpty(targetCollection); }
public void UpdateStructuresWithImportedData_NoCurrentStructuresWithImportedData_AddsNewStructure() { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); StructureCollection <StabilityPointStructure> targetCollection = failureMechanism.StabilityPointStructures; var strategy = new StabilityPointStructureReplaceDataStrategy(failureMechanism); var importedCollection = new[] { new TestStabilityPointStructure() }; // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedCollection, sourcePath); // Assert Assert.AreEqual(sourcePath, targetCollection.SourcePath); CollectionAssert.AreEqual(new[] { targetCollection }, affectedObjects); CollectionAssert.AreEqual(importedCollection, targetCollection); }
public void UpdateStructuresWithImportedData_SourceFilePathNull_ThrowsArgumentNullException() { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); var strategy = new StabilityPointStructureReplaceDataStrategy(failureMechanism); // Call void Call() => strategy.UpdateStructuresWithImportedData(Enumerable.Empty <StabilityPointStructure>(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("sourceFilePath", exception.ParamName); }
public void UpdateStructuresWithImportedData_ImportedDataCollectionNull_ThrowsArgumentNullException() { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); var strategy = new StabilityPointStructureReplaceDataStrategy(failureMechanism); // Call void Call() => strategy.UpdateStructuresWithImportedData(null, sourcePath); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("importedDataCollection", exception.ParamName); }
public void UpdateStructuresWithImportedData_CalculationWithOutputAndStructure_CalculationUpdatedAndReturnsAffectedObject() { // Setup var structure = new TestStabilityPointStructure(); var calculation = new TestStabilityPointStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new StabilityPointStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculation); StructureCollection <StabilityPointStructure> targetCollection = failureMechanism.StabilityPointStructures; targetCollection.AddRange(new[] { structure }, sourcePath); var strategy = new StabilityPointStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <StabilityPointStructure>(), sourcePath); // Assert Assert.IsNull(calculation.InputParameters.Structure); Assert.IsFalse(calculation.HasOutput); CollectionAssert.IsEmpty(targetCollection); CollectionAssert.AreEquivalent(new IObservable[] { calculation, calculation.InputParameters, targetCollection }, affectedObjects); }
public void UpdateStructuresWithImportedData_DifferentSourcePath_UpdatesSourcePath() { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); StructureCollection <StabilityPointStructure> targetCollection = failureMechanism.StabilityPointStructures; var strategy = new StabilityPointStructureReplaceDataStrategy(failureMechanism); var newSourcePath = "some/other/path/toStructures"; // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <StabilityPointStructure>(), newSourcePath); // Assert Assert.AreEqual(newSourcePath, targetCollection.SourcePath); CollectionAssert.AreEqual(new[] { targetCollection }, affectedObjects); }
public void UpdateStructuresWithImportedData_ImportedDataContainsDuplicateIds_ThrowsUpdateDataException() { // Setup const string duplicateId = "I am a duplicate id"; StabilityPointStructure[] importedClosingStructures = { new TestStabilityPointStructure(duplicateId, "name"), new TestStabilityPointStructure(duplicateId, "Other name") }; var strategy = new StabilityPointStructureReplaceDataStrategy(new StabilityPointStructuresFailureMechanism()); // Call TestDelegate call = () => strategy.UpdateStructuresWithImportedData(importedClosingStructures, sourcePath); // Assert var exception = Assert.Throws <UpdateDataException>(call); string expectedMessage = "Kunstwerken moeten een unieke id hebben. " + $"Gevonden dubbele elementen: {duplicateId}."; Assert.AreEqual(expectedMessage, exception.Message); }