Пример #1
0
 public SyncTryFrame(
     TryFrameType frameType,
     Func <object, object> action,
     SyncCatchClause catchClause)
     : base(frameType, catchClause)
 {
     Action = action;
 }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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()));
        }
Пример #5
0
        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);
        }