Exemplo n.º 1
0
        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_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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void UpdateStructuresWithImportedData_NoCurrentStructuresWithImportedData_AddsNewStructure()
        {
            // Setup
            var importedStructures = new[]
            {
                new TestClosingStructure()
            };

            var failureMechanism = new ClosingStructuresFailureMechanism();
            var strategy         = new ClosingStructureReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures,
                                                                                                  sourceFilePath);

            // Assert
            StructureCollection <ClosingStructure> actualCollection = failureMechanism.ClosingStructures;

            CollectionAssert.AreEqual(importedStructures, actualCollection);
            CollectionAssert.AreEqual(new[]
            {
                actualCollection
            }, affectedObjects);
            Assert.AreEqual(sourceFilePath, actualCollection.SourcePath);
        }
Exemplo n.º 5
0
        public void UpdateStructuresWithImportedData_WithoutCurrentStructuresAndReadStructuresHaveDuplicateNames_ThrowsUpdateDataException()
        {
            // Setup
            const string duplicateId    = "I am a duplicate id";
            var          readStructures = new[]
            {
                new TestStabilityPointStructure(duplicateId, "First Name"),
                new TestStabilityPointStructure(duplicateId, "Second Name")
            };

            var targetCollection = new StructureCollection <StabilityPointStructure>();
            var strategy         = new StabilityPointStructureUpdateDataStrategy(new StabilityPointStructuresFailureMechanism());

            // 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.IsEmpty(targetCollection);
        }
Exemplo n.º 6
0
        public override StructureCollection ParserMethod(string path, ref string name, Tuple <string, object>[] args)
        {
            StructureCollection model    = new StructureCollection();
            XmlDocument         document = new XmlDocument();

            //  document.Load(path);

            if (IsAstah(document))
            {
                throw new Exception("The file loaded is not a XML generated by ArgoUML. Please reload file.");
            }

            ProcessStartInfo startInfo = new ProcessStartInfo("ArgoParser.jar");

            startInfo.Arguments = path + "###ARGO";
            Process p = Process.GetProcessById(Process.Start(startInfo).Id);

            //wait until the process ends
            while (!p.HasExited)
            {
                ;
            }
            String tempPath    = System.IO.Path.GetTempPath();
            string partialName = "IntermediateFile";

            DirectoryInfo auxDirectory = new DirectoryInfo(tempPath);

            FileInfo[] filesInDir = auxDirectory.GetFiles(partialName + "*.xml");
            document.Load(filesInDir.FirstOrDefault().FullName);
            listModelingStructure.Add(FromXmi(document, ref name));
            model.listGeneralStructure.AddRange(listModelingStructure);
            File.Delete(filesInDir.FirstOrDefault().FullName);

            return(model);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Removes the <paramref name="structure"/> and clears all dependent data, either directly or indirectly.
        /// </summary>
        /// <param name="structure">The structure to be removed.</param>
        /// <param name="failureMechanism">The <see cref="ClosingStructuresFailureMechanism"/>
        /// to clear the data from.</param>
        /// <returns>All objects affected by the removal.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static IEnumerable <IObservable> RemoveStructure(ClosingStructure structure,
                                                                ClosingStructuresFailureMechanism failureMechanism)
        {
            if (structure == null)
            {
                throw new ArgumentNullException(nameof(structure));
            }

            if (failureMechanism == null)
            {
                throw new ArgumentNullException(nameof(failureMechanism));
            }

            IEnumerable <StructuresCalculation <ClosingStructuresInput> > calculations =
                failureMechanism.Calculations.Cast <StructuresCalculation <ClosingStructuresInput> >();

            StructuresCalculation <ClosingStructuresInput>[] calculationWithRemovedStructure = calculations
                                                                                               .Where(c => ReferenceEquals(c.InputParameters.Structure, structure))
                                                                                               .ToArray();

            List <IObservable> changedObservables = ClearStructureDependentData(calculationWithRemovedStructure);

            StructureCollection <ClosingStructure> structures = failureMechanism.ClosingStructures;

            structures.Remove(structure);
            changedObservables.Add(structures);

            return(changedObservables);
        }
