public void Should_emit_distinct_device_colors() { var scheduler = new TestScheduler(); var pollingInterval = scheduler.CreateColdObservable( new Recorded <Notification <long> >(10, Notification.CreateOnNext(1L)), new Recorded <Notification <long> >(20, Notification.CreateOnNext(2L)), new Recorded <Notification <long> >(30, Notification.CreateOnNext(2L)) ); var red = System.Drawing.Color.FromArgb(255, 0, 0).ToOpenRGBColor(); var green = System.Drawing.Color.FromArgb(0, 255, 0).ToOpenRGBColor(); var blue = System.Drawing.Color.FromArgb(0, 0, 255).ToOpenRGBColor(); var corsairH150i = new Device(); corsairH150i.SetColors(red, green); corsairH150i.SetName("Corsair H150"); var devices = new Device[] { corsairH150i }; var corsairH150iUnchanged = new Device(); corsairH150iUnchanged.SetColors(red, green); corsairH150iUnchanged.SetName("Corsair H150"); var devicesUnchanged = new Device[] { corsairH150iUnchanged }; var updatedCorsairH150i = new Device(); updatedCorsairH150i.SetColors(green, blue); updatedCorsairH150i.SetName("Corsair H150"); var updatedDevices = new Device[] { updatedCorsairH150i }; OpenRGBClientMock.SetupSequence(it => it.GetAllControllerData()) .Returns(devices) .Returns(devicesUnchanged) .Returns(updatedDevices); var subject = new OpenRGBSource( Options, OpenRGBClientMock.Object, pollingInterval ); var actual = scheduler.Start( () => subject.Get() as IObservable <Dictionary <string, DeviceState> >, created: 0, subscribed: 0, disposed: 100 ); var deviceState = new DeviceState(new List <System.Drawing.Color> { red.ToSystemColor(), green.ToSystemColor() }); var deviceStateUpdated = new DeviceState(new List <System.Drawing.Color> { green.ToSystemColor(), blue.ToSystemColor() }); var expected = new Recorded <Notification <Dictionary <string, DeviceState> > >[] { OnNext(10, (Dictionary <string, DeviceState> actual) => actual["Corsair H150"].Colors.SequenceEqual(deviceState.Colors)), OnNext(30, (Dictionary <string, DeviceState> actual) => actual["Corsair H150"].Colors.SequenceEqual(deviceStateUpdated.Colors)), }; ReactiveAssert.AreElementsEqual(expected, actual.Messages); }
public void CombineTest() { var testScheduler = new TestScheduler(); var history = testScheduler.CreateColdObservable( OnNext(1L, new DummyNotification { EventId = 1 }), OnNext(2L, new DummyNotification { EventId = 2 }), OnNext(3L, new DummyNotification { EventId = 3 }), OnNext(4L, new DummyNotification { EventId = 4 }), OnCompleted(new DummyNotification(), 5L)); var live = testScheduler.CreateHotObservable( OnNext(1L, new DummyNotification { EventId = 3 }), OnNext(2L, new DummyNotification { EventId = 4 }), OnNext(3L, new DummyNotification { EventId = 5 }), OnNext(4L, new DummyNotification { EventId = 6 }), OnNext(5L, new DummyNotification { EventId = 7 }), OnNext(6L, new DummyNotification { EventId = 8 }), OnNext(7L, new DummyNotification { EventId = 9 }) ); var observer = testScheduler.CreateObserver <ICacheNotification>(); history.Combine(live).Subscribe(observer); testScheduler.AdvanceTo(6L); ReactiveAssert.AreElementsEqual( new[] { OnNext <ICacheNotification>(5, n => n.EventId == 1), OnNext <ICacheNotification>(5, n => n.EventId == 2), OnNext <ICacheNotification>(5, n => n.EventId == 3), OnNext <ICacheNotification>(5, n => n.EventId == 4), OnNext <ICacheNotification>(5, n => n.EventId == 5), OnNext <ICacheNotification>(5, n => n.EventId == 6), OnNext <ICacheNotification>(5, n => n.EventId == 7), OnNext <ICacheNotification>(6, n => n.EventId == 8) }, observer.Messages); }
public void ModelExposesTermsAfterLoadTerms() { var model = TermListViewModelFixture.CreateViewModelLoaded(this._termsServiceMock.Object, Mock.Of <ITermEditViewModel>()); ReactiveAssert.AreElementsEqual(TermListViewModelFixture.SampleTerms, model.Terms.Cast <Term>()); }
public static void AreResponsesEquivalent(IEnumerable <Recorded <Notification <Response> > > actual, IEnumerable <Recorded <Notification <Response> > > expected) { ReactiveAssert.AreElementsEqual( expected.Where(ResponseFilter()), actual.Where(ResponseFilter())); }
public void AvoidOverlappingStreams_ByUsingSwitchOperator() { /****************************************************** * * you start with Stream that create sub stream of string, * each sub stream is built of single char representation. * * --#----------------@----------------*------------------ * * | * * #--##--###--####--#####--######--#######--######## * * | * * @--@@--@@@--@@@@--@@@@--@@@@@--@@@@@@ * * | * * *---**---***---**** * * you should find a way to get output stream where * listen to the latest sub stream. * * the output stream should be look like: * * --#--##--###--####-@--@@--@@@--@@@@-*---**---***---**** * * in other words you have to avoid overlapping char. * ******************************************************/ var scheduler = new TestScheduler(); var observer = scheduler.CreateObserver <string>(); var source = new Subject <char>(); var overlapped = from c in source // create stream per char select Observable.Interval(TimeSpan.FromMilliseconds(1), scheduler). Select(l => new string(c, (int)l + 1)); // multiply the char //Solution: use switch instead of Merge var flatten = overlapped.Switch(); flatten.Subscribe(observer); source.OnNext('#'); scheduler.AdvanceBy(TimeSpan.FromMilliseconds(3).Ticks); source.OnNext('@'); scheduler.AdvanceBy(TimeSpan.FromMilliseconds(3).Ticks); source.OnNext('*'); scheduler.AdvanceBy(TimeSpan.FromMilliseconds(3).Ticks); var results = observer. Messages .Where(m => m.Value.Kind == NotificationKind.OnNext) .Select(m => m.Value.Value).ToArray(); ReactiveAssert.AreElementsEqual( new[] { "#", "##", "###", "@", "@@", "@@@", "*", "**", "***" }, results); }
public void Buffer_ShouldProduceOn_CountOrTimeoutOrFlush_ByUsingAmbAndDefferedRecursion() { //Arrange var timeThreshold = TimeSpan.FromMilliseconds(20); var countThreshold = 3; var testScheduler = new TestScheduler(); var testObserver = testScheduler.CreateObserver <IList <int> >(); var source = testScheduler.CreateHotObservable( new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(1).Ticks, Notification.CreateOnNext(0)), new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(2).Ticks, Notification.CreateOnNext(1)), new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(3).Ticks, Notification.CreateOnNext(2)), // Spew above due to count new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(4).Ticks, Notification.CreateOnNext(3)), // Spew above due to timeout new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(25).Ticks, Notification.CreateOnNext(4)), // Spew above due to flush new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(33).Ticks, Notification.CreateOnNext(5)), //Spew above due to timeout new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(54).Ticks, Notification.CreateOnNext(6)), new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(64).Ticks, Notification.CreateOnNext(7)), //Spew above due to timeout new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(75).Ticks, Notification.CreateOnNext(8)), new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(76).Ticks, Notification.CreateOnNext(9)), new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(77).Ticks, Notification.CreateOnNext(10)), // Spew above due to count new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(96).Ticks, Notification.CreateOnNext(11)), // Spew above due to flush new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(98).Ticks, Notification.CreateOnNext(12)), new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(99).Ticks, Notification.CreateOnNext(13)), new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(100).Ticks, Notification.CreateOnNext(14)), // Spew above due to count new Recorded <Notification <int> >(TimeSpan.FromMilliseconds(101).Ticks, Notification.CreateOnCompleted <int>()) ); var manualFlush = testScheduler.CreateHotObservable( new Recorded <Notification <Unit> >(TimeSpan.FromMilliseconds(27).Ticks, Notification.CreateOnNext(Unit.Default)), new Recorded <Notification <Unit> >(TimeSpan.FromMilliseconds(97).Ticks, Notification.CreateOnNext(Unit.Default)), new Recorded <Notification <Unit> >(TimeSpan.FromMilliseconds(101).Ticks, Notification.CreateOnCompleted <Unit>()) ); var timeOrCountOrFlush = GetTimeOrCount(source, testScheduler, timeThreshold, countThreshold, manualFlush); //Act source.Buffer(timeOrCountOrFlush).Where(b => b.Any()).Subscribe(testObserver); //Assert testScheduler.Start(); var results = testObserver.Messages .Where(m => m.Value.Kind == NotificationKind.OnNext) .Select(m => m.Value.Value).ToArray(); Assert.AreEqual(8, results.Length); ReactiveAssert.AreElementsEqual(new[] { 0, 1, 2 }, results[0]); ReactiveAssert.AreElementsEqual(new[] { 3 }, results[1]); ReactiveAssert.AreElementsEqual(new[] { 4 }, results[2]); ReactiveAssert.AreElementsEqual(new[] { 5 }, results[3]); ReactiveAssert.AreElementsEqual(new[] { 6, 7 }, results[4]); ReactiveAssert.AreElementsEqual(new[] { 8, 9, 10 }, results[5]); ReactiveAssert.AreElementsEqual(new[] { 11 }, results[6]); ReactiveAssert.AreElementsEqual(new[] { 12, 13, 14 }, results[7]); }
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); }
protected void AssertEqual <T>(IEnumerable <T> actual, params IEnumerable <T>[] expected) { ReactiveAssert.AreElementsEqual(EnumerableEx.Concat(expected), actual); }
protected void AssertEqual <T>(IEnumerable <T> actual, params T[] expected) { ReactiveAssert.AreElementsEqual(expected, actual); }