Created
February 22, 2014 01:41
-
-
Save mattjohnsonpint/9147377 to your computer and use it in GitHub Desktop.
Testing fluent mappings in linq to lucene
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using Lucene.Net.Linq; | |
using Lucene.Net.Linq.Fluent; | |
using Lucene.Net.Store; | |
using Lucene.Net.Util; | |
using NUnit.Framework; | |
namespace LinqLuceneTest | |
{ | |
public class Customer | |
{ | |
public int Id { get; set; } | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
} | |
[TestFixture] | |
public class FluentLuceneTest | |
{ | |
private readonly Customer[] customers = | |
{ | |
new Customer { Id = 1, FirstName = "Alice", LastName = "Anderson" }, | |
new Customer { Id = 2, FirstName = "Bob", LastName = "Anderson" }, | |
new Customer { Id = 3, FirstName = "Charlie", LastName = "Anderson" }, | |
new Customer { Id = 4, FirstName = "Donald", LastName = "Duck" } | |
}; | |
public class CustomerMap : ClassMap<Customer> | |
{ | |
public CustomerMap() | |
: base(Version.LUCENE_30) | |
{ | |
Key(x => x.Id); | |
Property(x => x.FirstName); | |
Property(x => x.LastName); | |
} | |
} | |
[Test] | |
public void Can_Get_Results_When_Using_Fluent_Mappings() | |
{ | |
var map = new CustomerMap(); | |
using (var directory = new RAMDirectory()) | |
using (var provider = new LuceneDataProvider(directory, Version.LUCENE_30)) | |
{ | |
provider.Settings.EnableMultipleEntities = false; | |
var mapper = map.ToDocumentMapper(); | |
using (var session = provider.OpenSession(mapper)) | |
{ | |
session.Add(this.customers); | |
} | |
using (var session = provider.OpenSession(mapper)) | |
{ | |
var query = session.Query().Where(x => x.LastName == "Anderson"); | |
var results = query.ToList(); | |
Assert.AreEqual(3, results.Count); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment