From ad4e6d9c8721af61df91b48bae57e194cb13c56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Pa=C5=A1ko?= <patrik.pasko@twinzo.eu> Date: Wed, 17 Jul 2024 06:45:12 +0000 Subject: [PATCH] - added generic requests --- README.md | 3 ++ SDK/Connection/V3/Layers.cs | 20 +++++++ SDK/SDK.csproj | 2 +- Test/Test/V3/Layers.cs | 101 +++++++++++++++++++++++++++++++++--- 4 files changed, 119 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 006fb0d..38fb171 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,9 @@ await devkitConnector.AddSensorData(sensorContracts); * **Areas** * `GetAreas()` - Get all areas * `GetArea(id)` - Get area by ID + * `AddArea(areaContract)` - Add an area with specified properties + * `UpdateArea(areaContract)` - Update an existing area with new properties + * `DeleteArea(id)` - Delete an existing area by ID * **Authorization** * `Authenticate(login, password)` - Authenticate with login and password as user/device/sensor * **Beacons** diff --git a/SDK/Connection/V3/Layers.cs b/SDK/Connection/V3/Layers.cs index ff91eb3..5fb8842 100644 --- a/SDK/Connection/V3/Layers.cs +++ b/SDK/Connection/V3/Layers.cs @@ -47,5 +47,25 @@ namespace SDK return response; } + + public async Task<LayerContract> AddLayer(LayerContract layer) + { + string subUrl = Address.UrlCombine(Address.Layers); + var response = await PostRequest<LayerContract>(subUrl, layer); + + return response; + } + + public async Task UpdateLayer(LayerContract layer) + { + string subUrl = Address.UrlCombine(Address.Layers, Convert.ToString(layer.Id)); + await PatchRequest<LayerContract>(subUrl, layer); + } + + public async Task DeleteLayer(int id) + { + string subUrl = Address.UrlCombine(Address.Layers, Convert.ToString(id)); + await DeleteRequest(subUrl); + } } } diff --git a/SDK/SDK.csproj b/SDK/SDK.csproj index 437f3bd..3aa8f8a 100644 --- a/SDK/SDK.csproj +++ b/SDK/SDK.csproj @@ -5,7 +5,7 @@ <TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks> <AssemblyVersion>2021.6.28.25</AssemblyVersion> <FileVersion>2021.6.28.25</FileVersion> - <Version>5.2.0</Version> + <Version>5.3.0</Version> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> </PropertyGroup> diff --git a/Test/Test/V3/Layers.cs b/Test/Test/V3/Layers.cs index 7578b27..da4ded0 100644 --- a/Test/Test/V3/Layers.cs +++ b/Test/Test/V3/Layers.cs @@ -21,19 +21,108 @@ namespace Test.V3 }; server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + "/localization").UsingPost()) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBodyAsJson(new LayerContract[] { + .RespondWith(Response.Create().WithStatusCode(200) + .WithBodyAsJson( + new LayerContract[] { new LayerContract(){ Id = 1, } - }) - ); + })); var response = await devkitConnector.GetLocalizationLayers(bodyContent); + Assert.IsInstanceOfType(response, typeof(LayerContract[])); + } + + [TestCategory("Layer")] + [TestMethod] + public async Task GetNoGoLayers_ShouldReturnLayers() + { + server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + "/device/login").UsingGet()) + .RespondWith(Response.Create().WithStatusCode(200) + .WithBodyAsJson(new LayerContract[] + { + new LayerContract() + { + Id = 1, + } + })); + var response = await devkitConnector.GetNoGoLayers("login"); Assert.IsInstanceOfType(response, typeof(LayerContract[])); } + + [TestCategory("Layer")] + [TestMethod] + public async Task GetLayers_ShouldReturnLayers() + { + server.Given(Request.Create().WithPath(PATH_BASE + LAYERS).UsingGet()) + .RespondWith(Response.Create().WithStatusCode(200) + .WithBodyAsJson(new LayerContract[] + { + new LayerContract() + { + Id = 1, + } + })); + + var response = await devkitConnector.GetLayers(); + Assert.IsInstanceOfType(response, typeof(LayerContract[])); + } + + [TestCategory("Layer")] + [TestMethod] + public async Task GetLayer_ShouldReturnLayer() + { + server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + "/1").UsingGet()) + .RespondWith(Response.Create().WithStatusCode(200) + .WithBodyAsJson(new LayerContract() + { + Id = 1, + })); + + var response = await devkitConnector.GetLayer(1); + Assert.IsInstanceOfType(response, typeof(LayerContract)); + } + + public async Task AddLayer_ShouldReturnLayer() + { + var layer = new LayerContract() + { + Id = 1, + }; + + server.Given(Request.Create().WithPath(PATH_BASE + LAYERS).UsingPost()) + .RespondWith(Response.Create().WithStatusCode(200) + .WithBodyAsJson(layer)); + + var response = await devkitConnector.AddLayer(layer); + Assert.IsInstanceOfType(response, typeof(LayerContract)); + } + + [TestCategory("Layer")] + [TestMethod] + public async Task UpdateLayer_ShouldReturnOk() + { + var layer = new LayerContract() + { + Id = 1, + }; + + server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + "/1").UsingPatch()) + .RespondWith(Response.Create().WithStatusCode(200) + .WithBodyAsJson(layer)); + + await devkitConnector.UpdateLayer(layer); + } + + [TestCategory("Layer")] + [TestMethod] + public async Task DeleteLayer_ShouldReturnOk() + { + server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + "/1").UsingDelete()) + .RespondWith(Response.Create().WithStatusCode(200)); + + await devkitConnector.DeleteLayer(1); + } } } -- GitLab