Пример #1
0
        public void AddElementTest()
        {
            var outerCollection = new ObservableCollection <Observable>(Enumerable.Range(1, 8).Select(i => new Observable(2 * i + 1)));
            var innerCollection = new ObservableCollection <Notify>(Enumerable.Range(1, 10).Select(i => new Notify {
                Prop = i
            }));
            var zrool = new ZipReadOnlyObservableList <Observable, Notify, int>(outerCollection, innerCollection,
                                                                                (x, y) => System.Reactive.Linq.Observable.Return(x.Prop + y.Prop));
            var copy = zrool.ListSelect(x => x);

            outerCollection.Add(new Observable(99));
            outerCollection.Insert(2, new Observable(8));
            outerCollection.Add(new Observable(4));

            innerCollection.Insert(0, new Notify {
                Prop = 0
            });
            innerCollection.Add(new Notify {
                Prop = 17
            });
            innerCollection.Insert(0, new Notify {
                Prop = 13
            });

            var expectedValues = new HashSet <int>(outerCollection.Zip(innerCollection, (x, y) => x.Prop + y.Prop));

            Assert.IsTrue(expectedValues.SetEquals(zrool));
            Assert.IsTrue(expectedValues.SetEquals(copy));
        }
Пример #2
0
        public void TriggerTest()
        {
            var baseline        = new System.Reactive.Subjects.BehaviorSubject <int>(0);
            var outerCollection = new ObservableCollection <Observable>(Enumerable.Range(1, 10).Select(i => new Observable(2 * i + 1)));
            var innerCollection = new ObservableCollection <Notify>(Enumerable.Range(1, 5).Select(i => new Notify {
                Prop = i
            }));
            var zrool = new ZipReadOnlyObservableList <Observable, Notify, int>(outerCollection, innerCollection,
                                                                                (x, y) => x.Subject.CombineLatest(y.ObserveAll().Select(b => b.Prop), (a, b) => a + b).CombineLatest(baseline, (a, b) => a + b));
            var copy = zrool.ListSelect(x => x);

            outerCollection[8].Prop = 4;
            innerCollection[2].Prop = 0;
            outerCollection[3].Prop = 100;

            var expectedValues = new HashSet <int>(outerCollection.Zip(innerCollection, (x, y) => x.Prop + y.Prop + baseline.Value));

            Assert.IsTrue(expectedValues.SetEquals(zrool));
            Assert.IsTrue(expectedValues.SetEquals(copy));

            baseline.OnNext(2);

            expectedValues = new HashSet <int>(outerCollection.Zip(innerCollection, (x, y) => x.Prop + y.Prop + baseline.Value));
            Assert.IsTrue(expectedValues.SetEquals(zrool));
            Assert.IsTrue(expectedValues.SetEquals(copy));
        }
Пример #3
0
        public void IteratorTest()
        {
            var outerCollection = new ObservableCollection <Observable>(new List <Observable>()
            {
                new Observable(3), new Observable(2), new Observable(1)
            });
            var innerCollection = new ObservableCollection <Notify>(Enumerable.Range(2, 10).Select(i => new Notify {
                Prop = i
            }));
            var zrool = new ZipReadOnlyObservableList <Observable, Notify, int>(outerCollection, innerCollection,
                                                                                (x, y) => System.Reactive.Linq.Observable.Return(x.Prop + y.Prop));

            Assert.AreEqual(zrool.Count, 3);
            Assert.IsTrue(new HashSet <int>(new[] { 5, 5, 5 }).SetEquals(zrool));
        }