public void CanAdd() { var f1 = new SyncTryFrame( TryFrameType.Action, _ => new object(), null); var f2 = new SyncTryFrame( TryFrameType.CatchClause, null, new SyncCatchClause( _ => 9, typeof(ArithmeticException))); var frames = new[] { f1, }; var x = new SyncTryFrames(frames); var y = x.Add(f2); Assert.AreEqual(1, x.Length); Assert.AreEqual(2, y.Length); Assert.AreSame(f1, x[0]); Assert.AreSame(f1, y[0]); Assert.AreSame(f2, y[1]); }
public SyncTryFrames Add(SyncTryFrame frame) { var clausesLength = Frames.Length; var arr = new SyncTryFrame[clausesLength + 1]; Array.Copy(Frames, arr, clausesLength); arr[clausesLength] = frame; return(new SyncTryFrames(arr)); }
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 async Task CanConvertToAsync() { var wasF2Called = false; var f1 = new SyncTryFrame( TryFrameType.Action, _ => "my expected value", null); var f2 = new SyncTryFrame( TryFrameType.CatchClause, null, new SyncCatchClause( _ => { wasF2Called = true; return(9); }, typeof(ArithmeticException))); var frames = new[] { f1, f2 }; var x = new SyncTryFrames(frames); var y = x.ToAsync(); Assert.AreEqual(2, y.Length); var y1 = y[0]; Assert.AreEqual(f1.FrameType, y1.FrameType); Assert.IsNull(y1.CatchClause); Assert.AreEqual("my expected value", await y1.Action(new object())); var y2 = y[1]; Assert.AreEqual(f2.FrameType, y2.FrameType); Assert.IsNull(y2.Action); Assert.AreEqual(typeof(ArithmeticException), y2.CatchClause.ExceptionType); await y2.CatchClause.Handler(new ArithmeticException()); Assert.IsTrue(wasF2Called); }