Exemplo n.º 8
0
        public void Import_ReuseOfCanceledImportToValidTargetWithValidFile_ReturnsTrue()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp"));

            ReferenceLine referenceLine          = CreateReferenceLine();
            var           importTarget           = new StructureCollection <TestStructure>();
            var           testStructuresImporter = new TestStructuresImporter(importTarget,
                                                                              referenceLine,
                                                                              filePath,
                                                                              updateStrategy,
                                                                              messageProvider);

            testStructuresImporter.SetProgressChanged((description, step, steps) => testStructuresImporter.Cancel());

            bool importResult = testStructuresImporter.Import();

            // Precondition
            Assert.IsFalse(importResult);
            testStructuresImporter.SetProgressChanged(null);

            // Call
            importResult = testStructuresImporter.Import();

            // Assert
            Assert.IsTrue(importResult);
        }
Exemplo n.º 9
0
        public void Import_InvalidCsvFile_LogAndFalse()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <ClosingStructure> >();

            mocks.ReplayAll();
            string filePath = Path.Combine(commonIoTestDataPath, "CorrectShpIncompleteCsv",
                                           "Kunstwerken.shp");

            ReferenceLine referenceLine      = CreateReferenceLine();
            var           importTarget       = new StructureCollection <ClosingStructure>();
            var           structuresImporter = new ClosingStructuresImporter(importTarget, referenceLine,
                                                                             filePath, messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = structuresImporter.Import();

            // Assert
            string csvFilePath = Path.ChangeExtension(filePath, "csv");
            string message     = CreateExpectedErrorMessage(
                csvFilePath, "Coupure Den Oever (90k1)", "KUNST1",
                new[]
            {
                "De waarde voor parameter 'KW_BETSLUIT3' op regel 13, kolom 'Numeriekewaarde', moet in het bereik [0,0, 360,0] liggen.",
                "Parameter 'KW_BETSLUIT5' komt meerdere keren voor."
            });

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Error), 1
                                                            );
            Assert.IsFalse(importResult);
            Assert.AreEqual(0, importTarget.Count);
            Assert.IsNull(importTarget.SourcePath);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Loads all currentLevelIndex-specific data for a specific currentLevelIndex in a given ROM image
        /// </summary>
        /// <param name="rom">The Rom object to load data from</param>
        /// <param name="currentLevelIndex">The currentLevelIndex to load</param>
        public Level(MetroidRom rom, LevelIndex level)
        {
            this.rom   = rom;
            data       = rom.data;
            this.index = level;

            Format    = rom.Format.CreateLevelFormat(this);
            this.Bank = rom.Format.Banks[Format.LevelBankIndex];

            Bytes = new ByteIndexer(this);
            PCpu  = new PointerIndexer(this);
            PRom  = new PRomIndexer(this);

            pointers_deprecated = new LevelPointers(rom, this);

            structures = new StructureCollection(this);
            screens    = new ScreenCollection(this);

            patternGroups = new PatternGroupIndexTable(this);
            LoadPatterns();
            LoadPalette();

            combos  = new ComboTable(rom, Format.ComboDataOffset);
            sprites = Graphic.LevelSprites.GetSprites(level);
            itemTable_DEPRECATED = new ItemLoader(this, rom);
            //structures = new StructureCollection(this);
            altMusic = new AlternateMusicRooms(rom, this);

            this.Items = new ItemCollection(this);
            Items.LoadItems();

            TilePhysicsTableLocation = Format.GetTilePhysicsTableLocation();
        }
