Skip to content

Commit

Permalink
Merge pull request #12 from ZEXSM/feature/coverage
Browse files Browse the repository at this point in the history
Update readme
  • Loading branch information
ZEXSM committed Jul 25, 2019
2 parents c1023e9 + b01754a commit cd71feb
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ _TeamCity*
# Visual Studio code coverage results
*.coverage
*.coveragexml
coverage/

# NCrunch
_NCrunch_*
Expand Down
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: csharp
sudo: required
sudo: false
dist: trusty
os: linux
mono: none
dotnet: 2.1.502
branches:
Expand All @@ -9,12 +10,16 @@ branches:
before_script:
- dotnet restore
script:
- dotnet build
- dotnet test ./test/OData.QueryBuilder.Test -c $CONFIGURATION -f netcoreapp2.1
after_success:
- cd src/OData.QueryBuilder && dotnet minicover instrument --workdir ../../coverage --parentdir ../ --assemblies test/**/bin/$CONFIGURATION/**/*.dll --sources src/**/*.cs && dotnet minicover reset --workdir ../../coverage && cd ../../
- dotnet test --no-build ./test/OData.QueryBuilder.Test
- cd src/OData.QueryBuilder && dotnet minicover uninstrument --workdir ../../coverage && dotnet minicover report --workdir ../../coverage && dotnet minicover coverallsreport --workdir ../../coverage --root-path ../../ --output "coveralls.json" --service-name "travis-ci" --service-job-id $TRAVIS_JOB_ID && cd ../../
before_deploy:
- git checkout origin/master && git fetch && git remote set-url origin https://${GITHUB_OAUTH_TOKEN}@github.com/ZEXSM/OData.QueryBuilder.git
- export 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).$(echo $LAST_TAG | cut -d. -f 2).$(($(echo $LAST_TAG | cut -d. -f 3)+1))
- echo $VERSION_ARRAY
- export PACKAGE_VERSION=${CURRENT_TAG:-$DEFAULT_PACKAGE_VERSION}
- git tag v$PACKAGE_VERSION && git push origin v$PACKAGE_VERSION
- dotnet pack -c $CONFIGURATION -p:PackageVersion=$PACKAGE_VERSION
Expand Down
90 changes: 45 additions & 45 deletions OData.QueryBuilder.sln
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.705
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FA1582AB-A13D-44A4-A46D-2DAE1111A2BB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{26982440-340F-48A2-9D73-44DB6C52EBF1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OData.QueryBuilder", "src\OData.QueryBuilder\OData.QueryBuilder.csproj", "{E4D8F027-2B79-4794-9B75-D08C2BA066B8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OData.QueryBuilder.Test", "test\OData.QueryBuilder.Test\OData.QueryBuilder.Test.csproj", "{537E849E-5291-49F9-BD2A-9F4A01DB1561}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "items", "items", "{179F88B9-A06D-4505-9266-A5D66004601C}"
ProjectSection(SolutionItems) = preProject
.travis.yml = .travis.yml
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E4D8F027-2B79-4794-9B75-D08C2BA066B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4D8F027-2B79-4794-9B75-D08C2BA066B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4D8F027-2B79-4794-9B75-D08C2BA066B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4D8F027-2B79-4794-9B75-D08C2BA066B8}.Release|Any CPU.Build.0 = Release|Any CPU
{537E849E-5291-49F9-BD2A-9F4A01DB1561}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{537E849E-5291-49F9-BD2A-9F4A01DB1561}.Debug|Any CPU.Build.0 = Debug|Any CPU
{537E849E-5291-49F9-BD2A-9F4A01DB1561}.Release|Any CPU.ActiveCfg = Release|Any CPU
{537E849E-5291-49F9-BD2A-9F4A01DB1561}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E4D8F027-2B79-4794-9B75-D08C2BA066B8} = {FA1582AB-A13D-44A4-A46D-2DAE1111A2BB}
{537E849E-5291-49F9-BD2A-9F4A01DB1561} = {26982440-340F-48A2-9D73-44DB6C52EBF1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1D51B9A3-94B0-48DF-BFF5-110B13303535}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.705
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FA1582AB-A13D-44A4-A46D-2DAE1111A2BB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{26982440-340F-48A2-9D73-44DB6C52EBF1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OData.QueryBuilder", "src\OData.QueryBuilder\OData.QueryBuilder.csproj", "{E4D8F027-2B79-4794-9B75-D08C2BA066B8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OData.QueryBuilder.Test", "test\OData.QueryBuilder.Test\OData.QueryBuilder.Test.csproj", "{537E849E-5291-49F9-BD2A-9F4A01DB1561}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "items", "items", "{179F88B9-A06D-4505-9266-A5D66004601C}"
ProjectSection(SolutionItems) = preProject
.travis.yml = .travis.yml
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E4D8F027-2B79-4794-9B75-D08C2BA066B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4D8F027-2B79-4794-9B75-D08C2BA066B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4D8F027-2B79-4794-9B75-D08C2BA066B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4D8F027-2B79-4794-9B75-D08C2BA066B8}.Release|Any CPU.Build.0 = Release|Any CPU
{537E849E-5291-49F9-BD2A-9F4A01DB1561}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{537E849E-5291-49F9-BD2A-9F4A01DB1561}.Debug|Any CPU.Build.0 = Debug|Any CPU
{537E849E-5291-49F9-BD2A-9F4A01DB1561}.Release|Any CPU.ActiveCfg = Release|Any CPU
{537E849E-5291-49F9-BD2A-9F4A01DB1561}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E4D8F027-2B79-4794-9B75-D08C2BA066B8} = {FA1582AB-A13D-44A4-A46D-2DAE1111A2BB}
{537E849E-5291-49F9-BD2A-9F4A01DB1561} = {26982440-340F-48A2-9D73-44DB6C52EBF1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1D51B9A3-94B0-48DF-BFF5-110B13303535}
EndGlobalSection
EndGlobal
205 changes: 105 additions & 100 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,100 +1,105 @@
# OData.QueryBuilder
Библиотека позволяющая собрать OData запрос на основе модели данных

