public void TryReadStructure_NoStructureToFindStructuresEmpty_ReturnsTrue()
        {
            // Setup
            string filePath = Path.Combine(readerPath, "validConfiguration.xml");

            var calculationGroup = new CalculationGroup();

            var importer = new CalculationConfigurationImporter(filePath, calculationGroup);

            // Call
            bool valid = importer.PublicTryReadStructure(null, "name", Enumerable.Empty<StructureBase>(),
                                                         out StructureBase structure);

            // Assert
            Assert.IsTrue(valid);
            Assert.IsNull(structure);
        }
        public void TryReadStructure_NoCalculationName_ThrowsArgumentNullException()
        {
            // Setup
            string filePath = Path.Combine(readerPath, "validConfiguration.xml");

            var calculationGroup = new CalculationGroup();

            var importer = new CalculationConfigurationImporter(filePath, calculationGroup);

            // Call
            void Call() => importer.PublicTryReadStructure(
                null, null, Enumerable.Empty<TestStructure>(), out StructureBase _);

            // Assert
            var exception = Assert.Throws<ArgumentNullException>(Call);
            Assert.AreEqual("calculationName", exception.ParamName);
        }
        public void TryReadHydraulicBoundaryLocation_NoHydraulicBoundaryLocationToFindHydraulicBoundaryLocationsEmpty_ReturnsTrue()
        {
            // Setup
            string filePath = Path.Combine(readerPath, "validConfiguration.xml");

            var calculationGroup = new CalculationGroup();

            var importer = new CalculationConfigurationImporter(filePath, calculationGroup);

            // Call
            bool valid = importer.PublicTryReadHydraulicBoundaryLocation(
                null, "name", Enumerable.Empty<HydraulicBoundaryLocation>(), out HydraulicBoundaryLocation location);

            // Assert
            Assert.IsTrue(valid);
            Assert.IsNull(location);
        }
        public void PublicTrySetScenarioParameters_NoScenario_NoDataAddedToModelReturnsTrue()
        {
            // Setup
            var mockRepository = new MockRepository();
            var calculationScenario = mockRepository.StrictMock<ICalculationScenario>();
            mockRepository.ReplayAll();

            var importer = new CalculationConfigurationImporter(Path.Combine(readerPath, "validConfiguration.xml"),
                                                                new CalculationGroup());

            // Call
            bool successful = importer.PublicTrySetScenarioParameters(null, calculationScenario);

            // Assert
            Assert.IsTrue(successful);

            mockRepository.VerifyAll();
        }
        public void Import_InvalidFile_CancelImportWithErrorMessage()
        {
            // Setup
            string filePath = Path.Combine(readerPath, "invalidFolderNoName.xml");
            var importer = new CalculationConfigurationImporter(filePath, new CalculationGroup());

            // Call
            var importSuccessful = true;
            void Call() => importSuccessful = importer.Import();

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(1, msgs.Length);
                StringAssert.StartsWith($"Fout bij het lezen van bestand '{filePath}': het XML-document dat de configuratie voor de berekeningen beschrijft is niet geldig.", msgs[0]);
            });

            Assert.IsFalse(importSuccessful);
        }
        public void GivenImport_WhenImporting_ThenExpectedProgressMessagesGenerated()
        {
            // Given
            string filePath = Path.Combine(readerPath, "validConfiguration.xml");
            var progressChangeNotifications = new List<ProgressNotification>();

            var importer = new CalculationConfigurationImporter(filePath, new CalculationGroup());
            importer.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(
                                            new ProgressNotification(description, step, steps)));

            // When
            importer.Import();

            // Then
            var expectedProgressNotifications = new[]
            {
                new ProgressNotification("Inlezen berekeningenconfiguratie.", 1, 3),
                new ProgressNotification("Valideren berekeningenconfiguratie.", 2, 3),
                new ProgressNotification("Geïmporteerde data toevoegen aan het faalmechanisme.", 3, 3)
            };
            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressNotifications, progressChangeNotifications);
        }