Exemplo n.º 11
0
        public void Import_ValidIncompleteFile_LogAndFalse()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <ClosingStructure> >();

            mocks.ReplayAll();

            string filePath = Path.Combine(commonIoTestDataPath, "CorrectFiles", "Kunstwerken.shp");

            ReferenceLine referenceLine = CreateReferenceLine();
            var           importTarget  = new StructureCollection <ClosingStructure>();
            var           importer      = new ClosingStructuresImporter(importTarget, referenceLine, filePath,
                                                                        messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = importer.Import();

            // Assert
            string csvFilePath = Path.ChangeExtension(filePath, "csv");
            string message     = CreateExpectedErrorMessage(csvFilePath, "Gemaal Leemans (93k3)", "KUNST2", new[]
            {
                "Geen geldige parameter definities gevonden."
            });

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Error));
            Assert.IsFalse(importResult);
            Assert.AreEqual(0, importTarget.Count);
            Assert.IsNull(importTarget.SourcePath);
        }
        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 VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var mainWindow        = mocks.Stub <IMainWindow>();
            var gui = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            using (var plugin = new HeightStructuresPlugin())
            {
                plugin.Gui = gui;

                var failureMechanism = new HeightStructuresFailureMechanism();
                failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation <HeightStructuresInput>());

                var structures = new StructureCollection <HeightStructure>();
                var context    = new HeightStructuresContext(structures, failureMechanism, assessmentSection);

                ImportInfo importInfo = GetImportInfo(plugin);

                // Call
                bool updatesVerified = importInfo.VerifyUpdates(context);

                // Assert
                Assert.IsTrue(updatesVerified);
                mocks.VerifyAll();
            }
        }
        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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of <see cref="StructuresImporter{TCollection}"/>.
        /// </summary>
        /// <param name="importTarget">The import target.</param>
        /// <param name="referenceLine">The reference line used to check if the imported structures are intersecting it.</param>
        /// <param name="filePath">The path to the file to import from.</param>
        /// <param name="messageProvider">The message provider to provide messages during importer actions.</param>
        /// <param name="structureUpdateStrategy">The strategy to update the imported data.</param>
        /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
        protected StructuresImporter(StructureCollection <TStructure> importTarget,
                                     ReferenceLine referenceLine,
                                     string filePath,
                                     IImporterMessageProvider messageProvider,
                                     IStructureUpdateStrategy <TStructure> structureUpdateStrategy)
            : base(filePath, importTarget)
        {
            if (referenceLine == null)
            {
                throw new ArgumentNullException(nameof(referenceLine));
            }

            if (structureUpdateStrategy == null)
            {
                throw new ArgumentNullException(nameof(structureUpdateStrategy));
            }

            if (messageProvider == null)
            {
                throw new ArgumentNullException(nameof(messageProvider));
            }

            this.referenceLine           = referenceLine;
            this.messageProvider         = messageProvider;
            this.structureUpdateStrategy = structureUpdateStrategy;
        }
Exemplo n.º 17
0
        //public Tuple<List<GeneralUseStructure>, StructureType> listGeneralStructure;

        #region Constructor
        public ControlUnit(StructureType type)
        {
            exporter                 = ParsedStructureExporterFactory.CreateExporter();
            validator                = ValidatorFactory.CreateValidator();
            sequenceGenerator        = SequenceGeneratorFactory.CreateSequenceGenerator(type);
            scriptGenerator          = ScriptGeneratorFactory.CreateScriptGenerator();
            this.structureCollection = new StructureCollection();
        }
