public void values_can_be_triggered_by_time_or_count() { var scheduler = new TestScheduler(); var source = scheduler.CreateColdObservable( // start #1 (@0) new Recorded <Notification <int> >(10, OnNext(1)), new Recorded <Notification <int> >(12, OnNext(2)), new Recorded <Notification <int> >(14, OnNext(3)), // start #2 (@ 15) new Recorded <Notification <int> >(16, OnNext(4)), new Recorded <Notification <int> >(20, OnNext(5)), new Recorded <Notification <int> >(24, OnNext(6)), new Recorded <Notification <int> >(28, OnNext(7)), // start #3 (@ 28) // start #4 (@ 43) new Recorded <Notification <int> >(50, OnNext(8)), new Recorded <Notification <int> >(51, OnCompleted()) ); var stats = new StatsObserver <IList <int> >(); source.BufferWithTimeOrCount(new TimeSpan(15), 4, scheduler) .Subscribe(stats); scheduler.Run(); Assert.AreEqual(4, stats.NextCount); Assert.AreEqual(3, stats.NextValues[0].Count); Assert.AreEqual(4, stats.NextValues[1].Count); Assert.AreEqual(0, stats.NextValues[2].Count); Assert.AreEqual(1, stats.NextValues[3].Count); }
public void SetUp() { source = new Subject<int>(); windows = new List<StatsSubject<Unit>>(); windowsStats = new List<StatsObserver<int>>(); overallStats = new StatsObserver<int>(); subscription = source.Window(() => { StatsSubject<Unit> window = new StatsSubject<Unit>(); windows.Add(window); return window; }) .Subscribe(o => { var stats = new StatsObserver<int>(); windowsStats.Add(stats); o.Subscribe(stats); }, overallStats.OnError, overallStats.OnCompleted); }
public void values_cannot_be_replayed_out_of_order() { ManualScheduler scheduler = new ManualScheduler(); ReplaySubject <int> subject = new ReplaySubject <int>(scheduler); StatsObserver <int> stats = new StatsObserver <int>(); subject.OnNext(1); subject.OnNext(2); subject.Subscribe(stats); Assert.IsFalse(stats.NextCalled); scheduler.RunNext(); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1 })); subject.OnNext(3); scheduler.RunNext(); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1, 2 })); scheduler.RunNext(); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1, 2, 3 })); subject.OnCompleted(); scheduler.RunNext(); Assert.IsTrue(stats.CompletedCalled); }
public void finally_action_is_executed_if_disposition_source_subscription_throws_exception() { StatsObserver<int> stats = new StatsObserver<int>(); bool finallyCalled = true; try { Observable.CreateWithDisposable<int>(obs => { return Disposable.Create(() => { throw new ApplicationException(); }); }) .Finally(() => { finallyCalled = true; }) .Subscribe(stats) .Dispose(); } finally { Assert.IsTrue(finallyCalled); } }
public void last_value_is_received_after_completed_if_any_connection_is_disposed() { Subject<int> subject = new Subject<int>(); var stats = new StatsObserver<int>(); var obs = subject.Prune(); var connectionA = obs.Connect(); var connectionB = obs.Connect(); subject.OnNext(1); subject.OnNext(2); subject.OnNext(3); connectionA.Dispose(); subject.OnCompleted(); connectionB.Dispose(); obs.Subscribe(stats); Assert.IsFalse(stats.NextCalled); Assert.IsFalse(stats.CompletedCalled); }
public void window_includes_onerror() { ManualScheduler scheduler = new ManualScheduler(); ReplaySubject <int> subject = new ReplaySubject <int>(TimeSpan.FromMilliseconds(10), scheduler); StatsObserver <int> stats = new StatsObserver <int>(); DateTime start = DateTime.UtcNow; scheduler.Now = start; subject.OnNext(1); scheduler.Now = start.AddMilliseconds(5); subject.OnNext(2); scheduler.Now = start.AddMilliseconds(10); subject.OnError(new Exception()); scheduler.Now = start.AddMilliseconds(11); subject.Subscribe(stats); scheduler.RunAll(); Assert.AreEqual(1, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2 })); Assert.IsTrue(stats.ErrorCalled); }
public void values_are_taken_from_each_selected_value() { var stats = new StatsObserver<int>(); var source = new Subject<int>(); var first = new Subject<int>(); var second = new Subject<int>(); var remaining = new Queue<IObservable<int>>(); remaining.Enqueue(first); remaining.Enqueue(second); var manObs = source .SelectMany(x => remaining.Dequeue()) .Subscribe(stats); source.OnNext(0); first.OnNext(1); source.OnNext(2); second.OnNext(3); first.OnNext(4); second.OnNext(5); Assert.AreEqual(4, stats.NextCount); Assert.AreEqual(1, stats.NextValues[0]); Assert.AreEqual(3, stats.NextValues[1]); Assert.AreEqual(4, stats.NextValues[2]); Assert.AreEqual(5, stats.NextValues[3]); }
public void finally_action_is_executed_if_disposition_source_subscription_throws_exception() { StatsObserver <int> stats = new StatsObserver <int>(); bool finallyCalled = true; try { Observable.CreateWithDisposable <int>(obs => { return(Disposable.Create(() => { throw new ApplicationException(); })); }) .Finally(() => { finallyCalled = true; }) .Subscribe(stats) .Dispose(); } finally { Assert.IsTrue(finallyCalled); } }
public void SetUp() { stats = new StatsObserver <string>(); left = new StatsSubject <int>(); right = new StatsSubject <int>(); leftWindows = new List <StatsSubject <Unit> >(); rightWindows = new List <StatsSubject <Unit> >(); leftValueAction = rightValueAction = () => { }; combineAction = (l, r) => String.Format("{0},{1}", l, r); subscription = left.Join(right, leftVal => { leftValueAction(); var leftWindow = new StatsSubject <Unit>(); leftWindows.Add(leftWindow); return(leftWindow); }, rightVal => { rightValueAction(); var rightWindow = new StatsSubject <Unit>(); rightWindows.Add(rightWindow); return(rightWindow); }, (l, r) => combineAction(l, r) ) .Subscribe(stats); }
public void complete_does_not_unsubscribe_from_other_subjects() { var subjectA = new StatsSubject <int>(); var subjectB = new StatsSubject <int>(); var subjectC = new StatsSubject <int>(); var subjectD = new StatsSubject <int>(); var stats = new StatsObserver <string>(); Observable.Join( subjectA.And(subjectB).Then((x, y) => x.ToString() + "," + y.ToString()), subjectC.And(subjectD).Then((x, y) => x.ToString() + "," + y.ToString()) ) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); subjectA.OnCompleted(); Assert.AreEqual(0, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); }
public void merges_multiple_joins_that_share_sources() { var subjectA = new Subject <int>(); var subjectB = new Subject <int>(); var subjectC = new Subject <int>(); var stats = new StatsObserver <string>(); Observable.Join( subjectA.And(subjectB).Then((x, y) => String.Concat(x.ToString(), ",", y.ToString())), subjectA.And(subjectC).Then((x, y) => String.Concat(x.ToString(), "x", y.ToString())) ) .Subscribe(stats); subjectA.OnNext(0); subjectC.OnNext(2); subjectA.OnNext(0); subjectB.OnNext(1); Assert.AreEqual(2, stats.NextCount); Assert.AreEqual("0x2", stats.NextValues[0]); Assert.AreEqual("0,1", stats.NextValues[1]); }
public void live_values_are_sent_through_scheduler() { ManualScheduler scheduler = new ManualScheduler(); BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler); StatsObserver<int> stats = new StatsObserver<int>(); subject.Subscribe(stats); subject.OnNext(1); subject.OnNext(2); subject.OnCompleted(); Assert.IsFalse(stats.NextCalled); scheduler.RunNext(); Assert.AreEqual(1, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0 })); Assert.IsFalse(stats.CompletedCalled); scheduler.RunNext(); Assert.AreEqual(2, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1 })); Assert.IsFalse(stats.CompletedCalled); scheduler.RunNext(); Assert.AreEqual(3, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1, 2 })); Assert.IsFalse(stats.CompletedCalled); scheduler.RunNext(); Assert.IsTrue(stats.CompletedCalled); }
public void Unsubscribe(StatsObserver observer) { if (observers.Contains(observer)) { observers.Remove(observer); } }
public void complete_does_not_unsubscribe_from_other_subjects() { var subjectA = new StatsSubject<int>(); var subjectB = new StatsSubject<int>(); var subjectC = new StatsSubject<int>(); var subjectD = new StatsSubject<int>(); var stats = new StatsObserver<string>(); Observable.Join( subjectA.And(subjectB).Then((x,y) => x.ToString() + "," + y.ToString()), subjectC.And(subjectD).Then((x,y) => x.ToString() + "," + y.ToString()) ) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); subjectA.OnCompleted(); Assert.AreEqual(0, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); }
public void values_can_be_triggered_by_time_or_count() { var scheduler = new TestScheduler(); var source = scheduler.CreateColdObservable( // start #1 (@0) new Recorded<Notification<int>>(10, OnNext(1)), new Recorded<Notification<int>>(12, OnNext(2)), new Recorded<Notification<int>>(14, OnNext(3)), // start #2 (@ 15) new Recorded<Notification<int>>(16, OnNext(4)), new Recorded<Notification<int>>(20, OnNext(5)), new Recorded<Notification<int>>(24, OnNext(6)), new Recorded<Notification<int>>(28, OnNext(7)), // start #3 (@ 28) // start #4 (@ 43) new Recorded<Notification<int>>(50, OnNext(8)), new Recorded<Notification<int>>(51, OnCompleted()) ); var stats = new StatsObserver<IList<int>>(); source.BufferWithTimeOrCount(new TimeSpan(15), 4, scheduler) .Subscribe(stats); scheduler.Run(); Assert.AreEqual(4, stats.NextCount); Assert.AreEqual(3, stats.NextValues[0].Count); Assert.AreEqual(4, stats.NextValues[1].Count); Assert.AreEqual(0, stats.NextValues[2].Count); Assert.AreEqual(1, stats.NextValues[3].Count); }
public void each_subscriber_is_scheduled_individually() { ManualScheduler scheduler = new ManualScheduler(); AsyncSubject<int> subject = new AsyncSubject<int>(scheduler); StatsObserver<int> statsA = new StatsObserver<int>(); StatsObserver<int> statsB = new StatsObserver<int>(); subject.OnNext(1); subject.OnNext(2); subject.OnNext(3); subject.OnCompleted(); subject.Subscribe(statsA); subject.Subscribe(statsB); scheduler.RunNext(); Assert.IsTrue(statsA.NextCalled); Assert.IsFalse(statsB.NextCalled); scheduler.RunNext(); Assert.IsTrue(statsB.NextCalled); }
public void live_values_are_sent_through_scheduler() { ManualScheduler scheduler = new ManualScheduler(); BehaviorSubject <int> subject = new BehaviorSubject <int>(0, scheduler); StatsObserver <int> stats = new StatsObserver <int>(); subject.Subscribe(stats); subject.OnNext(1); subject.OnNext(2); subject.OnCompleted(); Assert.IsFalse(stats.NextCalled); scheduler.RunNext(); Assert.AreEqual(1, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0 })); Assert.IsFalse(stats.CompletedCalled); scheduler.RunNext(); Assert.AreEqual(2, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1 })); Assert.IsFalse(stats.CompletedCalled); scheduler.RunNext(); Assert.AreEqual(3, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1, 2 })); Assert.IsFalse(stats.CompletedCalled); scheduler.RunNext(); Assert.IsTrue(stats.CompletedCalled); }
public void values_are_taken_from_each_selected_value() { var stats = new StatsObserver <int>(); var source = new Subject <int>(); var first = new Subject <int>(); var second = new Subject <int>(); var remaining = new Queue <IObservable <int> >(); remaining.Enqueue(first); remaining.Enqueue(second); var manObs = source .SelectMany(x => remaining.Dequeue()) .Subscribe(stats); source.OnNext(0); first.OnNext(1); source.OnNext(2); second.OnNext(3); first.OnNext(4); second.OnNext(5); Assert.AreEqual(4, stats.NextCount); Assert.AreEqual(1, stats.NextValues[0]); Assert.AreEqual(3, stats.NextValues[1]); Assert.AreEqual(4, stats.NextValues[2]); Assert.AreEqual(5, stats.NextValues[3]); }
public void matches_values_in_order_when_sent_out_of_order() { var subjectA = new Subject <int>(); var subjectB = new Subject <int>(); var stats = new StatsObserver <string>(); Observable.Join( subjectA.And(subjectB).Then((x, y) => String.Concat(x.ToString(), ",", y.ToString())) ) .Subscribe(stats); subjectA.OnNext(0); subjectA.OnNext(1); subjectA.OnCompleted(); subjectB.OnNext(10); subjectB.OnNext(11); subjectB.OnCompleted(); Assert.AreEqual(2, stats.NextCount); Assert.AreEqual("0,10", stats.NextValues[0]); Assert.AreEqual("1,11", stats.NextValues[1]); Assert.IsTrue(stats.CompletedCalled); }
public void honours_window_for_replays_with_priority_to_most_recent() { ManualScheduler scheduler = new ManualScheduler(); ReplaySubject <int> subject = new ReplaySubject <int>(TimeSpan.FromMilliseconds(10), scheduler); StatsObserver <int> stats = new StatsObserver <int>(); DateTime start = DateTime.UtcNow; scheduler.Now = start; subject.OnNext(1); scheduler.Now = start.AddMilliseconds(5); subject.OnNext(2); scheduler.Now = start.AddMilliseconds(10); subject.OnNext(3); scheduler.Now = start.AddMilliseconds(11); subject.Subscribe(stats); scheduler.RunAll(); Assert.AreEqual(2, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2, 3 })); Assert.IsFalse(stats.CompletedCalled); }
static void Main(string[] args) { var config = new ConfigurationBuilder() .AddEnvironmentVariables() .AddJsonFile("appsettings.json", true) .Build(); var deviceConnectionString = config["AzureIotHub:AccessKey"]; var deviceId = config["AzureIotHub:DeviceId"]; TelemetryConfiguration.Active.InstrumentationKey = config["ApplicationInsights:InstrumentationKey"]; var ip = config["Device:IP"]; var port = int.Parse(config["Device:Port"]); if (args.Any()) { ip = args[0]; if (args.Length > 1) { port = int.Parse(args[1]); } } Console.WriteLine($"Connecting to {ip}:{port}..."); Console.WriteLine($"Creating IoT Hub client for {deviceId}"); var tc = new TelemetryClient(); var logger = new AiLog(tc); var iotClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, TransportType.Amqp); var iotOb = new IotHubObserver(iotClient, logger); var consoleOb = new StatsObserver(); var c = new Connector(ip, port, logger, iotOb, consoleOb); }
public void with_both_window_and_buffer_size_values_can_be_ignored_by_window() { ManualScheduler scheduler = new ManualScheduler(); ReplaySubject <int> subject = new ReplaySubject <int>(3, TimeSpan.FromMilliseconds(10), scheduler); StatsObserver <int> stats = new StatsObserver <int>(); DateTime start = DateTime.UtcNow; scheduler.Now = start; // ignored by window subject.OnNext(1); scheduler.Now = start.AddMilliseconds(5); subject.OnNext(2); scheduler.Now = start.AddMilliseconds(8); subject.OnCompleted(); scheduler.Now = start.AddMilliseconds(11); subject.Subscribe(stats); scheduler.RunAll(); Assert.AreEqual(1, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2 })); Assert.IsTrue(stats.CompletedCalled); }
public void time_offset_excludes_values_of_exact_offset() { var stats = new StatsObserver<IList<int>>(); var valueScheduler = new ManualScheduler(); var bufferScheduler = new ManualScheduler(); DateTimeOffset startTime = DateTimeOffset.UtcNow; Observable.Range(0, 5, valueScheduler) .BufferWithTime(TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(20), bufferScheduler) .Subscribe(stats); Assert.IsFalse(stats.NextCalled); bufferScheduler.Now = startTime.AddMilliseconds(10); valueScheduler.RunNext(); bufferScheduler.Now = startTime.AddMilliseconds(20); // exact offset value valueScheduler.RunNext(); bufferScheduler.Now = startTime.AddMilliseconds(30); valueScheduler.RunNext(); bufferScheduler.RunNext(); bufferScheduler.RunNext(); Assert.AreEqual(2, stats.NextCount); Assert.AreEqual(1, stats.NextValues[1].Count); }
public void each_subscriber_is_scheduled_individually() { ManualScheduler scheduler = new ManualScheduler(); AsyncSubject <int> subject = new AsyncSubject <int>(scheduler); StatsObserver <int> statsA = new StatsObserver <int>(); StatsObserver <int> statsB = new StatsObserver <int>(); subject.OnNext(1); subject.OnNext(2); subject.OnNext(3); subject.OnCompleted(); subject.Subscribe(statsA); subject.Subscribe(statsB); scheduler.RunNext(); Assert.IsTrue(statsA.NextCalled); Assert.IsFalse(statsB.NextCalled); scheduler.RunNext(); Assert.IsTrue(statsB.NextCalled); }
public void unsubscribes_from_other_after_value() { var stats = new StatsObserver <int>(); Observable.Range(0, 5).SkipUntil(Observable.Return(1).Concat(Observable.Throw <int>(new ApplicationException()))) .Subscribe(stats); }
public void values_are_skipped_when_not_connected() { Subject <int> subject = new Subject <int>(); var stats = new StatsObserver <int>(); var obs = subject.Prune(); var connectionA = obs.Connect(); subject.OnNext(1); subject.OnNext(2); // last connected value connectionA.Dispose(); subject.OnNext(3); // not connected here var connectionB = obs.Connect(); subject.OnCompleted(); connectionB.Dispose(); obs.Subscribe(stats); Assert.IsTrue(stats.NextCalled); Assert.AreEqual(2, stats.NextValues[0]); Assert.IsTrue(stats.CompletedCalled); }
public void SetUp() { source = new Subject <int>(); windows = new List <StatsSubject <Unit> >(); windowsStats = new List <StatsObserver <int> >(); overallStats = new StatsObserver <int>(); subscription = source.Window(() => { StatsSubject <Unit> window = new StatsSubject <Unit>(); windows.Add(window); return(window); }) .Subscribe(o => { var stats = new StatsObserver <int>(); windowsStats.Add(stats); o.Subscribe(stats); }, overallStats.OnError, overallStats.OnCompleted); }
public void time_offset_excludes_values_of_exact_offset() { var stats = new StatsObserver <IList <int> >(); var valueScheduler = new ManualScheduler(); var bufferScheduler = new ManualScheduler(); DateTimeOffset startTime = DateTimeOffset.UtcNow; Observable.Range(0, 5, valueScheduler) .BufferWithTime(TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(20), bufferScheduler) .Subscribe(stats); Assert.IsFalse(stats.NextCalled); bufferScheduler.Now = startTime.AddMilliseconds(10); valueScheduler.RunNext(); bufferScheduler.Now = startTime.AddMilliseconds(20); // exact offset value valueScheduler.RunNext(); bufferScheduler.Now = startTime.AddMilliseconds(30); valueScheduler.RunNext(); bufferScheduler.RunNext(); bufferScheduler.RunNext(); Assert.AreEqual(2, stats.NextCount); Assert.AreEqual(1, stats.NextValues[1].Count); }
public void last_value_is_received_after_completed_if_any_connection_is_disposed() { Subject <int> subject = new Subject <int>(); var stats = new StatsObserver <int>(); var obs = subject.Prune(); var connectionA = obs.Connect(); var connectionB = obs.Connect(); subject.OnNext(1); subject.OnNext(2); subject.OnNext(3); connectionA.Dispose(); subject.OnCompleted(); connectionB.Dispose(); obs.Subscribe(stats); Assert.IsFalse(stats.NextCalled); Assert.IsFalse(stats.CompletedCalled); }
public void values_are_buffered_in_specified_time() { var scheduler = new TestScheduler(); var source = scheduler.CreateColdObservable( // start #1 (@0) new Recorded <Notification <int> >(10, OnNext(1)), new Recorded <Notification <int> >(12, OnNext(2)), // start #2 (@ 15) // start #3 (@ 30) new Recorded <Notification <int> >(40, OnNext(3)), // start #4 (@ 45) new Recorded <Notification <int> >(50, OnNext(4)), new Recorded <Notification <int> >(51, OnCompleted()) ); var stats = new StatsObserver <IList <int> >(); source.BufferWithTime(new TimeSpan(15), scheduler) .Subscribe(stats); scheduler.Run(); Assert.AreEqual(4, stats.NextCount); Assert.AreEqual(2, stats.NextValues[0].Count); Assert.AreEqual(0, stats.NextValues[1].Count); Assert.AreEqual(1, stats.NextValues[2].Count); Assert.AreEqual(1, stats.NextValues[3].Count); }
public void values_are_buffered_in_specified_time() { var scheduler = new TestScheduler(); var source = scheduler.CreateColdObservable( // start #1 (@0) new Recorded<Notification<int>>(10, OnNext(1)), new Recorded<Notification<int>>(12, OnNext(2)), // start #2 (@ 15) // start #3 (@ 30) new Recorded<Notification<int>>(40, OnNext(3)), // start #4 (@ 45) new Recorded<Notification<int>>(50, OnNext(4)), new Recorded<Notification<int>>(51, OnCompleted()) ); var stats = new StatsObserver<IList<int>>(); source.BufferWithTime(new TimeSpan(15), scheduler) .Subscribe(stats); scheduler.Run(); Assert.AreEqual(4, stats.NextCount); Assert.AreEqual(2, stats.NextValues[0].Count); Assert.AreEqual(0, stats.NextValues[1].Count); Assert.AreEqual(1, stats.NextValues[2].Count); Assert.AreEqual(1, stats.NextValues[3].Count); }
public void exception_thrown_in_error_action_is_bubbled() { StatsObserver <int> stats = new StatsObserver <int>(); Observable.Throw <int>(new Exception()) .Do(x => { }, e => { throw new ApplicationException(); }) .Subscribe(stats); }
public void exception_thrown_in_next_action_bubbles_when_complete_action_is_specifid() { StatsObserver <int> stats = new StatsObserver <int>(); Observable.Range(0, 2) .Do(x => { throw new ApplicationException(); }, e => { }, () => { }) .Subscribe(stats); }
public void repeat_with_no_arguments_repeats_forever() { var stats = new StatsObserver <int>(); Observable.Repeat(1).Take(100).Subscribe(stats); Assert.AreEqual(100, stats.NextCount); }
public void repeatCount_includes_initial_subscription() { var stats = new StatsObserver <int>(); Observable.Repeat(1, 2).Subscribe(stats); Assert.AreEqual(2, stats.NextCount); }
public void exception_thrown_in_next_action_bubbles_when_complete_action_is_specifid() { StatsObserver<int> stats = new StatsObserver<int>(); Observable.Range(0, 2) .Do(x => { throw new ApplicationException(); }, e => { }, () => { }) .Subscribe(stats); }
public void exception_thrown_in_error_action_is_bubbled() { StatsObserver<int> stats = new StatsObserver<int>(); Observable.Throw<int>(new Exception()) .Do(x => { }, e => { throw new ApplicationException(); }) .Subscribe(stats); }
public void supports_null_cancelable_value() { StatsObserver <int> stats = new StatsObserver <int>(); Observable.CreateWithDisposable <int>(x => null) .Subscribe(stats) .Dispose(); }
public void repeatCount_includes_initial_subscription() { var stats = new StatsObserver<int>(); Observable.Return(1).Repeat(2).Subscribe(stats); Assert.AreEqual(2, stats.NextCount); }
public void error_thrown_by_keyselector_sent_to_onerror() { var stats = new StatsObserver <IGroupedObservable <int, int> >(); source.ToObservable().GroupByUntil(x => { throw new Exception(); return(x.Key); }, x => x.Value, g => Observable.Never <int>()) .Subscribe(stats); Assert.IsTrue(stats.ErrorCalled); }
public void error_thrown_by_keycomparer_sent_to_onerror() { var stats = new StatsObserver <IGroupedObservable <int, int> >(); source.ToObservable().GroupBy(x => x.Key, x => x.Value, new AnonymousComparer <int>((x, y) => { throw new Exception(); })) .Subscribe(stats); Assert.IsTrue(stats.ErrorCalled); }
public void error_thrown_by_elementselector_sent_to_onerror() { var stats = new StatsObserver <IGroupedObservable <int, int> >(); source.ToObservable().GroupBy(x => x.Key, x => { throw new Exception(); return(x.Key); }) .Subscribe(stats); Assert.IsTrue(stats.ErrorCalled); }
public void throws_argument_error_when_return_value_is_null() { StatsObserver <int> stats = new StatsObserver <int>(); Observable.Create <int>(x => null) .Subscribe(stats); Assert.IsTrue(stats.ErrorCalled); }
public void empty_sequence_returns_true() { var stats = new StatsObserver<bool>(); Observable.Empty<int>().All(x => x > 2).Subscribe(stats); Assert.IsTrue(stats.CompletedCalled); Assert.IsTrue(stats.NextCalled); Assert.IsTrue(stats.NextValues[0]); }
public void no_values_are_emitted_if_one_source_is_empty() { var stats = new StatsObserver<String>(); Observable.Empty<int>().ForkJoin(Observable.Return(1), selector) .Subscribe(stats); Assert.AreEqual(0, stats.NextCount); Assert.IsTrue(stats.CompletedCalled); }
public void catch_with_observer_does_not_fire_onerror() { StatsObserver<int> observer = new StatsObserver<int>(); Observable.Throw<int>(new ApplicationException()) .Catch(Observable.Empty<int>()) .Subscribe(observer); Assert.IsFalse(observer.ErrorCalled); }
public void exception_thrown_in_complete_action_is_bubbled() { StatsObserver<int> stats = new StatsObserver<int>(); Observable.Range(0, 2) .Do(x => { }, () => { throw new ApplicationException(); }) .Subscribe(stats); Assert.IsTrue(stats.ErrorCalled); }
public void no_values_are_emitted_on_empty_sequence() { var stats = new StatsObserver<int>(); Observable.Empty<int>() .TakeLast(3) .Subscribe(stats); Assert.AreEqual(0, stats.NextCount); }
public void exception_thrown_in_next_action_bubbles_when_all_actions_are_specifid() { StatsObserver<int> stats = new StatsObserver<int>(); Observable.Range(0, 2) .Do(x => { throw new ApplicationException(); }, e => { }, () => { }) .Subscribe(stats); Assert.IsTrue(stats.ErrorCalled); }
public void empty_sequence() { var stats = new StatsObserver<bool>(); Observable.Empty<int>() .All(x => true) .Subscribe(stats); Assert.IsTrue(stats.NextValues[0]); }
public void value_equals_number_of_values() { StatsObserver<int> stats = new StatsObserver<int>(); Observable.Range(5, 3).Count().Subscribe(stats); Assert.AreEqual(1, stats.NextCount); Assert.AreEqual(3, stats.NextValues[0]); Assert.IsTrue(stats.CompletedCalled); }
public void finally_action_is_executed_after_complete() { StatsObserver<int> stats = new StatsObserver<int>(); Observable.Empty<int>() .Finally(() => { Assert.IsTrue(stats.CompletedCalled); }) .Subscribe(stats); }
public void finally_action_is_executed_after_error() { StatsObserver<int> stats = new StatsObserver<int>(); Observable.Throw<int>(new ApplicationException()) .Finally(() => { Assert.IsTrue(stats.ErrorCalled); }) .Subscribe(stats); }
public void catch_with_action_fires_original_error_if_error_is_not_of_specified_type() { StatsObserver<int> observer = new StatsObserver<int>(); Observable.Throw<int>(new OverflowException()) .Catch<int, ApplicationException>(e => { Assert.Fail("Unexpected call to defer action"); return null; }) .Subscribe(observer); Assert.IsTrue(observer.ErrorCalled); Assert.IsInstanceOf<OverflowException>(observer.Error); }
public void outputs_one_value_after_completion() { StatsObserver<int> stats = new StatsObserver<int>(); Observable.Range(0, 5) .Aggregate((x, y) => x + y) .Subscribe(stats); Assert.AreEqual(1, stats.NextCount); Assert.AreEqual(10, stats.NextValues[0]); }
public void raises_error_on_empty_source() { StatsObserver<int> stats = new StatsObserver<int>(); Observable.Empty<int>() .Aggregate((x, y) => x + y) .Subscribe(stats); Assert.IsTrue(stats.ErrorCalled); Assert.IsFalse(stats.CompletedCalled); }
public void catch_with_action_raises_original_error_if_action_returns_null() { StatsObserver<int> observer = new StatsObserver<int>(); Observable.Throw<int>(new OverflowException()) .Catch<int, ApplicationException>(e => null) .Subscribe(observer); Assert.IsTrue(observer.ErrorCalled); Assert.IsInstanceOf<OverflowException>(observer.Error); }
public void catch_with_action_fires_error_if_last_observer_raises_error() { StatsObserver<int> observer = new StatsObserver<int>(); Observable.Throw<int>(new Exception()) .Catch<int, Exception>(e => Observable.Throw<int>(new ApplicationException())) .Subscribe(observer); Assert.IsTrue(observer.ErrorCalled); Assert.IsInstanceOf<ApplicationException>(observer.Error); }
public void SetUp() { stats = new StatsObserver<IObservable<int>>(); subject = new Subject<int>(); timeSpan = TimeSpan.FromMilliseconds(50); timeShift = TimeSpan.FromMilliseconds(10); scheduler = new TestScheduler(); }
public void does_not_call_accumulator_for_first_value_initial_value_not_supplied() { StatsObserver<int> stats = new StatsObserver<int>(); List<int> accumulatorValues = new List<int>(); Observable.Range(0, 5) .Aggregate((x, y) => { accumulatorValues.Add(y); return x + y; }) .Subscribe(stats); Assert.AreEqual(1, accumulatorValues[0]); }