public void CurrentPath_SurfaceLineCollectionHasPathSet_ReturnsExpectedPath() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); const string expectedFilePath = "some/path"; var surfaceLines = new MacroStabilityInwardsSurfaceLineCollection(); surfaceLines.AddRange(new[] { new MacroStabilityInwardsSurfaceLine(string.Empty) }, expectedFilePath); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var context = new MacroStabilityInwardsSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); // Call string currentPath = updateInfo.CurrentPath(context); // Assert Assert.AreEqual(expectedFilePath, currentPath); mocks.VerifyAll(); }
public void Create_WithSurfaceLines_ReturnFailureMechanismEntityWithSurfaceLineEntities() { // Setup var failureMechanism = new MacroStabilityInwardsFailureMechanism(); MacroStabilityInwardsSurfaceLineCollection surfaceLines = failureMechanism.SurfaceLines; surfaceLines.AddRange(new[] { CreateSurfaceLine(new Random(31)) }, "path"); var registry = new PersistenceRegistry(); // Call FailureMechanismEntity entity = failureMechanism.Create(registry); // Assert Assert.IsNotNull(entity); Assert.AreEqual(surfaceLines.Count, entity.SurfaceLineEntities.Count); for (var i = 0; i < surfaceLines.Count; i++) { AssertSurfaceLine(surfaceLines[i], entity.SurfaceLineEntities.ElementAt(i)); } string surfaceLineCollectionSourcePath = entity.MacroStabilityInwardsFailureMechanismMetaEntities .Single() .SurfaceLineCollectionSourcePath; TestHelper.AssertAreEqualButNotSame(surfaceLines.SourcePath, surfaceLineCollectionSourcePath); }
public void ChildNodeObjects_Always_ReturnsChildrenOfData() { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); var surfaceLine1 = new MacroStabilityInwardsSurfaceLine("Line A"); var surfaceLine2 = new MacroStabilityInwardsSurfaceLine("Line B"); var surfaceLines = new MacroStabilityInwardsSurfaceLineCollection(); surfaceLines.AddRange(new[] { surfaceLine1, surfaceLine2 }, "path"); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var surfaceLinesContext = new MacroStabilityInwardsSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); mocks.ReplayAll(); // Call object[] objects = info.ChildNodeObjects(surfaceLinesContext); // Assert CollectionAssert.AreEqual(new[] { surfaceLine1, surfaceLine2 }, objects); }
public void ForeColor_CollectionWithSurfaceLines_ReturnsControlText() { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); var surfaceLine1 = new MacroStabilityInwardsSurfaceLine("Line A"); var surfaceLine2 = new MacroStabilityInwardsSurfaceLine("Line B"); var surfaceLines = new MacroStabilityInwardsSurfaceLineCollection(); surfaceLines.AddRange(new[] { surfaceLine1, surfaceLine2 }, "path"); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var surfaceLinesContext = new MacroStabilityInwardsSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); mocks.ReplayAll(); // Call Color foreColor = info.ForeColor(surfaceLinesContext); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), foreColor); }
public void UpdateSurfaceLinesWithImportedData_WithCurrentCollectionNotEmptyAndImportedDataHasPartialOverlap_UpdatesTargetCollection() { // Setup const string updatedSurfaceLineName = "Name A"; const string removedSurfaceLineName = "Name B"; const string addedSurfaceLineName = "Name C"; var surfaceLineOne = new MacroStabilityInwardsSurfaceLine(updatedSurfaceLineName); var surfaceLineTwo = new MacroStabilityInwardsSurfaceLine(removedSurfaceLineName); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); MacroStabilityInwardsSurfaceLineCollection surfaceLineCollection = failureMechanism.SurfaceLines; surfaceLineCollection.AddRange(new[] { surfaceLineOne, surfaceLineTwo }, sourceFilePath); MacroStabilityInwardsSurfaceLine readSurfaceLineOne = DeepCloneAndModifyPoints(surfaceLineOne); var readSurfaceLineTwo = new MacroStabilityInwardsSurfaceLine(addedSurfaceLineName); MacroStabilityInwardsSurfaceLine[] readSurfaceLines = { readSurfaceLineOne, readSurfaceLineTwo }; var strategy = new MacroStabilityInwardsSurfaceLineUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(readSurfaceLines, sourceFilePath); // Assert MacroStabilityInwardsSurfaceLine[] expectedSurfaceLineCollection = { surfaceLineOne, readSurfaceLineTwo }; CollectionAssert.AreEqual(expectedSurfaceLineCollection, surfaceLineCollection); MacroStabilityInwardsSurfaceLine updatedSurfaceLine = surfaceLineCollection[0]; Assert.AreSame(surfaceLineOne, updatedSurfaceLine); Assert.AreEqual(readSurfaceLineOne, updatedSurfaceLine); MacroStabilityInwardsSurfaceLine addedSurfaceLine = surfaceLineCollection[1]; Assert.AreSame(readSurfaceLineTwo, addedSurfaceLine); Assert.AreEqual(readSurfaceLineTwo, addedSurfaceLine); CollectionAssert.AreEquivalent(new IObservable[] { readSurfaceLineOne, surfaceLineCollection }, affectedObjects); }
public void Constructor_WithData_ReturnExpectedValues() { // Setup const string someFilePath = "location/to/a/file"; var collection = new MacroStabilityInwardsSurfaceLineCollection(); collection.AddRange(Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), someFilePath); // Call var properties = new MacroStabilityInwardsSurfaceLineCollectionProperties(collection); // Assert Assert.IsInstanceOf <ObjectProperties <MacroStabilityInwardsSurfaceLineCollection> >(properties); Assert.AreSame(collection, properties.Data); Assert.AreEqual(someFilePath, properties.SourcePath); }
public void UpdateSurfaceLinesWithImportedData_WithCurrentLinesAndImportedMultipleLinesWithSameNames_ThrowsUpdateDataException() { // Setup const string duplicateName = "Duplicate name it is"; var expectedSurfaceLine = new MacroStabilityInwardsSurfaceLine(duplicateName); Point3D[] expectedGeometry = { new Point3D(0, 1, 2), new Point3D(3, 4, 5), new Point3D(6, 7, 8) }; expectedSurfaceLine.SetGeometry(expectedGeometry); MacroStabilityInwardsSurfaceLine[] expectedCollection = { expectedSurfaceLine }; var targetCollection = new MacroStabilityInwardsSurfaceLineCollection(); targetCollection.AddRange(expectedCollection, sourceFilePath); MacroStabilityInwardsSurfaceLine[] importedSurfaceLines = { new MacroStabilityInwardsSurfaceLine(duplicateName), new MacroStabilityInwardsSurfaceLine(duplicateName) }; var strategy = new MacroStabilityInwardsSurfaceLineUpdateDataStrategy(new MacroStabilityInwardsFailureMechanism()); // Call TestDelegate call = () => strategy.UpdateSurfaceLinesWithImportedData(importedSurfaceLines, 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); MacroStabilityInwardsSurfaceLine actualSurfaceLine = targetCollection[0]; Assert.AreEqual(expectedSurfaceLine.Name, actualSurfaceLine.Name); CollectionAssert.AreEqual(expectedGeometry, actualSurfaceLine.Points); }
public void IsEnabled_SurfaceLineCollectionSourcePathSet_ReturnTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var surfaceLines = new MacroStabilityInwardsSurfaceLineCollection(); surfaceLines.AddRange(Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), "some/path"); var context = new MacroStabilityInwardsSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); // Call bool isEnabled = updateInfo.IsEnabled(context); // Assert Assert.IsTrue(isEnabled); mocks.VerifyAll(); }
public void UpdateSurfaceLinesWithImportedData_CalculationWithOutputAndAssignedLineDeleted_ClearsCalculationOutput() { // Setup MacroStabilityInwardsSurfaceLine surfaceLine = CreateValidSurfaceLineForCalculations(); var calculation = new MacroStabilityInwardsCalculation { InputParameters = { SurfaceLine = surfaceLine }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculation); MacroStabilityInwardsSurfaceLineCollection surfaceLineCollection = failureMechanism.SurfaceLines; surfaceLineCollection.AddRange(new[] { surfaceLine }, sourceFilePath); var strategy = new MacroStabilityInwardsSurfaceLineUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), sourceFilePath).ToArray(); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.SurfaceLine); CollectionAssert.AreEquivalent(new IObservable[] { surfaceLineCollection, calculation, calculation.InputParameters }, affectedObjects); }
public void UpdateSurfaceLinesWithImportedData_WithCurrentCollectionNotEmptyAndImportedDataHasFullOverlap_UpdatesTargetCollection() { // Setup var failureMechanism = new MacroStabilityInwardsFailureMechanism(); const string collectionSurfaceLineName = "Name A"; var targetSurfaceLine = new MacroStabilityInwardsSurfaceLine(collectionSurfaceLineName); MacroStabilityInwardsSurfaceLineCollection targetCollection = failureMechanism.SurfaceLines; targetCollection.AddRange(new[] { targetSurfaceLine }, sourceFilePath); MacroStabilityInwardsSurfaceLine readSurfaceLine = DeepCloneAndModifyPoints(targetSurfaceLine); MacroStabilityInwardsSurfaceLine[] readSurfaceLines = { readSurfaceLine }; var strategy = new MacroStabilityInwardsSurfaceLineUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(readSurfaceLines, sourceFilePath); // Assert Assert.AreEqual(1, targetCollection.Count); Assert.AreSame(targetSurfaceLine, targetCollection[0]); Assert.AreEqual(readSurfaceLine, targetSurfaceLine); CollectionAssert.AreEqual(new IObservable[] { targetCollection, targetSurfaceLine }, affectedObjects); }
public void UpdateSurfaceLinesWithImportedData_OnlyGeometryChanged_UpdatesGeometryOnly() { // Setup MacroStabilityInwardsSurfaceLine surfaceLine = CreateValidSurfaceLineForCalculations(); MacroStabilityInwardsSurfaceLine surfaceLineToUpdateFrom = CreateValidSurfaceLineForCalculations(); var expectedGeometry = new List <Point3D> { new Point3D(0, 1, 2), new Point3D(3, 4, 5), new Point3D(6, 7, 8) }; expectedGeometry.AddRange(surfaceLine.Points); surfaceLineToUpdateFrom.SetGeometry(expectedGeometry); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); MacroStabilityInwardsSurfaceLineCollection targetCollection = failureMechanism.SurfaceLines; targetCollection.AddRange(new[] { surfaceLine }, sourceFilePath); var strategy = new MacroStabilityInwardsSurfaceLineUpdateDataStrategy(failureMechanism); // Call strategy.UpdateSurfaceLinesWithImportedData(new[] { surfaceLineToUpdateFrom }, sourceFilePath); // Assert Assert.AreEqual(surfaceLineToUpdateFrom.Name, surfaceLine.Name); Assert.AreEqual(surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint, surfaceLine.ReferenceLineIntersectionWorldPoint); CollectionAssert.AreEqual(surfaceLineToUpdateFrom.Points, surfaceLine.Points); }
public void UpdateSurfaceLinesWithImportedData_MultipleCalculationsWithSurfaceLinesOneWithRemovedLine_OnlyUpdatesCalculationWithRemovedSurfaceLine() { // Setup const string removedSurfaceLineName = "Name A"; const string unaffectedSurfaceLineName = "Name B"; var removedSurfaceLine = new MacroStabilityInwardsSurfaceLine(removedSurfaceLineName); removedSurfaceLine.SetGeometry(new[] { new Point3D(1, 2, 3), new Point3D(4, 5, 6) }); var affectedCalculation = new MacroStabilityInwardsCalculation { InputParameters = { SurfaceLine = removedSurfaceLine }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var unaffectedGeometry = new[] { new Point3D(10, 9, 8), new Point3D(7, 6, 5) }; var unaffectedSurfaceLine = new MacroStabilityInwardsSurfaceLine(unaffectedSurfaceLineName); unaffectedSurfaceLine.SetGeometry(unaffectedGeometry); var unAffectedCalculation = new MacroStabilityInwardsCalculation { InputParameters = { SurfaceLine = unaffectedSurfaceLine }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); MacroStabilityInwardsSurfaceLineCollection collection = failureMechanism.SurfaceLines; collection.AddRange(new[] { removedSurfaceLine, unaffectedSurfaceLine }, sourceFilePath); failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); failureMechanism.CalculationsGroup.Children.Add(unAffectedCalculation); MacroStabilityInwardsSurfaceLine importedUnaffectedSurfaceLine = DeepCloneName(unaffectedSurfaceLine); importedUnaffectedSurfaceLine.SetGeometry(unaffectedGeometry); var strategy = new MacroStabilityInwardsSurfaceLineUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(new[] { importedUnaffectedSurfaceLine }, "path").ToArray(); // Assert Assert.IsTrue(unAffectedCalculation.HasOutput); MacroStabilityInwardsInput unaffectedInput = unAffectedCalculation.InputParameters; Assert.AreSame(unaffectedSurfaceLine, unaffectedInput.SurfaceLine); Assert.AreEqual(unaffectedSurfaceLine, unaffectedInput.SurfaceLine); Assert.IsFalse(affectedCalculation.HasOutput); MacroStabilityInwardsInput affectedInput = affectedCalculation.InputParameters; Assert.IsNull(affectedInput.SurfaceLine); CollectionAssert.AreEquivalent(new IObservable[] { collection, affectedCalculation, affectedInput }, affectedObjects); }