Skip to content

Commit

Permalink
ContractResolverForDataProperty property for custom contract resolver…
Browse files Browse the repository at this point in the history
… on data property

release 3.1.0
  • Loading branch information
pofider committed Aug 13, 2020
1 parent 267d679 commit 31e1a14
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
28 changes: 27 additions & 1 deletion jsreport.Client.Test/ReportingServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
using Shouldly;
using jsreport.Binary;
using jsreport.Types;
using Newtonsoft.Json.Serialization;

namespace jsreport.Client.Test
{
[TestFixture]
[SingleThreaded]
public class ReportingServiceTest
{
private IReportingService _reportingService;
private ReportingService _reportingService;
private ILocalWebServerReportingService _localReportingService;

[SetUp]
Expand Down Expand Up @@ -52,6 +53,31 @@ public async Task ChromePdfTest()
}
}

[Test]
public async Task SerializationDataContractResolverTest()
{
_reportingService.ContractResolverForDataProperty = new CamelCasePropertyNamesContractResolver();
var result = await _reportingService.RenderAsync(new
{
template = new
{
content = "{{helloWorld}}",
engine = "handlebars",
recipe = "html"
},
data = new
{
HelloWorld = "foo"
}
});

using (var reader = new StreamReader(result.Content))
{
reader.ReadToEnd().ShouldStartWith("foo");
}
}


[Test]
public async Task HtmlTest()
{
Expand Down
4 changes: 2 additions & 2 deletions jsreport.Client.Test/jsreport.Client.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<Otherwise>
<ItemGroup>
<ProjectReference Include="..\jsreport.Client\jsreport.Client.csproj" />
<PackageReference Include="jsreport.Local" Version="2.0.0" />
<PackageReference Include="jsreport.Binary" Version="2.4.0" />
<PackageReference Include="jsreport.Local" Version="2.2.3" />
<PackageReference Include="jsreport.Binary" Version="2.9.0" />
</ItemGroup>
</Otherwise>
</Choose>
Expand Down
18 changes: 12 additions & 6 deletions jsreport.Client/ReportingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Newtonsoft.Json;
using jsreport.Types;
using jsreport.Shared;
using Newtonsoft.Json.Serialization;

namespace jsreport.Client
{
Expand Down Expand Up @@ -44,6 +45,11 @@ public class ReportingService : IReportingService
/// Timeout for http client requests
/// </summary>
public TimeSpan? HttpClientTimeout { get; set; }

/// <summary>
/// json.net contract resolver used for serializing rendering request data property
/// </summary>
public IContractResolver ContractResolverForDataProperty { get; set; }

public ReportingService(string serviceUri, string username, string password) : this(serviceUri)
{
Expand Down Expand Up @@ -81,7 +87,7 @@ protected virtual HttpClient CreateClient()
/// <returns>Report result promise</returns>
public Task<Report> RenderAsync(RenderRequest request, CancellationToken ct = default(CancellationToken))
{
return RenderAsync(SerializerHelper.SerializeRenderRequest(request), ct);
return RenderAsync(SerializerHelper.SerializeRenderRequest(request, ContractResolverForDataProperty), ct);
}

// <summary>
Expand All @@ -93,7 +99,7 @@ protected virtual HttpClient CreateClient()
/// <returns>Report result promise</returns>
public Task<Report> RenderAsync(string templateShortid, object data, CancellationToken ct = default(CancellationToken))
{
return RenderAsync(SerializerHelper.SerializeRenderRequest(templateShortid, data), ct);
return RenderAsync(SerializerHelper.SerializeRenderRequest(templateShortid, data, ContractResolverForDataProperty), ct);
}

/// <summary>
Expand All @@ -105,7 +111,7 @@ protected virtual HttpClient CreateClient()
/// <returns>Report result promise</returns>
public Task<Report> RenderAsync(string templateShortid, string jsonData, CancellationToken ct = default(CancellationToken))
{
return RenderAsync(SerializerHelper.SerializeRenderRequest(templateShortid, jsonData), ct);
return RenderAsync(SerializerHelper.SerializeRenderRequest(templateShortid, jsonData, ContractResolverForDataProperty), ct);
}

/// <summary>
Expand All @@ -116,7 +122,7 @@ protected virtual HttpClient CreateClient()
/// <returns>Report result promise</returns>
public Task<Report> RenderAsync(object request, CancellationToken ct = default(CancellationToken))
{
return RenderAsync(SerializerHelper.SerializeRenderRequest(request), ct);
return RenderAsync(SerializerHelper.SerializeRenderRequest(request, ContractResolverForDataProperty), ct);
}

/// <summary>
Expand All @@ -128,7 +134,7 @@ protected virtual HttpClient CreateClient()
/// <returns>Report result promise</returns>
public Task<Report> RenderByNameAsync(string templateName, string jsonData, CancellationToken ct = default(CancellationToken))
{
return RenderAsync(SerializerHelper.SerializeRenderRequestForName(templateName, jsonData), ct);
return RenderAsync(SerializerHelper.SerializeRenderRequestForName(templateName, jsonData, ContractResolverForDataProperty), ct);
}

/// <summary>
Expand All @@ -140,7 +146,7 @@ protected virtual HttpClient CreateClient()
/// <returns>Report result promise</returns>
public Task<Report> RenderByNameAsync(string templateName, object data, CancellationToken ct = default(CancellationToken))
{
return RenderAsync(SerializerHelper.SerializeRenderRequestForName(templateName, data), ct);
return RenderAsync(SerializerHelper.SerializeRenderRequestForName(templateName, data, ContractResolverForDataProperty), ct);
}

private async Task<Report> RenderAsync(string request, CancellationToken ct = default(CancellationToken))
Expand Down
12 changes: 6 additions & 6 deletions jsreport.Client/jsreport.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard1.6;net45</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<PackageId>jsreport.Client</PackageId>
<Title>jsreport Client</Title>
<Authors>Jan Blaha</Authors>
Expand All @@ -12,12 +12,12 @@
<PackageTags>jsreport;report;pdf</PackageTags>
<RepositoryUrl>https://github.com/jsreport/net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>3.0.1</Version>
<AssemblyVersion>3.0.1</AssemblyVersion>
<Version>3.1.0</Version>
<AssemblyVersion>3.1.0</AssemblyVersion>
<Company>jsreport</Company>
<PackageReleaseNotes>Release notes are at https://github.com/jsreport/jsreport-dotnet-client/releases</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<FileVersion>3.0.1.0</FileVersion>
<FileVersion>3.1.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.4.0" />
Expand All @@ -34,8 +34,8 @@
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="jsreport.Types" Version="2.2.7" />
<PackageReference Include="jsreport.Shared" Version="2.0.1" />
<PackageReference Include="jsreport.Types" Version="2.7.0" />
<PackageReference Include="jsreport.Shared" Version="2.3.0" />
</ItemGroup>
</Otherwise>
</Choose>
Expand Down

0 comments on commit 31e1a14

Please sign in to comment.