Esempio n. 1
0
        public void TestScalarPausing()
        {
            OcConsumer consumer = new OcConsumer("Tag");

            Assert.AreEqual(consumer.Tag, "Tag");

            Scalar <int>        scalar        = new Scalar <int>(0);
            ScalarPausing <int> scalarPausing = scalar.ScalarPausing(3).For(consumer);

            Assert.AreEqual(scalarPausing.IsPaused, false);
            scalarPausing.IsPaused = true;
            scalar.Change(1);
            scalar.Change(2);
            scalar.Change(3);
            scalar.Change(4);
            scalarPausing.LastChangesToApplyOnResumeCount = 2;

            int[] values = new [] { 3, 4 };
            int   index  = 0;

            scalarPausing.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "Value" && !scalarPausing.InactivationInProgress)
                {
                    Assert.AreEqual(scalarPausing.Value, values[index++]);

                    Assert.Throws <ObservableComputationsInconsistencyException>(() => scalarPausing.IsPaused = true);
                }
            };

            scalarPausing.IsPaused = false;
            Assert.AreEqual(scalarPausing.Value, 4);
            consumer.Dispose();
        }
Esempio n. 2
0
        public void TestScalarPausing2()
        {
            OcConsumer consumer = new OcConsumer();
            Scalar <ObservableCollection <int> > sourceScalar =
                new Scalar <ObservableCollection <int> >(new ObservableCollection <int>(new int[] { 1, 2, 3 }).Selecting(i => i).For(consumer));


            ScalarPausing <ObservableCollection <int> > scalarPausing = sourceScalar.ScalarPausing(true).For(consumer);

            scalarPausing.PropertyChanged += (sender, args) =>
            {
                Assert.IsTrue(scalarPausing.IsResuming);
            };

            sourceScalar.Change(new ObservableCollection <int>(new int[] { 1, 2, 3, 5, 6 }).Selecting(i => i).For(consumer));
            scalarPausing.IsPaused = false;
            scalarPausing.ValidateInternalConsistency();
        }