Querying for RavenDB documents using multiple properties -
i need make query against document collection matches several properties.
(cross post mailing list: https://groups.google.com/forum/?fromgroups=#!topic/ravendb/r5f1zr2jd_o)
here document:
public class sessiontoken { [jsonproperty("jti")] public string id { get; set; } [jsonproperty("aud")] public uri audience { get; set; } [jsonproperty("sub")] public string subject { get; set; } [jsonproperty("claims")] public dictionary<string, string> claims { get; set; } }
and here test:
[testfixture] public class ravendbtests { private idocumentstore documentstore; [setup] public void setup() { this.documentstore = new embeddabledocumentstore() { runinmemory = true }; this.documentstore.initialize(); } [test] public async void firstordefault_whensessiontokenexists_shouldreturnsessiontoken() { var c = new sessiontoken() { audience = new uri("http://localhost"), subject = "nunit", claims = new dictionary<string, string>() { { claimtypes.system, "nunit" } } }; using (var session = this.documentstore.openasyncsession()) { await session.storeasync(c); await session.savechangesasync(); // check if token exists in database without using clause var alltokens = await session.query<sessiontoken>().tolistasync(); assert.that(alltokens.any(x => x.subject == "nunit" && x.audience == new uri("http://localhost"))); // try getting token clause var token = await session.query<sessiontoken>().customize(x => x.waitfornonstaleresults()).where(x => x.subject == "nunit" && x.audience == new uri("http://localhost")).tolistasync(); assert.isnotnullorempty(token.first().id); } } }
the last assert 1 failing. must admit im not sure whether bug or failure on part.
far understand, supposed work.
ps. i´ve tried standalone document store embedded without running in memory, same result.
you getting stale results. in unit test, need allow time indexing occur.
add .customize(x=> x.waitfornonstaleresults())
queries , test should pass.
also, think left id
property off question when cut/paste because doesn't compile as-is.
update
per discussion in comments, issue applying [jsonproperty]
attribute id
property. since id
property represents document key, , not serialized part of json document, can't apply [jsonproperty]
attribute it.
Comments
Post a Comment