private void AssertTrowsException <T>(string line)
            where T : Exception
        {
            ConsoleOutputReceiver receiver = new ConsoleOutputReceiver();

            Assert.Throws <T>(() => receiver.ThrowOnError(line));
        }
        public void TrowOnErrorTest()
        {
            AssertTrowsException <FileNotFoundException>("/dev/test: not found");
            AssertTrowsException <FileNotFoundException>("No such file or directory");
            AssertTrowsException <UnknownOptionException>("Unknown option -h");
            AssertTrowsException <CommandAbortingException>("/dev/test: Aborting.");
            AssertTrowsException <FileNotFoundException>("/dev/test: applet not found");
            AssertTrowsException <PermissionDeniedException>("/dev/test: permission denied");
            AssertTrowsException <PermissionDeniedException>("/dev/test: access denied");

            // Should not thrown an exception
            ConsoleOutputReceiver receiver = new ConsoleOutputReceiver();

            receiver.ThrowOnError("Stay calm and watch cat movies.");
        }
        private void AssertTrowsException <T>(string line)
            where T : Exception
        {
            ConsoleOutputReceiver receiver = new ConsoleOutputReceiver();

            try
            {
                receiver.ThrowOnError(line);
                throw new AssertFailedException($"An exception of type {typeof(T).FullName} was not thrown");
            }
            catch (T)
            {
                // All OK - an exception of type T was thrown
            }
            catch (Exception ex)
            {
                throw new AssertFailedException($"An exception of type {typeof(T).FullName} was expected, but of type {ex.GetType().FullName} was thrown instead.");
            }
        }