public SyncTryFrame( TryFrameType frameType, Func <object, object> action, SyncCatchClause catchClause) : base(frameType, catchClause) { Action = action; }
public void CanCreate() { Func <Exception, object> handler = exception => 9; var type = typeof(ArithmeticException); var x = new SyncCatchClause(handler, type); Assert.AreSame(handler, x.Handler); Assert.AreEqual(type, x.ExceptionType); }
public void CanCreate() { var type = TryFrameType.CatchClause; Func <object, object> action = o => o; var clause = new SyncCatchClause(exception => 9, typeof(ArithmeticException)); var x = new SyncTryFrame(type, action, clause); Assert.AreEqual(type, x.FrameType); Assert.AreSame(action, x.Action); Assert.AreSame(clause, x.CatchClause); }
public void CanDetermineHandlerCompatibility() { Func <Exception, object> handler = exception => 9; var type = typeof(OperationCanceledException); var x = new SyncCatchClause(handler, type); Assert.IsTrue(x.CanHandle(new OperationCanceledException())); Assert.IsTrue(x.CanHandle(new TaskCanceledException())); Assert.IsFalse(x.CanHandle(new ArithmeticException())); Assert.IsFalse(x.CanHandle(new ArgumentNullException())); }
public async Task CanConvertToAsync() { var wasCalled = false; Func <Exception, object> handler = exception => { wasCalled = true; return(9); }; var type = typeof(ArithmeticException); var x = new SyncCatchClause(handler, type); var y = x.ToAsync(); Assert.AreEqual(type, y.ExceptionType); Assert.IsFalse(wasCalled); await y.Handler(new ArithmeticException()); Assert.IsTrue(wasCalled); }