public void UpdateStructuresWithImportedData_SingleChange_UpdatesOnlySingleChange(ClosingStructure readStructure) { // Setup ClosingStructure structure = new TestClosingStructure(); var failureMechanism = new ClosingStructuresFailureMechanism(); StructureCollection <ClosingStructure> targetCollection = failureMechanism.ClosingStructures; targetCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert AssertClosingStructures(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { targetCollection, structure }, affectedObjects); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasNoOverlap_UpdatesTargetCollection() { // Setup var targetStructure = new TestClosingStructure("target id"); var failureMechanism = new ClosingStructuresFailureMechanism(); StructureCollection <ClosingStructure> structures = failureMechanism.ClosingStructures; structures.AddRange(new[] { targetStructure }, sourceFilePath); var readStructure = new TestClosingStructure("read id"); TestClosingStructure[] importedStructures = { readStructure }; var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures, sourceFilePath); // Assert CollectionAssert.AreEqual(importedStructures, structures); Assert.AreSame(readStructure, structures[0]); CollectionAssert.AreEquivalent(new IObservable[] { structures }, affectedObjects); }
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_WithCurrentStructureAndImportedMultipleStructuresWithSameId_ThrowsUpdateDataException() { // Setup const string duplicateId = "I am a duplicate id"; var expectedStructure = new TestClosingStructure(duplicateId, "expectedStructure"); TestClosingStructure[] expectedCollection = { expectedStructure }; var targetCollection = new StructureCollection <ClosingStructure>(); targetCollection.AddRange(expectedCollection, sourceFilePath); var readStructures = new[] { new TestClosingStructure(duplicateId, "Structure"), new TestClosingStructure(duplicateId, "Other structure") }; var strategy = new ClosingStructureUpdateDataStrategy(new ClosingStructuresFailureMechanism()); // Call void Call() => strategy.UpdateStructuresWithImportedData(readStructures, 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(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_CalculationWithStructureImportedStructureWithSameId_UpdatesCalculationInput() { // Setup const string sameId = "sameId"; StabilityPointStructure readStructure = new TestStabilityPointStructure(sameId, "new structure"); StabilityPointStructure structure = new TestStabilityPointStructure(sameId, "original structure"); var calculation = new TestStabilityPointStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; StructureCollection <StabilityPointStructure> targetDataCollection = failureMechanism.StabilityPointStructures; targetDataCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert Assert.IsTrue(calculation.HasOutput); AssertStabilityPointStructure(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { targetDataCollection, structure, calculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_CalculationWithSameReference_OnlyReturnsDistinctCalculationInput() { // Setup const string affectedId = "affectedId"; var affectedStructure = new TestClosingStructure(affectedId, "Old name"); var affectedCalculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = affectedStructure }, Output = new TestStructuresOutput() }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { affectedCalculation, affectedCalculation } } }; StructureCollection <ClosingStructure> structures = failureMechanism.ClosingStructures; structures.AddRange(new[] { affectedStructure }, sourceFilePath); var structureToUpdateFrom = new TestClosingStructure(affectedId, "New name"); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { structureToUpdateFrom }, sourceFilePath); // Assert CollectionAssert.AreEquivalent(new IObservable[] { structures, affectedStructure, affectedCalculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_CalculationWithRemovedStructure_UpdatesCalculation() { // Setup const string sameId = "sameId"; ClosingStructure structure = new TestClosingStructure(sameId, "original structure"); var calculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; StructureCollection <ClosingStructure> targetDataCollection = failureMechanism.ClosingStructures; targetDataCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <ClosingStructure>(), sourceFilePath); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.Structure); CollectionAssert.AreEqual(new IObservable[] { targetDataCollection, calculation, calculation.InputParameters }, affectedObjects); }
public void Constructor_WithData_ReturnExpectedValues() { // Setup const string someFilePath = "location/to/a/file"; var collection = new StructureCollection <StructureBase>(); collection.AddRange(Enumerable.Empty <StructureBase>(), someFilePath); // Call var properties = new StructureCollectionProperties <StructureBase>(collection); // Assert Assert.IsInstanceOf <ObjectProperties <StructureCollection <StructureBase> > >(properties); Assert.AreSame(collection, properties.Data); Assert.AreEqual(someFilePath, properties.SourcePath); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasPartialOverlap_UpdatesTargetCollection() { // Setup const string commonId = "common id"; var updatedStructure = new TestClosingStructure(commonId, "old name"); var removedStructure = new TestClosingStructure("removed id"); var failureMechanism = new ClosingStructuresFailureMechanism(); StructureCollection <ClosingStructure> structures = failureMechanism.ClosingStructures; structures.AddRange(new[] { removedStructure, updatedStructure }, sourceFilePath); var structureToUpdateFrom = new TestClosingStructure(commonId, "new name"); var addedStructure = new TestClosingStructure("added id"); TestClosingStructure[] importedStructures = { structureToUpdateFrom, addedStructure }; var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures, sourceFilePath); // Assert Assert.AreEqual(2, structures.Count); Assert.AreSame(updatedStructure, structures[0]); AssertClosingStructures(structureToUpdateFrom, updatedStructure); Assert.AreSame(addedStructure, structures[1]); CollectionAssert.AreEquivalent(new IObservable[] { updatedStructure, structures }, affectedObjects); }
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 IsEnabled_SourcePathSet_ReturnTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); var structures = new StructureCollection <HeightStructure>(); structures.AddRange(Enumerable.Empty <HeightStructure>(), "some path"); var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection); // Call bool isEnabled = updateInfo.IsEnabled(context); // Assert Assert.IsTrue(isEnabled); mocks.VerifyAll(); }
public void CurrentPath_StructureCollectionHasPathSet_ReturnsExpectedPath() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); const string expectedFilePath = "some/path"; var structures = new StructureCollection <HeightStructure>(); structures.AddRange(Enumerable.Empty <HeightStructure>(), expectedFilePath); var failureMechanism = new HeightStructuresFailureMechanism(); var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection); // Call string currentPath = updateInfo.CurrentPath(context); // Assert Assert.AreEqual(expectedFilePath, currentPath); mocks.VerifyAll(); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasFullOverlap_UpdatesTargetCollection() { // Setup const string commonId = "common id"; var targetStructure = new TestStabilityPointStructure(commonId, "old name"); var failureMechanism = new StabilityPointStructuresFailureMechanism(); StructureCollection <StabilityPointStructure> structures = failureMechanism.StabilityPointStructures; structures.AddRange(new[] { targetStructure }, sourceFilePath); var readStructure = new TestStabilityPointStructure(commonId, "new name"); TestStabilityPointStructure[] importedStructures = { readStructure }; var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures, sourceFilePath); // Assert Assert.AreEqual(1, structures.Count); Assert.AreSame(targetStructure, structures[0]); AssertStabilityPointStructure(readStructure, targetStructure); CollectionAssert.AreEquivalent(new IObservable[] { targetStructure, structures }, affectedObjects); }
public void UpdateStructuresWithImportedData_MultipleCalculationWithStructureOneWithRemovedStructure_OnlyUpdatesCalculationWithRemovedStructure() { // Setup const string removedId = "affectedId"; const string unaffectedId = "unaffectedId"; const string unaffectedStructureName = "unaffectedStructure"; var removedStructure = new TestClosingStructure(removedId, "Old name"); var unaffectedStructure = new TestClosingStructure(unaffectedId, unaffectedStructureName); var affectedCalculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = removedStructure }, Output = new TestStructuresOutput() }; var unaffectedCalculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = unaffectedStructure }, Output = new TestStructuresOutput() }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { affectedCalculation, unaffectedCalculation } } }; StructureCollection <ClosingStructure> targetDataCollection = failureMechanism.ClosingStructures; targetDataCollection.AddRange(new[] { removedStructure, unaffectedStructure }, sourceFilePath); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); ClosingStructure readUnaffectedStructure = new TestClosingStructure(unaffectedId, unaffectedStructureName); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readUnaffectedStructure }, sourceFilePath); // Assert Assert.IsFalse(affectedCalculation.HasOutput); Assert.IsNull(affectedCalculation.InputParameters.Structure); Assert.IsTrue(unaffectedCalculation.HasOutput); ClosingStructure inputParametersUnaffectedStructure = unaffectedCalculation.InputParameters.Structure; Assert.AreSame(unaffectedStructure, inputParametersUnaffectedStructure); AssertClosingStructures(readUnaffectedStructure, inputParametersUnaffectedStructure); CollectionAssert.AreEquivalent(new IObservable[] { affectedCalculation, affectedCalculation.InputParameters, targetDataCollection }, affectedObjects); }