Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public void PagingTest_02()
        {
            Scalar <ObservableCollection <int> > items = new Scalar <ObservableCollection <int> >(null);
            Paging <int> paging = items.Paging(2);

            paging.ValidateConsistency();

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

            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();
        }
        private void test(int[] charsCounts)
        {
            string testNum    = string.Empty;
            int    index      = 0;
            int    charsCount = 0;
            int    indexOld   = 0;
            int    indexNew   = 0;
            int    index1     = 0;
            ObservableCollection <string> strings;
            StringsConcatenating          stringsConcatenating;
            Scalar <string> separatorScalar;

            try
            {
                trace(testNum        = "1", charsCounts, index, charsCount, indexOld, indexNew);
                strings              = getObservableCollections(charsCounts);
                separatorScalar      = new Scalar <string>("*");
                stringsConcatenating = strings.StringsConcatenating(separatorScalar).For(consumer);
                test(stringsConcatenating, separatorScalar);

                for (index = 0; index < charsCounts.Length; index++)
                {
                    trace(testNum   = "2", charsCounts, index, charsCount, indexOld, indexNew);
                    strings         = getObservableCollections(charsCounts);
                    separatorScalar = new Scalar <string>("*");
                    StringsConcatenating concatenating1 = strings.StringsConcatenating(separatorScalar).For(consumer);
                    strings.RemoveAt(index);
                    test(concatenating1, separatorScalar);
                }

                for (index = 0; index <= charsCounts.Length; index++)
                {
                    for (charsCount = 0; charsCount <= charsCounts.Length; charsCount++)
                    {
                        trace(testNum   = "11", charsCounts, index, charsCount, indexOld, indexNew);
                        strings         = getObservableCollections(charsCounts);
                        separatorScalar = new Scalar <string>("*");
                        StringsConcatenating concatenating2 = strings.StringsConcatenating(separatorScalar).For(consumer);
                        strings.Insert(index, getString(charsCount));
                        test(concatenating2, separatorScalar);
                    }
                }

                for (index = 0; index < charsCounts.Length; index++)
                {
                    trace(testNum   = "6", charsCounts, index, charsCount, indexOld, indexNew);
                    strings         = getObservableCollections(charsCounts);
                    separatorScalar = new Scalar <string>("*");
                    StringsConcatenating concatenating3 = strings.StringsConcatenating(separatorScalar).For(consumer);
                    strings[index] = string.Empty;
                    test(concatenating3, separatorScalar);

                    for (charsCount = 0; charsCount <= charsCounts.Length; charsCount++)
                    {
                        trace(testNum   = "3", charsCounts, index, charsCount, indexOld, indexNew);
                        strings         = getObservableCollections(charsCounts);
                        separatorScalar = new Scalar <string>("*");
                        StringsConcatenating concatenating2 = strings.StringsConcatenating(separatorScalar).For(consumer);
                        strings[index] = getString(charsCount);
                        test(concatenating2, separatorScalar);
                    }
                }

                for (index = 0; index < charsCounts.Length; index++)
                {
                    trace(testNum   = "4", charsCounts, index, charsCount, indexOld, indexNew);
                    strings         = getObservableCollections(charsCounts);
                    separatorScalar = new Scalar <string>("*");
                    StringsConcatenating concatenating1 = strings.StringsConcatenating(separatorScalar).For(consumer);
                    strings[index] = null;
                    test(concatenating1, separatorScalar);

                    for (charsCount = 0; charsCount <= charsCounts.Length; charsCount++)
                    {
                        trace(testNum   = "5", charsCounts, index, charsCount, indexOld, indexNew);
                        strings         = getObservableCollections(charsCounts);
                        separatorScalar = new Scalar <string>("*");
                        StringsConcatenating concatenating2 = strings.StringsConcatenating(separatorScalar).For(consumer);
                        strings[index] = getString(charsCount);
                        test(concatenating2, separatorScalar);
                    }
                }

                for (indexOld = 0; indexOld < charsCounts.Length; indexOld++)
                {
                    for (indexNew = 0; indexNew < charsCounts.Length; indexNew++)
                    {
                        trace(testNum   = "6", charsCounts, index, charsCount, indexOld, indexNew);
                        strings         = getObservableCollections(charsCounts);
                        separatorScalar = new Scalar <string>("*");
                        StringsConcatenating concatenating2 = strings.StringsConcatenating(separatorScalar).For(consumer);
                        strings.Move(indexOld, indexNew);
                        test(concatenating2, separatorScalar);
                    }
                }
            }
            catch (Exception e)
            {
                string traceString = getTraceString(
                    testNum,
                    charsCounts,
                    index,
                    charsCount,
                    indexOld,
                    indexNew,
                    index1);
                _textFileOutputLog.AppentLine(traceString);
                _textFileOutputLog.AppentLine(e.Message);
                _textFileOutputLog.AppentLine(e.StackTrace);
                throw new Exception(traceString, e);
            }

            writeUsefulTest(getTestString(charsCounts));
        }