Example #1
0
        public static void RecordExceptionReturnsExceptionFromAwaitableObjectResult()
        {
            var exceptionToThrow = new Exception();

            Assert.That(
                ExceptionHelper.RecordException(new Func <Task>(() => TaskFromException(exceptionToThrow)), "someParamName"),
                Is.SameAs(exceptionToThrow));
        }
Example #2
0
        public static void RecordExceptionThrowsProperExceptionForDelegatesThatHaveOneMoreParameterThanTheBoundMethod()
        {
            var methodInfo = typeof(Foo).GetMethod(nameof(Foo.DummyInstanceMethod));
            var delegateThatParameterizesTheInstance = (Action <Foo>)methodInfo.CreateDelegate(typeof(Action <Foo>));

            Assert.That(
                () => ExceptionHelper.RecordException(delegateThatParameterizesTheInstance, "someParamName"),
                Throws.ArgumentException);
        }
Example #3
0
        public static void RecordExceptionHandlesDelegatesThatHaveOneFewerParameterThanTheBoundMethod()
        {
            Assert.That(
                ExceptionHelper.RecordException(new TestDelegate(new Foo(null).ThrowingExtensionMethod), "someParamName"),
                Is.Null);

            var exceptionToThrow = new Exception();

            Assert.That(
                ExceptionHelper.RecordException(new TestDelegate(new Foo(exceptionToThrow).ThrowingExtensionMethod), "someParamName"),
                Is.SameAs(exceptionToThrow));
        }
Example #4
0
 public static void RecordExceptionThrowsForDelegateThatRequiresParameters()
 {
     Assert.That(
         () => ExceptionHelper.RecordException(new Action <object>(_ => { }), "someParamName"),
         Throws.ArgumentException.With.Property("ParamName").EqualTo("someParamName"));
 }
Example #5
0
 public static void RecordExceptionThrowsForNullDelegate()
 {
     Assert.That(
         () => ExceptionHelper.RecordException(null, "someParamName"),
         Throws.ArgumentNullException.With.Property("ParamName").EqualTo("someParamName"));
 }