Exemplo n.º 18
0
 public TestStructuresImporter(StructureCollection <TestStructure> importTarget,
                               ReferenceLine referenceLine,
                               string filePath,
                               IStructureUpdateStrategy <TestStructure> structureUpdateStrategy,
                               IImporterMessageProvider messageProvider)
     : base(importTarget, referenceLine, filePath, messageProvider, structureUpdateStrategy)
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// Creates a new instance of <see cref="ClosingStructuresImporter"/>.
 /// </summary>
 /// <param name="importTarget">The closing structures to import on.</param>
 /// <param name="referenceLine">The reference line used to check if the <see cref="ClosingStructure"/>
 /// objects found in the file are intersecting it.</param>
 /// <param name="filePath">The path to the file to import from.</param>
 /// <param name="messageProvider">The message provider to provide messages during importer actions.</param>
 /// <param name="updateStrategy">The strategy to update the structures with imported data.</param>
 /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
 public ClosingStructuresImporter(StructureCollection <ClosingStructure> importTarget,
                                  ReferenceLine referenceLine,
                                  string filePath,
                                  IImporterMessageProvider messageProvider,
                                  IStructureUpdateStrategy <ClosingStructure> updateStrategy)
     : base(importTarget, referenceLine, filePath, messageProvider, updateStrategy)
 {
 }
Exemplo n.º 20
0
 private void Init()
 {
     gSC  = new StructureCollection();
     gVal = new AzValues(gOwer);
     base.SystemUsers.GetDataByName(Pub.Session.GetManager(gOwer));
     //gstrDefaultTable = "";
     gCache = new Ly.IO.Json();
 }
Exemplo n.º 21
0
        /// <summary>
        /// Creates a new instance of <see cref="StructureCollectionProperties{TStructure}"/>.
        /// </summary>
        /// <param name="collection">The collection for which the properties are shown.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="collection"/>
        /// is <c>null</c>.</exception>
        public StructureCollectionProperties(StructureCollection <TStructure> collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            data = collection;
        }
        public void Import_MissingParametersAndDuplicateIrrelevantParameter_LogWarningAndContinueImport()
        {
            // Setup
            var    importTarget = new StructureCollection <HeightStructure>();
            string filePath     = Path.Combine(testDataPath, nameof(HeightStructuresImporter),
                                               "MissingAndDuplicateIrrelevantParameters", "Kunstwerken.shp");

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var strategy        = mocks.StrictMock <IStructureUpdateStrategy <HeightStructure> >();

            strategy.Expect(s => s.UpdateStructuresWithImportedData(null, null)).IgnoreArguments()
            .WhenCalled(invocation =>
            {
                Assert.AreSame(invocation.Arguments[1], filePath);

                var readStructures = (IEnumerable <HeightStructure>)invocation.Arguments[0];
                Assert.AreEqual(1, readStructures.Count());
                HeightStructure structure = readStructures.First();
                var defaultStructure      = new HeightStructure(new HeightStructure.ConstructionProperties
                {
                    Name     = "test",
                    Location = new Point2D(0, 0),
                    Id       = "id"
                });
                Assert.AreEqual(defaultStructure.StructureNormalOrientation, structure.StructureNormalOrientation);
                DistributionAssert.AreEqual(defaultStructure.FlowWidthAtBottomProtection, structure.FlowWidthAtBottomProtection);
                Assert.AreEqual(defaultStructure.FailureProbabilityStructureWithErosion, structure.FailureProbabilityStructureWithErosion);
            })
            .Return(Enumerable.Empty <IObservable>());
            mocks.ReplayAll();

            ReferenceLine referenceLine = CreateReferenceLine();

            var importer = new HeightStructuresImporter(importTarget, referenceLine, filePath,
                                                        messageProvider, strategy);

            var importResult = false;

            // Call
            Action call = () => importResult = importer.Import();

            // Assert
            TestHelper.AssertLogMessages(call, msgs =>
            {
                string[] messages = msgs.ToArray();
                Assert.AreEqual(5, messages.Length);

                const string structure = "'Coupure Den Oever (90k1)' (KUNST1)";

                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_HOOGTE1' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[0]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_HOOGTE3' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[1]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_HOOGTE6' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[2]);
                // Don't care about the other message.
            });
            Assert.IsTrue(importResult);
        }
