public async Task ShouldCreateIndexAndLinkToDocument()
{
_store.RegisterIndexes<PersonIndexProvider>();
using (var session = _store.CreateSession())
{
var bill = new Person
{
Firstname = "Bill",
Lastname = "Gates",
};
var steve = new Person
{
Firstname = "Steve",
Lastname = "Balmer"
};
session.Save(bill);
session.Save(steve);
}
using (var session = _store.CreateSession())
{
Assert.Equal(2, await session.QueryIndexAsync<PersonByName>().Count());
Assert.Equal(1, await session.QueryIndexAsync<PersonByName>(x => x.Name == "Bill").Count());
Assert.Equal(1, await session.QueryIndexAsync<PersonByName>(x => x.Name == "Steve").Count());
Assert.Equal(0, await session.QueryIndexAsync<PersonByName>(x => x.Name == "Joe").Count());
var person = await session
.QueryAsync<Person, PersonByName>()
.Where(x => x.Name == "Bill")
.FirstOrDefault();
Assert.NotNull(person);
Assert.Equal("Bill", person.Firstname);
}
}