Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit fb01ba7

Browse files
author
IharYakimush
authored
Merge pull request #9 from IharYakimush/develop
1.1.0
2 parents 4930c55 + 866253d commit fb01ba7

File tree

61 files changed

+5308
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5308
-124
lines changed

Community.Data.OData.Linq.sln

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2024
4+
VisualStudioVersion = 15.0.27130.2027
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.OData.Linq", "Community.Data.OData.Linq\Community.OData.Linq.csproj", "{0EA4A9B7-BEE7-4500-8676-0B18E7B369D2}"
77
EndProject
@@ -14,6 +14,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
README.md = README.md
1515
EndProjectSection
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.OData.Linq.Demo", "Community.OData.Linq.Demo\Community.OData.Linq.Demo.csproj", "{DE428072-2C49-4F4A-8F2E-DB976C0BC797}"
18+
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.OData.Linq.Json", "Community.OData.Linq.Json\Community.OData.Linq.Json.csproj", "{6C454F01-28D1-49B1-BE98-244E5DA2D095}"
20+
EndProject
1721
Global
1822
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1923
CodeAnalysis|Any CPU = CodeAnalysis|Any CPU
@@ -33,6 +37,18 @@ Global
3337
{6B5E0D65-A1AE-4EB4-A496-B6588F03D373}.Debug|Any CPU.Build.0 = Debug|Any CPU
3438
{6B5E0D65-A1AE-4EB4-A496-B6588F03D373}.Release|Any CPU.ActiveCfg = Release|Any CPU
3539
{6B5E0D65-A1AE-4EB4-A496-B6588F03D373}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.CodeAnalysis|Any CPU.ActiveCfg = Debug|Any CPU
41+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.CodeAnalysis|Any CPU.Build.0 = Debug|Any CPU
42+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.Release|Any CPU.ActiveCfg = Release|Any CPU
45+
{DE428072-2C49-4F4A-8F2E-DB976C0BC797}.Release|Any CPU.Build.0 = Release|Any CPU
46+
{6C454F01-28D1-49B1-BE98-244E5DA2D095}.CodeAnalysis|Any CPU.ActiveCfg = Debug|Any CPU
47+
{6C454F01-28D1-49B1-BE98-244E5DA2D095}.CodeAnalysis|Any CPU.Build.0 = Debug|Any CPU
48+
{6C454F01-28D1-49B1-BE98-244E5DA2D095}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49+
{6C454F01-28D1-49B1-BE98-244E5DA2D095}.Debug|Any CPU.Build.0 = Debug|Any CPU
50+
{6C454F01-28D1-49B1-BE98-244E5DA2D095}.Release|Any CPU.ActiveCfg = Release|Any CPU
51+
{6C454F01-28D1-49B1-BE98-244E5DA2D095}.Release|Any CPU.Build.0 = Release|Any CPU
3652
EndGlobalSection
3753
GlobalSection(SolutionProperties) = preSolution
3854
HideSolutionNode = FALSE

Community.Data.OData.Linq.xTests/Community.OData.Linq.xTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
<ItemGroup>
2727
<ProjectReference Include="..\Community.Data.OData.Linq\Community.OData.Linq.csproj" />
28+
<ProjectReference Include="..\Community.OData.Linq.Json\Community.OData.Linq.Json.csproj" />
2829
</ItemGroup>
2930

