Skip to content

Commit

Permalink
fix: decimal values convert to query (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZEXSM authored Oct 12, 2022
1 parent 4c2eb8c commit 339874f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"minicover": {
"version": "3.4.1",
"version": "3.4.8",
"commands": [
"minicover"
]
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,7 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

coverage-hits/
coverage.json
coveralls.json
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ after_success:
- dotnet test --no-build ./test/OData.QueryBuilder.Test -c $CONFIGURATION -f netcoreapp3.1
- dotnet minicover uninstrument
- dotnet minicover report
- dotnet minicover coverallsreport --output "coveralls.json" --service-name "travis-ci" --service-job-id $TRAVIS_JOB_ID
- dotnet minicover coverallsreport --service-name "travis-ci" --service-job-id $TRAVIS_JOB_ID
before_deploy:
- git checkout origin/main && git fetch && git remote set-url origin https://${GITHUB_OAUTH_TOKEN}@github.com/ZEXSM/OData.QueryBuilder.git
- PR_TITLE=$(git log -1 --pretty='%f')
Expand Down
7 changes: 4 additions & 3 deletions OData.QueryBuilder.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30204.135
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FA1582AB-A13D-44A4-A46D-2DAE1111A2BB}"
EndProject
Expand All @@ -13,6 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OData.QueryBuilder.Test", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "items", "items", "{179F88B9-A06D-4505-9266-A5D66004601C}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
.travis.yml = .travis.yml
README.md = README.md
EndProjectSection
Expand All @@ -24,7 +25,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".config", ".config", "{B8F3
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OData.QueryBuilder.Benchmark", "test\OData.QueryBuilder.Benchmark\OData.QueryBuilder.Benchmark.csproj", "{3C66CF4E-8FA0-4E81-90DB-B22234A2670C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OData.QueryBuilder.Fakes", "test\OData.QueryBuilder.Fakes\OData.QueryBuilder.Fakes.csproj", "{421FF96A-2F4E-4589-AF2A-604FDC8BE2AC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OData.QueryBuilder.Fakes", "test\OData.QueryBuilder.Fakes\OData.QueryBuilder.Fakes.csproj", "{421FF96A-2F4E-4589-AF2A-604FDC8BE2AC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 1 addition & 0 deletions src/OData.QueryBuilder/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static IEnumerable<string> ReplaceWithStringBuilder(this ICollection<stri
ICollection collection => collection.CollectionToQuery(),
IEnumerable enumerable => enumerable.EnumerableToQuery(),
Guid @guid => $"{@guid}",
decimal @decimal => Convert.ToString(@decimal, CultureInfo.InvariantCulture),
_ => @object.GetType().IsPrimitive ? Convert.ToString(@object, CultureInfo.InvariantCulture) : $"'{@object}'",
};

Expand Down
15 changes: 15 additions & 0 deletions test/OData.QueryBuilder.Test/ODataQueryCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,21 @@ public void ODataQueryBuilder_Function_Length_Success()
uri.Should().Be("ODataType?$filter=length(TypeCode) gt 0");
}

[Fact(DisplayName = "Try convert decimal => Success")]
public void ODataQueryBuilderList_Decimal_Success()
{
decimal decimalValue = 10.3M;
double doubleValue = 20;

var uri = _odataQueryBuilderDefault
.For<ODataTypeEntity>(s => s.ODataType)
.ByList()
.Filter(s => s.Sum == decimalValue && s.Money == doubleValue)
.ToUri();

uri.Should().Be("http://mock/odata/ODataType?$filter=Sum eq 10.3 and Money eq 20");
}

[Fact(DisplayName = "Function Cast => Success")]
public void ODataQueryBuilder_Function_Cast_Success()
{
Expand Down

0 comments on commit 339874f

Please sign in to comment.