[![Build Status](https://travis-ci.com/ZEXSM/OData.QueryBuilder.svg?branch=master)](https://travis-ci.com/ZEXSM/OData.QueryBuilder)
[![Coverage Status](https://coveralls.io/repos/github/ZEXSM/OData.QueryBuilder/badge.svg?branch=master)](https://coveralls.io/github/ZEXSM/OData.QueryBuilder?branch=master)
[![Nuget Status](https://img.shields.io/nuget/dt/OData.QueryBuilder.svg)](https://www.nuget.org/packages/OData.QueryBuilder)

## Установка
Чтобы установить `OData.QueryBuilder` из `Visual Studio`, найдите `OData.QueryBuilder` в пользовательском интерфейсе диспетчера пакетов `NuGet` или выполните следующую команду в консоли диспетчера пакетов:
```
Install-Package OData.QueryBuilder -Version 1.0.0
```

Чтобы добавить ссылку на основной проект `dotnet`, выполните в командной строке следующее:

```
dotnet add -v 1.0.0 OData.QueryBuilder
```

## Использование

1. Создать экземпляр билдера

Преждем чем начать строить `OData` запрос, необходимо создать новый экземпляр объекта `OData.QueryBuilder` с указанием модели данных и базового пути:

```charp
var odataQueryBuilder = new ODataQueryBuilder<Модель данных сущностей>(<base_url>);
```

2. Указать ресурс для которого будет строиться запрос

```charp
odataQueryBuilder.For<Модель сущности>(s => s.<ресурс>)
```

3. Выборать тип запроса

Билдер позволяет строить запросы по ключу и списку.
* ByKey(<ключ>)
* Expand
* Select
* ToUri
* ByList()
* Expand
* Filter
* Select
* OrderBy
* OrderByDescending
* Top
* Skip
* Count
* ToUri
4. Получить Uri запроса от билдера
```charp
odataQueryBuilder.ToUri()
```

## Примеры

#### ByKey - по ключу
1. Запрос по ключу с простым `Expand`
```charp
var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
.For<ODataTypeEntity>(s => s.ODataType)
.ByKey(223123123)
.Expand(s => s.ODataKind)
.ToUri();
```
> http://mock/odata/ODataType(223123123)?$expand=ODataKind
2. Запрос по ключу с вложенными `Expand` и `Select`
```charp
var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
.For<ODataTypeEntity>(s => s.ODataType)
.ByKey(223123123)
.Expand(f =>
{
f.For<ODataKindEntity>(s => s.ODataKind)
.Expand(ff => ff.For<ODataCodeEntity>(s => s.ODataCode)
.Select(s => s.IdCode));
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind);
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind);
})
.Select(s => new { s.IdType, s.Sum })
.ToUri();
```
> http://mock/odata/ODataType(223123123)?$expand=ODataKind($expand=ODataCode($select=IdCode)),ODataKindNew($select=IdKind),ODataKindNew($select=IdKind)&$select=IdType,Sum
#### ByList - по списку
1. Запрос по списку с простым `Expand`
```charp
var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
.For<ODataTypeEntity>(s => s.ODataType)
.ByList()
.Expand(s => new { s.ODataKind })
.ToUri();
```
> http://mock/odata/ODataType?$expand=ODataKind
# OData.QueryBuilder
Library provides linq syntax and allows you to build OData queries based on the data model

[![Build Status](https://travis-ci.com/ZEXSM/OData.QueryBuilder.svg?branch=master)](https://travis-ci.com/ZEXSM/OData.QueryBuilder)
[![Coverage Status](https://coveralls.io/repos/github/ZEXSM/OData.QueryBuilder/badge.svg?branch=master)](https://coveralls.io/github/ZEXSM/OData.QueryBuilder?branch=master)
[![Nuget Status](https://img.shields.io/nuget/dt/OData.QueryBuilder.svg)](https://www.nuget.org/packages/OData.QueryBuilder)

## Benefits
* Expression is not used to `Compile()`, which generates `MSIL` code, which leads to memory leaks
* Support for nested `OData` extenders with a choice of filtering
* Support `OData` functions `Date`, `Any`, `All`
* Support `OData` operator `IN`

## Installation
To install `OData.QueryBuilder` from` Visual Studio`, find `OData.QueryBuilder` in the` NuGet` package manager user interface or enter the following command in the package manager console:
```
Install-Package OData.QueryBuilder -Version 1.0.0
```

To add a link to the main dotnet project, run the following command line:
```
dotnet add -v 1.0.0 OData.QueryBuilder
```

## Usage

1. Build instance

As soon as possible, create a new instance of the OData.QueryBuilder object indicating the data models and the base path:

```csharp
var odataQueryBuilder = new ODataQueryBuilder<Your entity model>(<base_url>);
```

2. Specify the resource for which the request will be built

```csharp
odataQueryBuilder.For<Your data model>(s => s.<Your resource model>)
```

3. Select request type

The builder allows you to build queries on the key and the list:
* ByKey(<Key>)
* Expand
* Select
* ToUri
* ByList()
* Expand
* Filter
* Select
* OrderBy
* OrderByDescending
* Top
* Skip
* Count
* ToUri
4. Get a Uri request from the builder
```csharp
odataQueryBuilder.ToUri()
```

## Examples

#### By key
1. Key request with a simple `Expand`
```csharp
var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
.For<ODataTypeEntity>(s => s.ODataType)
.ByKey(223123123)
.Expand(s => s.ODataKind)
.ToUri();
```
> http://mock/odata/ODataType(223123123)?$expand=ODataKind
2. Key request with nested `Expand` и `Select`
```csharp
var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
.For<ODataTypeEntity>(s => s.ODataType)
.ByKey(223123123)
.Expand(f =>
{
f.For<ODataKindEntity>(s => s.ODataKind)
.Expand(ff => ff.For<ODataCodeEntity>(s => s.ODataCode)
.Select(s => s.IdCode));
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind);
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind);
})
.Select(s => new { s.IdType, s.Sum })
.ToUri();
```
> http://mock/odata/ODataType(223123123)?$expand=ODataKind($expand=ODataCode($select=IdCode)),ODataKindNew($select=IdKind),ODataKindNew($select=IdKind)&$select=IdType,Sum
#### By list
1. Query list with a simple `Expand`
```csharp
var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
.For<ODataTypeEntity>(s => s.ODataType)
.ByList()
.Expand(s => new { s.ODataKind })
.ToUri();
```
> http://mock/odata/ODataType?$expand=ODataKind
29 changes: 16 additions & 13 deletions src/OData.QueryBuilder/OData.QueryBuilder.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>true</IsPackable>
<TargetFramework>netstandard1.3</TargetFramework>
<NuspecFile>bin\$(Configuration)\$(TargetFramework)\OData.QueryBuilder.nuspec</NuspecFile>
<NuspecProperties>version=$(PackageVersion)</NuspecProperties>
</PropertyGroup>
<ItemGroup>
<None Update="OData.QueryBuilder.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>true</IsPackable>
<TargetFramework>netstandard1.3</TargetFramework>
<NuspecFile>bin\$(Configuration)\$(TargetFramework)\OData.QueryBuilder.nuspec</NuspecFile>
<NuspecProperties>version=$(PackageVersion)</NuspecProperties>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="MiniCover" Version="2.0.0-ci-20181108093139" />
</ItemGroup>
<ItemGroup>
<None Update="OData.QueryBuilder.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Loading

0 comments on commit cd71feb

Please sign in to comment.