Skip to content

Commit 1af0dbb

Browse files
authored
Merge pull request #65 from Intechnity-com/master
Release 1.0.20
2 parents b5a9396 + a77a070 commit 1af0dbb

13 files changed

Lines changed: 169 additions & 31 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Unit Test With Coverage
2+
on:
3+
workflow_dispatch:
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- name: Setup .NET
10+
uses: actions/setup-dotnet@v1
11+
with:
12+
dotnet-version: 6.0.x
13+
- name: Restore dependencies
14+
run: dotnet restore
15+
- name: Build
16+
run: dotnet build --no-restore
17+
- name: Run Unit Tests
18+
run: dotnet test -p:CollectCoverage=true -p:CoverletOutput=TestResults/ -p:CoverletOutputFormat=opencover --no-build --verbosity normal PortaCapena.OdooJsonRpcClient.Tests/
19+
- name: Create Test Coverage Badge
20+
uses: simon-k/dotnet-code-coverage-badge@v1.0.0
21+
id: create_coverage_badge
22+
with:
23+
label: Test Coverage
24+
color: brightgreen
25+
path: PortaCapena.OdooJsonRpcClient.Tests/TestResults/coverage.opencover.xml
26+
gist-filename: code-coverage.json
27+
gist-id: 54596b8c061e5c3c25b3072822a105a0
28+
gist-auth-token: ${{ secrets.GIST_AUTH_TOKEN }}
29+
- name: Print code coverage
30+
run: echo "Code coverage percentage ${{steps.create_coverage_badge.outputs.percentage}}%"
31+
32+
33+

.github/workflows/pr_build.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: .NET Build with Tests
1+
name: Build and Test
22

33
on:
44
push:
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup .NET
1919
uses: actions/setup-dotnet@v1
2020
with:
21-
dotnet-version: 3.1.x
21+
dotnet-version: 6.0.x
2222

2323
- name: Restore dependencies
2424
run: dotnet restore
@@ -45,7 +45,7 @@ jobs:
4545
fi
4646
4747
- name: Test
48-
run: dotnet test PortaCapena.OdooJsonRpcClient.Tests/PortaCapena.OdooJsonRpcClient.Tests.csproj --configuration $config --no-build --no-restore --logger:"liquid.md;LogFileName=${{github.workspace}}/${{env.file_name}};Title=${{env.title}};"
48+
run: dotnet test PortaCapena.OdooJsonRpcClient.Tests/PortaCapena.OdooJsonRpcClient.Tests.csproj --configuration $config --no-build --no-restore --logger:"liquid.md;LogFileName=${{github.workspace}}/${{env.file_name}};Title=${{env.title}};" --collect:"XPlat Code Coverage" --results-directory ./coverage
4949

5050
# upload report as build artifact
5151
- name: Upload a Build Artifact
@@ -64,3 +64,23 @@ jobs:
6464
with:
6565
path: ${{env.file_name}}
6666

67+
- name: Code Coverage Report
68+
uses: irongut/CodeCoverageSummary@v1.3.0
69+
with:
70+
filename: coverage/**/coverage.cobertura.xml
71+
badge: true
72+
fail_below_min: true
73+
format: markdown
74+
hide_branch_rate: false
75+
hide_complexity: true
76+
indicators: true
77+
output: both
78+
thresholds: '5 60'
79+
80+
- name: Add Coverage Comment
81+
uses: marocchino/sticky-pull-request-comment@v2
82+
if: github.event_name == 'pull_request'
83+
with:
84+
recreate: true
85+
path: code-coverage-results.md
86+

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup .NET
1616
uses: actions/setup-dotnet@v1
1717
with:
18-
dotnet-version: 3.1.x
18+
dotnet-version: 6.0.x
1919

2020
- name: Install dependencies
2121
run: dotnet restore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Generated\ Files/
3535
# MSTest test Results
3636
[Tt]est[Rr]esult*/
3737
[Bb]uild[Ll]og.*
38+
TestResults/
3839

3940
# NUNIT
4041
*.VisualState.xml

PortaCapena.OdooJsonRpcClient.Example/PortaCapena.OdooJsonRpcClient.Example.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77

