Exemple #1
0
        public void FilterParserTest001()
        {
            var filter   = "Hello World!";
            var expected = new FilterParserResult(
                new[]
            {
                new FilterParserResultGroup(
                    new[]
                {
                    new FilterParserResultEntry(CommonMetaData.Artist, FilterParserEntryOperator.Match, "*Hello World!*"),
                    new FilterParserResultEntry(CommonMetaData.Album, FilterParserEntryOperator.Match, "*Hello World!*"),
                    new FilterParserResultEntry(CommonMetaData.Title, FilterParserEntryOperator.Match, "*Hello World!*"),
                },
                    FilterParserGroupOperator.Or
                    )
            }
                );
            var actual = default(IFilterParserResult);

            Assert.IsTrue(this.Core.Components.FilterParser.TryParse(
                              filter,
                              out actual
                              ));
            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public void FilterParserTest004()
        {
            var filter   = "artist:custard cream year>:1990 year<2000";
            var expected = new FilterParserResult(
                new[]
            {
                new FilterParserResultGroup(
                    new[]
                {
                    new FilterParserResultEntry(CommonMetaData.Artist, FilterParserEntryOperator.Match, "*custard cream*"),
                    new FilterParserResultEntry(CommonMetaData.Year, FilterParserEntryOperator.GreaterEqual, "1990"),
                    new FilterParserResultEntry(CommonMetaData.Year, FilterParserEntryOperator.Less, "2000"),
                },
                    FilterParserGroupOperator.And
                    )
            }
                );
            var actual = default(IFilterParserResult);

            Assert.IsTrue(this.Core.Components.FilterParser.TryParse(
                              filter,
                              out actual
                              ));
            Assert.AreEqual(expected, actual);
        }
Exemple #3
0
        public void FilterParserTest005()
        {
            var filter   = "5* cream cakes";
            var expected = new FilterParserResult(
                new[]
            {
                new FilterParserResultGroup(
                    new[]
                {
                    new FilterParserResultEntry(CommonStatistics.Rating, FilterParserEntryOperator.Equal, "5"),
                },
                    FilterParserGroupOperator.And
                    ),
                new FilterParserResultGroup(
                    new[]
                {
                    new FilterParserResultEntry(CommonMetaData.Artist, FilterParserEntryOperator.Match, "*cream cakes*"),
                    new FilterParserResultEntry(CommonMetaData.Album, FilterParserEntryOperator.Match, "*cream cakes*"),
                    new FilterParserResultEntry(CommonMetaData.Title, FilterParserEntryOperator.Match, "*cream cakes*"),
                },
                    FilterParserGroupOperator.Or
                    )
            }
                );
            var actual = default(IFilterParserResult);

            Assert.IsTrue(this.Core.Components.FilterParser.TryParse(
                              filter,
                              out actual
                              ));
            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        public void FilterParserTest006()
        {
            var minRating     = "4";
            var maxLastPlayed = DateTimeHelper.ToString(DateTime.Now.AddDays(-30).Date);
            var filter        = string.Format("rating>:{0} lastplayed<{1}", minRating, maxLastPlayed);
            var expected      = new FilterParserResult(
                new[]
            {
                new FilterParserResultGroup(
                    new[]
                {
                    new FilterParserResultEntry(CommonStatistics.Rating, FilterParserEntryOperator.GreaterEqual, "4"),
                }
                    ),
                new FilterParserResultGroup(
                    new[]
                {
                    new FilterParserResultEntry(CommonStatistics.LastPlayed, FilterParserEntryOperator.Less, maxLastPlayed)
                }
                    )
            }
                );
            var actual = default(IFilterParserResult);

            Assert.IsTrue(this.Core.Components.FilterParser.TryParse(
                              filter,
                              out actual
                              ));
            Assert.AreEqual(expected, actual);
        }
Exemple #5
0
        public bool TryParse(string filter, out IFilterParserResult result)
        {
            var groups = new List <IFilterParserResultGroup>();

            while (!string.IsNullOrEmpty(filter))
            {
                var success = default(bool);
                foreach (var provider in this.Providers)
                {
                    var group = default(IFilterParserResultGroup);
                    if (provider.TryParse(ref filter, out group))
                    {
                        groups.Add(group);
                        success = true;
                        break;
                    }
                }
                if (!success)
                {
                    break;
                }
            }
            result = new FilterParserResult(groups);
            return(string.IsNullOrEmpty(filter));
        }
Exemple #6
0
        public void FilterParserTest003()
        {
            var filter   = "artist:custard cream";
            var expected = new FilterParserResult(
                new[]
            {
                new FilterParserResultGroup(
                    new[]
                {
                    new FilterParserResultEntry(CommonMetaData.Artist, FilterParserEntryOperator.Match, "*custard cream*")
                }
                    )
            }
                );
            var actual = default(IFilterParserResult);

            Assert.IsTrue(this.Core.Components.FilterParser.TryParse(
                              filter,
                              out actual
                              ));
            Assert.AreEqual(expected, actual);
        }