|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using Octokit.GraphQL.Core.Builders; |
3 | 4 | using Octokit.GraphQL.Core.UnitTests.Models; |
4 | 5 | using Xunit; |
@@ -668,9 +669,9 @@ public void Repository_Select_Object() |
668 | 669 | { |
669 | 670 | var expected = @"query { |
670 | 671 | repository(owner: ""foo"", name: ""bar"") { |
671 | | - forkCount |
672 | | - name |
673 | | - description |
| 672 | + intField1: forkCount |
| 673 | + stringField1: name |
| 674 | + stringField2: description |
674 | 675 | } |
675 | 676 | }"; |
676 | 677 |
|
@@ -724,9 +725,9 @@ public void Repository_Select_Object_Fragment() |
724 | 725 | } |
725 | 726 | } |
726 | 727 | fragment repositoryName on Repository { |
727 | | - forkCount |
728 | | - name |
729 | | - description |
| 728 | + intField1: forkCount |
| 729 | + stringField1: name |
| 730 | + stringField2: description |
730 | 731 | }"; |
731 | 732 |
|
732 | 733 | var fragment = new Fragment<Repository, TestModelObject>("repositoryName", repository => new TestModelObject |
@@ -786,9 +787,9 @@ public void Repository_Select_Use_Object_Fragment_Twice() |
786 | 787 | } |
787 | 788 | } |
788 | 789 | fragment repositoryName on Repository { |
789 | | - forkCount |
790 | | - name |
791 | | - description |
| 790 | + intField1: forkCount |
| 791 | + stringField1: name |
| 792 | + stringField2: description |
792 | 793 | }"; |
793 | 794 |
|
794 | 795 | var repositoryName = new Fragment<Repository, TestModelObject>("repositoryName", repository => new TestModelObject |
@@ -877,12 +878,92 @@ fragment issueTitle on Issue { |
877 | 878 | Assert.Equal(expected, query.ToString(2), ignoreLineEndingDifferences: true); |
878 | 879 | } |
879 | 880 |
|
| 881 | + [Fact] |
| 882 | + public void Issue_Select_Two_In_Anon_Object() |
| 883 | + { |
| 884 | + var expected = @"query { |
| 885 | + repository(owner: ""foo"", name: ""bar"") { |
| 886 | + someData: issues(labels: [""asdf""]) { |
| 887 | + nodes { |
| 888 | + title |
| 889 | + } |
| 890 | + } |
| 891 | + someData2: issues(labels: [""asdf""]) { |
| 892 | + nodes { |
| 893 | + title |
| 894 | + } |
| 895 | + } |
| 896 | + } |
| 897 | +}"; |
| 898 | + |
| 899 | + Arg<IEnumerable<string>>? labels = new[] { "asdf" }; |
| 900 | + |
| 901 | + var expression = new Query().Repository("foo", "bar").Select(repository => new |
| 902 | + { |
| 903 | + SomeData = repository.Issues(null, null, null, null, labels) |
| 904 | + .Nodes |
| 905 | + .Select(issue => new { issue.Title }) |
| 906 | + .ToList(), |
| 907 | + SomeData2 = repository.Issues(null, null, null, null, labels) |
| 908 | + .Nodes |
| 909 | + .Select(issue => new { issue.Title }) |
| 910 | + .ToList(), |
| 911 | + }); |
| 912 | + |
| 913 | + var query = expression.Compile(); |
| 914 | + |
| 915 | + Assert.Equal(expected, query.ToString(2), ignoreLineEndingDifferences: true); |
| 916 | + } |
| 917 | + |
| 918 | + [Fact] |
| 919 | + public void Issue_Select_Two_In_Object() |
| 920 | + { |
| 921 | + var expected = @"query { |
| 922 | + repository(owner: ""foo"", name: ""bar"") { |
| 923 | + someData: issues(labels: [""asdf""]) { |
| 924 | + nodes { |
| 925 | + title |
| 926 | + } |
| 927 | + } |
| 928 | + someData2: issues(labels: [""asdf""]) { |
| 929 | + nodes { |
| 930 | + title |
| 931 | + } |
| 932 | + } |
| 933 | + } |
| 934 | +}"; |
| 935 | + |
| 936 | + Arg<IEnumerable<string>>? labels = new[] { "asdf" }; |
| 937 | + |
| 938 | + var expression = new Query().Repository("foo", "bar").Select(repository => new TestIssueSets |
| 939 | + { |
| 940 | + SomeData = repository.Issues(null, null, null, null, labels) |
| 941 | + .Nodes |
| 942 | + .Select(issue => new { issue.Title }) |
| 943 | + .ToList(), |
| 944 | + SomeData2 = repository.Issues(null, null, null, null, labels) |
| 945 | + .Nodes |
| 946 | + .Select(issue => new { issue.Title }) |
| 947 | + .ToList(), |
| 948 | + }); |
| 949 | + |
| 950 | + var query = expression.Compile(); |
| 951 | + |
| 952 | + Assert.Equal(expected, query.ToString(2), ignoreLineEndingDifferences: true); |
| 953 | + } |
| 954 | + |
880 | 955 | class TestModelObject |
881 | 956 | { |
882 | 957 | public string StringField1; |
883 | 958 | public string StringField2; |
884 | 959 | public int IntField1; |
885 | 960 | public int IntField2; |
886 | 961 | } |
| 962 | + |
| 963 | + public class TestIssueSets |
| 964 | + { |
| 965 | + public IReadOnlyList<object> SomeData { get; set; } |
| 966 | + public IReadOnlyList<object> SomeData2 { get; set; } |
| 967 | + } |
887 | 968 | } |
888 | 969 | } |
0 commit comments