88
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
99
</PropertyGroup>
1010

11+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
1112
<ItemGroup>
1213
<PackageReference Include="FluentAssertions" Version="5.10.3" />
1314
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using FluentAssertions;
3+
using System.Linq;
4+
using PortaCapena.OdooJsonRpcClient.Models;
5+
using PortaCapena.OdooJsonRpcClient.Shared.Models;
6+
using Xunit;
7+
using PortaCapena.OdooJsonRpcClient.Converters;
8+
using Newtonsoft.Json;
9+
using Xunit.Abstractions;
10+
using System.IO;
11+
12+
namespace PortaCapena.OdooJsonRpcClient.Tests
13+
{
14+
15+
public class OdooModelMapperTests
16+
{
17+
[Fact]
18+
public void CanMap_StringToEnum()
19+
{
20+
object output;
21+
22+
/*
23+
* In StatusPurchaseOrderOdooEnum we have this declaration :
24+
*
25+
* [EnumMember(Value = "done")]
26+
* Locked = 5,
27+
*
28+
* So the JValue should be "done" (String) and the output should be Locked
29+
* */
30+
31+
OdooModelMapper.ConverOdooPropertyToDotNet(
32+
typeof(StatusPurchaseOrderOdooEnum),
33+
new Newtonsoft.Json.Linq.JValue("done"),
34+
out output
35+
);
36+
37+
var result = (StatusPurchaseOrderOdooEnum)output;
38+
39+
Assert.Equal(StatusPurchaseOrderOdooEnum.Locked, result);
40+
}
41+
42+
43+
[Fact]
44+
public void CanMap_IntegerToEnum()
45+
{
46+
object output;
47+
48+
/*
49+
* In PriorityPurchaseOrderOdooEnum we have this declaration :
50+
*
51+
* [EnumMember(Value = "1")]
52+
* Urgent = 2,
53+
*
54+
* So the JValue should be 1 (Integer) and the output should be Urgent
55+
* */
56+
57+
OdooModelMapper.ConverOdooPropertyToDotNet(
58+
typeof(PriorityPurchaseOrderOdooEnum),
59+
new Newtonsoft.Json.Linq.JValue(1),
60+
out output
61+
);
62+
63+
var result = (PriorityPurchaseOrderOdooEnum)output;
64+
65+
Assert.Equal(PriorityPurchaseOrderOdooEnum.Urgent, result);
66+
}
67+
}
68+
}

PortaCapena.OdooJsonRpcClient.Tests/PortaCapena.OdooJsonRpcClient.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77

@@ -20,16 +20,16 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="FluentAssertions" Version="5.10.3" />
23+
<PackageReference Include="FluentAssertions" Version="6.8.0" />
2424
<PackageReference Include="LiquidTestReports.Markdown" Version="1.0.9" />
2525
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
2626
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
27-
<PackageReference Include="xunit" Version="2.4.1" />
28-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
27+
<PackageReference Include="xunit" Version="2.4.2" />
28+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
2929
<PrivateAssets>all</PrivateAssets>
3030
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3131
</PackageReference>
32-
<PackageReference Include="coverlet.collector" Version="1.3.0">
32+
<PackageReference Include="coverlet.collector" Version="3.2.0">
3333
<PrivateAssets>all</PrivateAssets>
3434
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3535
</PackageReference>

