forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System.Linq; | ||
using Raven.Client.Indexes; | ||
using Xunit; | ||
|
||
namespace Raven.Client.Tests.Bugs | ||
{ | ||
public class UsingStartsWith : LocalClientTest | ||
{ | ||
[Fact] | ||
public void DefaultIndexingBehaviourDoesNotAllowStartsWith() | ||
{ | ||
using (var store = this.NewDocumentStore()) | ||
{ | ||
var index = new IndexDefinition<Blog, BlogTagItem>() | ||
{ | ||
Map = docs => from doc in docs | ||
from tag in doc.Tags | ||
select new | ||
{ | ||
tag.Name | ||
}, | ||
Reduce = results => from result in results | ||
group result by result.Name into g | ||
select new | ||
{ | ||
Name = g.Key, | ||
Count = g.Count() | ||
} | ||
|
||
}.ToIndexDefinition(store.Conventions); | ||
|
||
store.DatabaseCommands.PutIndex("TagInfo", index); | ||
|
||
|
||
using (var session = store.OpenSession()) | ||
{ | ||
var newBlog = new Blog() | ||
{ | ||
Tags = new[]{ | ||
new BlogTag() { Name = "SuperCallaFragalisticExpealadocious" } | ||
} | ||
}; | ||
session.Store(newBlog); | ||
session.SaveChanges(); | ||
|
||
var result = session.Query<BlogTagItem>("TagInfo") | ||
.Customize(x => x.WaitForNonStaleResults()) | ||
.Where(x => x.Name.StartsWith("Su")) | ||
.FirstOrDefault(); | ||
|
||
Assert.Null(result); | ||
} | ||
} | ||
} | ||
|
||
public class BlogTagItem | ||
{ | ||
public string Name { get; set; } | ||
public int Count { get; set; } | ||
} | ||
|
||
public class Blog | ||
{ | ||
public string Title | ||
{ | ||
get; | ||
set; | ||
} | ||
|
||
public string Category | ||
{ | ||
get; | ||
set; | ||
} | ||
|
||
public BlogTag[] Tags | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
|
||
public class BlogTag | ||
{ | ||
public string Name { get; set; } | ||
} | ||
} | ||
} |
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