0
我需要針對匹配多個屬性的文檔集合進行查詢。
(從郵件列表交叉後:https://groups.google.com/forum/?fromgroups=#!topic/ravendb/r5f1zr2jd_o)使用多個屬性查詢RavenDB文檔
下面是文檔:
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; }
}
這裏是測試:
[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 the token exists in the database without using Where 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 back with Where 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);
}
}
}
最後斷言是失敗的一個。 我必須承認我不確定這是我的錯誤還是失敗。
據我瞭解,這應該是工作。
PS。我曾嘗試過使用獨立文檔存儲,並且沒有在內存中運行,但結果相同。
今天試過。結果仍然是一樣的。 BTW。更新原始帖子以反映更改。 – azzlack 2013-04-07 12:27:30
您的測試通過了我。完全如此。你使用的是什麼版本/內部版本? – 2013-04-07 17:22:05
我使用的版本是2330. – azzlack 2013-04-08 09:15:46