PortaCapena.OdooJsonRpcClient/Converters/OdooModelMapper.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ public static bool ConverOdooPropertyToDotNet(Type dotnetType, JToken value, out
5252
result = DateTime.Parse(stringTime);
5353
return true;
5454

55+
// Enum part accept both string and integer to avoid issue #54
5556
case JTokenType.String when dotnetType.IsEnum:
57+
case JTokenType.Integer when dotnetType.IsEnum:
5658
result = ConvertToDotNetEnum(dotnetType, value.ToString());
5759
return true;
5860

5961
case JTokenType.String when dotnetType.IsGenericType && dotnetType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
6062
dotnetType.GenericTypeArguments.Length == 1 && dotnetType.GenericTypeArguments[0].IsEnum:
63+
case JTokenType.Integer when dotnetType.IsGenericType && dotnetType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
64+
dotnetType.GenericTypeArguments.Length == 1 && dotnetType.GenericTypeArguments[0].IsEnum:
6165
var nullableType = Nullable.GetUnderlyingType(dotnetType);
6266
result = ConvertToDotNetEnum(nullableType, value);
6367
return true;
@@ -219,7 +223,13 @@ public static string ConvertOdooNameToDotNet(string odooName)
219223
{
220224
odooName = odooName.Replace("+", "Plus");
221225
var odooNameCleaned = Regex.Replace(odooName, "[^A-Za-z0-9-]", "_");
222-
var dotnetKeys = odooNameCleaned.Split('_', '-', '.', ',', ' ', ':', ';', '/', '\\', '*', '+', '(', ')', '[', ']').Select(x => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(x));
226+
var dotnetKeys = odooNameCleaned
227+
.Split('_', '-', '.', ',', ' ', ':', ';', '/', '\\', '*', '+', '(', ')', '[', ']')
228+
.Select(x => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(x))
229+
.Where(x => !string.IsNullOrEmpty(x))
230+
.ToList();
231+
if (dotnetKeys.Count == 0)
232+
dotnetKeys.Add("None");
223233
return string.Join(string.Empty, dotnetKeys);
224234
}
225235

PortaCapena.OdooJsonRpcClient/Models/OdooConfig.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace PortaCapena.OdooJsonRpcClient.Models
1+
using System;
2+
3+
namespace PortaCapena.OdooJsonRpcClient.Models
24
{
35
public class OdooConfig
46
{
@@ -7,30 +9,32 @@ public class OdooConfig
79
public string DbName { get; }
810
public string UserName { get; }
911
public string Password { get; }
12+
public TimeSpan Timeout { get; }
1013

1114
public OdooContext Context { get; }
1215

1316

14-
public OdooConfig(string apiUrl, string dbName, string userName, string password)
17+
public OdooConfig(string apiUrl, string dbName, string userName, string password, TimeSpan timeout = default(TimeSpan))
1518
{
1619
this.ApiUrl = apiUrl.TrimEnd(new[] { '/' });
1720
this.DbName = dbName;
1821
this.UserName = userName;
1922
this.Password = password;
2023
this.Context = new OdooContext();
24+
this.Timeout = timeout;
2125
}
2226

23-
public OdooConfig(string apiUrl, string dbName, string userName, string password, OdooContext context) : this(apiUrl, dbName, userName, password)
27+
public OdooConfig(string apiUrl, string dbName, string userName, string password, OdooContext context, TimeSpan timeout = default(TimeSpan)) : this(apiUrl, dbName, userName, password, timeout)
2428
{
2529
this.Context = new OdooContext(context);
2630
}
2731

28-
public OdooConfig(string apiUrl, string dbName, string userName, string password, string language) : this(apiUrl, dbName, userName, password)
32+
public OdooConfig(string apiUrl, string dbName, string userName, string password, string language, TimeSpan timeout = default(TimeSpan)) : this(apiUrl, dbName, userName, password, timeout)
2933
{
3034
this.Context = new OdooContext(language);
3135
}
3236

33-
public OdooConfig(string apiUrl, string dbName, string userName, string password, string language, string timezone) : this(apiUrl, dbName, userName, password)
37+
public OdooConfig(string apiUrl, string dbName, string userName, string password, string language, string timezone, TimeSpan timeout = default(TimeSpan)) : this(apiUrl, dbName, userName, password, timeout)
3438
{
3539
this.Context = new OdooContext(language, timezone);
3640
}

PortaCapena.OdooJsonRpcClient/Models/OdooPropertyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public static OdooValueTypeEnum ToOdooValueTypeEnum(string value)
8989
case "boolean":
9090
return OdooValueTypeEnum.Boolean;
9191
case "char":
92+
case "json":
9293
return OdooValueTypeEnum.Char;
9394
case "date":
9495
return OdooValueTypeEnum.Date;

0 commit comments

Comments
 (0)