예제 #1
0
        public void Test()
        {
            var sorting1 = Sorting.Ascending("Name");

            Assert.Equal(SortingMode.Ascending, sorting1.Mode);
            Assert.Equal("Name", sorting1.Name);

            var sorting2 = Sorting.Descending("Name");

            Assert.Equal(SortingMode.Descending, sorting2.Mode);
            Assert.Equal("Name", sorting2.Name);

            var sortings1 = sorting1 + sorting2;

            Assert.Equal(1, sortings1.Length);

            Assert.Equal(SortingMode.Descending, sortings1[0].Mode);
            Assert.Equal("Name", sortings1[0].Name);

            var sortings2 = sortings1 + Sorting.Ascending("PhoneNumber");

            Assert.Equal(2, sortings2.Length);

            Assert.Equal(SortingMode.Ascending, sortings2[1].Mode);
            Assert.Equal("PhoneNumber", sortings2[1].Name);
        }
예제 #2
0
        public void Test()
        {
            var sorting1 = Sorting.Ascending("Id", "Name");

            Assert.Equal(SortingMode.Ascending, sorting1.Mode);
            Assert.Equal("Id, Name", sorting1.MembersText);
            Assert.Equal(2, sorting1.Members.Length);
            Assert.Equal("Id", sorting1.Members[0]);
            Assert.Equal("Name", sorting1.Members[1]);

            var sorting2 = Sorting.Descending("Amount", "CreatedTime");

            Assert.Equal(SortingMode.Descending, sorting2.Mode);
            Assert.Equal("Amount, CreatedTime", sorting2.MembersText);
            Assert.Equal(2, sorting2.Members.Length);
            Assert.Equal("Amount", sorting2.Members[0]);
            Assert.Equal("CreatedTime", sorting2.Members[1]);

            var sortings1 = sorting1 + sorting2;

            Assert.Equal(2, sortings1.Length);

            Assert.Equal(SortingMode.Ascending, sortings1[0].Mode);
            Assert.Equal("Id, Name", sortings1[0].MembersText);

            Assert.Equal(SortingMode.Descending, sortings1[1].Mode);
            Assert.Equal("Amount, CreatedTime", sortings1[1].MembersText);

            var sortings2 = sortings1 + Sorting.Ascending("PhoneNumber, HomeAddress.City");

            Assert.Equal(3, sortings2.Length);

            Assert.Equal(SortingMode.Ascending, sortings2[0].Mode);
            Assert.Equal("Id, Name", sortings2[0].MembersText);

            Assert.Equal(SortingMode.Descending, sortings2[1].Mode);
            Assert.Equal("Amount, CreatedTime", sortings2[1].MembersText);

            Assert.Equal(SortingMode.Ascending, sortings2[2].Mode);
            Assert.Equal("PhoneNumber, HomeAddress.City", sortings2[2].MembersText);
        }
            public bool AddSorting()
            {
                if (_current == null)
                {
                    return(true);
                }

                if (_bufferIndex == 0)
                {
                    _onError?.Invoke("SyntaxError: Expected sorting fields in the data schema, but missing.");
                    return(false);
                }

                if (_bufferIndex == 1)
                {
                    if (_buffer[0] == '~' || _buffer[0] == '!')
                    {
                        _onError?.Invoke("SyntaxError: Expected sorting descending field in the data schema, but missing.");
                        return(false);
                    }
                    else if (char.IsDigit(_buffer[0]))
                    {
                        _onError?.Invoke("SyntaxError: The sorting field of the data schema cannot start with a digit.");
                        return(false);
                    }
                }

                var sorting = _buffer[0] == '~' || _buffer[0] == '!' ?
                              Sorting.Descending(new string(_buffer, 1, _bufferIndex - 1)) :
                              Sorting.Ascending(new string(_buffer, 0, _bufferIndex));

                _bufferIndex = 0;

                _current.AddSorting(sorting);
                return(true);
            }
            public bool AddSorting()
            {
                if (_current == null)
                {
                    return(true);
                }

                if (_bufferIndex == 0)
                {
                    _onError?.Invoke("");
                    return(false);
                }

                if (_bufferIndex == 1)
                {
                    if (_buffer[0] == '~' || _buffer[0] == '!')
                    {
                        _onError?.Invoke("");
                        return(false);
                    }
                    else if (char.IsDigit(_buffer[0]))
                    {
                        _onError?.Invoke("");
                        return(false);
                    }
                }

                var sorting = _buffer[0] == '~' || _buffer[0] == '!' ?
                              Sorting.Descending(new string(_buffer, 1, _bufferIndex - 1)) :
                              Sorting.Ascending(new string(_buffer, 0, _bufferIndex));

                _bufferIndex = 0;

                _current.AddSorting(sorting);
                return(true);
            }