コード例 #1
0
ファイル: GetitTests.cs プロジェクト: robertvanhaecke/Getit
        public async Task Query_Get_ReturnsJObjectCorrect()
        {
            string  responseData = File.ReadAllText("TestData/nearest-dealer-response-data.json");
            JObject gqlResponse  = JsonConvert.DeserializeObject <JObject>(responseData);

            IGetit getit  = Substitute.For <IGetit>();
            Config config = new Config("https://randy.butternubs.com/graphql");

            IQuery query     = getit.Query();
            IQuery subSelect = getit.Query();

            // Nearest Dealer has a sub-select of a dealer
            subSelect
            .Name("Dealer")
            .Select("id", "subId", "name", "make");

            // main query, with distance, and sub-select
            query
            .Name("NearestDealer")
            .Select("distance")
            .Select(subSelect)
            .Where("zip", "91302")
            .Where("makeId", 2345);

            getit.Get <JObject>(query, config).Returns(gqlResponse);

            JObject results = await getit.Get <JObject>(query, config);

            // Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(results.Value <JArray>("NearestDealer")[0].Value <double>("distance") >= 0.0);
        }
コード例 #2
0
ファイル: GetitTests.cs プロジェクト: robertvanhaecke/Getit
        public async Task Query_Get_ReturnsCorrect()
        {
            // Arrange
            string responseData = File.ReadAllText("TestData/batch-query-response-data.json");
            IGetit getit        = Substitute.For <IGetit>();
            Config config       = new Config("https://randy.butternubs.com/graphql");

            IQuery query     = getit.Query();
            IQuery subSelect = getit.Query();

            // Nearest Dealer has a sub-select of a dealer
            subSelect
            .Name("Dealer")
            .Select("id", "subId", "name", "make");

            // main query, with distance, and sub-select
            query
            .Name("NearestDealer")
            .Select("distance")
            .Select(subSelect)
            .Where("zip", "91302")
            .Where("makeId", 16);

            getit.Get <string>(query, config).Returns(responseData);

            string results = await getit.Get <string>(query, config);

            // Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(results.IndexOf("Randy Butternubs Aston Martin", StringComparison.Ordinal) >= 0);
        }
コード例 #3
0
ファイル: GetitTests.cs プロジェクト: robertvanhaecke/Getit
        public async Task Query_BatchGet_ReturnsCorrect()
        {
            // Arrange
            string responseData = File.ReadAllText("TestData/batch-query-response-data.json");

            IGetit getit  = Substitute.For <IGetit>();
            Config config = new Config("https://randy.butternubs.com/graphql");

            IQuery query               = getit.Query();
            IQuery subSelect           = getit.Query();
            IQuery batchQuery          = getit.Query();
            IQuery batchSubSelectQuery = getit.Query();

            // Nearest Dealer has a sub-select of a dealer
            subSelect
            .Name("Dealer")
            .Select("id", "subId", "name", "make");

            // query, with distance, and sub-select
            query
            .Name("NearestDealer")
            .Alias("SecondQuery")
            .Select("distance")
            .Select(subSelect)
            .Where("zip", "91302")
            .Where("makeId", 2345);

            // Nearest Dealer has a sub-select of a dealer
            batchSubSelectQuery
            .Name("Dealer")
            .Select("id", "subId", "name");

            // main query, with distance, and sub-select
            batchQuery
            .Name("NearestDealer")
            .Alias("BatchQuery")
            .Select("distance")
            .Select(batchSubSelectQuery)
            .Where("zip", "91302")
            .Where("makeId", 16)
            .Batch(query);

            getit.Get <string>(batchQuery, config).Returns(responseData);

            // get the json results as a strings
            string results = await getit.Get <string>(batchQuery, config);

            // Assert
            Assert.IsNotNull(results);

            // check for 2 as the query is the same, should be
            // further down the line...
            int firstIndex  = results.IndexOf("Randy Butternubs Aston Martin", StringComparison.Ordinal);
            int secondIndex = results.IndexOf("Randy Butternubs Aston Martin", 11 + firstIndex, StringComparison.Ordinal);

            // will fail if both -1
            Assert.IsTrue(secondIndex > firstIndex);
        }
コード例 #4
0
ファイル: GetitTests.cs プロジェクト: sganz/Getit
        public async Task Get_ValidConfig_ReturnsJson()
        {
            // Arrange
            IGetit getit = Substitute.For <IGetit>();
            IQuery query = new Query();

            query.Raw("{Version}");
            getit.Get <String>(query).ReturnsForAnyArgs(@"{""Version"": ""1234""}");

            // Act
            String jsonResults = await getit.Get <String>(query);

            // Assert
            Assert.AreEqual(@"{""Version"": ""1234""}", jsonResults);
        }