public void ReturnStringContainsIgnoreCaseTest()
        {
            var expected = "name ~ *\"Foo\"*";

            Expression <Func <Game, bool> > predicate = (g) => g.Name.Contains("Foo", StringComparison.InvariantCultureIgnoreCase);

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnSimpleIntTest()
        {
            var expected = "follows = 3";

            Expression <Func <Game, bool> > predicate = (g) => g.Follows == 3;

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnStringContainsTest()
        {
            var expected = "name = *\"Foo\"*";

            Expression <Func <Game, bool> > predicate = (g) => g.Name.Contains("Foo");

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnBooleanFalseComparisonTest()
        {
            var expected = "early_access = false";

            Expression <Func <Game, bool> > predicate = (g) => g.EarlyAccess == false;;

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnStringDifferentFromTest()
        {
            var expected = "name != \"Foo\"";

            Expression <Func <Game, bool> > predicate = (g) => g.Name != "Foo";

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnNullComparisonTest()
        {
            var expected = "slug = null";

            Expression <Func <Game, bool> > predicate = (g) => g.Slug == null;;

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnFullOneLevelPathFiltersWithOrTest()
        {
            var expected = "franchise.name = \"Worms\"";

            Expression <Func <Game, bool> > predicate = (g) => g.Franchise.Name == "Worms";

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnFullTwoLevelPathFiltersWithOrTest()
        {
            var expected = "cover.picture.url = \"https://covers.com\"*";

            Expression <Func <Game, bool> > predicate = (g) => g.Cover.Picture.Url.StartsWith("https://covers.com");

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnStringMatchesAllNotNewArrayTest()
        {
            var expected = "alternative_names = !{1,2,3}";

            Expression <Func <Game, bool> > predicate = (g) => !(new int[] { 1, 2, 3 }.Equals(g.AlternativeNames));

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnIntMatchesNewArrayTest()
        {
            var expected = "alternative_names = [1,2,3]";

            Expression <Func <Game, bool> > predicate = (g) => new int[] { 1, 2, 3 }.IsContainedIn(g.AlternativeNames);

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnIntNotInNewArrayTest()
        {
            var expected = "follows = !(3,4,5)";

            Expression <Func <Game, bool> > predicate = (g) => !(new uint[] { 3, 4, 5 }.Contains(g.Follows));

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnStringNotInNewArrayTest()
        {
            var expected = "name = !(\"Foo\",\"Bar\",\"Baz\")";

            Expression <Func <Game, bool> > predicate = (g) => !(new[] { "Foo", "Bar", "Baz" }.Contains(g.Name));

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnStringEndsWithIgnoreCaseVariantTest()
        {
            var expected = "name ~ *\"Foo\"";

            Expression <Func <Game, bool> > predicate = (g) => g.Name.EndsWith("Foo", true, CultureInfo.InvariantCulture);

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        public void ReturnStringEqualPascalCaseToTest()
        {
            var expected = "Name = \"Foo\"";

            Expression <Func <Game, bool> > predicate = (g) => g.Name == "Foo";

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, new RequestBuilderConfiguration {
                CaseContract = CaseContract.PascalCase
            }));
        }
        public void ReturnMultipleFiltersWithOrTest()
        {
            var expected = "name = *\"Foo\" & follows = (3,4,5) | alternative_names = !{1,2,3}";

            Expression <Func <Game, bool> > predicate = (g) =>
                                                        g.Name.EndsWith("Foo") &&
                                                        new uint[] { 3, 4, 5 }.Contains(g.Follows) ||
            !(new int[] { 1, 2, 3 }.Equals(g.AlternativeNames));

            Assert.AreEqual(expected, WherePredicateInterpreter.Run(predicate.Body, configuration));
        }
        /// <summary>
        /// Sets the where clause to send to the API.<br/>
        /// Each call replace the previous<br/>
        /// Prepares the <strong>where</strong> statement of the Apicalypse query.
        /// </summary>
        /// <param name="predicate">A predicate expression that provides a conditional test</param>
        /// <returns>The request builder, to chain the statements</returns>
        public RequestBuilder <T> Where(Expression <Func <T, bool> > predicate)
        {
            filters = WherePredicateInterpreter.Run(predicate.Body, configuration);

            return(this);
        }