Esempio n. 1
0
        public void TestSearchExact()
        {
            // Arrange & Act
            var response = Factual.Fetch("places", new Query().SearchExact("a b c"));
            var raw      = Factual.RawQuery("t/places", "q=\"a b c\"");

            // Assert
            AssertReceivedOkResponse(response);
            Assert.AreEqual(response, raw);
        }
Esempio n. 2
0
        public void TestNewRawGetComplex()
        {
            // Arrange
            var CategoryLabel = "Food & Beverage";
            var Offset        = 0;
            var Lat           = 34.06018;
            var Lng           = -118.41835;
            var Radius        = 5000;

            // Act
            var result = Factual.RawQuery("t/places", new Dictionary <string, object>
            {
                {
                    "filters", new Dictionary <string, object>
                    {
                        {
                            "category_labels", CategoryLabel
                        }
                    }
                },
                {
                    "limit", 5
                },
                {
                    "offset", Offset
                },
                {
                    "include_count", (Offset == 0).ToString()
                },
                {
                    "geo", new Dictionary <string, object>
                    {
                        {
                            "$circle", new Dictionary <string, object>
                            {
                                {
                                    "$center", "[" + Lat + "," + Lng + "]"
                                },
                                {
                                    "$meters", Radius
                                }
                            }
                        }
                    }
                }
            }
                                          );

            var raw = Factual.RawQuery("t/places", "filters={\"category_labels\":\"Food %26 Beverage\"}&limit=5&offset=0&include_count=true&geo={\"$circle\":{\"$center\":[34.06018,-118.41835],\"$meters\":5000}}");

            // Assert
            AssertReceivedOkResponse(result);
            AssertReceivedOkResponse(raw);
            Assert.AreEqual(result, raw);
        }
Esempio n. 3
0
        public void RawQueryTest()
        {
            // Arrange
            var rawParameters = "filters={\"name\":{\"$bw\":\"Star\"}}&include_count=true";

            // Act
            string  result = Factual.RawQuery("t/global", rawParameters);
            dynamic json   = JsonConvert.DeserializeObject(result);

            // Assert
            Assert.AreEqual("ok", (string)json.status);
        }
Esempio n. 4
0
        public void TestCoreExample2()
        {
            // Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .Field("name")
                                         .BeginsWith("Star"));
            var raw = Factual.RawQuery("t/places", "filters={\"name\":{\"$bw\":\"Star\"}}");

            // Assert
            AssertReceivedOkResponse(response);
            Assert.AreEqual(response, raw);
        }
Esempio n. 5
0
        public void TestCoreExample5()
        {
            //Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .Field("name").Equal("The Counter")
                                         .WithIn(new Circle(Latitude, Longitude, Meters)));

            var raw = Factual.RawQuery("t/places", "filters={\"name\":{\"$eq\":\"The Counter\"}}&geo={\"$circle\":{\"$center\":[34.06018,-118.41835],\"$meters\":5000}}");

            //Assert
            AssertReceivedOkResponse(response);
            AssertNotEmpty(response);
            Assert.AreEqual(response, raw);
        }
Esempio n. 6
0
        public void TestDiffsResponse()
        {
            // Arrange
            DiffsQuery diffs = new DiffsQuery()
                               .After(1403106402094)
                               .Before(1403106404094);

            // Act
            var response = Factual.Fetch("places-us", diffs);
            var raw      = Factual.RawQuery("t/places-us/diffs?start=1403106402094&end=1403106404094");

            // Assert
            Assert.AreEqual(response, raw);
        }
Esempio n. 7
0
        public void TestSelectFieldsOnly()
        {
            //Arrange
            var response = Factual.Fetch("places", new Query().Field("country").Equal("US").Only("address", "country"));

            AssertReceivedOkResponse(response);
            AssertAll(response, "country", "us");

            var raw = Factual.RawQuery("t/places", "filters={\"country\":{\"$eq\":\"US\"}}&select=address,country");

            //Assert

            Assert.AreEqual(response, raw);
        }
