Skip to content

Commit

Permalink
Added factories do tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TSchmiedlechner committed Apr 30, 2020
1 parent 468d07d commit 0520468
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="fiskaltrust.interface" Version="1.3.0-rc1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
<PackageReference Include="Grpc.Core" Version="2.28.1" />
<PackageReference Include="protobuf-net.Grpc.Native" Version="1.0.37" />
</ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions src/fiskaltrust.Middleware.Interface.Http/HttpPos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class HttpPos : IPOS
public HttpPos(POSOptions options)
{
_url = options.Url.Replace("rest://", "http://").Replace("xml://", "http://");
_url = _url.EndsWith("/") ? _url : $"{_url}/ ";
_options = options;
}

Expand Down Expand Up @@ -147,17 +148,20 @@ async Task<ReceiptResponse> IPOS.SignAsync(ReceiptRequest request)

private async Task<TResponse> JsonSignAsync<TRequest, TResponse>(TRequest request, string endpoint)
{
var jsonstring = JsonConvert.SerializeObject(request);
var jsonstring = JsonConvert.SerializeObject(request, new JsonSerializerSettings
{
DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
});
var jsonContent = new StringContent(jsonstring, Encoding.UTF8, "application/json");

using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_url);

using (var response = await client.PostAsync(Path.Combine(_url, endpoint), jsonContent))
using (var response = await client.PostAsync(endpoint, jsonContent))
{
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
response.EnsureSuccessStatusCode();

return JsonConvert.DeserializeObject<TResponse>(content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<ItemGroup>
<PackageReference Include="fiskaltrust.interface" Version="1.3.0-rc1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
</ItemGroup>

<PropertyGroup>
<PackageId>fiskaltrust.Middleware.Interface.Http</PackageId>
<Authors>fiskaltrust</Authors>
Expand All @@ -26,5 +26,6 @@
<ItemGroup>
<ProjectReference Include="..\fiskaltrust.ifPOS\fiskaltrust.Middleware.Interface.csproj" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFrameworks>net40;net461</TargetFrameworks>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="fiskaltrust.interface" Version="1.3.0-rc1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461' OR '$(TargetFramework)' == 'net40'">
<ProjectReference Include="..\..\src\fiskaltrust.Middleware.Interface.Soap\fiskaltrust.Middleware.Interface.Soap.csproj" />

<Reference Include="System.ServiceModel" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
Expand Down Expand Up @@ -53,8 +55,11 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461' OR '$(TargetFramework)' == 'netcoreapp3.0'">
<PackageReference Include="Grpc.Core" Version="2.26.0" />
<PackageReference Include="protobuf-net.Grpc.Native" Version="1.0.22" />
<ProjectReference Include="..\..\src\fiskaltrust.Middleware.Interface.Http\fiskaltrust.Middleware.Interface.Http.csproj" />
<ProjectReference Include="..\..\src\fiskaltrust.Middleware.Interface.Grpc\fiskaltrust.Middleware.Interface.Grpc.csproj" />

<PackageReference Include="Grpc.Core" Version="2.28.1" />
<PackageReference Include="protobuf-net.Grpc.Native" Version="1.0.37" />
<PackageReference Include="System.Interactive.Async" Version="4.0.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
<PackageReference Include="System.Linq.Async" Version="4.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using fiskaltrust.ifPOS.Tests.Helpers;
using fiskaltrust.ifPOS.Tests.Helpers.Wcf;
using fiskaltrust.Middleware.Interface.Soap;
using System;
using System.ServiceModel;

Expand All @@ -23,7 +24,7 @@ public WcfV0ServerAndV0ClientIPOSTests()
_serviceHost = null;
}

protected override ifPOS.v0.IPOS CreateClient() => WcfHelper.GetProxy<ifPOS.v0.IPOS>(_url);
protected override ifPOS.v0.IPOS CreateClient() => new SoapPosFactory().CreatePosAsync(new ifPOS.v1.POSOptions { Url = _url });

protected override void StartHost() => _serviceHost = WcfHelper.StartHost<ifPOS.v0.IPOS>(_url, new DummyPOS());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using fiskaltrust.ifPOS.Tests.Helpers;
using fiskaltrust.ifPOS.Tests.Helpers.Wcf;
using fiskaltrust.Middleware.Interface.Soap;
using System;
using System.ServiceModel;

Expand All @@ -23,7 +24,7 @@ public WcfV0ServerAndV1ClientIPOSTests()
_serviceHost = null;
}

protected override ifPOS.v0.IPOS CreateClient() => WcfHelper.GetProxy<ifPOS.v1.IPOS>(_url);
protected override ifPOS.v0.IPOS CreateClient() => new SoapPosFactory().CreatePosAsync(new ifPOS.v1.POSOptions { Url = _url });