Exemplo n.º 23
0
        public void Import_MissingParametersAndDuplicateIrrelevantParameter_LogWarningAndContinueImportWithDefaultValues()
        {
            // Setup
            var    importTarget = new StructureCollection <ClosingStructure>();
            string filePath     = Path.Combine(testDataPath, nameof(ClosingStructuresImporter),
                                               "MissingAndDuplicateIrrelevantParameters", "Kunstwerken.shp");

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.StrictMock <IStructureUpdateStrategy <ClosingStructure> >();

            updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i =>
            {
                Assert.AreEqual(filePath, i.Arguments[1]);

                var defaultStructure = new ClosingStructure(new ClosingStructure.ConstructionProperties
                {
                    Name     = "test",
                    Location = new Point2D(0, 0),
                    Id       = "id"
                });

                var readStructures = (IEnumerable <ClosingStructure>)i.Arguments[0];
                Assert.AreEqual(1, readStructures.Count());
                ClosingStructure importedStructure = readStructures.First();
                DistributionAssert.AreEqual(defaultStructure.StorageStructureArea, importedStructure.StorageStructureArea);
                DistributionAssert.AreEqual(defaultStructure.LevelCrestStructureNotClosing, importedStructure.LevelCrestStructureNotClosing);
                DistributionAssert.AreEqual(defaultStructure.AreaFlowApertures, importedStructure.AreaFlowApertures);
                Assert.AreEqual(defaultStructure.FailureProbabilityReparation, importedStructure.FailureProbabilityReparation);
            });
            mocks.ReplayAll();

            ReferenceLine referenceLine = CreateReferenceLine();

            var structuresImporter = new ClosingStructuresImporter(importTarget, referenceLine,
                                                                   filePath, messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = structuresImporter.Import();

            // Assert
            TestHelper.AssertLogMessages(call, msgs =>
            {
                string[] messages = msgs.ToArray();
                Assert.AreEqual(10, messages.Length);

                const string structure = "'Coupure Den Oever (90k1)' (KUNST1)";

                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT1' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[0]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT5' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[3]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT8' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[6]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT14' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[8]);
                // Don't care about the other messages.
            });
            Assert.IsTrue(importResult);
        }
Exemplo n.º 24
0
        //public string ToolName() { return null; }
        //public string ToolVersion() { return null; }
        //TODO: Button Activation/Deactivation sequence parameters. Different GUI?
        //TODO: Function-specific structure holder component to externalize structure variable definition from ControlUnit

        #region Public Methods
        public void LoadModelingStructure(String path, String parserType)
        {
            parser = ParserFactory.CreateParser(parserType);
            String name = "";

            this.path = path;
            ResetAttributes();
            structureCollection = parser.ParserMethod(path, ref name, null);
            this.Name           = name;
        }
Exemplo n.º 25
0
        public void Import_VarianceValuesNeedConversion_WarnUserAboutConversion()
        {
            // Setup
            var    importTarget = new StructureCollection <ClosingStructure>();
            string filePath     = Path.Combine(testDataPath, "StructuresVarianceValueConversion",
                                               "Kunstwerken.shp");

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.StrictMock <IStructureUpdateStrategy <ClosingStructure> >();

            updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i =>
            {
                Assert.AreEqual(filePath, i.Arguments[1]);

                var closingStructures = (IEnumerable <ClosingStructure>)i.Arguments[0];
                Assert.AreEqual(1, closingStructures.Count());

                ClosingStructure structure = closingStructures.First();
                Assert.AreEqual(0.2, structure.StorageStructureArea.CoefficientOfVariation.Value);
                Assert.AreEqual(20, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value);
                Assert.AreEqual(50, structure.WidthFlowApertures.StandardDeviation.Value);
                Assert.AreEqual(2.2, structure.LevelCrestStructureNotClosing.StandardDeviation.Value);
                Assert.AreEqual(3.3, structure.InsideWaterLevel.StandardDeviation.Value);
                Assert.AreEqual(4.4, structure.ThresholdHeightOpenWeir.StandardDeviation.Value);
                Assert.AreEqual(5.5, structure.AreaFlowApertures.StandardDeviation.Value);
                Assert.AreEqual(0.1, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value);
                Assert.AreEqual(6.6, structure.FlowWidthAtBottomProtection.StandardDeviation.Value);
            });
            mocks.ReplayAll();

            ReferenceLine referenceLine = CreateReferenceLine();

            var importer = new ClosingStructuresImporter(importTarget, referenceLine, filePath,
                                                         messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = importer.Import();

            // Assert
            string[] expectedMessages =
            {
                "De variatie voor parameter 'KW_BETSLUIT1' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 10).",
                "De variatie voor parameter 'KW_BETSLUIT2' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 11).",
                "De variatie voor parameter 'KW_BETSLUIT4' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 13).",
                "De variatie voor parameter 'KW_BETSLUIT5' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 14).",
                "De variatie voor parameter 'KW_BETSLUIT6' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 15).",
                "De variatie voor parameter 'KW_BETSLUIT7' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 16).",
                "De variatie voor parameter 'KW_BETSLUIT8' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 17).",
                "De variatie voor parameter 'KW_BETSLUIT9' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 18).",
                "De variatie voor parameter 'KW_BETSLUIT10' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 19)."
            };
            TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages);
            Assert.IsTrue(importResult);
        }
