Exemple #1
0
        public void Calculate_WithCustomParser_ParsersExecutedAndOutputSet()
        {
            // Setup
            var parser     = new TestParser();
            var calculator = new TestHydraRingCalculator(HydraRingCalculationSettingsTestFactory.CreateSettings(),
                                                         parser);

            // Call
            calculator.PublicCalculate(new TestHydraRingCalculationInput());

            // Assert
            Assert.IsTrue(!string.IsNullOrEmpty(calculator.OutputDirectory));
            Assert.IsTrue(parser.Parsed);
        }
Exemple #2
0
        public void Calculate_LastErrorFilePresent_LastErrorFileContentSet()
        {
            // Setup
            var settings   = new HydraRingCalculationSettings("D:\\HLCD.sqlite", string.Empty, false);
            var calculator = new TestHydraRingCalculator(settings, new TestParser());

            // Call
            calculator.PublicCalculate(new TestHydraRingCalculationInput());

            // Assert
            var expectedContent = $"Hydraulic database {settings.HlcdFilePath} not found.\r\n";

            Assert.AreEqual(expectedContent, calculator.LastErrorFileContent);
        }
Exemple #3
0
        public void Calculate_IllustrationPointsParserThrowsException_SetsIllustrationPointsParserError()
        {
            // Setup
            var calculator = new TestHydraRingCalculator(HydraRingCalculationSettingsTestFactory.CreateSettings(),
                                                         new TestParser());

            // Call
            calculator.PublicCalculate(new TestHydraRingCalculationInput());

            // Assert
            const string expectedMessage = "Er konden geen illustratiepunten worden uitgelezen.";

            Assert.AreEqual(expectedMessage, calculator.IllustrationPointsParserErrorMessage);
            Assert.IsNull(calculator.IllustrationPointsResult);
        }
Exemple #4
0
        public void Calculate_WithCustomParserThrowingHydraRingFileParserException_HydraRingCalculationExceptionThrown()
        {
            // Setup
            var parseException = new HydraRingFileParserException("message", new Exception());
            var parser         = new TestParser(parseException);
            var calculator     = new TestHydraRingCalculator(HydraRingCalculationSettingsTestFactory.CreateSettings(),
                                                             parser);

            // Call
            void Call() => calculator.PublicCalculate(new TestHydraRingCalculationInput());

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

            Assert.AreEqual(parseException.Message, exception.Message);
            Assert.AreSame(parseException.InnerException, exception.InnerException);
        }
Exemple #5
0
        public void Calculate_NoPreprocessorDirectoryWhenRequired_ThrowsInvalidOperationException()
        {
            // Setup
            var parser     = new TestParser();
            var settings   = new HydraRingCalculationSettings("D:\\hlcd.sqlite", string.Empty, false);
            var calculator = new TestHydraRingCalculator(settings, parser);
            var hydraRingCalculationInput = new TestHydraRingCalculationInput
            {
                PreprocessorSetting = new PreprocessorSetting(1, 2, new NumericsSetting(1, 4, 50, 0.15, 0.05, 0.01, 0.01, 0, 2, 20000, 100000, 0.1, -6, 6))
            };

            // Call
            void Call() => calculator.PublicCalculate(hydraRingCalculationInput);

            // Assert
            string message = Assert.Throws <InvalidOperationException>(Call).Message;

            Assert.AreEqual("Preprocessor directory required but not specified.", message);
        }
Exemple #6
0
        public void Calculate_WithCustomParserThrowingSupportedCalculatedException_HydraRingCalculationExceptionThrown(Type exceptionType)
        {
            // Setup
            var supportedException = (Exception)Activator.CreateInstance(exceptionType,
                                                                         "Exception message",
                                                                         new Exception("InnerException"));
            var parser     = new TestParser(supportedException);
            var calculator = new TestHydraRingCalculator(HydraRingCalculationSettingsTestFactory.CreateSettings(),
                                                         parser);

            // Call
            void Call() => calculator.PublicCalculate(new TestHydraRingCalculationInput());

            // Assert
            var    exception       = Assert.Throws <HydraRingCalculationException>(Call);
            string expectedMessage = "Het besturingssysteem geeft de volgende melding:"
                                     + Environment.NewLine
                                     + $"{supportedException.Message}";

            Assert.AreEqual(expectedMessage, exception.Message);
            Assert.AreSame(supportedException.InnerException, exception.InnerException);
        }