public void ExpressionExtensions_GetNameTest() { TestClass c = new TestClass(); Assert.AreEqual("TestProperty", ExpressionMethods.GetName((() => c.TestProperty)), "GetName returned the incorrect name of the property in the selector method"); }
public void RepositoryOwner_Repository_Query() { var expression = new Query() .RepositoryOwner("foo") .Repository("bar") .Select((Repository x) => new { x.Id, x.Name, Owner = x.Owner.Select(o => new { o.Login }), x.IsFork, x.IsPrivate, }); Expression <Func <JObject, IEnumerable <object> > > expected = data => ExpressionMethods.SelectEntity( data["data"]["repositoryOwner"]["repository"], x => new { Id = x["id"].ToObject <string>(), Name = x["name"].ToObject <string>(), Owner = ExpressionMethods.SelectEntity(x["owner"], o => new { Login = o["login"].ToObject <string>() }), IsFork = x["isFork"].ToObject <string>(), IsPrivate = x["isPrivate"].ToObject <string>(), }); var query = new QueryBuilder().Build(expression); Assert.Equal(expected.ToString(), query.Expression.ToString()); }
public void Union() { var expression = new RootQuery() .Union .Select(x => x.Simple) .Select(x => new { x.Name, x.Description, }); Expression <Func <JObject, object> > expected = data => ExpressionMethods.Select( ((Func <JToken, IQueryable <JToken> >)(x => ExpressionMethods.ChildrenOfType(x, "Simple")))((data["data"]["union"])), x => new { Name = x["name"].ToObject <string>(), Description = x["description"].ToObject <string>(), }); // We need to remove the (Func<JToken, IQueryable<JToken>>) cast that is needed by // C# but not by expression trees. expected = (Expression <Func <JObject, object> >)RemoveConvert.Default.Visit(expected); var query = new QueryBuilder().Build(expression); Assert.Equal(expected.ToString(), query.Expression.ToString()); }
public void AutoMapperTestCaseThatFails() { var expressionMethods = new ExpressionMethods(); // Doesn't work with many expressionMethods.GetById(1, x => x.Info, x => x.Profile); }
public void AutoMapperTestCaseThatWorks() { var expressionMethods = new ExpressionMethods(); // Works with one expressionMethods.GetById(1, x => x.Info); }
private bool EvaluateChildren(State state) { if (Time == state.CurrentTime) { return(ExpressionMethods.CheckExpressionSatisfaction(Expression, state.Fluents) == FluentValue.True); } return(state.Children.All(EvaluateChildren)); }
public void Data_Select_Single_Member() { var expression = new RootQuery() .Data .Select(x => x.Id); Expression <Func <JObject, IEnumerable <string> > > expected = data => ExpressionMethods.SelectEntity(data["data"]["data"], x => x["id"].ToObject <string>()); var query = new QueryBuilder().Build(expression); Assert.Equal(expected.ToString(), query.Expression.ToString()); }
public void Search_User_Name_Via_Edges() { var expression = new Query() .Search("foo", SearchType.User, 30) .Edges.Select(x => x.Node) .Select(x => x.User.Name); Expression <Func <JObject, IEnumerable <object> > > expected = data => ExpressionMethods.Select( ExpressionMethods.ChildrenOfType(data["data"]["search"]["edges"], "User"), x => x["name"].ToObject <string>()); var query = new QueryBuilder().Build(expression); Assert.Equal(expected.ToString(), query.Expression.ToString()); }
public void SimpleQuery_Select_Multiple_Members() { var expression = new RootQuery() .Simple("foo", 2) .Select(x => new { x.Name, x.Description }); Expression <Func <JObject, object> > expected = data => ExpressionMethods.SelectEntity(data["data"]["simple"], x => new { Name = x["name"].ToObject <string>(), Description = x["description"].ToObject <string>(), }); var query = new QueryBuilder().Build(expression); Assert.Equal(expected.ToString(), query.Expression.ToString()); }
public void Nested_Selects() { var expression = new RootQuery() .Data .Select(x => new { x.Id, Items = x.Items.Select(i => i.Name), }); Expression <Func <JObject, object> > expected = data => ExpressionMethods.SelectEntity( data["data"]["data"], x => new { Id = x["id"].ToObject <string>(), Items = ExpressionMethods.SelectEntity(x["items"], i => i["name"].ToObject <string>()) }); var query = new QueryBuilder().Build(expression); Assert.Equal(expected.ToString(), query.Expression.ToString()); }
/// <summary> /// Gets the command associated with the given property and delegates. /// <b>For use outside of property setters and getters</b> /// </summary> /// <param name="execute">Action to be performed by the command. Recieves the command parameter as an argument</param> /// <param name="canExecute">Predicate that is used to determine if the command can be executed</param> /// <param name="selector">The expression that selects the appropriate property</param> /// <returns>The command composed of the supplied delegates</returns> protected ICommand GetCommand <T>(Action <object> execute, Predicate <object> canExecute, Expression <Func <T> > selector) { return(this.GetCommand(execute, canExecute, ExpressionMethods.GetName(selector))); }
/// <summary> /// Gets the command associated with the given property and delegates. /// <b>For use outside of property setters and getters</b> /// </summary> /// <param name="execute">Action to be performed by the command. Recieves the command parameter as an argument</param> /// <param name="canExecute">Func that is used to determine if the command can be executed</param> /// <param name="selector">The expression that selects the appropriate property</param> /// <returns>The command composed of the supplied delegates</returns> protected ICommand GetCommand <T>(Action <object> execute, Func <bool> canExecute, Expression <Func <T> > selector) { return(this.GetCommand(execute, (x => canExecute()), ExpressionMethods.GetName(selector))); }
/// <summary> /// Gets the command associated with the given property and delegate. /// <b>For use outside of property setters and getters</b> /// </summary> /// <param name="execute">Action to be performed by the command</param> /// <param name="selector">The expression that selects the appropriate property</param> /// <returns>The command composed of the supplied delegate</returns> protected ICommand GetCommand <T>(Action execute, Expression <Func <T> > selector) { return(this.GetCommand((x => execute()), (x => true), ExpressionMethods.GetName(selector))); }