internal SshNativeException(
            LIBSSH2_ERROR code,
            string errorMessage)
            : base(errorMessage)
        {
            Debug.Assert(code != LIBSSH2_ERROR.NONE);

            this.ErrorCode = code;
        }
Exemple #2
0
 public static void ThrowsAggregateExceptionWithError(
     LIBSSH2_ERROR expected,
     TestDelegate code)
 {
     ThrowsNativeExceptionWithError(
         null,
         expected,
         () =>
     {
         try
         {
             code();
         }
         catch (AggregateException e)
         {
             throw e.Unwrap();
         }
     });
 }
Exemple #3
0
        public static void ThrowsNativeExceptionWithError(
            SshSession session,
            LIBSSH2_ERROR expected,
            Action action)
        {
            try
            {
                action();
                Assert.Fail("Expected SshNativeException with error " + expected);
            }
            catch (Exception e) when(!(e is AssertionException))
            {
                Assert.IsInstanceOf(typeof(SshNativeException), e.Unwrap());
                Assert.AreEqual(expected, ((SshNativeException)e.Unwrap()).ErrorCode);

                if (session != null)
                {
                    Assert.IsTrue(session.LastError == LIBSSH2_ERROR.NONE ||
                                  session.LastError == expected);
                }
            }
        }
Exemple #4
0
        public SshNativeException CreateException(LIBSSH2_ERROR error)
        {
            var lastError = (LIBSSH2_ERROR)UnsafeNativeMethods.libssh2_session_last_error(
                this.sessionHandle,
                out IntPtr errorMessage,
                out int errorMessageLength,
                0);

            if (lastError == error)
            {
                return(new SshNativeException(
                           error,
                           Marshal.PtrToStringAnsi(errorMessage, errorMessageLength)));
            }
            else
            {
                // The last error is something else, so create a generic
                // exception
                return(new SshNativeException(
                           error,
                           $"SSH operation failed: {error}"));
            }
        }