protected override void StartHost() => _serviceHost = WcfHelper.StartHost<ifPOS.v0.IPOS>(_url, new DummyPOS());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using fiskaltrust.ifPOS.Tests.Helpers;
using fiskaltrust.ifPOS.Tests.Helpers.Wcf;
using fiskaltrust.Middleware.Interface.Soap;
using System;
using System.ServiceModel;

Expand All @@ -23,7 +24,7 @@ public WcfV1ServerAndV0ClientIPOSTests()
_serviceHost = null;
}

protected override ifPOS.v0.IPOS CreateClient() => WcfHelper.GetProxy<ifPOS.v0.IPOS>(_url);
protected override ifPOS.v0.IPOS CreateClient() => new SoapPosFactory().CreatePosAsync(new ifPOS.v1.POSOptions { Url = _url });

protected override void StartHost() => _serviceHost = WcfHelper.StartHost<ifPOS.v0.IPOS>(_url, new DummyPOSV1());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using fiskaltrust.ifPOS.Tests.Helpers;
using fiskaltrust.ifPOS.Tests.Helpers.Wcf;
using fiskaltrust.Middleware.Interface.Soap;
using System;
using System.ServiceModel;

Expand All @@ -23,7 +24,7 @@ public WcfV1ServerAndV1ClientIPOSTests()
_serviceHost = null;
}

protected override ifPOS.v0.IPOS CreateClient() => WcfHelper.GetProxy<ifPOS.v1.IPOS>(_url);
protected override ifPOS.v0.IPOS CreateClient() => new SoapPosFactory().CreatePosAsync(new ifPOS.v1.POSOptions { Url = _url });

protected override void StartHost() => _serviceHost = WcfHelper.StartHost<ifPOS.v1.IPOS>(_url, new DummyPOSV1());

Expand Down
4 changes: 2 additions & 2 deletions test/fiskaltrust.ifPOS.Tests/v1/IPOS/Grpc/GrpcIPOSV1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using fiskaltrust.ifPOS.Tests.Helpers;
using fiskaltrust.ifPOS.Tests.Helpers.Grpc;
using fiskaltrust.ifPOS.v1;
using fiskaltrust.Middleware.Interface.Grpc;
using FluentAssertions;
using Grpc.Core;
using NUnit.Framework;
Expand All @@ -23,8 +24,7 @@ public class GrpcIPOSV1Tests : IPOSV1Tests
_server = null;
}


protected override ifPOS.v1.IPOS CreateClient() => GrpcHelper.GetClient<ifPOS.v1.IPOS>(_host, _port);
protected override ifPOS.v1.IPOS CreateClient() => new GrpcPosFactory().CreatePosAsync(new POSOptions { Url = $"http://{_host}:{_port}" });

protected override void StartHost()
{
Expand Down
7 changes: 7 additions & 0 deletions test/fiskaltrust.ifPOS.Tests/v1/IPOS/Wcf/HttpIPOSV1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
#if !NET40
using fiskaltrust.Middleware.Interface.Http;
#endif

namespace fiskaltrust.ifPOS.Tests.v1.IPOS
{
Expand All @@ -33,7 +36,11 @@ public HttpIPOSV1Tests()
_serviceHost = null;
}

#if NET40
protected override ifPOS.v1.IPOS CreateClient() => WcfHelper.GetRestProxy<ifPOS.v1.IPOS>(_url);
#else
protected override ifPOS.v1.IPOS CreateClient() => new HttpPosFactory().CreatePosAsync(new ifPOS.v1.POSOptions { Url = _url });
#endif

protected override void StartHost() => _serviceHost = WcfHelper.StartRestHost<ifPOS.v1.IPOS>(_url, new DummyPOSV1());

Expand Down
3 changes: 2 additions & 1 deletion test/fiskaltrust.ifPOS.Tests/v1/IPOS/Wcf/WcfIPOSV1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using fiskaltrust.ifPOS.Tests.Helpers;
using fiskaltrust.ifPOS.Tests.Helpers.Wcf;
using fiskaltrust.ifPOS.v0;
using fiskaltrust.Middleware.Interface.Soap;
using FluentAssertions;
using NUnit.Framework;
using System;
Expand All @@ -26,7 +27,7 @@ public WcfIPOSV1Tests()
_serviceHost = null;
}

protected override ifPOS.v1.IPOS CreateClient() => WcfHelper.GetProxy<ifPOS.v1.IPOS>(_url);
protected override ifPOS.v1.IPOS CreateClient() => new SoapPosFactory().CreatePosAsync(new ifPOS.v1.POSOptions { Url = _url });

protected override void StartHost() => _serviceHost = WcfHelper.StartHost<ifPOS.v1.IPOS>(_url, new DummyPOSV1());

Expand Down

0 comments on commit 0520468

Please sign in to comment.