Created
June 1, 2017 17:12
-
-
Save brunomlopes/f3b611b0c6bfbd176c682db55deacf83 to your computer and use it in GitHub Desktop.
Unit test for a problem with queries with @ symbols
This file contains hidden or 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
class Entity | |
{ | |
public string Id { get; set; } | |
public string AuthorId { get; set; } | |
public string Title { get; set; } | |
public string Language { get; set; } | |
} | |
class Index : AbstractIndexCreationTask<Entity> | |
{ | |
public Index() | |
{ | |
Map = entities => from entity in entities | |
select new | |
{ | |
entity.AuthorId, | |
entity.Title, | |
entity.Language, | |
}; | |
} | |
} | |
public class TestsForAt : RavenTestBase | |
{ | |
[Fact] | |
public void ShouldAtBeEscaped() | |
{ | |
var store = NewDocumentStore(); | |
new Index().Execute(store); | |
using (var session = store.OpenSession()) | |
{ | |
session.Store(new Entity | |
{ | |
AuthorId= "users/42", | |
Title= "@andrew is a fine guy", | |
Language = "en" | |
}); | |
session.SaveChanges(); | |
} | |
using (var session = store.OpenSession()) | |
{ | |
var requestedLangs = new[] {"en", "pt"}; | |
var query = session.Query<Entity, Index>() | |
.Customize(q => q.WaitForNonStaleResults()) | |
.Where(e => e.AuthorId == "users/42" && e.Title.StartsWith("@") && e.Language.In(requestedLangs)); | |
Assert.Contains("@andrew is a fine guy", | |
query.ToList().Select(e => e.Title).ToList()); | |
} | |
} | |
[Fact] | |
public void EscapingAtDoesNotWork() | |
{ | |
var store = NewDocumentStore(); | |
new Index().Execute(store); | |
using (var session = store.OpenSession()) | |
{ | |
session.Store(new Entity | |
{ | |
AuthorId= "users/42", | |
Title= "@andrew is a fine guy", | |
Language = "en" | |
}); | |
session.SaveChanges(); | |
} | |
using (var session = store.OpenSession()) | |
{ | |
var requestedLangs = new[] {"en", "pt"}; | |
var query = session.Query<Entity, Index>() | |
.Customize(q => q.WaitForNonStaleResults()) | |
.Where(e => e.AuthorId == "users/42" && e.Title.StartsWith(@"\@") && e.Language.In(requestedLangs)); | |
Assert.Contains("@andrew is a fine guy", | |
query.ToList().Select(e => e.Title).ToList()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment