Пример #1
0
        public void UpdateSurfaceLinesWithImportedData_WithCurrentAndImportedDataAreDifferent_ReplacesCurrentWithImportedData()
        {
            // Setup
            var targetSurfaceLine = new PipingSurfaceLine("Name A");
            var failureMechanism  = new PipingFailureMechanism();

            failureMechanism.SurfaceLines.AddRange(new[]
            {
                targetSurfaceLine
            }, sourceFilePath);

            var readSurfaceLine = new PipingSurfaceLine("Name B");

            var strategy = new PipingSurfaceLineReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(new[]
            {
                readSurfaceLine
            }, sourceFilePath);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                failureMechanism.SurfaceLines
            }, affectedObjects);

            PipingSurfaceLine[] expectedSurfaceLines =
            {
                readSurfaceLine
            };
            CollectionAssert.AreEqual(expectedSurfaceLines, failureMechanism.SurfaceLines);
        }
Пример #2
0
        public void UpdateSurfaceLinesWithImportedData_SourceFilePathNull_ThrowsArgumentNullException()
        {
            // Setup
            var strategy = new PipingSurfaceLineReplaceDataStrategy(new PipingFailureMechanism());

            // Call
            void Call() => strategy.UpdateSurfaceLinesWithImportedData(Enumerable.Empty <PipingSurfaceLine>(), null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("sourceFilePath", exception.ParamName);
        }
Пример #3
0
        public void UpdateSurfaceLinesWithImportedData_ReadSurfaceLinesNull_ThrowsArgumentNullException()
        {
            // Setup
            var strategy = new PipingSurfaceLineReplaceDataStrategy(new PipingFailureMechanism());

            // Call
            void Call() => strategy.UpdateSurfaceLinesWithImportedData(null, string.Empty);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("importedDataCollection", exception.ParamName);
        }
Пример #4
0
        public void UpdateSurfaceLinesWithImportedData_CalculationWithOutputSurfaceLine_CalculationUpdatedAndReturnsAffectedObject()
        {
            // Setup
            var existingSurfaceLine = new PipingSurfaceLine(string.Empty);

            existingSurfaceLine.SetGeometry(new[]
            {
                new Point3D(0, 1, 2),
                new Point3D(3, 4, 5)
            });

            var calculation = new SemiProbabilisticPipingCalculationScenario
            {
                InputParameters =
                {
                    SurfaceLine = existingSurfaceLine
                },
                Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties())
            };

            var failureMechanism = new PipingFailureMechanism();

            failureMechanism.SurfaceLines.AddRange(new[]
            {
                existingSurfaceLine
            }, sourceFilePath);
            failureMechanism.CalculationsGroup.Children.Add(calculation);

            var strategy = new PipingSurfaceLineReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(Enumerable.Empty <PipingSurfaceLine>(),
                                                                                                    sourceFilePath).ToArray();

            // Assert
            Assert.IsFalse(calculation.HasOutput);
            Assert.IsNull(calculation.InputParameters.SurfaceLine);
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                calculation,
                calculation.InputParameters,
                failureMechanism.SurfaceLines
            }, affectedObjects);
        }
Пример #5
0
        public void UpdateSurfaceLinesWithImportedData_DifferentSourcePath_UpdatesSourcePathOfTargetCollection()
        {
            // Setup
            var failureMechanism = new PipingFailureMechanism();
            PipingSurfaceLineCollection targetCollection = failureMechanism.SurfaceLines;

            var          strategy      = new PipingSurfaceLineReplaceDataStrategy(failureMechanism);
            const string newSourcePath = "some/other/path";

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(Enumerable.Empty <PipingSurfaceLine>(),
                                                                                                    newSourcePath);

            // Assert
            CollectionAssert.AreEqual(new IObservable[]
            {
                targetCollection
            }, affectedObjects);
            CollectionAssert.IsEmpty(targetCollection);
            Assert.AreEqual(newSourcePath, targetCollection.SourcePath);
        }
Пример #6
0
        public void UpdateSurfaceLinesWithImportedData_ImportedDataContainsDuplicateNames_ThrowsUpdateDataException()
        {
            // Setup
            const string duplicateName = "Duplicate name it is";

            PipingSurfaceLine[] importedSurfaceLines =
            {
                new PipingSurfaceLine(duplicateName),
                new PipingSurfaceLine(duplicateName)
            };

            var strategy = new PipingSurfaceLineReplaceDataStrategy(new PipingFailureMechanism());

            // Call
            TestDelegate call = () => strategy.UpdateSurfaceLinesWithImportedData(importedSurfaceLines,
                                                                                  sourceFilePath);

            // Assert
            var    exception       = Assert.Throws <UpdateDataException>(call);
            string expectedMessage = "Profielschematisaties moeten een unieke naam hebben. " +
                                     $"Gevonden dubbele elementen: {duplicateName}.";

            Assert.AreEqual(expectedMessage, exception.Message);
        }
Пример #7
0
        public void UpdateSurfaceLinesWithImportedData_NoCurrentLinesWithImportedData_AddsNewSurfaceLines()
        {
            // Setup
            var importedSurfaceLines = new[]
            {
                new PipingSurfaceLine(string.Empty)
            };

            var failureMechanism = new PipingFailureMechanism();
            var strategy         = new PipingSurfaceLineReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(importedSurfaceLines,
                                                                                                    sourceFilePath);

            // Assert
            PipingSurfaceLineCollection actualCollection = failureMechanism.SurfaceLines;

            CollectionAssert.AreEqual(importedSurfaceLines, actualCollection);
            CollectionAssert.AreEqual(new[]
            {
                actualCollection
            }, affectedObjects);
        }