Skip to content

Commit

Permalink
Merge pull request #22 from ZEXSM/feature-add-top-to-nested-expand
Browse files Browse the repository at this point in the history
#ZEXSM#feature add top to nested expand
  • Loading branch information
ZEXSM committed Apr 7, 2020
2 parents c9767cb + 47a4f88 commit d113c6d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ dotnet add -v 1.0.0 OData.QueryBuilder
* [Select](#Select)
* [OrderBy](#OrderBy)
* [OrderByDescending](#OrderByDescending)
* [Top](#Top)
* [Select](#Select)
* [ByList](#ByList)
* [Expand](#Expand)
* [Filter](#Filter)
* [Select](#Select)
* [OrderBy](#OrderBy)
* [OrderByDescending](#OrderByDescending)
* [Top](#Top)
* [Filter](#Filter)
* [Select](#Select)
* [OrderBy](#OrderBy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public interface IODataQueryNestedParameter<TEntity>
IODataQueryNestedParameter<TEntity> OrderBy(Expression<Func<TEntity, object>> entityNestedOrderBy);

IODataQueryNestedParameter<TEntity> OrderByDescending(Expression<Func<TEntity, object>> entityNestedOrderByDescending);

IODataQueryNestedParameter<TEntity> Top(int number);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,12 @@ public IODataQueryNestedParameter<TEntity> Select(Expression<Func<TEntity, objec

return this;
}

public IODataQueryNestedParameter<TEntity> Top(int number)
{
_queryBuilder.Append($"$top={number};");

return this;
}
}
}
18 changes: 18 additions & 0 deletions test/OData.QueryBuilder.Test/ODataQueryBuilderByKeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ public void ODataQueryBuilderList_ExpandNested_OrderByDescending_Success()
uri.OriginalString.Should().Be("http://mock/odata/ODataType(223123123)?$expand=ODataKindNew($select=IdKind;$orderby=EndDate desc)");
}

[Fact(DisplayName = "(ODataQueryBuilderKey) Expand nested top => Success")]
public void ODataQueryBuilderList_ExpandNested_Top_Success()
{
var uri = _odataQueryBuilder
.For<ODataTypeEntity>(s => s.ODataType)
.ByKey(223123123)
.Expand(f =>
{
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind)
.OrderByDescending(s => s.EndDate)
.Top(1);
})
.ToUri();

uri.OriginalString.Should().Be("http://mock/odata/ODataType(223123123)?$expand=ODataKindNew($select=IdKind;$orderby=EndDate desc;$top=1)");
}

[Fact(DisplayName = "(ODataQueryBuilderKey) Expand nested Filter => Success")]
public void ODataQueryBuilderKey_Expand_Nested_Filter_Success()
{
Expand Down
18 changes: 18 additions & 0 deletions test/OData.QueryBuilder.Test/ODataQueryBuilderByListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ public void ODataQueryBuilderList_ExpandNested_OrderBy_Success()
uri.OriginalString.Should().Be("http://mock/odata/ODataType?$expand=ODataKindNew($select=IdKind;$orderby=EndDate asc)");
}

[Fact(DisplayName = "(ODataQueryBuilderList) Expand nested top => Success")]
public void ODataQueryBuilderList_ExpandNested_Top_Success()
{
var uri = _odataQueryBuilder
.For<ODataTypeEntity>(s => s.ODataType)
.ByList()
.Expand(f =>
{
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind)
.Top(1)
.OrderBy(s => s.EndDate);
})
.ToUri();

uri.OriginalString.Should().Be("http://mock/odata/ODataType?$expand=ODataKindNew($select=IdKind;$top=1;$orderby=EndDate asc)");
}

[Fact(DisplayName = "(ODataQueryBuilderList) Expand nested orderby desc => Success")]
public void ODataQueryBuilderList_ExpandNested_OrderByDescending_Success()
{
Expand Down

0 comments on commit d113c6d

Please sign in to comment.