Skip to content

Commit

Permalink
oplossing voor datum issue (#2)
Browse files Browse the repository at this point in the history
* issue met datum

* Update .gitignore

* crt verwijderd

* Update .gitignore

* Update ApiClientTests.cs
  • Loading branch information
MannusEtten committed May 27, 2022
1 parent ce7c199 commit 57e9414
Show file tree
Hide file tree
Showing 10 changed files with 491 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,8 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# certificaten
.crt
*.crt
60 changes: 59 additions & 1 deletion HR.KvkConnector.Tests/ApiClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,72 @@
using HR.KvkConnector.Tests.Fixture;
using System;
using System.Linq;
using HR.KvkConnector.Tests.Fixture;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using System.Threading.Tasks;
using FluentAssertions;
using HR.KvkConnector.Model.Zoeken;

namespace HR.KvkConnector.Tests
{
[TestClass]
public class ApiClientTests
{

[TestMethod]
public async Task GetVestiging_No_Issue_DateTime()
{
IApiClient client = new ApiClient(new Uri("https://api.kvk.nl/api/v1"), "l7xxd760b2c8441c490c941d6f2f81e6e387");
var result = await client.GetVestigingsprofielAsync("000051127369");
result.MaterieleRegistratie.DatumAanvang.Value.Date.Should().Be(new DateTime(2022, 1,3));
}

[TestMethod]
public async Task GetVestiging_DateTime_Reset_To_Minimum_Value()
{
IApiClient client = new ApiClient(new Uri("https://api.kvk.nl/api/v1"), "l7xxd760b2c8441c490c941d6f2f81e6e387");
var result = await client.GetVestigingsprofielAsync("000019061714");
result.MaterieleRegistratie.DatumAanvang.Value.Date.Should().Be(new DateTime(1, 1, 1));
}


[TestMethod]
public async Task GetZoeken_TestData_From_Live_Service_KVK()
{
IApiClient client = new ApiClient(new Uri("https://api.kvk.nl/api/v1"), "l7xxd760b2c8441c490c941d6f2f81e6e387");
var result = await client.ZoekenAsync(new Parameters() { KvkNummer = "85058769" });
var handelsNaam = result.Resultaten.First().Handelsnaam;
handelsNaam.Should().Be("the Right Direction B.V.");
}

[TestMethod]
public async Task GetZoeken_TestData_From_Test_Service_KVK()
{
IApiClient client = new ApiClient(new Uri("https://developers.kvk.nl/test/api/v1"), string.Empty);
var result = await client.ZoekenAsync(new Parameters() {KvkNummer = "68750110"});
var handelsNaam = result.Resultaten.First().Handelsnaam;
handelsNaam.Should().Be("Test BV Donald");
}

[TestMethod]
public async Task GetBasisprofielAsync_TestData_From_Test_Service_KVK()
{
IApiClient client = new ApiClient(new Uri("https://developers.kvk.nl/test/api/v1"), string.Empty);
var result = await client.GetBasisprofielAsync("68727720");
result.Handelsnamen.Count().Should().Be(1);
}

[TestMethod]
public async Task GetVestigingenAsync_TestData_From_Test_Service_KVK()
{
IApiClient client = new ApiClient(new Uri("https://developers.kvk.nl/test/api/v1"), string.Empty);

// Act
var vestigingen = await client.GetVestigingenAsync(kvkNummer: "90001354");
vestigingen.Vestigingen.First().Vestigingsnummer.Should().Be("990000541921");
}

[TestMethod]
public async Task GetBasisprofielAsync_ByDefault_ReturnsObjectDeserializedFromJson()
{
Expand Down
16 changes: 16 additions & 0 deletions HR.KvkConnector.Tests/HR.KvkConnector.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
Expand All @@ -27,4 +28,19 @@
<ProjectReference Include="..\HR.KvkConnector\HR.KvkConnector.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
63 changes: 63 additions & 0 deletions HR.KvkConnector.Tests/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions HR.KvkConnector.Tests/Properties/Resources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
1 change: 0 additions & 1 deletion HR.KvkConnector/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ private async Task<TResult> GetFromJsonAsync<TResult>(string requestUri, Cancell
var httpError = JsonSerializer.Deserialize<HttpError>(jsonString);
throw new ApiException((HttpStatusCode)httpError.StatusCode, httpError.ToApiError());
}

return JsonSerializer.Deserialize<TResult>(jsonString);
}
}
Expand Down
23 changes: 23 additions & 0 deletions HR.KvkConnector/HR.KvkConnector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,27 @@
<EmbeddedResource Include="Properties\Certificates\*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="6.0.4" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Folder Include="Conversion\" />
</ItemGroup>

</Project>
16 changes: 14 additions & 2 deletions HR.KvkConnector/Model/MaterieleRegistratie.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Globalization;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace HR.KvkConnector.Model
{
Expand All @@ -9,13 +11,23 @@ public class MaterieleRegistratie
/// <summary>
/// Startdatum onderneming.
/// </summary>
public DateTime? DatumAanvang
{
get
{
DateTime.TryParseExact(DatumAanvraagAsText, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var result);
return result;
}
}


[DataMember(Name = "datumAanvang")]
public DateTime? DatumAanvang { get; set; }
public string DatumAanvraagAsText { get; set; }

/// <summary>
/// Einddatum onderneming.
/// </summary>
[DataMember(Name = "datumEinde")]
public DateTime? DatumEinde { get; set; }
}
}
}
Loading

0 comments on commit 57e9414

Please sign in to comment.