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();
        }
 private static void test(StringsConcatenating stringsConcatenating, Scalar <string> separatorScalar)
 {
     stringsConcatenating.ValidateConsistency();
     separatorScalar.Change("");
     stringsConcatenating.ValidateConsistency();
     separatorScalar.Change("~!");
     stringsConcatenating.ValidateConsistency();
     separatorScalar.Change("#$%");
     stringsConcatenating.ValidateConsistency();
     separatorScalar.Change("^&");
     stringsConcatenating.ValidateConsistency();
 }
 private void test(StringsConcatenating stringsConcatenating, Scalar <string> separatorScalar)
 {
     stringsConcatenating.ValidateInternalConsistency();
     separatorScalar.Change("");
     stringsConcatenating.ValidateInternalConsistency();
     separatorScalar.Change("~!");
     stringsConcatenating.ValidateInternalConsistency();
     separatorScalar.Change("#$%");
     stringsConcatenating.ValidateInternalConsistency();
     separatorScalar.Change("^&");
     stringsConcatenating.ValidateInternalConsistency();
     consumer.Dispose();
 }
Esempio n. 4
0
        public void  ScalarProcessingVoid_Test()
        {
            Item          item       = new Item();
            Scalar <Item> itemScalar = new Scalar <Item>(item);

            itemScalar.ScalarProcessing((i, current) =>
            {
                i.ProcessedAsNew = true;
            });
            Assert.IsTrue(item.ProcessedAsNew);
            item = new Item();
            itemScalar.Change(item);
            itemScalar.Change(item);
        }
        public void  ScalarProcessingVoid_Test()
        {
            Item          item       = new Item();
            Scalar <Item> itemScalar = new Scalar <Item>(item);

            itemScalar.ScalarProcessing((i, current) =>
            {
                i.ProcessedAsNew = true;
            }).IsNeededFor(consumer);
            Assert.IsTrue(item.ProcessedAsNew);
            item = new Item();
            itemScalar.Change(item);
            itemScalar.Change(item);
            consumer.Dispose();
        }
        public void ScalarProcessing_Test()
        {
            Item          item       = new Item();
            Scalar <Item> itemScalar = new Scalar <Item>(item);
            object        token      = null;

            itemScalar.ScalarProcessing <Item, object>(
                (newItem, current) =>
            {
                newItem.ProcessedAsNew = true;
                return(newItem.Token);
            },
                (oldItem, current, retVal) =>
            {
                Assert.AreEqual(retVal, token);
                oldItem.ProcessedAsOld = true;
            }).For(consumer);
            Assert.IsTrue(item.ProcessedAsNew);
            token = item.Token;
            Item newItem1 = new Item();

            itemScalar.Change(newItem1);
            Assert.IsTrue(item.ProcessedAsNew);
            Assert.IsTrue(item.ProcessedAsOld);
            Assert.IsTrue(newItem1.ProcessedAsNew);
            token = newItem1.Token;
            consumer.Dispose();
            Assert.IsTrue(item.ProcessedAsNew);
            Assert.IsTrue(item.ProcessedAsOld);
            Assert.IsTrue(newItem1.ProcessedAsNew);
            Assert.IsTrue(newItem1.ProcessedAsOld);
        }
