Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs =================================================================== diff -u -r020439f88aaed9dd51967acbc8518f37c95791d1 -rae137e9d1b26f1b37e47f2b4a6bf9ae03c6c9b2e --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision 020439f88aaed9dd51967acbc8518f37c95791d1) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision ae137e9d1b26f1b37e47f2b4a6bf9ae03c6c9b2e) @@ -29,6 +29,7 @@ using Core.Common.IO.Exceptions; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Probabilistics; @@ -96,8 +97,9 @@ public void Write_InvalidDirectoryRights_ThrowCriticalFileWriteException() { // Setup - string directoryPath = TestHelper.GetScratchPadPath(nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException)); - using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException))) + const string testName = nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException); + string directoryPath = TestHelper.GetScratchPadPath(testName); + using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), testName)) { string filePath = Path.Combine(directoryPath, "test.xml"); disposeHelper.LockDirectory(FileSystemRights.Write); @@ -321,7 +323,38 @@ } [Test] - [TestCaseSource(nameof(CalculationConfigurations))] + public void Write_CalculationOfTypeOtherThanGiven_ThrowsCriticalFileWriteExceptionWithInnerArgumentException() + { + // Setup + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + mocks.ReplayAll(); + + string filePath = TestHelper.GetScratchPadPath("test.xml"); + + try + { + // Call + TestDelegate test = () => new SimpleCalculationConfigurationWriter().Write(new[] + { + calculation + }, filePath); + + // Assert + var exception = Assert.Throws(test); + var innerException = exception.InnerException; + Assert.IsNotNull(innerException); + Assert.AreEqual($"Cannot write calculation of type '{calculation.GetType()}' using this writer.", innerException.Message); + } + finally + { + File.Delete(filePath); + } + mocks.VerifyAll(); + } + + [Test] + [TestCaseSource(nameof(GetCalculationConfigurations))] public void Write_DifferentCalculationAndCalculationGroupConfigurations_ValidFile(IEnumerable configuration, string expectedFileContentsFileName) { // Setup @@ -369,7 +402,7 @@ } } - private static IEnumerable CalculationConfigurations() + private static IEnumerable GetCalculationConfigurations() { var calculation1 = new TestCalculation("calculation1"); var calculation2 = new TestCalculation("calculation2");