Skip to content

Commit

Permalink
#ZEXSM#add nested order by to expand (#21)
Browse files Browse the repository at this point in the history
* #ZEXSM#add nested order by to expand
* #ZEXSM#travis fix create package version
  • Loading branch information
ZEXSM authored Apr 4, 2020
1 parent d7c7b70 commit c9767cb
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 8 deletions.
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: csharp
sudo: false
language: csharp
dist: trusty
os: linux
mono: none
Expand All @@ -19,18 +18,22 @@ after_success:
before_deploy:
- git checkout origin/master && git fetch && git remote set-url origin https://${GITHUB_OAUTH_TOKEN}@github.com/ZEXSM/OData.QueryBuilder.git
- PR_TITLE=$(git log -1 --pretty='%f')
- FEATURE=$([[ $PR_TITLE == 'feature' ]] && echo 1 || echo 0)
- RELEASE=$([[ $PR_TITLE == 'release' ]] && echo 1 || echo 0)
- LAST_TAG=$(echo $(git describe --tags $(git rev-list --tags --max-count=1)) | cut -d'v' -f 2)
- export CURRENT_TAG=$(($(echo $LAST_TAG | cut -d. -f 1)+$RELEASE)).$(($(echo $LAST_TAG | cut -d. -f 2)+$FEATURE)).$(($(echo $LAST_TAG | cut -d. -f 3)+1))
- PACKAGE_VERSION=${CURRENT_TAG:-$DEFAULT_PACKAGE_VERSION}
- CURRENT_MAJOR=$(echo $LAST_TAG | cut -d. -f 1)
- CURRENT_MINOR=$(echo $LAST_TAG | cut -d. -f 2)
- CURRENT_PATCH=$(echo $LAST_TAG | cut -d. -f 3)
- MAJOR=$([ "$(echo $PR_TITLE | grep -oP 'release')" == "release" ] && echo $(($CURRENT_MAJOR+1)) || echo $CURRENT_MAJOR)
- MINOR=$(([ "$(echo $PR_TITLE | grep -oP 'release')" == "release" ] && echo 0) || ([ "$(echo $PR_TITLE | grep -oP 'feature')" == "feature" ] && echo $(($CURRENT_MINOR+1))) || echo $CURRENT_MINOR)
- PATCH=$(([ "$(echo $PR_TITLE | grep -oP 'release')" == "release" ] && echo 0) || ([ "$(echo $PR_TITLE | grep -oP 'feature')" == "feature" ] && echo 0) || echo $(($CURRENT_PATCH+1)))
- NEW_TAG=$(echo $MAJOR.$MINOR.$PATCH)
- PACKAGE_VERSION=${NEW_TAG:-$DEFAULT_PACKAGE_VERSION}
- git tag v$PACKAGE_VERSION && git push origin v$PACKAGE_VERSION
- dotnet pack -c $CONFIGURATION -p:PackageVersion=$PACKAGE_VERSION
deploy:
provider: releases
name: v$CURRENT_TAG
api_key: $GITHUB_OAUTH_TOKEN
skip_cleanup: true
token: $GITHUB_OAUTH_TOKEN
cleanup: true
repo: ZEXSM/OData.QueryBuilder
on:
branch: master
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ dotnet add -v 1.0.0 OData.QueryBuilder
* [Expand](#Expand)
* [Filter](#Filter)
* [Select](#Select)
* [OrderBy](#OrderBy)
* [OrderByDescending](#OrderByDescending)
* [Select](#Select)
* [ByList](#ByList)
* [Expand](#Expand)
* [Filter](#Filter)
* [Select](#Select)
* [OrderBy](#OrderBy)
* [OrderByDescending](#OrderByDescending)
* [Filter](#Filter)
* [Select](#Select)
* [OrderBy](#OrderBy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ public interface IODataQueryNestedParameter<TEntity>
IODataQueryNestedParameter<TEntity> Filter(Expression<Func<TEntity, bool>> entityNestedFilter);

IODataQueryNestedParameter<TEntity> Select(Expression<Func<TEntity, object>> entityNestedSelect);

IODataQueryNestedParameter<TEntity> OrderBy(Expression<Func<TEntity, object>> entityNestedOrderBy);

IODataQueryNestedParameter<TEntity> OrderByDescending(Expression<Func<TEntity, object>> entityNestedOrderByDescending);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ public IODataQueryNestedParameter<TEntity> Filter(Expression<Func<TEntity, bool>
return this;
}

public IODataQueryNestedParameter<TEntity> OrderBy(Expression<Func<TEntity, object>> entityNestedOrderBy)
{
var entityNestedOrderByQuery = entityNestedOrderBy.Body.ToODataQuery(string.Empty);

_queryBuilder.Append($"$orderby={entityNestedOrderByQuery} asc;");

return this;
}

public IODataQueryNestedParameter<TEntity> OrderByDescending(Expression<Func<TEntity, object>> entityNestedOrderByDescending)
{
var entityNestedOrderByDescendingQuery = entityNestedOrderByDescending.Body.ToODataQuery(string.Empty);

_queryBuilder.Append($"$orderby={entityNestedOrderByDescendingQuery} desc;");

return this;
}

public IODataQueryNestedParameter<TEntity> Select(Expression<Func<TEntity, object>> entitySelectNested)
{
var entitySelectNestedQuery = entitySelectNested.Body.ToODataQuery(string.Empty);
Expand Down
35 changes: 35 additions & 0 deletions test/OData.QueryBuilder.Test/ODataQueryBuilderByKeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,41 @@ public void ODataQueryBuilderKey_ExpandNested_Select_Success()
uri.OriginalString.Should().Be("http://mock/odata/ODataType(223123123)?$expand=ODataKind($expand=ODataCode($select=IdCode)),ODataKindNew($select=IdKind),ODataKindNew($select=IdKind)&$select=IdType,Sum");
}


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

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

[Fact(DisplayName = "(ODataQueryBuilderKey) Expand nested orderby desc => Success")]
public void ODataQueryBuilderList_ExpandNested_OrderByDescending_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);
})
.ToUri();

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

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

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

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

[Fact(DisplayName = "(ODataQueryBuilderList) Expand nested orderby desc => Success")]
public void ODataQueryBuilderList_ExpandNested_OrderByDescending_Success()
{
var uri = _odataQueryBuilder
.For<ODataTypeEntity>(s => s.ODataType)
.ByList()
.Expand(f =>
{
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind)
.OrderByDescending(s => s.EndDate);
})
.ToUri();

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

[Fact(DisplayName = "(ODataQueryBuilderList) Select simple => Success")]
public void ODataQueryBuilderList_Select_Simple_Success()
{
Expand Down

0 comments on commit c9767cb

Please sign in to comment.