Esempio n. 8
0
        public void TestApiUrlOverride2()
        {
            // Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .Field("name")
                                         .BeginsWith("Star")
                                         .IncludeRowCount());

            Factual.FactualApiUrlOverride = "http://fakeurl.factual.com";
            Factual.RawQuery("t/places", "filters={\"name\":{\"$bw\":\"Star\"}}&include_count=true");

            // Assert
            AssertReceivedOkResponse(response);
        }
Esempio n. 9
0
        public void TestCoreExample3()
        {
            //Arrange & Act
            var response = Factual.Fetch("places", new Query().Search("Fried Chicken, Los Angeles"));

            Factual.Debug = true;
            var raw   = Factual.RawQuery("t/places", "q=Fried Chicken, Los Angeles");
            var test2 = Factual.RawQuery("t/places", "q=Fried Chicken%2C Los Angeles");

            //Assert
            AssertReceivedOkResponse(response);
            Assert.AreEqual(test2, raw);
            Assert.AreEqual(response, raw);
        }
Esempio n. 10
0
        public void TestDiffsResponse()
        {
            //Arrange
            DiffsQuery diffs = new DiffsQuery()
                               .After(1354916463822)
                               .Before(1354917903834);

            //Act
            var response = Factual.Fetch("places-us", diffs);
            var raw      = Factual.RawQuery("t/places-us/diffs?start=1354916463822&end=1354917903834");

            //Assert
            Assert.AreEqual(response, raw);
        }
Esempio n. 11
0
        public void TestCoreExample4()
        {
            //Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .Search("Fried Chicken,Los Angeles")
                                         .Offset(5)
                                         .Limit(5));
            dynamic jsonResponse = JsonConvert.DeserializeObject(response);
            var     raw          = Factual.RawQuery("t/places", "q=Fried+Chicken,Los+Angeles&offset=5&limit=5");

            //Assert
            AssertReceivedOkResponse(response);
            Assert.AreEqual(5, ((ICollection <JToken>)jsonResponse.response.data).Count);
            Assert.AreEqual(response, raw);
        }
Esempio n. 12
0
        public void TestNewRawGetSimple()
        {
            //Arrange & Act
            var response = Factual.RawQuery("t/places", "select=name,category_labels&include_count=True");
            var raw      = Factual.RawQuery("t/places", new Dictionary <string, object>
            {
                { "select", "name,category_labels" },
                { "include_count", true }
            });

            //Assert
            AssertReceivedOkResponse(response);
            AssertReceivedOkResponse(raw);
            Assert.AreEqual(response, raw);
        }
Esempio n. 13
0
        public void TestBlendedSort()
        {
            // Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .WithIn(new Circle(Latitude, Longitude, Meters))
                                         .SortBlendRankAndDistance(100, 50));

            AssertReceivedOkResponse(response);
            AssertNotEmpty(response);

            var raw = Factual.RawQuery("t/places", "geo={\"$circle\":{\"$center\":[34.06018,-118.41835],\"$meters\":5000}}&sort={\"placerank\":100,\"distance\":50}");

            // Assert
            Assert.AreEqual(response, raw);
        }
Esempio n. 14
0
        public void TestTimeouts()
        {
            // Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .Field("name")
                                         .BeginsWith("Star"));

            Factual.ConnectionTimeout = 2500;
            Factual.ReadTimeout       = 7500;
            var raw = Factual.RawQuery("t/places", "filters={\"name\":{\"$bw\":\"Star\"}}");

            // Assert
            AssertReceivedOkResponse(response);
            AssertReceivedOkResponse(raw);
            Assert.AreEqual(response, raw);
        }
Esempio n. 15
0
        public void TestIn()
        {
            //Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .Field("region").In("CA", "NM", "FL"));

            AssertReceivedOkResponse(response);
            AssertNotEmpty(response);
            AssertIn(response, "region", "CA", "NM", "FL");

            var raw = Factual.RawQuery("t/places", "filters={\"region\":{\"$in\":[\"CA\",\"NM\",\"FL\"]}}");

            //Assert

            Assert.AreEqual(response, raw);
        }