Exemplo n.º 26
0
        public override StructureCollection ParserMethod(String path, ref String name, Tuple <String, Object>[] args)
        {
            StructureCollection model    = new StructureCollection();
            XmlDocument         document = new XmlDocument();

            document.Load(path);
            ToOATS(document);
            model.listGeneralStructure.AddRange(listModelingStructure);

            return(model);
        }
Exemplo n.º 27
0
        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);
        }
 private static void AddEntitiesForHeightStructures(
     StructureCollection <HeightStructure> structures,
     FailureMechanismEntity entity,
     PersistenceRegistry registry)
 {
     for (var i = 0; i < structures.Count; i++)
     {
         HeightStructureEntity structureEntity = structures[i].Create(registry, i);
         entity.HeightStructureEntities.Add(structureEntity);
     }
 }
Exemplo n.º 29
0
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var mainWindow        = mocks.Stub <IMainWindow>();
            var gui = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            var failureMechanism = new StabilityPointStructuresFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation <StabilityPointStructuresInput>
            {
                Output = new TestStructuresOutput()
            });

            var structures = new StructureCollection <StabilityPointStructure>();
            var context    = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection);

            string textBoxMessage = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var helper = new MessageBoxTester(wnd);
                textBoxMessage = helper.Text;

                if (isActionConfirmed)
                {
                    helper.ClickOk();
                }
                else
                {
                    helper.ClickCancel();
                }
            };

            using (var plugin = new StabilityPointStructuresPlugin())
            {
                plugin.Gui = gui;
                ImportInfo importInfo = GetImportInfo(plugin);

                // Call
                bool updatesVerified = importInfo.VerifyUpdates(context);

                // Assert
                string expectedInquiryMessage = "Als u kunstwerken importeert, dan worden alle rekenresultaten van dit faalmechanisme verwijderd." +
                                                $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";
                Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
                Assert.AreEqual(isActionConfirmed, updatesVerified);
                mocks.VerifyAll();
            }
        }
Exemplo n.º 30
0
        public override StructureCollection ParserMethod(String path, ref String name, Tuple <String, Object>[] args)
        {
            ResetAttributes();
            StructureCollection model    = new StructureCollection();
            XmlDocument         document = new XmlDocument();

            document.Load(path);
            listModelingStructure.Add(FromXmi(document, ref name));
            model.listGeneralStructure.AddRange(listModelingStructure);

            return(model);
        }
