public async Task CanQueryWith_StartsWith() { await Seed(); QueryParameter[] args = { new QueryParameter { ContextValue = new ContextValue{ Values = new List <object>{ "Bar" }, Comparison = Comparisons.StringStartsWith }, MemberModel = new ModelMember(_type, _accessor, _members.Single(x => x.Name == "Name"), false) } }; var results = (await _inMemoryRepository.QueryAsync <InMemoryBar1>("test", args, null, null)).ToList(); results.Count.ShouldBe(5); results[0].Name.ShouldStartWith("Bar"); results[1].Name.ShouldStartWith("Bar"); results[2].Name.ShouldStartWith("Bar"); results[3].Name.ShouldStartWith("Bar"); results[4].Name.ShouldStartWith("Bar"); }
private static void PopulateField( TypeAccessor typeAccessor, object item, MemberSet members, KeyValuePair <string, object> d) { var field = members.Single(x => x.Name == d.Key); object value = d.Value; if (field.Type == typeof(Guid) && value is string strValue) { typeAccessor[item, d.Key] = Guid.Parse(strValue); return; } if (field.Type == typeof(decimal) && value is double dobValue) { typeAccessor[item, d.Key] = Convert.ToDecimal(dobValue); return; } if ((field.Type == typeof(DateTime) || field.Type == typeof(DateTimeOffset)) && value is DateTimeOffset dtmValue) { typeAccessor[item, d.Key] = dtmValue.DateTime; return; } if (field.IsList()) { if (value is Document[] doc1s) { typeAccessor[item, d.Key] = Populate(field, doc1s); return; } return; } if (field.Type != typeof(string) && field.Type.IsClass) { var t = TypeAccessor.Create(field.Type); var newItem = t.CreateNew(); foreach (var dItem in (Document)value) { PopulateField(t, newItem, t.GetMembers(), dItem); } typeAccessor[item, d.Key] = newItem; return; } typeAccessor[item, d.Key] = Convert.ChangeType(value, field.Type); }
private async Task <InMemoryBar1> GetById(int id) { QueryParameter[] args = { new QueryParameter { ContextValue = new ContextValue{ Values = new List <object>{ id }, Comparison = Comparisons.Equal }, MemberModel = new ModelMember(_type, _accessor, _members.Single(x => x.Name == "Id"), false) } }; return((await _inMemoryRepository.QueryAsync <InMemoryBar1>("ff", args, null, null)).SingleOrDefault()); }
public void CanHandleString() { var filter = new StringSearchFilter(); filter.CanHandle(Comparisons.Equal, _members.Single(m => m.Name == "StringValue")).ShouldBeTrue(); }
public async Task CanQueryWithMultipleStringEquals() { await Seed(); QueryParameter[] args = { new QueryParameter { ContextValue = new ContextValue{ Values = new List <object>{ "Bar 5" }, Comparison = Comparisons.Equal }, MemberModel = new ModelMember(_type, _accessor, _members.Single(x => x.Name == "Name"), false) }, new QueryParameter { ContextValue = new ContextValue{ Values = new List <object>{ "cat 5" }, Comparison = Comparisons.Equal }, MemberModel = new ModelMember(_type, _accessor, _members.Single(x => x.Name == "Category"), false) }, new QueryParameter { ContextValue = new ContextValue{ Values = new List <object>{ "Sa Sa Ba" }, Comparison = Comparisons.Equal }, MemberModel = new ModelMember(_type, _accessor, _members.Single(x => x.Name == "Description"), false) } }; var results = (await TableStorageRepository.QueryAsync <DocumentDbFoo3>("test", args, null, null)).ToList(); results.Count.ShouldBe(1); results[0].Id.ShouldBe("5"); }