public async Task <ActionResult> RegisterUser([Bind(Exclude = "UserId")] RegisterUserModel model) { ViewBag.Session = DynamicModels.GetSessionsMenus().FirstOrDefault(x => x.PlaceId == model.PlaceId); ViewBag.MultipleStepOpt = new MultipleStepProgressTabOption() { Steps = new List <string>() { "ثبت نام کاربر", "انتخاب صندلی", "تاییدیه نهایی جهت پرداخت", "عملیات پرداخت", "دریافت بلیت" }, CurrentStepIndex = 2 }; var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { model.UserId = (await Connections.Xalag.SqlConn.QueryAsync <int>("sp_User_Insert", new { model.FirstName, model.LastName, model.Birthday, model.MobileNo, model.NatrualCode, model.Email }, commandType: CommandType.StoredProcedure)).First(); } // If we got this far, something failed, redisplay form return(View(model)); }
void describe_First() { context["first taking in a 'where clause'"] = () => { before = () => models = new DynamicModels(new List<ExpandoObject>()); act = () => resultForFirst = models.First(new { Name = "Jane" }); context["no items in list"] = () => { it["result is null"] = () => resultForFirst.should_be(null); }; context["items exist in list that match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane" })); it["returns item"] = () => ((string)((dynamic)resultForFirst).Name).should_be("Jane"); }; }; context["first doesn't take in a 'where clause'"] = () => { before = () => { models = new DynamicModels(new List<ExpandoObject>()); models.Models.Add(new Gemini(new { Name = "Jane" })); }; act = () => resultForFirst = models.First(); it["returns first record"] = () => ((string)((dynamic)resultForFirst).Name).should_be("Jane"); }; }
void describe_Last() { context["last taking in a 'where clause'"] = () => { before = () => models = new DynamicModels(new List <Prototype>()); act = () => resultForFirst = models.Last(new { Name = "Jane" }); context["no items in list"] = () => { it["result is null"] = () => resultForFirst.should_be(null); }; context["items exist in list that match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane" })); it["returns item"] = () => ((string)((dynamic)resultForFirst).Name).should_be("Jane"); }; }; context["last doesn't take in a 'where clause'"] = () => { before = () => { models = new DynamicModels(new List <Prototype>()); models.Models.Add(new Gemini(new { Name = "Jane" })); }; act = () => resultForFirst = models.Last(); it["returns first record"] = () => ((string)((dynamic)resultForFirst).Name).should_be("Jane"); }; }
void it_creates_a_projection_for_empty_list() { models = new DynamicModels(new List<dynamic>()); var result = models.Select("Name") as IEnumerable<dynamic>; result.Count().should_be(0); }
void it_creates_a_projection_for_empty_list() { models = new DynamicModels(new List <dynamic>()); var result = models.Select("Name") as IEnumerable <dynamic>; result.Count().should_be(0); }
void describe_Any() { before = () => models = new DynamicModels(new List<Prototype>()); context["matching single property"] = () => { act = () => resultForAny = models.Any(new { Name = "Jane" }); context["no items in list"] = () => { it["any returns false"] = () => resultForAny.should_be_false(); }; context["items exist in list that match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; models.Models.Add(prototype); }; it["any returns true"] = () => resultForAny.should_be_true(); }; }; context["item exists in list that match multiple properties"] = () => { act = () => resultForAny = models.Any(new { Name = "Jane", Age = 15 }); context["entry exists where all properties match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; prototype.Age = 15; models.Models.Add(prototype); }; it["any returns true"] = () => resultForAny.should_be_true(); }; context["entry exists where all properties do not match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; prototype.Age = 10; models.Models.Add(prototype); }; it["any returns false"] = () => resultForAny.should_be_false(); }; }; }
void describe_Any() { before = () => models = new DynamicModels(new List <Prototype>()); context["matching single property"] = () => { act = () => resultForAny = models.Any(new { Name = "Jane" }); context["no items in list"] = () => { it["any returns false"] = () => resultForAny.should_be_false(); }; context["items exist in list that match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; models.Models.Add(prototype); }; it["any returns true"] = () => resultForAny.should_be_true(); }; }; context["item exists in list that match multiple properties"] = () => { act = () => resultForAny = models.Any(new { Name = "Jane", Age = 15 }); context["entry exists where all properties match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; prototype.Age = 15; models.Models.Add(prototype); }; it["any returns true"] = () => resultForAny.should_be_true(); }; context["entry exists where all properties do not match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; prototype.Age = 10; models.Models.Add(prototype); }; it["any returns false"] = () => resultForAny.should_be_false(); }; }; }
public virtual void AddNewAssociationMethod(DynamicModels collection, dynamic model) { collection.SetMember( "New", new DynamicFunctionWithParam(attributes => { return EntityFor(attributes); })); }
void it_creates_a_projection_for_populated_list_for_multiple_parameters() { models = new DynamicModels(new List <dynamic>() { new { Name = "Jane", Age = 15, Gender = "F" }, }); var result = (models.Select("Name", "Age") as IEnumerable <dynamic>).ToList(); (result[0].Name as string).should_be("Jane"); ((int)result[0].Age).should_be(15); }
void it_creates_a_projection_for_populated_list_for_multiple_parameters() { models = new DynamicModels(new List<dynamic>() { new { Name = "Jane", Age = 15, Gender = "F" }, }); var result = (models.Select("Name", "Age") as IEnumerable<dynamic>).ToList(); (result[0].Name as string).should_be("Jane"); ((int)result[0].Age).should_be(15); }
void describe_Any() { before = () => models = new DynamicModels(new List <Gemini>()); context["matching single property"] = () => { act = () => resultForAny = models.Any(new { Name = "Jane" }); context["no items in list"] = () => { it["any returns false"] = () => resultForAny.should_be_false(); }; context["items exist in list that match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane" })); it["any returns true"] = () => resultForAny.should_be_true(); }; }; context["any with no parameters just checks count (which is currently 0)"] = () => { act = () => resultForAny = models.Any(); it["return false"] = () => resultForAny.should_be_false(); }; context["item exists in list that match multiple properties"] = () => { act = () => resultForAny = models.Any(new { Name = "Jane", Age = 15 }); context["entry exists where all properties match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane", Age = 15 })); it["any returns true"] = () => resultForAny.should_be_true(); }; context["entry exists where all properties do not match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane", Age = 10 })); it["any returns false"] = () => resultForAny.should_be_false(); }; }; }
void describe_Any() { before = () => models = new DynamicModels(new List<Gemini>()); context["matching single property"] = () => { act = () => resultForAny = models.Any(new { Name = "Jane" }); context["no items in list"] = () => { it["any returns false"] = () => resultForAny.should_be_false(); }; context["items exist in list that match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane" })); it["any returns true"] = () => resultForAny.should_be_true(); }; }; context["any with no parameters just checks count (which is currently 0)"] = () => { act = () => resultForAny = models.Any(); it["return false"] = () => resultForAny.should_be_false(); }; context["item exists in list that match multiple properties"] = () => { act = () => resultForAny = models.Any(new { Name = "Jane", Age = 15 }); context["entry exists where all properties match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane", Age = 15 })); it["any returns true"] = () => resultForAny.should_be_true(); }; context["entry exists where all properties do not match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane", Age = 10 })); it["any returns false"] = () => resultForAny.should_be_false(); }; }; }
void it_creates_a_projection_for_populated_list_for_single_parameter() { models = new DynamicModels(new List <dynamic>() { new DynamicModel(new { Name = "Jane" }), new { Name = "Jane" }, new Gemini(new { Name = "Jane" }) }); var result = (models.Select("Name") as IEnumerable <dynamic>).ToList(); (result[0] as string).should_be("Jane"); (result[1] as string).should_be("Jane"); (result[2] as string).should_be("Jane"); }
void it_creates_a_projection_for_populated_list_for_single_parameter() { models = new DynamicModels(new List<dynamic>() { new DynamicModel(new { Name = "Jane" }), new { Name = "Jane" }, new Gemini(new { Name = "Jane" }) }); var result = (models.Select("Name") as IEnumerable<dynamic>).ToList(); (result[0] as string).should_be("Jane"); (result[1] as string).should_be("Jane"); (result[2] as string).should_be("Jane"); }
void describe_First() { before = () => models = new DynamicModels(new List <Gemini>()); act = () => resultForFirst = models.First(new { Name = "Jane" }); context["no items in list"] = () => { it["result is null"] = () => resultForFirst.should_be(null); }; context["items exist in list that match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane" })); it["returns item"] = () => resultForFirst.should_not_be_null(); }; }
public ActionResult Index(int placeId) { ViewBag.Title = "خرید بلیت"; ViewBag.Session = DynamicModels.GetSessionsMenus().FirstOrDefault(x => x.PlaceId == placeId); ViewBag.MultipleStepOpt = new MultipleStepProgressTabOption() { Steps = new List <string>() { "ثبت نام کاربر", "انتخاب صندلی", "تاییدیه نهایی جهت پرداخت", "عملیات پرداخت", "دریافت بلیت" }, CurrentStepIndex = 1 }; return(View()); }
void describe_Where() { before = () => models = new DynamicModels(new List<Gemini>()); context["matching single property"] = () => { act = () => resultList = models.Where(new { Name = "Jane" }); context["no items in list"] = () => { it["result list is empty"] = () => resultList.should_be_empty(); }; context["items exist in list that match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane" })); it["returns item"] = () => resultList.Count().should_be(1); }; }; context["item exists in list that match multiple properties"] = () => { act = () => resultList = models.Where(new { Name = "Jane", Age = 15 }); context["entry exists where all properties match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane", Age = 15 })); it["returns item"] = () => resultList.Count().should_be(1); }; context["entry exists where all properties do not match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane", Age = 10 })); it["result list is empty"] = () => resultList.should_be_empty(); }; }; }
void describe_Where() { before = () => models = new DynamicModels(new List <Gemini>()); context["matching single property"] = () => { act = () => resultList = models.Where(new { Name = "Jane" }); context["no items in list"] = () => { it["result list is empty"] = () => resultList.should_be_empty(); }; context["items exist in list that match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane" })); it["returns item"] = () => resultList.Count().should_be(1); }; }; context["item exists in list that match multiple properties"] = () => { act = () => resultList = models.Where(new { Name = "Jane", Age = 15 }); context["entry exists where all properties match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane", Age = 15 })); it["returns item"] = () => resultList.Count().should_be(1); }; context["entry exists where all properties do not match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane", Age = 10 })); it["result list is empty"] = () => resultList.should_be_empty(); }; }; }
void describe_OrderBy() { context["order by works for prototype objects"] = () => { before = () => { models = new DynamicModels(new List <Prototype>()); dynamic prototype = new Prototype(); prototype.Value = "A"; models.Models.Add(prototype); prototype = new Prototype(); prototype.Value = "B"; models.Models.Add(prototype); }; act = () => resultList = models.OrderBy(new { Value = "desc" }); it["ordering is applied"] = () => (resultList.First().Value as string).should_be("B"); }; }
void describe_OrderBy() { context["order by works for expando objects"] = () => { before = () => { models = new DynamicModels(new List<ExpandoObject>()); dynamic expando = new ExpandoObject(); expando.Value = "A"; models.Models.Add(expando); expando = new ExpandoObject(); expando.Value = "B"; models.Models.Add(expando); }; act = () => resultList = models.OrderBy(new { Value = "desc" }); it["ordering is applied"] = () => (resultList.First().Value as string).should_be("B"); }; }
void describe_First() { before = () => models = new DynamicModels(new List<Gemini>()); act = () => resultForFirst = models.First(new { Name = "Jane" }); context["no items in list"] = () => { it["result is null"] = () => resultForFirst.should_be(null); }; context["items exist in list that match"] = () => { before = () => models.Models.Add(new Gemini(new { Name = "Jane" })); it["returns item"] = () => resultForFirst.should_not_be_null(); }; }
void describe_OrderBy() { before = () => { models = new DynamicModels(new List<Gemini>()); models.Models.Add(new Gemini(new { Value1 = "C", Value2 = "X", Method = new DynamicFunction(() => "A") })); models.Models.Add(new Gemini(new { Value1 = "B", Value2 = "Y", Method = new DynamicFunction(() => "B") })); models.Models.Add(new Gemini(new { Value1 = "D", Value2 = "Y", Method = new DynamicFunction(() => "C") })); models.Models.Add(new Gemini(new { Value1 = "A", Value2 = "X", Method = new DynamicFunction(() => "D") })); }; it["orders records ascending"] = () => { resultList = models.OrderBy(new { Value1 = "asc" }); (resultList.First().Value1 as string).should_be("A"); }; it["orders records descending"] = () => { resultList = models.OrderBy(new { Value1 = "desc" }); (resultList.First().Value1 as string).should_be("D"); }; it["orders records based on multiple ascending specifications"] = () => { var orderBy = ( models.OrderBy(new { Value2 = "asc", Value1 = "asc", }) as IEnumerable<dynamic>).ToList(); (orderBy[0].Value1 as string).should_be("A"); (orderBy[0].Value2 as string).should_be("X"); (orderBy[1].Value2 as string).should_be("X"); (orderBy[1].Value1 as string).should_be("C"); }; it["orders records based on multiple descending specifications"] = () => { var orderBy = ( models.OrderBy(new { Value2 = "desc", Value1 = "desc" }) as IEnumerable<dynamic>).ToList(); (orderBy[0].Value1 as string).should_be("D"); (orderBy[0].Value2 as string).should_be("Y"); (orderBy[1].Value1 as string).should_be("B"); (orderBy[1].Value2 as string).should_be("Y"); }; it["order by can be applied to methods"] = () => { var orderBy = ( models.OrderBy(new { Method = "desc" }) as IEnumerable<dynamic>).ToList(); (orderBy[0].Method() as string).should_be("D"); }; it["order by can have an additonal project applied to it"] = () => { var orderBy = ( models.OrderBy(new { Method = "desc" }).Where(new { Value1 = "A" }) as IEnumerable<dynamic>).ToList(); (orderBy[0].Method() as string).should_be("D"); orderBy.Count.should_be(1); }; }
void describe_Count() { before = () => models = new DynamicModels(new List<Gemini>()); it["reports count"] = () => ((int)models.Count()).should_be(0); }
void describe_Count() { before = () => models = new DynamicModels(new List <Gemini>()); it["reports count"] = () => ((int)models.Count()).should_be(0); }
/* * This function is called through Edge.JS by lb-xm.js. * A Json definitions is passed and a DLL or CS code for the SDK is created as a result. */ public async Task <object> Invoke(object input) { // Process flags var inputs = ((Object[])input).Where(p => p != null).Select(p => p.ToString()).ToArray(); var flags = new HashSet <string>(inputs.Skip(2)); // Get json definition of the server string jsonModel = inputs[0]; if (flags.Contains("debug")) { WriteDefinitionsDebug(jsonModel); } // Create new templates and pass the definition Json to DynamicModels and DynamicRepos var dynamicModelsTemplate = new DynamicModels(); var dynamicReposTemplate = new DynamicRepos(); var constantCode = new HardcodedModels(); dynamicModelsTemplate.Session = new Dictionary <string, object>(); dynamicModelsTemplate.Session["jsonModel"] = jsonModel; dynamicReposTemplate.Session = new Dictionary <string, object>(); dynamicReposTemplate.Session["jsonModel"] = jsonModel; constantCode.Session = new Dictionary <string, object>(); constantCode.Session["jsonModel"] = jsonModel; if (flags.Contains("forms")) { Console.WriteLine(">> Parsing for Xamarin-Forms compatibility..."); constantCode.Session["XamarinForms"] = true; } else { constantCode.Session["XamarinForms"] = false; } if (flags.Contains("force")) { Console.WriteLine(">> Forcing SDK creation..."); dynamicReposTemplate.Session["force"] = true; } else { dynamicReposTemplate.Session["force"] = false; } // Create dynamic code from templates dynamicModelsTemplate.Initialize(); dynamicReposTemplate.Initialize(); constantCode.Initialize(); string code = constantCode.TransformText() + dynamicReposTemplate.TransformText() + dynamicModelsTemplate.TransformText(); if (!flags.Contains("force") && !handleUnsupported(code)) { return(false); } Directory.CreateDirectory(outputFolder); string currentPath = inputs[1]; if (flags.Contains("dll")) { Console.WriteLine(">> Compiling..."); return(await Compile(code, outputFolder + "/LBXamarinSDK.dll", currentPath)); } else { if (flags.Contains("check")) { if (await Compile(code, null, currentPath)) { Console.WriteLine(">> Check: Successful."); } else { Console.WriteLine(">> Check: Failed."); return(false); } } Console.WriteLine(">> Writing CS file: " + outputFolder + "/LBXamarinSDK.cs..."); System.IO.StreamWriter file = new System.IO.StreamWriter(outputFolder + "/LBXamarinSDK.cs"); file.Write(code); file.Close(); return(true); } }
public IEnumerable<dynamic> SelectManyRelatedTo(IEnumerable<dynamic> models, dynamic options) { if (DiscardCache(options)) selectManyRelatedToCache = null; if (selectManyRelatedToCache != null) return selectManyRelatedToCache; var many = Repository.Query(SelectClause(models.ToArray())).ToList(); foreach (var item in many) { var model = models.First(s => s.Id == item.GetMember(fromColumn)); item.SetMember(model.GetType().Name, new DynamicFunction(() => model)); } selectManyRelatedToCache = new DynamicModels(many); return selectManyRelatedToCache; }
private DynamicFunctionWithParam Query(dynamic model) { return (options) => { if (DiscardCache(options)) cachedCollection = null; if (cachedCollection != null) return cachedCollection; cachedCollection = new DynamicModels(Repository.Query(SelectClause(model))); AddNewAssociationMethod(cachedCollection, model); return cachedCollection; }; }
private void AddNewAssociationMethod(DynamicModels collection, DynamicModel model) { collection.SetMember( "New", new DynamicFunctionWithParam(attributes => { return EntityFor(model, attributes); })); }
public DynamicModels Execute(dynamic options, DynamicRepository repository, string associationName, string selectClause, IEnumerable<dynamic> models, string parentMemberName) { if (ShouldDiscardCache(options)) Cache = null; if (Cache != null) return Cache; var many = repository.Query(selectClause).ToList(); foreach (var item in many) { var model = models.First(s => s.Id == item.GetMember(parentMemberName)); item.SetMember(model.GetType().Name, model); } foreach (var model in models) { var assocation = model.AssociationNamed(associationName); var relatedTo = many.Where(s => s.GetMember(model.GetType().Name).Equals(model)).Select(s => s); assocation.EagerLoadMany.Cache = new DynamicModels(relatedTo); assocation.AddNewAssociationMethod(assocation.EagerLoadMany.Cache, model); } return new DynamicModels(many); }
/* * This function is called through Edge.JS by lb-xm.js. * A Json definitions is passed and a DLL or CS code for the SDK is created as a result. */ public async Task<object> Invoke(object input) { // Process flags var inputs = ((Object[])input).Where(p => p != null).Select(p => p.ToString()).ToArray(); var flags = new HashSet<string>(inputs.Skip(2)); // Get json definition of the server string jsonModel = inputs[0]; if (flags.Contains("debug")) { WriteDefinitionsDebug(jsonModel); } // Create new templates and pass the definition Json to DynamicModels and DynamicRepos var dynamicModelsTemplate = new DynamicModels(); var dynamicReposTemplate = new DynamicRepos(); var constantCode = new HardcodedModels(); dynamicModelsTemplate.Session = new Dictionary<string, object>(); dynamicModelsTemplate.Session["jsonModel"] = jsonModel; dynamicReposTemplate.Session = new Dictionary<string, object>(); dynamicReposTemplate.Session["jsonModel"] = jsonModel; constantCode.Session = new Dictionary<string, object>(); constantCode.Session["jsonModel"] = jsonModel; if(flags.Contains("forms")) { Console.WriteLine(">> Parsing for Xamarin-Forms compatibility..."); constantCode.Session["XamarinForms"] = true; } else { constantCode.Session["XamarinForms"] = false; } if (flags.Contains("force")) { Console.WriteLine(">> Forcing SDK creation..."); dynamicReposTemplate.Session["force"] = true; } else { dynamicReposTemplate.Session["force"] = false; } // Create dynamic code from templates dynamicModelsTemplate.Initialize(); dynamicReposTemplate.Initialize(); constantCode.Initialize(); string code = constantCode.TransformText() + dynamicReposTemplate.TransformText() + dynamicModelsTemplate.TransformText(); if(!flags.Contains("force") && !handleUnsupported(code)) { return false; } Directory.CreateDirectory(outputFolder); string currentPath = inputs[1]; if (flags.Contains("dll")) { Console.WriteLine(">> Compiling..."); return await Compile(code, outputFolder + "/LBXamarinSDK.dll", currentPath); } else { if (flags.Contains("check")) { if (await Compile(code, null, currentPath)) { Console.WriteLine(">> Check: Successful."); } else { Console.WriteLine(">> Check: Failed."); return false; } } Console.WriteLine(">> Writing CS file: " + outputFolder + "/LBXamarinSDK.cs..."); System.IO.StreamWriter file = new System.IO.StreamWriter(outputFolder + "/LBXamarinSDK.cs"); file.Write(code); file.Close(); return true; } }
private DynamicFunction Query(string foreignKey, dynamic model) { return () => { var collection = new DynamicModels(repository.All(foreignKey + " = @0", args: new[] { model.Expando.Id })); AddNewAssociationMethod(collection, model); return collection; }; }
public virtual void AddRepository(DynamicModels collection, DynamicRepository repository) { collection.SetMember("Repository", repository); }
private DynamicFunctionWithParam InnerJoinFor(dynamic model) { return (options) => { if (DiscardCache(options)) cachedCollection = null; if (cachedCollection != null) return cachedCollection; var models = (Repository.Query(InnerJoinSelectClause(fromColumn, toTable, throughTable, resolvedForeignKey, model)) as IEnumerable<dynamic>).ToList(); foreach (var m in models) AddReferenceBackToModel(m, model); cachedCollection = new DynamicModels(models); AddNewAssociationMethod(cachedCollection, model); return cachedCollection; }; }
void describe_OrderBy() { before = () => { models = new DynamicModels(new List <Gemini>()); models.Models.Add(new Gemini(new { Value1 = "C", Value2 = "X", Method = new DynamicFunction(() => "A") })); models.Models.Add(new Gemini(new { Value1 = "B", Value2 = "Y", Method = new DynamicFunction(() => "B") })); models.Models.Add(new Gemini(new { Value1 = "D", Value2 = "Y", Method = new DynamicFunction(() => "C") })); models.Models.Add(new Gemini(new { Value1 = "A", Value2 = "X", Method = new DynamicFunction(() => "D") })); }; it["orders records ascending"] = () => { resultList = models.OrderBy(new { Value1 = "asc" }); (resultList.First().Value1 as string).should_be("A"); }; it["orders records descending"] = () => { resultList = models.OrderBy(new { Value1 = "desc" }); (resultList.First().Value1 as string).should_be("D"); }; it["orders records based on multiple ascending specifications"] = () => { var orderBy = ( models.OrderBy(new { Value2 = "asc", Value1 = "asc", }) as IEnumerable <dynamic>).ToList(); (orderBy[0].Value1 as string).should_be("A"); (orderBy[0].Value2 as string).should_be("X"); (orderBy[1].Value2 as string).should_be("X"); (orderBy[1].Value1 as string).should_be("C"); }; it["orders records based on multiple descending specifications"] = () => { var orderBy = ( models.OrderBy(new { Value2 = "desc", Value1 = "desc" }) as IEnumerable <dynamic>).ToList(); (orderBy[0].Value1 as string).should_be("D"); (orderBy[0].Value2 as string).should_be("Y"); (orderBy[1].Value1 as string).should_be("B"); (orderBy[1].Value2 as string).should_be("Y"); }; it["order by can be applied to methods"] = () => { var orderBy = ( models.OrderBy(new { Method = "desc" }) as IEnumerable <dynamic>).ToList(); (orderBy[0].Method() as string).should_be("D"); }; it["order by can have an additonal project applied to it"] = () => { var orderBy = ( models.OrderBy(new { Method = "desc" }).Where(new { Value1 = "A" }) as IEnumerable <dynamic>).ToList(); (orderBy[0].Method() as string).should_be("D"); orderBy.Count.should_be(1); }; }
void describe_Where() { before = () => models = new DynamicModels(new List <Prototype>()); context["matching single property"] = () => { act = () => resultList = models.Where(new { Name = "Jane" }); context["no items in list"] = () => { it["result list is empty"] = () => resultList.should_be_empty(); }; context["items exist in list that match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; models.Models.Add(prototype); }; it["returns item"] = () => resultList.Count().should_be(1); }; }; context["item exists in list that match multiple properties"] = () => { act = () => resultList = models.Where(new { Name = "Jane", Age = 15 }); context["entry exists where all properties match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; prototype.Age = 15; models.Models.Add(prototype); }; it["returns item"] = () => resultList.Count().should_be(1); }; context["entry exists where all properties do not match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; prototype.Age = 10; models.Models.Add(prototype); }; it["result list is empty"] = () => resultList.should_be_empty(); }; }; context["chaining wheres"] = () => { before = () => { models.Models.Add(new Gemini(new { LastName = "Smith", FirstName = "Jane" })); models.Models.Add(new Gemini(new { LastName = "Smith", FirstName = "John" })); models.Models.Add(new Gemini(new { LastName = "Doe", FirstName = "John" })); }; act = () => resultList = models.Where(new { LastName = "Smith" }).Where(new { FirstName = "Jane" }); it["applies first filter then next filter"] = () => resultList.Count().should_be(1); }; context["value being compared is a dynamic function"] = () => { before = () => { models.Models.Add( new Gemini(new { LastName = new DynamicFunction(() => "Smith"), FirstName = new DynamicFunction(() => "Jane") })); models.Models.Add( new Gemini(new { LastName = new DynamicFunction(() => "Smith"), FirstName = new DynamicFunction(() => "John") })); models.Models.Add( new Gemini(new { LastName = new DynamicFunction(() => "Doe"), FirstName = new DynamicFunction(() => "John") })); }; act = () => { }; it["applies first filter then next filter"] = () => { resultList = models.Where(new { LastName = "Smith" }).Where(new { FirstName = "Jane" }); resultList.Count().should_be(1); }; }; }
void describe_OrderBy() { context["order by works for prototype objects"] = () => { before = () => { models = new DynamicModels(new List<Prototype>()); dynamic prototype = new Prototype(); prototype.Value = "A"; models.Models.Add(prototype); prototype = new Prototype(); prototype.Value = "B"; models.Models.Add(prototype); }; act = () => resultList = models.OrderBy(new { Value = "desc" }); it["ordering is applied"] = () => (resultList.First().Value as string).should_be("B"); }; }
public override void AddNewAssociationMethod(DynamicModels collection, dynamic model) { collection.SetMember("New", NewItemDelegate(model)); }
void describe_Where() { before = () => models = new DynamicModels(new List<Prototype>()); context["matching single property"] = () => { act = () => resultList = models.Where(new { Name = "Jane" }); context["no items in list"] = () => { it["result list is empty"] = () => resultList.should_be_empty(); }; context["items exist in list that match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; models.Models.Add(prototype); }; it["returns item"] = () => resultList.Count().should_be(1); }; }; context["item exists in list that match multiple properties"] = () => { act = () => resultList = models.Where(new { Name = "Jane", Age = 15 }); context["entry exists where all properties match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; prototype.Age = 15; models.Models.Add(prototype); }; it["returns item"] = () => resultList.Count().should_be(1); }; context["entry exists where all properties do not match"] = () => { before = () => { dynamic prototype = new Prototype(); prototype.Name = "Jane"; prototype.Age = 10; models.Models.Add(prototype); }; it["result list is empty"] = () => resultList.should_be_empty(); }; }; context["chaining wheres"] = () => { before = () => { models.Models.Add(new Gemini(new { LastName = "Smith", FirstName = "Jane" })); models.Models.Add(new Gemini(new { LastName = "Smith", FirstName = "John" })); models.Models.Add(new Gemini(new { LastName = "Doe", FirstName = "John" })); }; act = () => resultList = models.Where(new { LastName = "Smith" }).Where(new { FirstName = "Jane" }); it["applies first filter then next filter"] = () => resultList.Count().should_be(1); }; context["value being compared is a dynamic function"] = () => { before = () => { models.Models.Add( new Gemini(new { LastName = new DynamicFunction(() => "Smith"), FirstName = new DynamicFunction(() => "Jane") })); models.Models.Add( new Gemini(new { LastName = new DynamicFunction(() => "Smith"), FirstName = new DynamicFunction(() => "John") })); models.Models.Add( new Gemini(new { LastName = new DynamicFunction(() => "Doe"), FirstName = new DynamicFunction(() => "John") })); }; act = () => { }; it["applies first filter then next filter"] = () => { resultList = models.Where(new { LastName = "Smith" }).Where(new { FirstName = "Jane" }); resultList.Count().should_be(1); }; }; }
public virtual void AddNewAssociationMethod(DynamicModels collection, dynamic model) { collection.SetMember("New", NewItemDelegate()); }
public IEnumerable<dynamic> SelectManyRelatedTo(IEnumerable<dynamic> models, dynamic options) { if (DiscardCache(options)) selectManyRelatedToCache = null; if (selectManyRelatedToCache != null) return selectManyRelatedToCache; var many = Repository.Query(InnerJoinSelectClause(fromColumn, toTable, throughTable, resolvedForeignKey, models.ToArray())).ToList(); foreach (var item in many) { var model = models.First(s => s.Id == item.GetMember(fromColumn)); item.SetMember(model.GetType().Name, model); } selectManyRelatedToCache = new DynamicModels(many); return selectManyRelatedToCache; }