Exemplo n.º 31
0
 // constructors
 internal Structures(string pluginDataFolder, Encoding encoding)
 {
     this.Ground = new StructureCollection();
     this.Rail = new StructureCollection();
     this.WallL = new StructureCollection();
     this.WallR = new StructureCollection();
     this.DikeL = new StructureCollection();
     this.DikeR = new StructureCollection();
     this.Pole = new StructureCollection();
     this.PoleMirrored = new StructureCollection();
     this.FormL = new StructureCollection();
     this.FormR = new StructureCollection();
     this.FormCL = new StructureCollection();
     this.FormCR = new StructureCollection();
     this.RoofL = new StructureCollection();
     this.RoofR = new StructureCollection();
     this.RoofCL = new StructureCollection();
     this.RoofCR = new StructureCollection();
     this.CrackL = new StructureCollection();
     this.CrackR = new StructureCollection();
     this.FreeObj = new StructureCollection();
     this.Beacon = new Parser.StructureCollection();
     this.Cycle = new CycleCollection();
     this.Limits = new Parser.StructureCollection();
     /*
      * Set up the default objects.
      * */
     string poleFolder = OpenBveApi.Path.CombineFolder(pluginDataFolder, "poles");
     this.PoleMirrored.Set(0, 0, OpenBveApi.Path.CombineFile(poleFolder, "pole_1.csv"), true);
     this.Pole.Set(0, 0, OpenBveApi.Path.CombineFile(poleFolder, "pole_1.csv"), false);
     this.Pole.Set(0, 1, OpenBveApi.Path.CombineFile(poleFolder, "pole_2.csv"), false);
     this.Pole.Set(0, 2, OpenBveApi.Path.CombineFile(poleFolder, "pole_3.csv"), false);
     this.Pole.Set(0, 3, OpenBveApi.Path.CombineFile(poleFolder, "pole_4.csv"), false);
     string transponderFolder = OpenBveApi.Path.CombineFolder(pluginDataFolder, "transponders");
     this.Beacon.Set(-1, 0, OpenBveApi.Path.CombineFile(transponderFolder, "s.csv"), false);
     this.Beacon.Set(-2, 0, OpenBveApi.Path.CombineFile(transponderFolder, "sn.csv"), false);
     this.Beacon.Set(-3, 0, OpenBveApi.Path.CombineFile(transponderFolder, "falsestart.csv"), false);
     this.Beacon.Set(-4, 0, OpenBveApi.Path.CombineFile(transponderFolder, "porigin.csv"), false);
     this.Beacon.Set(-5, 0, OpenBveApi.Path.CombineFile(transponderFolder, "pstop.csv"), false);
     string stopFolder = OpenBveApi.Path.CombineFolder(pluginDataFolder, "stops");
     this.Stop = new Parser.Structure(0, 0, OpenBveApi.Path.CombineFile(stopFolder, "stop.csv"), false);
     string limitFolder = OpenBveApi.Path.CombineFolder(pluginDataFolder, "limits");
     this.Limits.Set(0, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_0.csv"), false);
     this.Limits.Set(1, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_1.csv"), false);
     this.Limits.Set(2, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_2.csv"), false);
     this.Limits.Set(3, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_3.csv"), false);
     this.Limits.Set(4, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_4.csv"), false);
     this.Limits.Set(5, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_5.csv"), false);
     this.Limits.Set(6, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_6.csv"), false);
     this.Limits.Set(7, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_7.csv"), false);
     this.Limits.Set(8, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_8.csv"), false);
     this.Limits.Set(9, 0, OpenBveApi.Path.CombineFile(limitFolder, "digit_9.csv"), false);
     this.Limits.Set(10, 0, OpenBveApi.Path.CombineFile(limitFolder, "unlimited.csv"), false);
     this.Limits.Set(11, 0, OpenBveApi.Path.CombineFile(limitFolder, "limit_left.csv"), false);
     this.Limits.Set(12, 0, OpenBveApi.Path.CombineFile(limitFolder, "limit_straight.csv"), false);
     this.Limits.Set(13, 0, OpenBveApi.Path.CombineFile(limitFolder, "limit_right.csv"), false);
 }