public void UpdateStructuresWithImportedData_WithCurrentAndImportedDataAreDifferent_ReplacesCurrentWithImportedData() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.HeightStructures.AddRange(new[] { new TestHeightStructure("id", "Original") }, sourceFilePath); var importedStructure = new TestHeightStructure("Different id", "Imported"); var strategy = new HeightStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { importedStructure }, sourceFilePath); // Assert CollectionAssert.AreEqual(new[] { failureMechanism.HeightStructures }, affectedObjects); TestHeightStructure[] expected = { importedStructure }; CollectionAssert.AreEqual(expected, failureMechanism.HeightStructures); }
public void UpdateStructuresWithImportedData_NoCurrentStructuresWithImportedData_AddsNewStructure() { // Setup var importedStructures = new[] { new TestHeightStructure() }; var failureMechanism = new HeightStructuresFailureMechanism(); var strategy = new HeightStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures, sourceFilePath); // Assert StructureCollection <HeightStructure> actualCollection = failureMechanism.HeightStructures; CollectionAssert.AreEqual(importedStructures, actualCollection); CollectionAssert.AreEqual(new[] { actualCollection }, affectedObjects); Assert.AreEqual(sourceFilePath, actualCollection.SourcePath); }
public void UpdateStructuresWithImportedData_SourceFilePathNull_ThrowsArgumentNullException() { // Setup var strategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism()); // Call void Call() => strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("sourceFilePath", exception.ParamName); }
public void UpdateStructuresWithImportedData_ReadHeightStructuresNull_ThrowsArgumentNullException() { // Setup var strategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism()); // Call TestDelegate test = () => strategy.UpdateStructuresWithImportedData(null, string.Empty); // Assert string paramName = Assert.Throws <ArgumentNullException>(test).ParamName; Assert.AreEqual("importedDataCollection", paramName); }
public void UpdateStructuresWithImportedData_CalculationWithOutputAndStructure_CalculationUpdatedAndReturnsAffectedObject() { // Setup var structure = new TestHeightStructure(); var calculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.HeightStructures.AddRange(new[] { structure }, sourceFilePath); var strategy = new HeightStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(), sourceFilePath).ToArray(); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.Structure); CollectionAssert.AreEquivalent(new IObservable[] { calculation, calculation.InputParameters, failureMechanism.HeightStructures }, affectedObjects); }
public void UpdateStructuresWithImportedData_NoCurrentStructures_SetsSourcePath() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); StructureCollection <HeightStructure> targetCollection = failureMechanism.HeightStructures; var strategy = new HeightStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(), sourceFilePath); // Assert CollectionAssert.IsEmpty(targetCollection); CollectionAssert.AreEqual(new[] { targetCollection }, affectedObjects); Assert.AreEqual(sourceFilePath, targetCollection.SourcePath); }
public void UpdateStructuresWithImportedData_DifferentSourcePath_UpdatesSourcePathOfTargetCollection() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); StructureCollection <HeightStructure> targetCollection = failureMechanism.HeightStructures; var strategy = new HeightStructureReplaceDataStrategy(failureMechanism); const string newSourcePath = "some/other/path"; // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(), newSourcePath); // Assert CollectionAssert.AreEqual(new IObservable[] { targetCollection }, affectedObjects); CollectionAssert.IsEmpty(targetCollection); Assert.AreEqual(newSourcePath, targetCollection.SourcePath); }
public void UpdateStructuresWithImportedData_ImportedDataContainsDuplicateIds_ThrowsUpdateDataException() { // Setup const string duplicateId = "I am a duplicate id"; HeightStructure[] importedHeightStructures = { new TestHeightStructure(duplicateId, "name"), new TestHeightStructure(duplicateId, "Other name") }; var strategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism()); // Call TestDelegate call = () => strategy.UpdateStructuresWithImportedData(importedHeightStructures, sourceFilePath); // Assert var exception = Assert.Throws <UpdateDataException>(call); string expectedMessage = "Kunstwerken moeten een unieke id hebben. " + $"Gevonden dubbele elementen: {duplicateId}."; Assert.AreEqual(expectedMessage, exception.Message); }