3031
</Project>
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
namespace Community.OData.Linq.xTests
2+
{
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
using Community.OData.Linq.xTests.SampleData;
7+
using Microsoft.OData;
8+
using Xunit;
9+
10+
public class ExpandTests
11+
{
12+
[Fact]
13+
public void EmptyExpand()
14+
{
15+
ISelectExpandWrapper[] result = ClassWithLink.CreateQuery().OData().SelectExpand().ToArray();
16+
17+
IDictionary<string, object> metadata = result[0].ToDictionary();
18+
19+
// Not expanded by default except auto expand attribute
20+
Assert.Equal(2, metadata.Count);
21+
}
22+
23+
[Fact]
24+
public void EmptyExpandSelectAll()
25+
{
26+
ISelectExpandWrapper[] result = ClassWithLink.CreateQuery().OData().SelectExpand("*").ToArray();
27+
28+
IDictionary<string, object> metadata = result[0].ToDictionary();
29+
30+
// Not expanded by default except auto expand attribute
31+
Assert.Equal(2, metadata.Count);
32+
}
33+
34+
[Fact]
35+
public void ExpandLink()
36+
{
37+
ISelectExpandWrapper[] result = ClassWithLink.CreateQuery().OData().SelectExpand(null, "Link1").ToArray();
38+
39+
IDictionary<string, object> metadata = result[0].ToDictionary();
40+
41+
// Not expanded by default
42+
Assert.Equal(3, metadata.Count);
43+
44+
Assert.Equal(6, (metadata["Link1"] as ISelectExpandWrapper).ToDictionary().Count);
45+
}
46+
47+
[Fact]
48+
public void ExpandSelect()
49+
{
50+
ISelectExpandWrapper[] result = ClassWithLink.CreateQuery().OData().SelectExpand("Name,Link1", "Link1").ToArray();
51+
52+
IDictionary<string, object> metadata = result[0].ToDictionary();
53+
54+
// Not expanded by default
55+
Assert.Equal(2, metadata.Count);
56+
Assert.Equal(6, (metadata["Link1"] as ISelectExpandWrapper).ToDictionary().Count);
57+
}
58+
59+
[Fact]
60+
public void ExpandLinkSelect()
61+
{
62+
ISelectExpandWrapper[] result = ClassWithLink.CreateQuery().OData().SelectExpand("Name", "Link1($select=Name)").ToArray();
63+
64+
IDictionary<string, object> metadata = result[0].ToDictionary();
65+
66+
// Not expanded by default
67+
Assert.Equal(2, metadata.Count);
68+
Assert.Equal(1, (metadata["Link1"] as ISelectExpandWrapper).ToDictionary().Count);
69+
}
70+
71+
[Fact]
72+
public void ExpandCollection()
73+
{
74+
ISelectExpandWrapper[] result = ClassWithCollection.CreateQuery().OData().SelectExpand("Name", "Link2").ToArray();
75+
76+
IDictionary<string, object> metadata = result[0].ToDictionary();
77+
78+
// Not expanded by default
79+
Assert.Equal(2, metadata.Count);
80+
Assert.Equal(2, (metadata["Link2"] as IEnumerable<ISelectExpandWrapper>).Count());
81+
}
82+
83+
[Fact]
84+
public void ExpandCollectionWithTop()
85+
{
86+
ISelectExpandWrapper[] result = ClassWithCollection.CreateQuery().OData().SelectExpand("Name", "Link2($top=1)").ToArray();
87+
88+
IDictionary<string, object> metadata = result[0].ToDictionary();
89+
90+
// Not expanded by default
91+
Assert.Equal(2, metadata.Count);
92+
Assert.Single((metadata["Link2"] as IEnumerable<ISelectExpandWrapper>));
93+
}
94+
95+
[Fact]
96+
public void ExpandCollectionWithTopDefaultPageSize()
97+
{
98+
ISelectExpandWrapper[] result = ClassWithCollection.CreateQuery().OData(s => s.QuerySettings.PageSize = 1).SelectExpand("Name", "Link2").ToArray();
99+
100+
IDictionary<string, object> metadata = result[0].ToDictionary();
101+
102+
// Not expanded by default
103+
Assert.Equal(2, metadata.Count);
104+
Assert.Single((metadata["Link2"] as IEnumerable<ISelectExpandWrapper>));
105+
}
106+
107+
[Fact]
108+
public void ExpandCollectionWithTop21()
109+
{
110+
ISelectExpandWrapper[] result = ClassWithCollection.CreateQuery().OData().SelectExpand("Name", "Link2($top=21)").ToArray();
111+
112+
IDictionary<string, object> metadata = result[0].ToDictionary();
113+
114+
// Not expanded by default
115+
Assert.Equal(2, metadata.Count);
116+
Assert.Equal(2, (metadata["Link2"] as IEnumerable<ISelectExpandWrapper>).Count());
117+
}
118+
119+
[Fact]
120+
public void ExpandCollectionWithTopExceedLimit()
121+
{
122+
Assert.Throws<ODataException>(
123+
() => ClassWithCollection.CreateQuery().OData().SelectExpand("Name", "Link2($top=101)"));
124+
}
125+
126+
[Fact]
127+
public void ExpandCollectionWithFilterAndSelect()
128+
{
129+
ISelectExpandWrapper[] result = ClassWithCollection.CreateQuery().OData().SelectExpand("Name", "Link2($filter=Id eq 311;$select=Name)").ToArray();
130+
131+
IDictionary<string, object> metadata = result[0].ToDictionary();
132+
133+
// Not expanded by default
134+
Assert.Equal(2, metadata.Count);
135+
IEnumerable<ISelectExpandWrapper> collection = metadata["Link2"] as IEnumerable<ISelectExpandWrapper>;
136+
Assert.Single(collection);
137+
138+
Assert.Equal(1, collection.Single().ToDictionary().Count);
139+
}
140+
141+
[Fact]
142+
public void ExpandCollectionWithNotExpandable()
143+
{
144+
Assert.Throws<ODataException>(
145+
() => SampleWithCustomKey.CreateQuery().OData().SelectExpand("Id", "NotExpandableLink"));
146+
}
147+
148+
[Fact]
149+
public void ExpandWithAttributes()
150+
{
151+
ISelectExpandWrapper[] result = SampleWithCustomKey.CreateQuery().OData().SelectExpand().ToArray();
152+
153+
IDictionary<string, object> metadata = result[0].ToDictionary();
154+
155+
// Not expanded by default
156+
Assert.Equal(4, metadata.Count);
157+
158+
Assert.Equal(6, (metadata["AutoExpandLink"] as ISelectExpandWrapper).ToDictionary().Count);
159+
Assert.Equal(6, (metadata["AutoExpandAndSelectLink"] as ISelectExpandWrapper).ToDictionary().Count);
160+
}
161+
162+
[Fact]
163+
public void ExpandWithAttributesAndExplicit()
164+
{
165+
ISelectExpandWrapper[] result = SampleWithCustomKey.CreateQuery().OData().SelectExpand("*", "AutoExpandAndSelectLink").ToArray();
166+
167+
IDictionary<string, object> metadata = result[0].ToDictionary();
168+
169+
// Not expanded by default
170+
Assert.Equal(3, metadata.Count);
171+
172+
Assert.Equal(6, (metadata["AutoExpandAndSelectLink"] as ISelectExpandWrapper).ToDictionary().Count);
173+
}
174+
175+
[Fact]
176+
public void ExpandMaxDeepNotExceed()
177+
{
178+
ISelectExpandWrapper[] result = SampleWithCustomKey.CreateQuery().OData().SelectExpand(null, "RecursiveLink($expand=RecursiveLink)").ToArray();
179+
180+
IDictionary<string, object> metadata = result[0].ToDictionary();
181+
182+
// Not expanded by default
183+
Assert.Equal(5, metadata.Count);
184+
185+
Assert.NotNull(metadata["RecursiveLink"]);
186+
}
187+
188+
[Fact]
189+
public void ExpandMaxDeepExceed()
190+
{
191+
Assert.Throws<ODataException>(
192+
() => SampleWithCustomKey.CreateQuery().OData().SelectExpand(null, "RecursiveLink($expand=RecursiveLink($expand=RecursiveLink))"));
193+
}
194+
}
195+
}

