public void CanDeserializeListsWithNull() { string stringJSON = @"{ ""node"": { ""__typename"": ""Product"", ""tags"": [ ""blue"", null, ""fancy"" ] } }"; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot response = new QueryRoot(dataJSON); CollectionAssert.AreEqual( new List <string>() { "blue", null, "fancy" }, ((Product)response.node()).tags() ); }
public void Get() { var yahooApiClient = new Mock <IYahooApiClient>(); var xchangeParser = new Mock <IXchangeParser>(); var utils = new RateUtils(yahooApiClient.Object, xchangeParser.Object); yahooApiClient.Setup(client => client.GetXchange("myPair", It.IsAny <Action <string> >())) .Callback <String, Action <string> >((pair, callBack) => callBack("myJson")); var queryRoot = new QueryRoot { Query = new Query { Results = new Results { Rate = new RateDetails { Rate = "123.45" } } } }; xchangeParser.Setup(parser => parser.Parse("myJson")).Returns(queryRoot); utils.GetXchangeRate( "myPair", rate => Assert.AreEqual("123.45", rate)); }
public QueryResponse(Dictionary <string, object> dataJSON) : base(dataJSON) { if (DataJSON != null) { _data = new QueryRoot(this.DataJSON); } }
private void SqlQuery_QueryAwake(QueryRoot sender, ref bool abort) { if (MessageBox.Show(@"You had typed something that is not a SELECT statement in the text editor and continued with visual query building." + @"Whatever the text in the editor is, it will be replaced with the SQL generated by the component. Is it right?", @"Active Query Builder .NET Demo", MessageBoxButtons.YesNo) == DialogResult.No) { abort = true; } }
private void OnVerificationRequestComplete(QueryRoot result, ShopifyError errors) { RequestInProgress = false; if (errors != null) { UpdateVerificationState(ShopCredentials.VerificationState.Invalid); } else { UpdateVerificationState(ShopCredentials.VerificationState.Verified); } }
public void CanDeserializeEnum() { string stringJSON = @"{ ""shop"": { ""currencyCode"": ""CAD"" } }"; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot response = new QueryRoot(dataJSON); Assert.AreEqual(CurrencyCode.CAD, response.shop().currencyCode()); }
public void WillReturnUnkownEnum() { string stringJSON = @"{ ""shop"": { ""currencyCode"": ""I AM NOT REAL"" } }"; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot response = new QueryRoot(dataJSON); Assert.AreEqual(CurrencyCode.UNKNOWN, response.shop().currencyCode()); }
public void CanDeserializeBasic() { string stringJSON = @"{ ""shop"": { ""name"": ""test-shop"" } }"; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot response = new QueryRoot(dataJSON); Assert.AreEqual("test-shop", response.shop().name()); }
public void DeserializeAliasedField() { string stringJSON = @"{ ""node___aliasName"": { ""__typename"": ""Product"", ""id"": ""1"" } }"; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot response = new QueryRoot(dataJSON); Assert.AreEqual("1", response.node(alias: "aliasName").id()); }
public void CanDeserializeInterfaces() { string stringJSON = @"{ ""node"": { ""__typename"": ""Product"", ""title"": ""I AM A PRODUCT"" } }"; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot query = new QueryRoot(dataJSON); Assert.IsTrue(query.node() is Node); Assert.IsTrue(query.node() is Product); }
public void GetBDCInfo(HttpContext context) { context.Request.ContentEncoding = Encoding.GetEncoding("utf-8"); string queryJson = context.Request.Form["PostData"].ToString(); QueryRoot queryModel = Newtonsoft.Json.JsonConvert.DeserializeObject <QueryRoot>(queryJson); if (null != queryModel.owners && queryModel.owners.Count > 0) { ReturnRoot root = GetBDCInfoByQLR(queryModel.owners); string json = Newtonsoft.Json.JsonConvert.SerializeObject(root); context.Response.ContentEncoding = Encoding.GetEncoding("utf-8"); context.Response.ContentType = "text/plain"; context.Response.Write(json); context.Response.End(); } }
public void InterfaceCanDeseralizeUnknownType() { string stringJSON = @"{ ""node"": { ""__typename"": ""IAmNotReal"", ""title"": ""I AM A PRODUCT"" } }"; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot query = new QueryRoot(dataJSON); Assert.IsTrue(query.node() is Node); Assert.IsTrue(query.node() is UnknownNode); }
public void TestGenericQuery() { ShopifyBuy.Init(new MockLoader()); QueryRoot response = null; ShopifyBuy.Client().Query( (q) => q.shop(s => s .name() ), (data, error) => { response = data; Assert.IsNull(error); } ); Assert.AreEqual("this is the test shop yo", response.shop().name()); }
public void ThrowsExceptionAliasedFieldWhichWasNotQueried() { string stringJSON = @"{}"; NoQueryException caughtError = null; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot response = new QueryRoot(dataJSON); try { response.node(alias: "aliasName").id(); } catch (NoQueryException error) { caughtError = error; } Assert.IsNotNull(caughtError); Assert.AreEqual("It looks like you did not query the field `node` with alias `aliasName`", caughtError.Message); }
public void BuildQuery(QueryRoot queryRoot) { queryRoot.Field <ListGraphType <AutoRegisteringObjectGraphType <UserModel> > >( "users", arguments: new QueryArguments( new QueryArgument <StringGraphType> { Name = "sortBy" }, new QueryArgument <BooleanGraphType> { Name = "descending" }, new QueryArgument <IntGraphType> { Name = "first" }, new QueryArgument <IntGraphType> { Name = "offset" }), resolve: context => { var userService = _contextAccessor.HttpContext.RequestServices.GetRequiredService <IUserService>(); //TODO pagination needed return(userService.GetUsersAsync(new GetUsersModel { SortBy = context.GetArgument <string>("sortBy"), Descending = context.GetArgument <bool>("descending") }).Result.Items); } ).AuthorizeWith("AdminPolicy"); queryRoot.Field <AutoRegisteringObjectGraphType <UserModel> >( "user", arguments: new QueryArguments( new QueryArgument <StringGraphType> { Name = "id" }), resolve: context => { var userService = _contextAccessor.HttpContext.RequestServices.GetRequiredService <IUserService>(); //TODO pagination needed return(userService.GetUserAsync(int.Parse(context.GetArgument <string>("id"))).Result); } ).AuthorizeWith("AdminPolicy"); }
public void ExceptionIsThrownForBlankAliasInResponse() { string stringJSON = @"{ ""aliasName___node"": { ""id"": ""1"" } }"; AliasException caughtError = null; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot response = new QueryRoot(dataJSON); try { response.node(alias: "").id(); } catch (AliasException error) { caughtError = error; } Assert.IsNotNull(caughtError); Assert.AreEqual("`alias` cannot be a blank string", caughtError.Message); }
public void AccessingFieldNotQueriedThrowsException() { Exception error = null; string stringJSON = @"{ ""shop"": { ""name"": ""test-shop"" } }"; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot response = new QueryRoot(dataJSON); try { response.shop().currencyCode(); } catch (NoQueryException e) { error = e; } Assert.IsNotNull(error); Assert.AreEqual("It looks like you did not query the field `currencyCode`", error.Message); }
public void ExceptionIsThrownForInvalidAliasNameForResponse() { string stringJSON = @"{ ""aliasName___customerAddress"": { ""city"": ""Toronto"" } }"; AliasException caughtError = null; Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON); QueryRoot response = new QueryRoot(dataJSON); try { response.node(alias: "$$$").id(); } catch (AliasException error) { caughtError = error; } Assert.IsNotNull(caughtError); Assert.AreEqual("`alias` was invalid format", caughtError.Message); }
private void AddColumns(QueryRoot root, SelectClause target) { foreach (var f in root.fields.Values) { var expression = GetFieldExpression(f, target); if (f.invert) { expression = new QueryFunctionExpression { KnownFunction = KnownQueryFunction.SqlNot, Arguments = new List <ISqlElement> { expression } } } ; target.Fields.Add(new SelectFieldExpression { Expression = expression, Alias = f.alias }); } }
public static Expression Create(QueryRoot queryRoot) { return(null); }
private void Query_SQLContextChanged(object sender, EventArgs eventArgs) { QueryRoot query = (QueryRoot)sender; SQLContext = query.SQLContext; }
public async Task SendAsyncShouldRetrieveAllPagesWhenThereIsOnlyOneConnectionInTheQuery() { var firstQueryRoot = new QueryRoot { Shops = new Connection <Shop> { Edges = new[] { new Edge <Shop> { Cursor = "Cursor1", Node = new Shop { Name = "Shop1" } } }, PageInfo = new PageInfo { HasNextPage = true, HasPreviousPage = false } } }; var secondQueryRoot = new QueryRoot { Shops = new Connection <Shop> { Edges = new[] { new Edge <Shop> { Cursor = "Cursor2", Node = new Shop { Name = "Shop2" } } }, PageInfo = new PageInfo { HasNextPage = false, HasPreviousPage = true } } }; _httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(call => { switch (call.ReceivedCalls().Count()) { case 1: return(Task.FromResult(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(new { data = firstQueryRoot })), StatusCode = HttpStatusCode.OK })); case 2: return(Task.FromResult(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(new { data = secondQueryRoot })), StatusCode = HttpStatusCode.OK })); default: throw new Exception("This should not happen"); } }); _client = new GraphQlRelayClient { _httpClient = _httpClient }; var result = await _client.QueryAllPagesAsync <QueryRoot>(new GraphQlRequestMessage { Query = "{ shops(first:1) { edges { cursor, node { name } }, pageInfo { hasNextPage, hasPreviousPage } } }" }); Assert.Equal(2, result.Count()); Assert.Equal(firstQueryRoot.Shops.Edges.First().Node.Name, result.ElementAt(0).Shops.Edges.First().Node.Name); Assert.Equal(secondQueryRoot.Shops.Edges.First().Node.Name, result.ElementAt(1).Shops.Edges.First().Node.Name); }