Esempio n. 7
0
        public void  ScalarProcessingVoid_Test()
        {
            Item          item       = new Item();
            Scalar <Item> itemScalar = new Scalar <Item>(item);

            itemScalar.ScalarProcessing(
                (newItem, current) =>
            {
                newItem.ProcessedAsNew = true;
            },
                (oldItem, current) =>
            {
                oldItem.ProcessedAsOld = true;
            }).For(consumer);
            Assert.IsTrue(item.ProcessedAsNew);
            Item newItem1 = new Item();

            itemScalar.Change(newItem1);
            Assert.IsTrue(item.ProcessedAsNew);
            Assert.IsTrue(item.ProcessedAsOld);
            Assert.IsTrue(newItem1.ProcessedAsNew);
            consumer.Dispose();
            Assert.IsTrue(item.ProcessedAsNew);
            Assert.IsTrue(item.ProcessedAsOld);
            Assert.IsTrue(newItem1.ProcessedAsNew);
            Assert.IsTrue(newItem1.ProcessedAsOld);
        }
        public void TestCollectionPausing()
        {
            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));


            CollectionPausing <int> collectionPausing = sourceScalar.CollectionPausing(true, CollectionPausingResumeType.ReplayChanges).For(consumer);

            collectionPausing.CollectionChanged += (sender, args) =>
            {
                Assert.IsTrue(collectionPausing.IsResuming);
            };

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

            collectionPausing.IsPaused = true;
            sourceScalar.Change(null);
            collectionPausing.IsPaused = false;
            collectionPausing.ValidateInternalConsistency();
        }
        public static void TestChangeSortDirection()
        {
            ObservableCollection <Item> items = getObservableCollection(new[] { 0, 2, 3, 7, 5, 2, 4, 7, 5, 6, 1, 5 },
                                                                        new[] { 0, 2, 3, 8, 1, 2, 4, 8, 2, 6, 1, 3 },
                                                                        new[] { 0, 2, 3, 7, 5, 2, 4, 0, 5, 6, 1, 5 });

            Scalar <ListSortDirection> listSortDirectionScalar = new Scalar <ListSortDirection>(ListSortDirection.Ascending);
            Ordering <Item, int?>      ordering  = items.Ordering(i => i.OrderNum, listSortDirectionScalar);
            ThenOrdering <Item, int?>  ordering1 = items.Ordering(i => i.OrderNum, listSortDirectionScalar).ThenOrdering(i => i.OrderNum2, listSortDirectionScalar);

            listSortDirectionScalar.Change(ListSortDirection.Descending);
            ordering.ValidateConsistency();
            ordering1.ValidateConsistency();
        }
        private void test(Item item, Scalar <Item> itemScalar)
        {
            Assert.IsTrue(item.ProcessedAsNew == 1);
            Item newItem1 = new Item();

            itemScalar.Change(newItem1);
            Assert.IsTrue(item.ProcessedAsNew == 1);
            Assert.IsTrue(item.ProcessedAsOld == 1);
            Assert.IsTrue(newItem1.ProcessedAsNew == 1);
            consumer.Dispose();
            Assert.IsTrue(item.ProcessedAsNew == 1);
            Assert.IsTrue(item.ProcessedAsOld == 1);
            Assert.IsTrue(newItem1.ProcessedAsNew == 1);
            Assert.IsTrue(newItem1.ProcessedAsOld == 1);
        }
Esempio n. 11
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();
        }
        public void ScalarProcessing_Test()
        {
            Item          item       = new Item();
            Scalar <Item> itemScalar = new Scalar <Item>(item);
            object        token      = null;

            itemScalar.ScalarProcessing <Item, object>((i, current, val) =>
            {
                Assert.AreEqual(current.ValueObject, token);
                i.ProcessedAsNew = true;
                return(i.Token);
            });
            Assert.IsTrue(item.ProcessedAsNew);
            token = item.Token;
            item  = new Item();
            itemScalar.Change(item);
            Assert.IsTrue(item.ProcessedAsNew);
        }