Esempio n. 16
0
        public void TestRowFiltersTwoBeginsWith()
        {
            // Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .Field("name").BeginsWith("McDonald's")
                                         .Field("locality").BeginsWith("Los"));

            AssertReceivedOkResponse(response);
            AssertNotEmpty(response);
            AssertStartsWith(response, "name", "McDonald");
            AssertStartsWith(response, "locality", "Los");

            var raw = Factual.RawQuery("t/places", "filters={\"$and\":[{\"name\":{\"$bw\":\"McDonald's\"}},{\"locality\":{\"$bw\":\"Los\"}}]}");

            // Assert
            Assert.AreEqual(response, raw);
        }
Esempio n. 17
0
        public void TestSortByDistance()
        {
            //Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .WithIn(new Circle(Latitude, Longitude, Meters))
                                         .SortAsc("$distance"));

            AssertReceivedOkResponse(response);
            AssertNotEmpty(response);
            AssertAscendingDoubles(response, "$distance");

            var raw = Factual.RawQuery("t/places", "geo={\"$circle\":{\"$center\":[34.06018,-118.41835],\"$meters\":5000}}&sort=$distance:asc");

            //Assert

            Assert.AreEqual(response, raw);
        }
Esempio n. 18
0
        //[ExpectedException(typeof(System.NullReferenceException))]
        public void TestApiUrlOverride1()
        {
            // Arrange & Act
            var response = Factual.Fetch("places", new Query()
                                         .Field("name")
                                         .BeginsWith("Star"));
            //Override FactualApiUrl
            //Factual.FactualApiUrlOverride = "http://fakeurl.factual.com";
            //Reset FactualApiUrl back to default
            //Factual.FactualApiUrlOverride = null;
            var raw = Factual.RawQuery("t/places", "filters={\"name\":{\"$bw\":\"Star\"}}");

            // Assert
            AssertReceivedOkResponse(response);
            AssertReceivedOkResponse(raw);
            Assert.AreEqual(response, raw);
        }
Esempio n. 19
0
        public void TestNestedOrWithinTheTopLevelAnd()
        {
            //Arrange & Act
            var query = new Query().Field("region").In("MA", "VT", "NH");

            query.Or
            (
                query.Field("name").BeginsWith("Coffee"),
                query.Field("name").BeginsWith("Star")
            );

            var response = Factual.Fetch("places", query);

            AssertReceivedOkResponse(response);
            AssertNotEmpty(response);
            AssertStartsWithEither(response, "name", "Coffee", "Star");

            var raw = Factual.RawQuery("t/places", "filters={\"$and\":[{\"region\":{\"$in\":[\"MA\",\"VT\",\"NH\"]}},{\"$or\":[{\"name\":{\"$bw\":\"Coffee\"}},{\"name\":{\"$bw\":\"Star\"}}]}]}");

            //Assert

            Assert.AreEqual(response, raw);
        }
Esempio n. 20
0
        public void TestNewRawGetComplex()
        {
            //Arrange & Act
            var response = Factual.RawQuery("t/restaurants", "filters={\"category\":\"Food %26 Beverage\"}&limit=5");
            var raw      = Factual.RawQuery("t/restaurants", new Dictionary <string, object>
            {
                {
                    "filters", JsonConvert.SerializeObject(new Dictionary <string, object>
                    {
                        {
                            "category", "Food & Beverage"
                        }
                    })
                },
                {
                    "limit", 5
                }
            });

            //Assert
            AssertReceivedOkResponse(response);
            AssertReceivedOkResponse(raw);
            Assert.AreEqual(response, raw);
        }
Esempio n. 21
0
        public void TestNewRawGetMonetize()
        {
            //Arrange & Act
            //var response = Factual.RawQuery("places/monetize", "filters={\"place_locality\":\"Los Angeles\"}&limit=5");
            var raw = Factual.RawQuery("places/monetize", new Dictionary <string, object>
            {
                {
                    "filters", new Dictionary <string, object>
                    {
                        {
                            "place_locality", "Los Angeles"
                        }
                    }
                },
                {
                    "limit", 5
                }
            });

            //Assert
            //AssertReceivedOkResponse(response);
            AssertReceivedOkResponse(raw);
            //Assert.AreEqual(response, raw);
        }