Exemplo n.º 1
0
        public void ShouldGetQueryFromAPredicate()
        {
            // Arrange
            var testAlbum  = "test album";
            var testArtist = "test artist";
            var testTrack  = "test track";
            var testUpc    = "test upc";

            var year1 = 2000;
            var year2 = 17;

            var hipster = Tag.Hipster;

            // Act
            var query = QueryProvider.Get <QueryFields>(f =>
                                                        f.Any.Contains("rock") &&
                                                        f.Album == testAlbum &&
                                                        ((testAlbum == f.Album &&
                                                          testArtist == f.Artist &&
                                                          f.Track != testTrack ||
                                                          hipster != f.Tag ||
                                                          f.Tag == Tag.New ||
                                                          "test genre" != f.Genre &&
                                                          !f.Upc.Contains(testUpc) &&
                                                          f.Isrc == "test isrc") &&
                                                         f.Year == 2015 &&
                                                         (f.Year >= (year1 + year2) &&
                                                          f.Year <= 2019) &&
                                                         !(2020 >= f.Year &&
                                                           f.Year >= 2018)));

            // Assert
            query.Should().Be("rock album:\"test album\" album:\"test album\" artist:\"test artist\" NOT track:\"test track\" OR NOT tag:hipster OR tag:new OR NOT genre:\"test genre\" NOT upc:test upc isrc:\"test isrc\" year:2015 year:2017-2019 NOT year:2018-2020");
        }
Exemplo n.º 2
0
 public void ShouldThrowArgumentExceptionWhenUnaryOperandIsNotSupported()
 {
     // Arrange + Act + Assert
     ((Action)(() => QueryProvider.Get <QueryFields>(f => !(f.Album == "test album" && f.Artist == "test artist"))))
     .ShouldThrow <ArgumentException>()
     .Which.Message.Should().Match("Unsupported NOT expression operand of type '*' has been found.");
 }
Exemplo n.º 3
0
        public void ShouldThrowArgumentExceptionWhenRangeIsNotValid()
        {
            // Arrange + Act + Assert
            ((Action)(() => QueryProvider.Get <QueryFields>(f => f.Album == "test album" && f.Year >= 2015)))
            .ShouldThrow <ArgumentException>()
            .Which.Message.Should().Be("Range must be the following sequence: BinaryExpression, ExpressionType, BinaryExpression.");

            ((Action)(() => QueryProvider.Get <QueryFields>(f => f.Album == "test album" && f.Year >= 2015 && f.Year < 2017)))
            .ShouldThrow <ArgumentException>()
            .Which.Message.Should().Be("Only bound expressions with 'GreaterThanOrEqual' or 'LessThanOrEqual' operators are supported.");

            var value = 123;

            ((Action)(() => QueryProvider.Get <QueryFields>(f => f.Album == "test album" && value >= 2015 && f.Year <= 2017)))
            .ShouldThrow <ArgumentException>()
            .Which.Message.Should().Be("One of the bound expression operands must be a query field.");

            ((Action)(() => QueryProvider.Get <QueryFields>(f => f.Album == "test album" && (f.Year >= 2015 || f.Year <= 2017))))
            .ShouldThrow <ArgumentException>()
            .Which.Message.Should().Be("Only range expressions with 'AndAlso' operator are supported.");

            ((Action)(() => QueryProvider.Get <TestQueryFields>(f => f.Album == "test album" && f.TestValue >= 2015 && f.Year <= 2017)))
            .ShouldThrow <ArgumentException>()
            .Which.Message.Should().Be("Both range bound expressions must reference the same query field.");

            ((Action)(() => QueryProvider.Get <QueryFields>(f => f.Album == "test album" && f.Year >= 2015 && f.Year >= 2017)))
            .ShouldThrow <ArgumentException>()
            .Which.Message.Should().Be("Range bound expressions must define a range.");
        }
Exemplo n.º 4
0
 public void ShouldThrowArgumentExceptionWhenContainsCallObjectIsNotAQueryField()
 {
     // Arrange + Act + Assert
     ((Action)(() => QueryProvider.Get <QueryFields>(f => "test".Contains("e"))))
     .ShouldThrow <ArgumentException>()
     .Which.Message.Should().Match("The Contains call object expression must be a query field.");
 }
Exemplo n.º 5
0
 public void ShouldThrowArgumentExceptionWhenNoneOfTheEqualityOperandsIsAQueryField()
 {
     // Arrange + Act + Assert
     ((Action)(() => QueryProvider.Get <QueryFields>(f => f == null)))
     .ShouldThrow <ArgumentException>()
     .Which.Message.Should().Match("One of the equal expression operands must be a query field.");
 }
 public void ShouldThrowArgumentExceptionWhenExpressionTypeIsNotSupported()
 {
     // Arrange + Act + Assert
     ((Action)(() => QueryProvider.Get <QueryFields>(f => f.Album == "test album" | f.Artist == "test artist")))
     .Should().Throw <ArgumentException>()
     .Which.Message.Should().Match("*Unsupported expression of type '*' has been found.*");
 }
Exemplo n.º 7
0
        public void ShouldGetQueryFromASingleStatementPredicate()
        {
            // Arrange + Act
            var query = QueryProvider.Get <QueryFields>(f => f.Genre.Contains("rock"));

            // Assert
            query.Should().Be("genre:rock");
        }
Exemplo n.º 8
0
        public void ShouldRemoveSpecialCharactersInPredicate()
        {
            // Arrange + Act
            var query = QueryProvider.Get <QueryFields>(
                f =>
                f.Artist == "test \" artist" &&
                f.Album.Contains("test \"\" album:album"),
                new QueryOptions {
                RemoveSpecialCharacters = true
            });

            // Assert
            query.Should().Be("artist:\"test  artist\" album:test  albumalbum");
        }
Exemplo n.º 9
0
        public void ShouldNormalizePartialMatchInPredicate()
        {
            // Arrange + Act
            var query = QueryProvider.Get <QueryFields>(
                f =>
                f.Artist.Contains("part1 part2 part3") &&
                !f.Album.Contains("me OR my") &&
                f.Track.Contains("    ") &&
                f.Any.Contains("any1 any2   any3"),
                new QueryOptions {
                NormalizePartialMatch = true
            });

            // Assert
            query.Should().Be("artist:part1 artist:part2 artist:part3 NOT album:me NOT album:or NOT album:my track: any1 any2 any3");
        }
Exemplo n.º 10
0
 public ISearchTypeQueryBuilder <T> Matching(Expression <Func <QueryFields, bool> > predicate, QueryOptions queryOptions)
 {
     return(new SearchTypeQueryBuilder <T>(this, this.entities, QueryProvider.Get(predicate, queryOptions)));
 }
Exemplo n.º 11
0
 public ISearchTypeQueryBuilder <T> Matching(Expression <Func <QueryFields, bool> > predicate)
 {
     return(new SearchTypeQueryBuilder(this.searchBuilder, this.entities, QueryProvider.Get(predicate)));
 }