Esempio n. 13
0
        public void PagingTest_02()
        {
            Scalar <ObservableCollection <int> > items = new Scalar <ObservableCollection <int> >(null);
            Paging <int> paging = items.Paging(2).IsNeededFor(consumer);

            paging.ValidateConsistency();

            items.Change(new ObservableCollection <int>(Enumerable.Range(1, 100)));
            paging.ValidateConsistency();

            void test()
            {
                paging.ValidateConsistency();
                var sourceScalarValue = items.Value;

                if (sourceScalarValue != null)
                {
                    sourceScalarValue.Insert(2, 1);
                    paging.ValidateConsistency();
                    sourceScalarValue[3] = 2;
                    paging.ValidateConsistency();
                    sourceScalarValue.RemoveAt(3);
                    paging.ValidateConsistency();
                    sourceScalarValue.Move(1, 3);
                    paging.ValidateConsistency();
                    sourceScalarValue.RemoveAt(0);
                    paging.ValidateConsistency();
                    sourceScalarValue.RemoveAt(0);
                    paging.ValidateConsistency();
                    sourceScalarValue.RemoveAt(0);
                    paging.ValidateConsistency();
                    sourceScalarValue.RemoveAt(0);
                    paging.ValidateConsistency();
                    sourceScalarValue.Insert(0, 2);
                    paging.ValidateConsistency();
                    sourceScalarValue.Insert(0, 3);
                    paging.ValidateConsistency();
                }

                if (sourceScalarValue != null)
                {
                    sourceScalarValue.Clear();
                    paging.ValidateConsistency();
                }

                if (sourceScalarValue != null)
                {
                    foreach (int i in Enumerable.Range(1, 100))
                    {
                        sourceScalarValue.Add(i);
                    }
                    paging.ValidateConsistency();
                }
            }

            paging.CurrentPage = 2;
            test();

            paging.CurrentPage = 3;
            test();

            paging.CurrentPage = 3;
            test();

            paging.PageSize = 10;
            test();

            paging.CurrentPage = 1;
            test();

            paging.CurrentPage = 3;
            test();

            paging.CurrentPage = 4;
            test();

            consumer.Dispose();
        }
Esempio n. 14
0
        public void PagingTest_02()
        {
            Scalar <ObservableCollection <int> > items = new Scalar <ObservableCollection <int> >(null);
            Paging <int> paging = items.Paging(2).For(consumer);

            paging.ValidateInternalConsistency();

            items.Change(new ObservableCollection <int>(Enumerable.Range(1, 100)));
            paging.ValidateInternalConsistency();

            void test()
            {
                paging.ValidateInternalConsistency();
                ObservableCollection <int> sourceScalarValue = items.Value;

                if (sourceScalarValue != null)
                {
                    sourceScalarValue.Insert(2, 1);
                    paging.ValidateInternalConsistency();
                    sourceScalarValue[3] = 2;
                    paging.ValidateInternalConsistency();
                    sourceScalarValue.RemoveAt(3);
                    paging.ValidateInternalConsistency();
                    sourceScalarValue.Move(1, 3);
                    paging.ValidateInternalConsistency();
                    sourceScalarValue.RemoveAt(0);
                    paging.ValidateInternalConsistency();
                    sourceScalarValue.RemoveAt(0);
                    paging.ValidateInternalConsistency();
                    sourceScalarValue.RemoveAt(0);
                    paging.ValidateInternalConsistency();
                    sourceScalarValue.RemoveAt(0);
                    paging.ValidateInternalConsistency();
                    sourceScalarValue.Insert(0, 2);
                    paging.ValidateInternalConsistency();
                    sourceScalarValue.Insert(0, 3);
                    paging.ValidateInternalConsistency();
                }

                if (sourceScalarValue != null)
                {
                    sourceScalarValue.Clear();
                    paging.ValidateInternalConsistency();
                }

                if (sourceScalarValue != null)
                {
                    foreach (int i in Enumerable.Range(1, 100))
                    {
                        sourceScalarValue.Add(i);
                    }
                    paging.ValidateInternalConsistency();
                }
            }

            paging.CurrentPage = 2;
            test();

            paging.CurrentPage = 3;
            test();

            paging.CurrentPage = 3;
            test();

            paging.PageSize = 10;
            test();

            Assert.AreEqual(paging.PageCount, 10);

            paging.CurrentPage = 1;
            test();

            paging.CurrentPage = 3;
            test();

            paging.CurrentPage = 4;
            test();

            paging.CurrentPage = 4;
            paging.PageSize    = 80;
            test();

            paging.CurrentPage = -1;
            test();

            items.Value.Clear();
            Assert.AreEqual(paging.PageCount, 1);

            consumer.Dispose();

            Assert.Throws <ObservableComputationsException>(() => items.Paging(-1));
            Assert.Throws <ObservableComputationsException>(() => items.Paging(2, -1));
        }