Пример #1
0
        // Cannot use standard Assert.Throws() when testing Span - Span and closures don't get along.
        public static E AssertThrows <E, T>(ReadOnlySpan <T> span, AssertThrowsActionReadOnly <T> action) where E : Exception
        {
            Exception exception;

            try
            {
                action(span);
                exception = null;
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            switch (exception)
            {
            case null:
                throw new ThrowsException(typeof(E));

            case E ex when(ex.GetType() == typeof(E)):
                return(ex);

            default:
                throw new ThrowsException(typeof(E), exception);
            }
        }
Пример #2
0
 // Cannot use standard Assert.Throws() when testing Span - Span and closures don't get along.
 public static void AssertThrows <E, T>(ReadOnlySpan <T> span, AssertThrowsActionReadOnly <T> action) where E : Exception
 {
     try
     {
         action(span);
         Assert.False(true, $"Expected exception: {typeof(E)}");
     }
     catch (Exception ex)
     {
         Assert.True(ex is E, $"Wrong exception thrown. Expected: {typeof(E)} Actual: {ex.GetType()}");
     }
 }
Пример #3
0
 // Cannot use standard Assert.Throws() when testing Span - Span and closures don't get along.
 public static void AssertThrows <E, T>(ReadOnlySpan <T> span, AssertThrowsActionReadOnly <T> action) where E : Exception
 {
     try
     {
         action(span);
         Assert.False(true, "Expected exception: " + typeof(E).GetType());
     }
     catch (E)
     {
     }
     catch (Exception wrongException)
     {
         Assert.False(true, "Wrong exception thrown: Expected " + typeof(E).GetType() + ": Actual: " + wrongException.GetType());
     }
 }
Пример #4
0
        // Cannot use standard Assert.Throws() when testing Span - Span and closures don't get along.
        public static void AssertThrows <E, T>(ReadOnlySpan <T> span, AssertThrowsActionReadOnly <T> action) where E : Exception
        {
            Exception exception;

            try
            {
                action(span);
                exception = null;
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (exception == null)
            {
                throw new ThrowsException(typeof(E));
            }

            if (exception.GetType() != typeof(E))
            {
                throw new ThrowsException(typeof(E), exception);
            }
        }
Пример #5
0
        public static E Throws <E, T>(string expectedParamName, ReadOnlySpan <T> span, AssertThrowsActionReadOnly <T> action)
            where E : ArgumentException
        {
            E exception = AssertThrows <E, T>(span, action);

            Assert.Equal(expectedParamName, exception.ParamName);
            return(exception);
        }