Created
October 2, 2013 16:08
-
-
Save kijanawoodard/6796148 to your computer and use it in GitHub Desktop.
Casting Transformer QueryInput
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
[TestFixture] | |
public class TransformerQueryInputTests : RavenTestBase | |
{ | |
[Test] | |
public void CanCastQueryInput() | |
{ | |
using (var store = NewDocumentStore()) | |
{ | |
new FooTransformer().Execute(store); | |
using (var session = store.OpenSession()) | |
{ | |
session.Store(new Foo { Id = "foos/1", Things = { "hello", "there" } }); | |
session.SaveChanges(); | |
var results = session.Load<FooTransformer, FooTransformer.Result>( | |
"foos/1", | |
configuration => configuration.AddQueryParam("take", 1) | |
); | |
Assert.AreEqual(1, results.Keys.Count); | |
} | |
} | |
} | |
public class Foo | |
{ | |
public string Id { get; set; } | |
public List<string> Things { get; set; } | |
public Foo() | |
{ | |
Things = new List<string>(); | |
} | |
} | |
public class FooTransformer : AbstractTransformerCreationTask<Foo> | |
{ | |
public class Result | |
{ | |
public List<string> Keys { get; set; } | |
} | |
public FooTransformer() | |
{ | |
TransformResults = foos => from foo in foos | |
select new | |
{ | |
Keys = foo.Things.Take(Query("take").Value<int>()) | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment