Created
May 29, 2013 13:55
-
-
Save kijanawoodard/5670428 to your computer and use it in GitHub Desktop.
Async Spatial Test
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 System.Threading.Tasks; | |
using Raven.Client; | |
using Raven.Client.Extensions; | |
using Raven.Client.Indexes; | |
using Raven.Tests.Helpers; | |
using Xunit; | |
namespace RavenTests | |
{ | |
public class IndexTests : RavenTestBase | |
{ | |
[Fact] | |
public async Task SpatialIndexTest() | |
{ | |
using (var db = NewDocumentStore()) | |
{ | |
new Promos_Index().Execute(db); | |
using (var session = db.OpenAsyncSession()) | |
{ | |
session.Store(new Promo | |
{ | |
Title = "IPHONES", | |
Coordinate = new Coordinate { latitude = 41.145556, longitude = -73.995 } | |
}); | |
session.Store(new Promo | |
{ | |
Title = "ANDROIDS", | |
Coordinate = new Coordinate { latitude = 41.145533, longitude = -73.999 } | |
}); | |
session.Store(new Promo | |
{ | |
Title = "BLACKBERRY", | |
Coordinate = new Coordinate { latitude = 12.233, longitude = -73.995 } | |
}); | |
session.SaveChangesAsync().Wait(); | |
WaitForIndexing(db); | |
var result = await session.Query<Promo, Promos_Index>() | |
.Customize( | |
x => x.WithinRadiusOf( | |
radius: 3.0, | |
latitude: 41.145556, | |
longitude: -73.995)) | |
.ToListAsync(); | |
Assert.Equal(2, result.Count); | |
} | |
} | |
} | |
public class Promo : Entity | |
{ | |
public string Title { get; set; } | |
public Coordinate Coordinate { get; set; } | |
} | |
public class Coordinate | |
{ | |
public double latitude { get; set; } | |
public double longitude { get; set; } | |
} | |
public class Entity | |
{ | |
public string Id { get; set; } | |
} | |
public class Promos_Index : AbstractIndexCreationTask<Promo> | |
{ | |
public Promos_Index() | |
{ | |
Map = promos => from p in promos | |
select new | |
{ | |
Title = p.Title, | |
Coordinate = p.Coordinate, | |
__ = SpatialGenerate(p.Coordinate.latitude, p.Coordinate.longitude) | |
}; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment