Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Calculator/HydraRingCalculatorBaseTest.cs =================================================================== diff -u -r38d9d0f48489006bc56c3b5e76b7c2bc3822f762 -r6c058f12138b8a73a78eacd10357d9caa81ed67d --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Calculator/HydraRingCalculatorBaseTest.cs (.../HydraRingCalculatorBaseTest.cs) (revision 38d9d0f48489006bc56c3b5e76b7c2bc3822f762) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Calculator/HydraRingCalculatorBaseTest.cs (.../HydraRingCalculatorBaseTest.cs) (revision 6c058f12138b8a73a78eacd10357d9caa81ed67d) @@ -21,6 +21,9 @@ using System; using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Security; using NUnit.Framework; using Ringtoets.HydraRing.Calculation.Calculator; using Ringtoets.HydraRing.Calculation.Data; @@ -61,20 +64,48 @@ } [Test] - public void Calculate_WithCustomParserThrowingException_HydraRingCalculationExceptionThrown() + public void Calculate_WithCustomParserThrowingHydraRingFileParserException_HydraRingCalculationExceptionThrown() { // Setup - var parser = new TestParser(true); + var parseException = new HydraRingFileParserException("message", new Exception()); + var parser = new TestParser(parseException); var calculator = new TestHydraRingCalculator("", parser); // Call TestDelegate test = () => calculator.PublicCalculate(); // Assert var exception = Assert.Throws(test); - const string expectedMessage = "Er is een kritieke fout opgetreden bij het uitvoeren van de berekening."; + Assert.AreEqual(parseException.Message, exception.Message); + Assert.AreSame(parseException.InnerException, exception.InnerException); + } + + [Test] + [TestCase(typeof(SecurityException))] + [TestCase(typeof(IOException))] + [TestCase(typeof(UnauthorizedAccessException))] + [TestCase(typeof(ArgumentException))] + [TestCase(typeof(NotSupportedException))] + [TestCase(typeof(Win32Exception))] + 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("", parser); + + // Call + TestDelegate test = () => calculator.PublicCalculate(); + + // Assert + var exception = Assert.Throws(test); + string expectedMessage = "Het besturingssysteem geeft de volgende melding:" + + Environment.NewLine + + $"{supportedException.Message}"; Assert.AreEqual(expectedMessage, exception.Message); - Assert.IsInstanceOf(exception.InnerException); + Assert.AreSame(supportedException.InnerException, exception.InnerException); } } @@ -145,20 +176,20 @@ internal class TestParser : IHydraRingFileParser { - private readonly bool throwParseException; + private readonly Exception exception; - public TestParser(bool throwParseException = false) + public TestParser(Exception exception = null) { - this.throwParseException = throwParseException; + this.exception = exception; } public bool Parsed { get; private set; } public void Parse(string workingDirectory, int sectionId) { - if (throwParseException) + if (exception != null) { - throw new HydraRingFileParserException(); + throw exception; } Parsed = true; }