-
-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
053b023
commit 14068e0
Showing
13 changed files
with
533 additions
and
154 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
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
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
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
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,40 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using FastExpressionCompiler; | ||
using Marten; | ||
using Marten.Testing.Documents; | ||
using Marten.Testing.Harness; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using Shouldly; | ||
|
||
namespace LinqTests.Acceptance.Support; | ||
|
||
public class SelectTransform<T>: LinqTestCase | ||
{ | ||
private readonly Expression<Func<Target, T>> _selector; | ||
|
||
public SelectTransform(Expression<Func<Target, T>> selector) | ||
{ | ||
_selector = selector; | ||
} | ||
|
||
public override async Task Compare(IQuerySession session, Target[] documents, TestOutputMartenLogger logger) | ||
{ | ||
var target = documents.FirstOrDefault(x => x.StringArray?.Length > 0 && x.NumberArray?.Length > 0 && x.Inner != null); | ||
var expected = documents.Select(_selector.CompileFast()).Take(1).Single(); | ||
|
||
var actual = await session.Query<Target>().Where(x => x.Id == target.Id).Select(_selector).SingleAsync(); | ||
|
||
var expectedJson = JsonConvert.SerializeObject(expected); | ||
var actualJson = JsonConvert.SerializeObject(actual); | ||
|
||
if (!JToken.DeepEquals(JObject.Parse(expectedJson), JObject.Parse(actualJson))) | ||
{ | ||
// This would you would assume throw | ||
actualJson.ShouldBe(expectedJson); | ||
} | ||
} | ||
} |
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
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,85 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using LinqTests.Acceptance.Support; | ||
using Marten.Testing.Documents; | ||
using Xunit.Abstractions; | ||
|
||
namespace LinqTests.Acceptance; | ||
|
||
public class select_clauses : LinqTestContext<select_clauses> | ||
{ | ||
public select_clauses(DefaultQueryFixture fixture, ITestOutputHelper output) : base(fixture) | ||
{ | ||
TestOutput = output; | ||
} | ||
|
||
private static void select<T>(Expression<Func<Target, T>> selector) | ||
{ | ||
testCases.Add(new SelectTransform<T>(selector)); | ||
} | ||
|
||
static select_clauses() | ||
{ | ||
var number = 10; | ||
|
||
select(x => new {Id = x.Id}); | ||
select(x => new {Foo = x.Id}); | ||
select(x => new {Id = x.Id, Inner = x.Inner}); | ||
select(x => new {Id = x.Id, Number = x.Number}); | ||
select(x => new {Id = x.Id, Other = x.NumberArray}); | ||
select(x => new {Id = x.Id, Other = x.Color}); | ||
select(x => new {Id = x.Id, Other = x.Children}); | ||
select(x => new {Id = x.Id, Other = x.Date}); | ||
select(x => new {Id = x.Id, Other = x.Decimal}); | ||
select(x => new {Id = x.Id, Other = x.Double}); | ||
select(x => new {Id = x.Id, Other = x.Flag}); | ||
select(x => new {Id = x.Id, Other = x.Double}); | ||
select(x => new {Id = x.Id, Other = x.Long}); | ||
select(x => new {Id = x.Id, Other = x.DateOffset}); | ||
select(x => new {Id = x.Id, Other = x.GuidArray}); | ||
select(x => new {Id = x.Id, Other = x.GuidDict}); | ||
select(x => new {Id = x.Id, Other = x.Float}); | ||
select(x => new {Id = x.Id, Other = x.NullableBoolean}); | ||
select(x => new {Id = x.Id, Other = x.NullableColor}); | ||
select(x => new {Id = x.Id, Other = x.StringArray}); | ||
select(x => new {Id = x.Id, Other = x.StringDict}); | ||
select(x => new {Id = x.Id, Other = x.TagsHashSet}); | ||
select(x => new {Id = x.Id, Name = x.String}); | ||
select(x => new {Id = x.Id, Name = "Harold"}); | ||
select(x => new {Id = x.Inner.Number, Name = x.Inner.String}); | ||
select(x => new {Id = 5, Name = x.Inner.String}); | ||
select(x => new {Id = number, Name = x.Inner.String}); | ||
select(x => new { Id = x.Id, Name = x.StringArray[0] }); | ||
select(x => new { Id = x.Id, Age = x.NumberArray[0] }); | ||
|
||
select(x => new Person { Age = x.Number, Name = x.String }); | ||
select(x => new Person(x.String, x.Number)); | ||
|
||
select(x => new { Id = x.Id, Person = new Person { Age = x.Number, Name = x.String } }); | ||
select(x => new { Id = x.Id, Person = new Person(x.String, x.Number) }); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(GetDescriptions))] | ||
public Task run_query(string description) | ||
{ | ||
return assertTestCase(description, Fixture.Store); | ||
} | ||
|
||
public class Person | ||
{ | ||
public Person() | ||
{ | ||
} | ||
|
||
public Person(string name, int age) | ||
{ | ||
Name = name; | ||
Age = age; | ||
} | ||
|
||
public string Name { get; set; } | ||
public int Age { 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
Oops, something went wrong.