public void TestMethod() { var scheduler = new TestScheduler(); var input = scheduler.CreateHotObservable( ReactiveTest.OnNext(100, "abc"), ReactiveTest.OnNext(200, "def"), ReactiveTest.OnNext(300, "ghi"), ReactiveTest.OnNext(400, "pqr"), ReactiveTest.OnNext(500, "test"), ReactiveTest.OnNext(600, "xyz"), ReactiveTest.OnCompleted <string>(800) ); var results = scheduler.Start( () => input.Buffer(() => input.Throttle(TimeSpan.FromTicks(100), scheduler)) .Select(b => string.Join(",", b)), created: 0, subscribed: 100, disposed: 800); ReactiveAssert.AreElementsEqual(results.Messages, new Recorded <Notification <string> >[] { ReactiveTest.OnNext(700, "def,ghi,pqr,test,xyz"), ReactiveTest.OnNext(800, ""), ReactiveTest.OnCompleted <string>(800) }); ReactiveAssert.AreElementsEqual(input.Subscriptions, new Subscription[] { ReactiveTest.Subscribe(100, 800), ReactiveTest.Subscribe(100, 700), ReactiveTest.Subscribe(700, 800) }); }
public void SwitchTest() { var scheduler = new TestScheduler(); var one = scheduler.CreateHotObservable(ReactiveTest.OnNext(10, 0), ReactiveTest.OnNext(20, 0), ReactiveTest.OnNext(30, 0), ReactiveTest.OnNext(40, 0), ReactiveTest.OnCompleted <int>(50)); var other = scheduler.CreateHotObservable(ReactiveTest.OnNext(10, 1), ReactiveTest.OnNext(20, 1), ReactiveTest.OnNext(30, 1), ReactiveTest.OnNext(40, 1), ReactiveTest.OnCompleted <int>(50)); var outer = scheduler.CreateHotObservable(ReactiveTest.OnNext <IObservable <int> >(5, one), ReactiveTest.OnNext <IObservable <int> >(15, other), ReactiveTest.OnNext <IObservable <int> >(25, one), ReactiveTest.OnNext <IObservable <int> >(35, other), ReactiveTest.OnCompleted <IObservable <int> >(60)); var res = scheduler.Start(() => outer.Switch(), 0, 0, ReactiveTest.Disposed); res.Messages.AssertEqual( ReactiveTest.OnNext(10, 0), ReactiveTest.OnNext(20, 1), ReactiveTest.OnNext(30, 0), ReactiveTest.OnNext(40, 1), ReactiveTest.OnCompleted <int>(60)); }
private void Then_n_projects_should_be_found() { var notifications = _sln.Projects.Select(p => ReactiveTest.OnNext(150, p)).ToList(); notifications.Add(ReactiveTest.OnCompleted <Project>(350)); ReactiveAssert.AreElementsEqual(notifications, _results.Messages); ReactiveAssert.AreElementsEqual(new Subscription[] { ReactiveTest.Subscribe(50, 350) }, _inputObservable.Subscriptions); }
private void Then_classes_in_the_project_should_be_indexed() { var tbase = 150; var notifications = _classes.Select((cls, i) => ReactiveTest.OnNext(i * 100 + tbase, cls)) .Append(ReactiveTest.OnCompleted <ClassDeclarationSyntax>(tbase + 400)) .ToArray(); ReactiveAssert.AreElementsEqual(notifications, _results.Messages); }
private void Given_a_way_to_scan_projects() { _projectScanner = new ProjectRescanner(); _scheduler = new TestScheduler(); _inputObservable = _scheduler.CreateColdObservable(_sln.Projects .Select((proj, i) => ReactiveTest.OnNext(i * 100 + 100, proj)) .Append(ReactiveTest.OnCompleted <Project>(_sln.Projects.Count() * 100 + 300)) .ToArray() ); }
public async Task Should_Complete_If_There_Are_No_Pending_Requests_SettleNext() { var testScheduler = new TestScheduler(); var(settler, _) = CreateSettler(testScheduler, TimeSpan.FromTicks(20), TimeSpan.FromTicks(100)); var observer = testScheduler.Start(() => settler.SettleNextInternal(), 100, 100, ReactiveTest.Disposed); observer.Messages.Should().ContainInOrder( ReactiveTest.OnNext(121, Unit.Default), ReactiveTest.OnCompleted(121, Unit.Default) ); }
public void Should_Timeout_If_A_Request_Takes_To_Long_SettleNext() { var testScheduler = new TestScheduler(); var(settler, requestSettler) = CreateSettler(testScheduler, TimeSpan.FromTicks(200), TimeSpan.FromTicks(800)); testScheduler.ScheduleAbsolute(0, () => requestSettler.OnStartRequest()); testScheduler.ScheduleAbsolute(ReactiveTest.Disposed, () => requestSettler.OnEndRequest()); var observer = testScheduler.Start(() => settler.SettleNextInternal(), 100, 100, ReactiveTest.Disposed); observer.Messages.Should().ContainInOrder( ReactiveTest.OnNext(902, Unit.Default), ReactiveTest.OnCompleted(902, Unit.Default) ); }
public void Should_Wait_For_Request_To_Finish_And_Then_Wait_SettleNext() { var testScheduler = new TestScheduler(); var(settler, requestSettler) = CreateSettler(testScheduler, TimeSpan.FromTicks(100), TimeSpan.FromTicks(800)); testScheduler.ScheduleAbsolute(0, () => requestSettler.OnStartRequest()); testScheduler.ScheduleAbsolute(300, () => requestSettler.OnEndRequest()); var observer = testScheduler.Start(() => settler.SettleNextInternal(), 100, 100, ReactiveTest.Disposed); observer.Messages.Should().ContainInOrder( ReactiveTest.OnNext(401, Unit.Default), ReactiveTest.OnCompleted(401, Unit.Default) ); }
public void Should_Wait_For_Request_To_Finish_And_Then_Wait(SettlerType settlerType) { var testScheduler = new TestScheduler(); var(settler, matcher) = CreateSettlers(testScheduler, TimeSpan.FromTicks(100), TimeSpan.FromTicks(800)); matcher.ScheduleRelativeStart(settlerType, 0); matcher.ScheduleRelativeEnd(settlerType, 300); var observer = testScheduler.Start(() => settler.Settle().Take(1), 100, 100, ReactiveTest.Disposed); observer.Messages.Should().ContainInOrder( ReactiveTest.OnNext(401, Unit.Default), ReactiveTest.OnCompleted(401, Unit.Default) ); }
public void Should_Timeout_If_A_Request_Takes_To_Long(SettlerType settlerType) { var testScheduler = new TestScheduler(); var(settler, matcher) = CreateSettlers(testScheduler, TimeSpan.FromTicks(200), TimeSpan.FromTicks(500)); matcher.ScheduleAbsoluteStart(settlerType, 0); matcher.ScheduleAbsoluteEnd(settlerType, ReactiveTest.Disposed); var observer = testScheduler.Start(() => settler.Settle(), 100, 100, ReactiveTest.Disposed); observer.Messages.Should().ContainInOrder( ReactiveTest.OnNext(601, Unit.Default), ReactiveTest.OnCompleted(802, Unit.Default) ); }
private static IEnumerable <Recorded <Notification <T> > > ToNotificationStream <T>(IEnumerable <T> stream, Func <T, DateTimeOffset> getTimestamp, DateTimeOffset?startAt, DateTimeOffset?endAt) { // ReSharper disable once PossibleMultipleEnumeration startAt = startAt ?? getTimestamp(stream.First()); // ReSharper disable once PossibleMultipleEnumeration endAt = endAt ?? getTimestamp(stream.Last()); // ReSharper disable once PossibleMultipleEnumeration var notifications = stream.Select(x => ReactiveTest.OnNext(getTimestamp(x).Ticks - startAt.Value.Ticks, x)) .Concat(new[] { ReactiveTest.OnCompleted <T>(endAt.Value.Ticks - startAt.Value.Ticks) }) .ToArray(); return(notifications); }
private static IEnumerable <Recorded <Notification <char> > > FromMarbles(string marbles) { var time = 0L; var syncEvents = false; foreach (var character in marbles) { if (character == ' ') { continue; } if (character == '(') { syncEvents = true; continue; } if (character == ')') { syncEvents = false; continue; } var marbleEvents = character switch { '#' => EnumerableEx.Return(ReactiveTest.OnError <char>(time, new Exception("end"))), '|' => EnumerableEx.Return(ReactiveTest.OnCompleted(time, character)), '-' => Enumerable.Empty <Recorded <Notification <char> > >(), _ => EnumerableEx.Return(ReactiveTest.OnNext(time, character)), }; foreach (var marble in marbleEvents) { yield return(marble); } if (syncEvents) { continue; } time += 10; } }
public void Should_Wait_For_Overlapping_Requests_To_Finish_And_Then_Wait_On_Either_Side(SettlerType settlerTypeA, SettlerType settlerTypeB) { var testScheduler = new TestScheduler(); var(settler, matcher) = CreateSettlers(testScheduler, TimeSpan.FromTicks(100), TimeSpan.FromTicks(800)); matcher.ScheduleAbsoluteStart(settlerTypeA, 0); matcher.ScheduleAbsoluteStart(settlerTypeB, 200); matcher.ScheduleAbsoluteEnd(settlerTypeA, 250); matcher.ScheduleAbsoluteEnd(settlerTypeB, 350); var observer = testScheduler.Start(() => settler.Settle().Take(1), 100, 100, ReactiveTest.Disposed); observer.Messages.Should().ContainInOrder( ReactiveTest.OnNext(351, Unit.Default), ReactiveTest.OnCompleted(351, Unit.Default) ); }
public ThrottleData(int[] pattern, int[,] expectedPattern) { Scheduler = new TestScheduler(); CompletedEvent = new[] { ReactiveTest.OnCompleted(_COMPLETE, _COMPLETE) }; Observer = Scheduler.CreateObserver <int>(); Source = Scheduler.CreateColdObservable(pattern.Select(v => ReactiveTest.OnNext(v, v)) .Concat(CompletedEvent) .ToArray());; Pattern = pattern; ExpectedPattern = new int[expectedPattern.GetLength(0)]; ExpectedTimes = new int[expectedPattern.GetLength(0)]; for (int i = 0; i < expectedPattern.GetLength(0); i++) { ExpectedPattern[i] = expectedPattern[i, 0]; ExpectedTimes[i] = expectedPattern[i, 1]; } Expected = ExpectedPattern.Zip(ExpectedTimes, (v, t) => ReactiveTest.OnNext(t, v)).Concat(CompletedEvent).ToList(); }
public void Should_Complete_After_Final_Request_Timeout(SettlerType settlerTypeA, SettlerType settlerTypeB, SettlerType settlerTypeC) { var testScheduler = new TestScheduler(); var(settler, matcher) = CreateSettlers(testScheduler, TimeSpan.FromTicks(100), TimeSpan.FromTicks(800)); matcher.ScheduleAbsoluteStart(settlerTypeA, 0); matcher.ScheduleAbsoluteEnd(settlerTypeA, 200); matcher.ScheduleAbsoluteStart(settlerTypeB, 300); matcher.ScheduleAbsoluteEnd(settlerTypeB, 400); matcher.ScheduleAbsoluteStart(settlerTypeC, 500); matcher.ScheduleAbsoluteEnd(settlerTypeC, 550); var observer = testScheduler.Start(() => settler.Settle(), 100, 100, 2000); observer.Messages.Should().ContainInOrder( ReactiveTest.OnNext(301, Unit.Default), ReactiveTest.OnCompleted(1452, Unit.Default) ); }
/// <summary> /// (original: Test a Flux that returns 10 random elements) /// </summary> public static void VerifyThat10ElementsEmitted() { var scheduler = new TestScheduler(); var random = new Random(); var testObservable = scheduler.CreateHotObservable( ReactiveTest.OnNext(10, random.Next(-100, 100)), ReactiveTest.OnNext(20, random.Next(-100, 100)), ReactiveTest.OnNext(30, random.Next(-100, 100)), ReactiveTest.OnNext(40, random.Next(-100, 100)), ReactiveTest.OnNext(50, random.Next(-100, 100)), ReactiveTest.OnNext(60, random.Next(-100, 100)), ReactiveTest.OnNext(70, random.Next(-100, 100)), ReactiveTest.OnNext(80, random.Next(-100, 100)), ReactiveTest.OnNext(90, random.Next(-100, 100)), ReactiveTest.OnNext(100, random.Next(-100, 100)), ReactiveTest.OnCompleted <int>(110)); var results = scheduler.Start(() => testObservable, created: 1, subscribed: 5, disposed: 120); Func <int, bool> valuesPredicate = value => value >= -100 && value <= 100; ReactiveAssert.AreElementsEqual(results.Messages, new Recorded <Notification <int> >[] { ReactiveTest.OnNext(10, valuesPredicate), ReactiveTest.OnNext(20, valuesPredicate), ReactiveTest.OnNext(30, valuesPredicate), ReactiveTest.OnNext(40, valuesPredicate), ReactiveTest.OnNext(50, valuesPredicate), ReactiveTest.OnNext(60, valuesPredicate), ReactiveTest.OnNext(70, valuesPredicate), ReactiveTest.OnNext(80, valuesPredicate), ReactiveTest.OnNext(90, valuesPredicate), ReactiveTest.OnNext(100, valuesPredicate), ReactiveTest.OnCompleted <int>(110) }); }
public void Should_Complete_After_Final_Request_Timeout() { var testScheduler = new TestScheduler(); var(settler, requestSettler) = CreateSettler(testScheduler, TimeSpan.FromTicks(100), TimeSpan.FromTicks(800)); testScheduler.ScheduleAbsolute(0, () => requestSettler.OnStartRequest()); testScheduler.ScheduleAbsolute(200, () => requestSettler.OnEndRequest()); testScheduler.ScheduleAbsolute(300, () => requestSettler.OnStartRequest()); testScheduler.ScheduleAbsolute(400, () => requestSettler.OnEndRequest()); testScheduler.ScheduleAbsolute(500, () => requestSettler.OnStartRequest()); testScheduler.ScheduleAbsolute(550, () => requestSettler.OnEndRequest()); var observer = testScheduler.Start(() => settler.Settle(), 100, 100, 3000); observer.Messages.Should().ContainInOrder( ReactiveTest.OnNext(301, Unit.Default), ReactiveTest.OnNext(501, Unit.Default), ReactiveTest.OnNext(651, Unit.Default), ReactiveTest.OnNext(1452, Unit.Default), ReactiveTest.OnCompleted(1452, Unit.Default) ); }
public void SelectManyTest() { //SelectMany is just: source.Select(selector).Merge(); var scheduler = new TestScheduler(); var one = scheduler.CreateHotObservable(ReactiveTest.OnNext(10, 0), ReactiveTest.OnNext(20, 0), ReactiveTest.OnNext(30, 0), ReactiveTest.OnNext(40, 0), ReactiveTest.OnCompleted <int>(50)); var other = scheduler.CreateHotObservable(ReactiveTest.OnNext(10, 1), ReactiveTest.OnNext(20, 1), ReactiveTest.OnNext(30, 1), ReactiveTest.OnNext(40, 1), ReactiveTest.OnCompleted <int>(50)); var outer = scheduler.CreateHotObservable(ReactiveTest.OnNext <IObservable <int> >(5, one), ReactiveTest.OnNext <IObservable <int> >(15, other), ReactiveTest.OnNext <IObservable <int> >(25, one), ReactiveTest.OnNext <IObservable <int> >(35, other), ReactiveTest.OnCompleted <IObservable <int> >(60)); var res = scheduler.Start(() => outer.SelectMany(x => x), 0, 0, ReactiveTest.Disposed); res.Messages.AssertEqual( ReactiveTest.OnNext(10, 0), ReactiveTest.OnNext(20, 0), ReactiveTest.OnNext(20, 1), ReactiveTest.OnNext(30, 0), ReactiveTest.OnNext(30, 0), ReactiveTest.OnNext(30, 1), ReactiveTest.OnNext(40, 0), ReactiveTest.OnNext(40, 0), ReactiveTest.OnNext(40, 1), ReactiveTest.OnNext(40, 1), ReactiveTest.OnCompleted <int>(60)); }
public void BuffetTimeoutTest() { var scheduler = new TestScheduler(); var source = scheduler.CreateHotObservable(ReactiveTest.OnNext(10, 1), ReactiveTest.OnNext(20, 2), ReactiveTest.OnNext(30, 3), ReactiveTest.OnNext(40, 4), ReactiveTest.OnNext(50, 5), ReactiveTest.OnNext(60, 6), ReactiveTest.OnNext(70, 7), ReactiveTest.OnNext(80, 8), ReactiveTest.OnNext(90, 9), ReactiveTest.OnCompleted <int>(100)); var res = scheduler.Start(() => source.Buffer(TimeSpan.FromTicks(20), scheduler), 0, 0, ReactiveTest.Disposed); res.Messages.AssertEqual( ReactiveTest.OnNext <IList <int> >(21, x => x.SequenceEqual(new [] { 1, 2 })), ReactiveTest.OnNext <IList <int> >(41, x => x.SequenceEqual(new [] { 3, 4 })), ReactiveTest.OnNext <IList <int> >(61, x => x.SequenceEqual(new [] { 5, 6 })), ReactiveTest.OnNext <IList <int> >(81, x => x.SequenceEqual(new [] { 7, 8 })), ReactiveTest.OnNext <IList <int> >(100, x => x.SequenceEqual(new [] { 9 })), ReactiveTest.OnCompleted <IList <int> >(100)); }
private void Given_a_way_to_scan_solutions() { _solutionScanner = new SolutionRescanner(); _scheduler = new TestScheduler(); _inputObservable = _scheduler.CreateColdObservable(ReactiveTest.OnNext(100, _sln), ReactiveTest.OnCompleted <Solution>(300)); }
private void Then_no_projects_should_be_found() { ReactiveAssert.AreElementsEqual(new Recorded <Notification <Project> >[] { ReactiveTest.OnCompleted <Project>(350) }, _results.Messages); ReactiveAssert.AreElementsEqual(new Subscription[] { ReactiveTest.Subscribe(50, 350) }, _inputObservable.Subscriptions); }