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
67 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
Raven.Tests/MailingList/transformedresults_customid_test.cs
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,66 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Raven.Client.Document; | ||
using Raven.Client.Indexes; | ||
using Xunit; | ||
|
||
namespace Raven.Tests.MailingList | ||
{ | ||
public class transformedresults_customid_test : RavenTest | ||
{ | ||
public class TestItem | ||
{ | ||
public string DocId { get; set; } | ||
public string Name { get; set; } | ||
public string City { get; set; } | ||
} | ||
|
||
public class TestResultItem | ||
{ | ||
public string DocId { get; set; } | ||
public string Name { get; set; } | ||
} | ||
|
||
|
||
[Fact] | ||
public void Can_project_InternalId_from_transformResults() | ||
{ | ||
using(GetNewServer()) | ||
using (var store = new DocumentStore { Url = "http://localhost:8080" }) | ||
{ | ||
store.Initialize(); | ||
store.Conventions.FindIdentityProperty = (x => x.Name == "DocId"); | ||
store.DatabaseCommands.PutIndex("TestItemsIndex", new IndexDefinitionBuilder<TestItem, TestItem> | ||
{ | ||
Map = items => from item in items select new { DocId = item.DocId, Name = item.Name, City = item.City }, | ||
TransformResults = (db, results) => from item in results | ||
select new { DocId = item.DocId, Name = item.Name }, | ||
}, true); | ||
|
||
using (var session = store.OpenSession()) | ||
{ | ||
session.Store(new TestItem() | ||
{ | ||
DocId = "testitems/500", | ||
Name = "My first item", | ||
City = "New york" | ||
}); | ||
session.Store(new TestItem() | ||
{ | ||
DocId = "testitems/501", | ||
Name = "My second item", | ||
City = "London" | ||
}); | ||
session.SaveChanges(); | ||
|
||
TestResultItem item = session | ||
.Advanced.LuceneQuery<TestResultItem>("TestItemsIndex") | ||
.WaitForNonStaleResults() | ||
.ToList().First(); | ||
|
||
Assert.NotNull(item.DocId); | ||
} | ||
} | ||
} | ||
} | ||
} |
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