public void FromEventPattern_Conversion_E5() { var scheduler = new TestScheduler(); var fe = new FromEventPattern(); scheduler.ScheduleAbsolute(50, () => fe.M5(1)); scheduler.ScheduleAbsolute(150, () => fe.M5(2)); scheduler.ScheduleAbsolute(250, () => fe.M5(3)); scheduler.ScheduleAbsolute(350, () => fe.M5(4)); scheduler.ScheduleAbsolute(450, () => fe.M5(5)); scheduler.ScheduleAbsolute(1050, () => fe.M5(6)); var results = scheduler.Start(() => Observable.FromEventPattern( h => fe.E5 += h, h => fe.E5 -= h) .Select(evt => new { evt.Sender, EventArgs = (FromEventPattern.TestEventArgs)evt.EventArgs })); results.Messages.AssertEqual( OnNext(250, new { Sender = (object)fe, EventArgs = new FromEventPattern.TestEventArgs { Id = 3 } }), OnNext(350, new { Sender = (object)fe, EventArgs = new FromEventPattern.TestEventArgs { Id = 4 } }), OnNext(450, new { Sender = (object)fe, EventArgs = new FromEventPattern.TestEventArgs { Id = 5 } }) ); }
public void FromEventPattern_E2_WithSender() { var scheduler = new TestScheduler(); var fe = new FromEventPattern(); scheduler.ScheduleAbsolute(50, () => fe.M2(1)); scheduler.ScheduleAbsolute(150, () => fe.M2(2)); scheduler.ScheduleAbsolute(250, () => fe.M2(3)); scheduler.ScheduleAbsolute(350, () => fe.M2(4)); scheduler.ScheduleAbsolute(450, () => fe.M2(5)); scheduler.ScheduleAbsolute(1050, () => fe.M2(6)); var results = scheduler.Start(() => Observable.FromEventPattern <EventHandler <FromEventPattern.TestEventArgs>, object, FromEventPattern.TestEventArgs>( h => fe.E2 += h, h => fe.E2 -= h) .Select(evt => new { evt.Sender, evt.EventArgs })); results.Messages.AssertEqual( OnNext(250, new { Sender = (object)fe, EventArgs = new FromEventPattern.TestEventArgs { Id = 3 } }), OnNext(350, new { Sender = (object)fe, EventArgs = new FromEventPattern.TestEventArgs { Id = 4 } }), OnNext(450, new { Sender = (object)fe, EventArgs = new FromEventPattern.TestEventArgs { Id = 5 } }) ); }
public void FromEventPattern_Conversion_E4() { var scheduler = new TestScheduler(); var fe = new FromEventPattern(); scheduler.ScheduleAbsolute(50, () => fe.M4(1)); scheduler.ScheduleAbsolute(150, () => fe.M4(2)); scheduler.ScheduleAbsolute(250, () => fe.M4(3)); scheduler.ScheduleAbsolute(350, () => fe.M4(4)); scheduler.ScheduleAbsolute(450, () => fe.M4(5)); scheduler.ScheduleAbsolute(1050, () => fe.M4(6)); var results = scheduler.Start(() => Observable.FromEventPattern <Action <int>, FromEventPattern.TestEventArgs>( h => new Action <int>(x => h(fe, new FromEventPattern.TestEventArgs { Id = x })), h => fe.E4 += h, h => fe.E4 -= h) .Select(evt => new { evt.Sender, evt.EventArgs })); results.Messages.AssertEqual( OnNext(250, new { Sender = (object)fe, EventArgs = new FromEventPattern.TestEventArgs { Id = 3 } }), OnNext(350, new { Sender = (object)fe, EventArgs = new FromEventPattern.TestEventArgs { Id = 4 } }), OnNext(450, new { Sender = (object)fe, EventArgs = new FromEventPattern.TestEventArgs { Id = 5 } }) ); }
public void FromEventPattern_ConversionThrows() { var ex = new Exception(); var fe = new FromEventPattern(); var res = Observable.FromEventPattern <Action <int>, FromEventPattern.TestEventArgs>( h => { throw ex; }, h => fe.E4 += h, h => fe.E4 -= h ); var err = default(Exception); res.Subscribe(_ => { Assert.True(false); }, ex_ => err = ex_, () => { Assert.True(false); }); Assert.Same(ex, err); }