public async Task ETW_Send_Receive_Test() { const int count = 4; // arrange using (var listener = new VisualRxEtwListener()) { // listen IObservable <Marble> listenStream = await listener.GetStreamAsync(); listenStream = listenStream.Replay().RefCount(); ITestableObserver <Marble> listenObserver = _scheduler.CreateObserver <Marble>(); listenStream .Subscribe(listenObserver); // publish var channel = new EtwVisualRxChannel(); await PublisherSetting.TryAddChannels(channel); PublisherSetting.AddFilter((key, provider) => true); // act var xs = Observable.Range(0, count, _scheduler) .Select(i => new Person(i)) .Monitor("Test", PublisherSetting); xs.Subscribe(v => { }); _scheduler.AdvanceBy(5); await listenStream //.Do(v => { },() => { }) .Take(count + 1); for (int i = 0; i < count; i++) { Assert.AreEqual(NotificationKind.OnNext, listenObserver.Messages[i].Value.Kind); var marble = listenObserver.Messages[i].Value.Value; var p = marble.GetValue <Person>(); Assert.AreEqual(i, p.Id); } Marble lastMarble = listenObserver.Messages[count].Value.Value; Assert.AreEqual(NotificationKind.OnCompleted, lastMarble.Kind); } }
public async Task Send_Receive_Test() { // arrange var testChannel = new TestVisualRxChannel(); await PublisherSetting.TryAddChannels(testChannel); PublisherSetting.AddFilter((key, provider) => true); // act var xs = Observable.Range(0, 10, _scheduler) .Monitor("Test", PublisherSetting); xs.Subscribe(v => { }); _scheduler.AdvanceBy(11); // verify var expected = Enumerable.Range(0, 10); var results = testChannel.Results.Select(m => m.GetValue <int>()); bool succeed = Enumerable.SequenceEqual(expected, results); Assert.IsTrue(succeed); Assert.IsTrue(testChannel.Completion.IsCompleted); }
public async Task MultiChannel_Filter_Test() { // arrange var testChannelA = new TestVisualRxChannel(Guid.NewGuid()); var testChannelB = new TestVisualRxChannel(Guid.NewGuid()); await PublisherSetting.TryAddChannels(testChannelA, testChannelB); // act var xs = Observable.Range(0, 10, _scheduler) .Monitor("Test", PublisherSetting); xs.Subscribe(v => { }); PublisherSetting.AddFilter((key, channel) => channel == testChannelA); _scheduler.AdvanceBy(11); // verify var expected = Enumerable.Range(0, 10); var results = testChannelA.Results.Select(m => m.GetValue <int>()); bool succeed = Enumerable.SequenceEqual(expected, results); Assert.IsTrue(succeed); Assert.IsTrue(testChannelA.Completion.IsCompleted); Assert.AreEqual(0, testChannelB.Results.Length); }