Community.Data.OData.Linq.xTests/FilterTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ public void WhereByNonFilterableThrowException()
114114
() => SimpleClass.CreateQuery().OData(s => s.EnableCaseInsensitive = false).Filter($"{nameof(SimpleClass.NameNotFilter)} eq 'nf1'"));
115115
}
116116

117+
[Fact]
118+
public void WhereByNotMappedThrow()
119+
{
120+
Assert.Throws<ODataException>(
121+
() => SimpleClass.CreateQuery().OData(s => s.EnableCaseInsensitive = false).Filter($"{nameof(SimpleClass.NotMapped)} eq 'nf1'"));
122+
}
123+
117124
[Fact]
118125
public void WhereByIgnoreDataMemberThrowException()
119126
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace Community.OData.Linq.xTests
2+
{
3+
using System.Linq;
4+
5+
using Community.OData.Linq.xTests.SampleData;
6+
using Community.OData.Linq.Json;
7+
8+
using Newtonsoft.Json;
9+
using Newtonsoft.Json.Linq;
10+
11+
using Xunit;
12+
13+
public class JsonTests
14+
{
15+
[Fact]
16+
public void SerializeSelectExpand()
17+
{
18+
JToken token = ClassWithCollection.CreateQuery().OData().SelectExpandJsonToken("Name", "Link2($filter=Id eq 311;$select=Name)");
19+
Assert.NotNull(token);
20+
21+
Assert.DoesNotContain("ModelID", token.ToString(Formatting.None));
22+
}
23+
}
24+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace Community.OData.Linq.xTests
2+
{
3+
using System;
4+
using System.Linq;
5+
6+
using Community.OData.Linq.xTests.SampleData;
7+
8+
using Microsoft.OData;
9+
10+
using Xunit;
11+
12+
public class ODataTests
13+
{
14+
[Fact]
15+
public void CustomKey()
16+
{
17+
var result = SampleWithCustomKey.CreateQuery().OData().Filter("Name eq 'n1'").ToArray();
18+
19+
Assert.Single(result);
20+
Assert.Equal("n1", result[0].Name);
21+
}
22+
23+
[Fact]
24+
public void WithoutKeyThrowException()
25+
{
26+
Assert.Throws<InvalidOperationException>(() => SampleWithoutKey.CreateQuery().OData());
27+
}
28+
}
29+
}

Community.Data.OData.Linq.xTests/Sample.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

Community.Data.OData.Linq.xTests/SampleData/ClassWithLink.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@ public static IQueryable<ClassWithLink> CreateQuery()
2525

2626
[NotNavigable]
2727
public virtual SimpleClass Link2 { get; set; }
28+
29+
[Select(SelectType = OData.Query.SelectExpandType.Automatic)]
30+
public virtual SimpleClass Link3 { get; set; }
31+
32+
[Select(SelectType = OData.Query.SelectExpandType.Disabled)]
33+
public virtual SimpleClass Link4 { get; set; }
2834
}
2935
}

0 commit comments

Comments
 (0)