Exemplo n.º 1
0
        public void Export_InvalidDirectoryRights_LogsErrorAndReturnsFalse()
        {
            // Setup
            string            filePath          = TestHelper.GetScratchPadPath(nameof(Export_InvalidDirectoryRights_LogsErrorAndReturnsFalse));
            AssessmentSection assessmentSection = CreateConfiguredAssessmentSection();

            var exporter = new AssemblyExporter(assessmentSection, filePath);

            using (var fileDisposeHelper = new FileDisposeHelper(filePath))
                using (new AssemblyToolCalculatorFactoryConfig())
                {
                    var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    AssessmentSectionAssemblyCalculatorStub assessmentSectionAssemblyCalculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator;
                    assessmentSectionAssemblyCalculator.CombinedFailureMechanismSectionAssemblyOutput = new CombinedFailureMechanismSectionAssemblyResultWrapper(
                        Array.Empty <CombinedFailureMechanismSectionAssembly>(), AssemblyMethod.BOI3A1, AssemblyMethod.BOI3B1, AssemblyMethod.BOI3C1);

                    fileDisposeHelper.LockFiles();

                    // Call
                    var isExported            = true;
                    void Call() => isExported = exporter.Export();

                    // Assert
                    string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. " +
                                             "Er zijn geen assemblageresultaten geëxporteerd.";
                    TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Error));
                    Assert.IsFalse(isExported);
                }
        }
Exemplo n.º 2
0
        public void Export_AssemblyCreatorExceptionThrown_LogsErrorAndReturnsFalse()
        {
            // Setup
            string            filePath          = TestHelper.GetScratchPadPath(nameof(Export_AssemblyCreatorExceptionThrown_LogsErrorAndReturnsFalse));
            AssessmentSection assessmentSection = CreateConfiguredAssessmentSection();

            var exporter = new AssemblyExporter(assessmentSection, filePath);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub failureMechanismSectionAssemblyCalculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
                failureMechanismSectionAssemblyCalculator.FailureMechanismSectionAssemblyResultOutput = new FailureMechanismSectionAssemblyResultWrapper(
                    new DefaultFailureMechanismSectionAssemblyResult(), AssemblyMethod.BOI0A1, AssemblyMethod.BOI0B1);

                // Call
                var isExported            = true;
                void Call() => isExported = exporter.Export();

                // Assert
                const string expectedMessage = "De assemblage kan niet succesvol worden afgerond. Inspecteer de resultaten van de faalmechanismen die onderdeel zijn van de assemblage of het veiligheidsoordeel voor meer details.";
                TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Error));
                Assert.IsFalse(isExported);
            }
        }
Exemplo n.º 3
0
        public void Export_SpecificFailureMechanismsWithSameName_ExpectedResultBasedOnInAssemblyState(
            bool firstSpecificFailureMechanismInAssembly,
            bool secondSpecificFailureMechanismInAssembly,
            bool isExportExpectedToBeSuccessful)
        {
            // Setup
            string            filePath          = TestHelper.GetScratchPadPath(nameof(Export_SpecificFailureMechanismsWithSameName_ExpectedResultBasedOnInAssemblyState));
            AssessmentSection assessmentSection = CreateConfiguredAssessmentSection();

            SpecificFailureMechanism specificFailureMechanism1 = assessmentSection.SpecificFailureMechanisms.ElementAt(0);
            SpecificFailureMechanism specificFailureMechanism2 = assessmentSection.SpecificFailureMechanisms.ElementAt(1);

            specificFailureMechanism1.InAssembly = firstSpecificFailureMechanismInAssembly;
            specificFailureMechanism2.InAssembly = secondSpecificFailureMechanismInAssembly;
            assessmentSection.SpecificFailureMechanisms.Last().Name = specificFailureMechanism1.Name;

            using (new FileDisposeHelper(filePath))
                using (new AssemblyToolCalculatorFactoryConfig())
                {
                    var exporter = new AssemblyExporter(assessmentSection, filePath);
                    SetCombinedFailureMechanismSectionAssemblyOutput(assessmentSection);

                    // Call & Assert
                    if (isExportExpectedToBeSuccessful)
                    {
                        Assert.IsTrue(exporter.Export());
                    }
                    else
                    {
                        var isExported = true;

                        const string expectedMessage = "Om assemblageresultaten te kunnen exporteren moeten alle specifieke faalmechanismen die onderdeel zijn van de assemblage een unieke naam hebben.";
                        TestHelper.AssertLogMessageWithLevelIsGenerated(() => isExported = exporter.Export(),
                                                                        new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Error));

                        Assert.IsFalse(isExported);
                    }
                }
        }
Exemplo n.º 4
0
        public void Export_FullyConfiguredAssessmentSectionAndValidAssemblyResults_ReturnsTrueAndCreatesFile()
        {
            // Setup
            string folderPath = TestHelper.GetScratchPadPath(nameof(Export_FullyConfiguredAssessmentSectionAndValidAssemblyResults_ReturnsTrueAndCreatesFile));

            Directory.CreateDirectory(folderPath);
            string filePath = Path.Combine(folderPath, "actualAssembly.gml");

            AssessmentSection assessmentSection = CreateConfiguredAssessmentSection();

            var exporter = new AssemblyExporter(assessmentSection, filePath);

            using (new FileDisposeHelper(filePath))
                using (new AssemblyToolCalculatorFactoryConfig())
                {
                    SetCombinedFailureMechanismSectionAssemblyOutput(assessmentSection);

                    try
                    {
                        // Call
                        bool isExported = exporter.Export();

                        // Assert
                        Assert.IsTrue(File.Exists(filePath));
                        Assert.IsTrue(isExported);

                        string expectedGmlFilePath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO),
                                                                  nameof(AssemblyExporter), "ExpectedGml.gml");
                        string expectedGml = File.ReadAllText(expectedGmlFilePath);
                        string actualGml   = File.ReadAllText(filePath);
                        Assert.AreEqual(expectedGml, actualGml);
                    }
                    finally
                    {
                        DirectoryHelper.TryDelete(folderPath);
                    }
                }
        }