Ejemplo n.º 1
0
        public void ItemsAddedAndRemovedTest()
        {
            var fixture = new ReactiveCollection<int>();
            var before_added = new List<int>();
            var before_removed = new List<int>();
            var added = new List<int>();
            var removed = new List<int>();

            fixture.BeforeItemsAdded.Subscribe(before_added.Add);
            fixture.BeforeItemsRemoved.Subscribe(before_removed.Add);
            fixture.ItemsAdded.Subscribe(added.Add);
            fixture.ItemsRemoved.Subscribe(removed.Add);

            fixture.Add(10);
            fixture.Add(20);
            fixture.Add(30);
            fixture.RemoveAt(1);
            fixture.Clear();

            var added_results = new[]{10,20,30};
            Assert.AreEqual(added_results.Length, added.Count);
            added_results.AssertSequenceAreEqual(added);

            var removed_results = new[]{20};
            Assert.AreEqual(removed_results.Length, removed.Count);
            removed_results.AssertSequenceAreEqual(removed);

            Assert.AreEqual(before_added.Count, added.Count);
            added.AssertSequenceAreEqual(before_added);

            Assert.AreEqual(before_removed.Count, removed.Count);
            removed.AssertSequenceAreEqual(before_removed);
        }
Ejemplo n.º 2
0
        public void ObservableCanExecuteShouldShowUpInCommand()
        {
            (new TestScheduler()).With(sched => {
                var input = new[] { true, true, false, true, false, false };
                var expected = new[] { true, false, true, false };

                var inputObs = input.ToObservable().Multicast(new Subject<bool>());
                var fixture = new ReactiveCommand(inputObs);

                var results = new List<bool>();
                fixture.CanExecuteObservable.Subscribe(x => results.Add(x));
                inputObs.Connect();
                sched.Start();

                expected.AssertSequenceAreEqual(results);
            });
        }
Ejemplo n.º 3
0
        public void CollectionCountChangedTest()
        {
            var fixture = new ReactiveCollection<int>();
            var before_output = new List<int>();
            var output = new List<int>();

            fixture.CollectionCountChanging.Subscribe(before_output.Add);
            fixture.CollectionCountChanged.Subscribe(output.Add);

            fixture.Add(10);
            fixture.Add(20);
            fixture.Add(30);
            fixture.RemoveAt(1);
            fixture.Clear();

            var before_results = new[] {0,1,2,3,2};
            Assert.AreEqual(before_results.Length, before_output.Count);
            before_results.AssertSequenceAreEqual(before_output);

            var results = new[]{1,2,3,2,0};
            results.AssertSequenceAreEqual(output);
        }