diff --git a/.gitignore b/.gitignore index 9491a2f..8add093 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,8 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +# certificaten +.crt +*.crt diff --git a/HR.KvkConnector.Tests/ApiClientTests.cs b/HR.KvkConnector.Tests/ApiClientTests.cs index f3046da..121d19c 100644 --- a/HR.KvkConnector.Tests/ApiClientTests.cs +++ b/HR.KvkConnector.Tests/ApiClientTests.cs @@ -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() { diff --git a/HR.KvkConnector.Tests/HR.KvkConnector.Tests.csproj b/HR.KvkConnector.Tests/HR.KvkConnector.Tests.csproj index d6890b2..4b71e85 100644 --- a/HR.KvkConnector.Tests/HR.KvkConnector.Tests.csproj +++ b/HR.KvkConnector.Tests/HR.KvkConnector.Tests.csproj @@ -17,6 +17,7 @@ + @@ -27,4 +28,19 @@ + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + diff --git a/HR.KvkConnector.Tests/Properties/Resources.Designer.cs b/HR.KvkConnector.Tests/Properties/Resources.Designer.cs new file mode 100644 index 0000000..9bb5d97 --- /dev/null +++ b/HR.KvkConnector.Tests/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace HR.KvkConnector.Tests.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HR.KvkConnector.Tests.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/HR.KvkConnector.Tests/Properties/Resources.resx b/HR.KvkConnector.Tests/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/HR.KvkConnector.Tests/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HR.KvkConnector/ApiClient.cs b/HR.KvkConnector/ApiClient.cs index 3398293..0ed5bdd 100644 --- a/HR.KvkConnector/ApiClient.cs +++ b/HR.KvkConnector/ApiClient.cs @@ -98,7 +98,6 @@ private async Task GetFromJsonAsync(string requestUri, Cancell var httpError = JsonSerializer.Deserialize(jsonString); throw new ApiException((HttpStatusCode)httpError.StatusCode, httpError.ToApiError()); } - return JsonSerializer.Deserialize(jsonString); } } diff --git a/HR.KvkConnector/HR.KvkConnector.csproj b/HR.KvkConnector/HR.KvkConnector.csproj index f403fc5..6fa163d 100644 --- a/HR.KvkConnector/HR.KvkConnector.csproj +++ b/HR.KvkConnector/HR.KvkConnector.csproj @@ -12,4 +12,27 @@ + + + + + + + True + True + Resources.resx + + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + + + + + + + diff --git a/HR.KvkConnector/Model/MaterieleRegistratie.cs b/HR.KvkConnector/Model/MaterieleRegistratie.cs index 50f7001..1905cdf 100644 --- a/HR.KvkConnector/Model/MaterieleRegistratie.cs +++ b/HR.KvkConnector/Model/MaterieleRegistratie.cs @@ -1,5 +1,7 @@ using System; +using System.Globalization; using System.Runtime.Serialization; +using System.Text.Json.Serialization; namespace HR.KvkConnector.Model { @@ -9,8 +11,18 @@ public class MaterieleRegistratie /// /// Startdatum onderneming. /// + 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; } /// /// Einddatum onderneming. @@ -18,4 +30,4 @@ public class MaterieleRegistratie [DataMember(Name = "datumEinde")] public DateTime? DatumEinde { get; set; } } -} +} \ No newline at end of file diff --git a/HR.KvkConnector/Properties/Resources.Designer.cs b/HR.KvkConnector/Properties/Resources.Designer.cs new file mode 100644 index 0000000..487daca --- /dev/null +++ b/HR.KvkConnector/Properties/Resources.Designer.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace HR.KvkConnector.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HR.KvkConnector.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] Staat_der_Nederlanden_EV_Root_CA { + get { + object obj = ResourceManager.GetObject("Staat der Nederlanden EV Root CA", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] webservers_kvk_nieuw { + get { + object obj = ResourceManager.GetObject("webservers_kvk_nieuw", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/HR.KvkConnector/Properties/Resources.resx b/HR.KvkConnector/Properties/Resources.resx new file mode 100644 index 0000000..13312bd --- /dev/null +++ b/HR.KvkConnector/Properties/Resources.resx @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\Staat der Nederlanden EV Root CA.crt;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\webservers_kvk_nieuw.crt;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file