diff --git a/README.md b/README.md index 38fb1712054d7fc65578c965d778b8ddba47b1e9..ac33cb72374eedb98e04535912c606e1c2027665 100644 --- a/README.md +++ b/README.md @@ -215,9 +215,20 @@ await devkitConnector.AddSensorData(sensorContracts); * **Layers** * `GetLayers()` - Get all layers * `GetLayer(id)` - Get layer by ID + * `GetNoGoLayers()` - Get all NoGo Layers + * `GetLocalizationLayers(deviceLogin)` - Get all localization layers for specified device + * `AddLayer(layerContract)` - Add a layer with specified properties + * `UpdateLayer(layerContract)` - Update an existing layer with new properties + * `DeleteLayer(id)` - Delete an existing layer by ID * **Localization** * `AddLocalizationData(deviceLocationContract)` - Add localization data for multiple devices in batch mode * `AddLocalizationData(locationContract)` - Add localization data for single device (in order to do this you need to be **authenticated** as said device - this can be avoided when using the batch mode above - [Example](#localization)) +* **Quantities** + * `GetQuantities()` - Get all quantities + * `GetQuantity(id)` - Get quantity by ID + * `AddQuantity(quantityContract)` - Add a quantity with specified properties + * `UpdateQuantity(quantityContract)` - Update an existing quantity with new properties + * `DeleteQuantity(id)` - Delete an existing quantity by ID * **Sectors** * `GetSectors()` - Get all sectors * `GetSector(id)` - Get sector by ID diff --git a/SDK/Connection/V3/Quantities.cs b/SDK/Connection/V3/Quantities.cs new file mode 100644 index 0000000000000000000000000000000000000000..6cdae78165987722136434f6c8f3ab6d5ab74ecf --- /dev/null +++ b/SDK/Connection/V3/Quantities.cs @@ -0,0 +1,39 @@ +using SDK.Models; +using System; +using System.Threading.Tasks; + +namespace SDK +{ + //(2/2) + public partial class DevkitConnectorV3 + { + public async Task<QuantityContract[]> GetQuantities(string queryString = "") + { + string subUrl = Address.UrlCombine(Address.Quantities, queryString); + return await GetRequest<QuantityContract[]>(subUrl); + } + public async Task<QuantityContract> GetQuantity(int id, string queryString = "") + { + string subUrl = Address.UrlCombine(Address.Quantities, Convert.ToString(id), queryString); + return await GetRequest<QuantityContract>(subUrl); + } + + public async Task<QuantityContract> AddQuantity(QuantityContract Quantity) + { + string subUrl = Address.UrlCombine(Address.Quantities); + return await PostRequest<QuantityContract>(subUrl, Quantity); + } + + public async Task UpdateQuantity(QuantityContract Quantity) + { + string subUrl = Address.UrlCombine(Address.Quantities, Convert.ToString(Quantity.Id)); + await PatchRequest<QuantityContract>(subUrl, Quantity); + } + + public async Task DeleteQuantity(int id) + { + string subUrl = Address.UrlCombine(Address.Quantities, Convert.ToString(id)); + await DeleteRequest(subUrl); + } + } +} diff --git a/SDK/Contracts/Data/QuantityContract.cs b/SDK/Contracts/Data/QuantityContract.cs new file mode 100644 index 0000000000000000000000000000000000000000..d3bc01647294a17422daf77b1b9cc85a94d78677 --- /dev/null +++ b/SDK/Contracts/Data/QuantityContract.cs @@ -0,0 +1,47 @@ +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; + +namespace SDK.Models +{ + [DataContract] + public class QuantityContract + { + [DataMember(Order = 1)] + public int Id { get; set; } + + [DataMember(Order = 2)] + public int BranchId { get; set; } + + [DataMember(Order = 3)] + [StringLength(255)] + public string Title { get; set; } + + [DataMember(Order = 4)] + public RangeContract Range { get; set; } + } + + [DataContract] + public class RangeContract + { + [Required] + [DataMember(Order = 1)] + public string Type { get; set; } + + [Required] + [DataMember(Order = 2)] + public RangesContract[] Ranges { get; set; } + } + + + [DataContract] + public class RangesContract + { + [Required] + [DataMember(Order = 1)] + public string Color { get; set; } + + [Required] + [DataMember(Order = 2)] + public string Value { get; set; } + } +} diff --git a/SDK/Helpers/Address.cs b/SDK/Helpers/Address.cs index eb9c36190b8524cc2fdcece3672921d3532264ad..be67972cd1c0fb4a0e3bf66c145c379bedcccc20 100644 --- a/SDK/Helpers/Address.cs +++ b/SDK/Helpers/Address.cs @@ -69,6 +69,8 @@ namespace SDK.Models public const string UtilsUnityLastVersion = "utils/unity-last-version/"; public const string UtilsUnityBundleInfo = "utils/unity-bundle-info/"; + public const string Quantities = "quantities/"; + public static string UrlCombine(params string[] items) { if (items?.Any() != true) diff --git a/SDK/SDK.csproj b/SDK/SDK.csproj index 3aa8f8a11ecd64ffbad8149e791d470efca3ed20..4f14aaadb77a833b1e32b3f1804e0a8ad1f56df0 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.3.0</Version> + <Version>5.4.0</Version> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> </PropertyGroup> diff --git a/Test/Test/TestData/Areas.cs b/Test/Test/TestData/Areas.cs index 7d20f4632e1af32cb3ccac48a07d079ee30c3d1f..bedddd29ff86b7efa40b43440b82683910e7a329 100644 --- a/Test/Test/TestData/Areas.cs +++ b/Test/Test/TestData/Areas.cs @@ -3,12 +3,13 @@ using System; namespace Test.TestData { - public static partial class TestData + public static class Areas { public static AreaContract GetArea() { return new AreaContract { + Id = 1, BranchId = 1, Guid = Guid.NewGuid(), Title = "area1", diff --git a/Test/Test/TestData/Beacons.cs b/Test/Test/TestData/Beacons.cs index 093f973a6768603d8f59cae5df8011cbbade5f80..3ad14dcd9b8cd78ce9102967f744bac969c994a0 100644 --- a/Test/Test/TestData/Beacons.cs +++ b/Test/Test/TestData/Beacons.cs @@ -2,7 +2,7 @@ namespace Test.TestData { - public static partial class TestData + public static class Beacons { public static BeaconContract GetBeacon() { diff --git a/Test/Test/TestData/Devices.cs b/Test/Test/TestData/Devices.cs index e569ee6db69b50038b5886e4fc4a98f4bc141dba..5d0b1a20e06fcee58b1e90d131d79d67cce3e454 100644 --- a/Test/Test/TestData/Devices.cs +++ b/Test/Test/TestData/Devices.cs @@ -1,11 +1,14 @@ using Core.Enum; using Microsoft.AspNetCore.Http; +using SDK.Contracts.Communication; using SDK.Contracts.Data; +using SDK.Enum; using SDK.Models; +using System; namespace Test.TestData { - public static partial class TestData + public static class Devices { public static DeviceContract GetDevice() { @@ -26,6 +29,43 @@ namespace Test.TestData }; } + public static DeviceContract[] GetDevices() + { + return new DeviceContract[] + { + new DeviceContract + { + Mac = "00:00:00:00:00:00", + BranchId = 1, + SectorId = 1, + Login = "sdk-device", + Title = "sdk-device", + X = 10.0, + Y = 10.0, + IsMoving = false, + FallStatus = FallType.OK, + DeviceTypeId = 8, + Position = false, + Geofence = false + }, + new DeviceContract + { + Mac = "00:00:00:00:00:01", + BranchId = 1, + SectorId = 1, + Login = "sdk-device", + Title = "sdk-device", + X = 10.0, + Y = 10.0, + IsMoving = false, + FallStatus = FallType.OK, + DeviceTypeId = 8, + Position = false, + Geofence = false + } + }; + } + public static DeviceLocationContract[] GetLocalizationDataBatch() { DistanceContract[] distanceContract1 = new[] @@ -69,5 +109,38 @@ namespace Test.TestData X = 0, Y = 0, Z = 0, Interval = 300, Distances = distanceContract1 }, }; } + + public static ManDownResponseContract GetManDownDataContract() + { + return new ManDownResponseContract() + { + Login = "device", + Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Action = ActionType.Create, + Success = true + }; + } + + public static ManDownResponseContract[] GetManDownDataContracts() + { + return new[] + { + new ManDownResponseContract() + { + Login = "device1", + Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Action = ActionType.Create, + Success = true + }, + new ManDownResponseContract() + { + Login = "device1", + Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(), + Action = ActionType.Create, + Success = true + } + }; + } + } } diff --git a/Test/Test/TestData/Layers.cs b/Test/Test/TestData/Layers.cs new file mode 100644 index 0000000000000000000000000000000000000000..abbbcf973bf34389b512083becd5f24e957035d1 --- /dev/null +++ b/Test/Test/TestData/Layers.cs @@ -0,0 +1,36 @@ +using SDK.Contracts.Data; + +namespace Test.TestData +{ + public static class Layers + { + public static LayerContract GetLayer() + { + return new LayerContract + { + Id = 1, + Title = "layer1", + BranchId = 1, + }; + } + + public static LayerContract[] GetLayers() + { + return new[] + { + new LayerContract + { + Id = 1, + Title = "layer1", + BranchId = 1, + }, + new LayerContract + { + Id = 2, + Title = "layer2", + BranchId = 1, + } + }; + } + } +} diff --git a/Test/Test/TestData/Quantities.cs b/Test/Test/TestData/Quantities.cs new file mode 100644 index 0000000000000000000000000000000000000000..269153e68fda891c21ea7ee00ac7b23226a24bdc --- /dev/null +++ b/Test/Test/TestData/Quantities.cs @@ -0,0 +1,87 @@ +using SDK.Models; + +namespace Test.TestData +{ + public static class Quantities + { + public static QuantityContract GetQuantity() + { + return new QuantityContract() + { + Id = 1, + BranchId = 1, + Title = "quantity", + Range = new RangeContract + { + Type = "type", + Ranges = new[] + { + new RangesContract + { + Color = "color", + Value = "value" + }, + new RangesContract + { + Color = "color", + Value = "value" + } + } + } + }; + } + + public static QuantityContract[] GetQuantities() + { + return new[] + { + new QuantityContract + { + Id = 1, + BranchId = 1, + Title = "quantity1", + Range = new RangeContract + { + Type = "type", + Ranges = new[] + { + new RangesContract + { + Color = "color", + Value = "value" + }, + new RangesContract + { + Color = "color", + Value = "value" + } + } + } + }, + new QuantityContract + { + Id = 2, + BranchId = 1, + Title = "quantity2", + Range = new RangeContract + { + Type = "type", + Ranges = new[] + { + new RangesContract + { + Color = "color", + Value = "value" + }, + new RangesContract + { + Color = "color", + Value = "value" + } + } + } + } + }; + } + } +} diff --git a/Test/Test/TestData/Sectors.cs b/Test/Test/TestData/Sectors.cs index e2e219f0618e96b9ac2e4b366c2752d771eab224..e5c8678cc9bdba464031c52870d0cb19b9d406f3 100644 --- a/Test/Test/TestData/Sectors.cs +++ b/Test/Test/TestData/Sectors.cs @@ -2,7 +2,7 @@ namespace Test.TestData { - public static partial class TestData + public static class Sectors { public static SectorContract GetSector() { diff --git a/Test/Test/TestData/Sensors.cs b/Test/Test/TestData/Sensors.cs index 967eb21815654705539903df450ae037d596c1d7..03a13bb30ce1aaba57d2ebdf4083636471c64167 100644 --- a/Test/Test/TestData/Sensors.cs +++ b/Test/Test/TestData/Sensors.cs @@ -3,7 +3,7 @@ using SDK.Models; namespace Test.TestData { - public static partial class TestData + public static class Sensors { public static SensorContract GetSensor() { diff --git a/Test/Test/TestData/Shifts.cs b/Test/Test/TestData/Shifts.cs index 950e5843a8d3fa2764a8057bd196d9dbab9964f5..07a99558ce9492c7b0ba3c25e317fe9672516370 100644 --- a/Test/Test/TestData/Shifts.cs +++ b/Test/Test/TestData/Shifts.cs @@ -2,14 +2,15 @@ namespace Test.TestData { - public static partial class TestData + public static class Shifts { public static ShiftContract GetShift() { return new ShiftContract { - BranchId = 1, + Id = 1, Title = "shift1", + BranchId = 1, StartTime = 1599644652178, StopTime = 1599644652178 }; @@ -21,6 +22,7 @@ namespace Test.TestData { new ShiftContract { + Id = 1, BranchId = 1, Title = "shift1", StartTime = 1599644652178, @@ -28,6 +30,7 @@ namespace Test.TestData }, new ShiftContract { + Id = 2, BranchId = 1, Title = "shift2", StartTime = 1599644652178, diff --git a/Test/Test/V3/Areas.cs b/Test/Test/V3/Areas.cs index 29c7f24b28d9625ad662eb97fbf4982dd2de23a4..058d2fb968e767f1526ec58537a4f7e9b3881949 100644 --- a/Test/Test/V3/Areas.cs +++ b/Test/Test/V3/Areas.cs @@ -16,16 +16,7 @@ namespace Test.V3 [TestMethod] public async Task GetAreas_ShouldReturnAreas() { - var bodyContent = new AreaContract() - { - Id = 1, - BranchId = 1, - Guid = Guid.NewGuid(), - Title = "area1", - Description = "description", - SectorId = 1, - LayerId = 1, - }; + var bodyContent = TestData.Areas.GetArea(); server.Given(Request.Create().WithPath(PATH_BASE + AREAS).UsingGet()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(new AreaContract[] { bodyContent })); @@ -39,22 +30,11 @@ namespace Test.V3 [TestMethod] public async Task GetArea_ShouldReturnArea() { - const int Id = 1; - var bodyContent = new AreaContract() - { - Id = 1, - BranchId = 1, - Guid = Guid.NewGuid(), - Title = "area1", - Description = "description", - SectorId = 1, - LayerId = 1, - }; - - server.Given(Request.Create().WithPath(PATH_BASE + AREAS + "/" + Id).UsingGet()) - .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); + server.Given(Request.Create().WithPath(PATH_BASE + AREAS + "/1").UsingGet()) + .RespondWith(Response.Create().WithStatusCode(200) + .WithBodyAsJson(TestData.Areas.GetArea())); - AreaContract response = await devkitConnector.GetArea(1); + var response = await devkitConnector.GetArea(1); Assert.IsInstanceOfType(response, typeof(AreaContract)); } @@ -62,16 +42,7 @@ namespace Test.V3 [TestMethod] public async Task AddArea_ShouldReturnArea() { - var bodyContent = new AreaContract() - { - Id = 1, - BranchId = 1, - Guid = Guid.NewGuid(), - Title = "area1", - Description = "description", - SectorId = 1, - LayerId = 1, - }; + var bodyContent = TestData.Areas.GetArea(); server.Given(Request.Create().WithPath(PATH_BASE + AREAS).UsingPost()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); @@ -84,16 +55,7 @@ namespace Test.V3 [TestMethod] public async Task UpdateArea_ShouldReturn200() { - var bodyContent = new AreaContract() - { - Id = 1, - BranchId = 1, - Guid = Guid.NewGuid(), - Title = "area1", - Description = "description", - SectorId = 1, - LayerId = 1, - }; + var bodyContent = TestData.Areas.GetArea(); server.Given(Request.Create().WithPath(PATH_BASE + AREAS + "/" + bodyContent.Id).UsingPatch()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); @@ -107,19 +69,9 @@ namespace Test.V3 public async Task DeleteArea_ShouldReturn200() { const int Id = 1; - var bodyContent = new AreaContract() - { - Id = 1, - BranchId = 1, - Guid = Guid.NewGuid(), - Title = "area1", - Description = "description", - SectorId = 1, - LayerId = 1, - }; server.Given(Request.Create().WithPath(PATH_BASE + AREAS + "/" + Id).UsingDelete()) - .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); + .RespondWith(Response.Create().WithStatusCode(200)); await devkitConnector.DeleteArea(Id); Assert.IsTrue(true); diff --git a/Test/Test/V3/Devices.cs b/Test/Test/V3/Devices.cs index d935767eef74bed01626ccfb618a2a9668d7a130..472750a38d8f9dcd3f2d2774a31e0c6e7789f7fe 100644 --- a/Test/Test/V3/Devices.cs +++ b/Test/Test/V3/Devices.cs @@ -36,9 +36,7 @@ namespace Test.V3 [TestMethod] public async Task GetDevice_GetAllDevices_ShouldReturn200() { - var bodyContent = new DeviceContract[] { - new DeviceContract(){ } - }; + var bodyContent = TestData.Devices.GetDevices(); server.Reset(); server.Given(Request.Create().WithPath(PATH_BASE + DEVICES).UsingGet()) @@ -54,10 +52,7 @@ namespace Test.V3 public async Task GetDevice_GetDeviceById_ShouldReturn200() { const int Id = 3; - var bodyContent = new DeviceContract() - { - Id = Id - }; + var bodyContent = TestData.Devices.GetDevice(); server.Given(Request.Create().WithPath(PATH_BASE + DEVICES + "/" + Id).UsingGet()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); @@ -72,10 +67,7 @@ namespace Test.V3 public async Task GetDevice_GetDeviceByLogin_ShouldReturn200() { const string Login = "login"; - var bodyContent = new DeviceContract() - { - Login = Login - }; + var bodyContent = TestData.Devices.GetDevice(); server.Given(Request.Create().WithPath(PATH_BASE + DEVICES + "/login/" + Login).UsingGet()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); @@ -90,10 +82,7 @@ namespace Test.V3 public async Task AddDevice_AddDevice_ShouldReturn200() { const string Login = "login"; - var bodyContent = new DeviceContract() - { - Login = Login - }; + var bodyContent = TestData.Devices.GetDevice(); server.Given(Request.Create().WithPath(PATH_BASE + DEVICES).UsingPost()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); @@ -109,13 +98,9 @@ namespace Test.V3 { const int Id = 1; - var bodyContent = new DeviceContract() - { - Id = Id - }; server.Given(Request.Create().WithPath(PATH_BASE + DEVICES + "/" + Id).UsingDelete()) - .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); + .RespondWith(Response.Create().WithStatusCode(200)); await devkitConnector.DeleteDevice(Id); } @@ -126,13 +111,7 @@ namespace Test.V3 { const string device = "Device1"; const long ts = 1000; - var bodyContent = new ManDownResponseContract() - { - Login = device, - Timestamp = ts, - Action = ActionType.Create, - Success = true - }; + var bodyContent = TestData.Devices.GetManDownDataContract(); server.Given(Request.Create().WithPath(PATH_BASE + DEVICES + "/man-down").UsingPost()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); @@ -154,15 +133,7 @@ namespace Test.V3 const string PATH = PATH_BASE + DEVICES + "/man-down/batch"; const string device = "Device1"; const long ts = 1000; - var bodyContent = new ManDownResponseContract[] { - new ManDownResponseContract() - { - Login = device, - Timestamp = ts, - Action = ActionType.Create, - Success = true - } - }; + var bodyContent = TestData.Devices.GetManDownDataContracts(); server.Given(Request.Create().WithPath(PATH).UsingPost()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); diff --git a/Test/Test/V3/Layers.cs b/Test/Test/V3/Layers.cs index da4ded08d7d3326ed3e26f597aca895116ab2105..570308fd3b3b53866eca3700ef7c9ea095b4d9d9 100644 --- a/Test/Test/V3/Layers.cs +++ b/Test/Test/V3/Layers.cs @@ -13,41 +13,29 @@ namespace Test.V3 [TestCategory("Layer")] [TestMethod] - public async Task GetLocalizationLayers_ShouldReturnLayers() + public async Task GetLocalizationLayersForDevice_ShouldReturnLayers() { - var bodyContent = new LoginContract() - { - Login = "login" - }; + var deviceLogin = "device1"; - server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + "/localization").UsingPost()) + server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + $"/localization/{deviceLogin}").UsingGet()) .RespondWith(Response.Create().WithStatusCode(200) - .WithBodyAsJson( - new LayerContract[] { - new LayerContract(){ - Id = 1, - } - })); - - var response = await devkitConnector.GetLocalizationLayers(bodyContent); + .WithBodyAsJson(TestData.Layers.GetLayers())); + + var response = await devkitConnector.GetLocalizationLayers(deviceLogin); Assert.IsInstanceOfType(response, typeof(LayerContract[])); } [TestCategory("Layer")] [TestMethod] - public async Task GetNoGoLayers_ShouldReturnLayers() + public async Task GetNoGoLayersForDevice_ShouldReturnLayers() { - server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + "/device/login").UsingGet()) + var deviceLogin = "device1"; + + server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + $"/device/{deviceLogin}").UsingGet()) .RespondWith(Response.Create().WithStatusCode(200) - .WithBodyAsJson(new LayerContract[] - { - new LayerContract() - { - Id = 1, - } - })); - - var response = await devkitConnector.GetNoGoLayers("login"); + .WithBodyAsJson(TestData.Layers.GetLayers())); + + var response = await devkitConnector.GetNoGoLayers(deviceLogin); Assert.IsInstanceOfType(response, typeof(LayerContract[])); } @@ -57,13 +45,7 @@ namespace Test.V3 { server.Given(Request.Create().WithPath(PATH_BASE + LAYERS).UsingGet()) .RespondWith(Response.Create().WithStatusCode(200) - .WithBodyAsJson(new LayerContract[] - { - new LayerContract() - { - Id = 1, - } - })); + .WithBodyAsJson(TestData.Layers.GetLayers())); var response = await devkitConnector.GetLayers(); Assert.IsInstanceOfType(response, typeof(LayerContract[])); @@ -75,10 +57,7 @@ namespace Test.V3 { server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + "/1").UsingGet()) .RespondWith(Response.Create().WithStatusCode(200) - .WithBodyAsJson(new LayerContract() - { - Id = 1, - })); + .WithBodyAsJson(TestData.Layers.GetLayer())); var response = await devkitConnector.GetLayer(1); Assert.IsInstanceOfType(response, typeof(LayerContract)); @@ -86,14 +65,12 @@ namespace Test.V3 public async Task AddLayer_ShouldReturnLayer() { - var layer = new LayerContract() - { - Id = 1, - }; + ; + var layer = TestData.Layers.GetLayer(); server.Given(Request.Create().WithPath(PATH_BASE + LAYERS).UsingPost()) .RespondWith(Response.Create().WithStatusCode(200) - .WithBodyAsJson(layer)); + .WithBodyAsJson(layer)); var response = await devkitConnector.AddLayer(layer); Assert.IsInstanceOfType(response, typeof(LayerContract)); @@ -103,14 +80,11 @@ namespace Test.V3 [TestMethod] public async Task UpdateLayer_ShouldReturnOk() { - var layer = new LayerContract() - { - Id = 1, - }; + var layer = TestData.Layers.GetLayer(); server.Given(Request.Create().WithPath(PATH_BASE + LAYERS + "/1").UsingPatch()) .RespondWith(Response.Create().WithStatusCode(200) - .WithBodyAsJson(layer)); + .WithBodyAsJson(layer)); await devkitConnector.UpdateLayer(layer); } diff --git a/Test/Test/V3/Quantities.cs b/Test/Test/V3/Quantities.cs new file mode 100644 index 0000000000000000000000000000000000000000..9eadc3c12b1bc09f9a714ce3cae11bfd2f728e5d --- /dev/null +++ b/Test/Test/V3/Quantities.cs @@ -0,0 +1,80 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SDK.Models; +using System.Threading.Tasks; +using WireMock.RequestBuilders; +using WireMock.ResponseBuilders; + +namespace Test.V3 +{ + [TestClass] + public class Quantities : Requests + { + const string QUANTITIES = "quantities"; + + [TestCategory("Quantities")] + [TestMethod] + public async Task GetQuantity_ShouldReturnQuantityContract() + { + const int Id = 1; + var bodyContent = TestData.Quantities.GetQuantity(); + + server.Given(Request.Create().WithPath(PATH_BASE + QUANTITIES + "/" + Id).UsingGet()) + .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); + + QuantityContract response = await devkitConnector.GetQuantity(1); + Assert.IsInstanceOfType(response, typeof(QuantityContract)); + } + + [TestCategory("Quantities")] + [TestMethod] + public async Task GetQuantities_ShouldReturnQuantityContracts() + { + var bodyContent = TestData.Quantities.GetQuantities(); + + server.Given(Request.Create().WithPath(PATH_BASE + QUANTITIES).UsingGet()) + .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); + + QuantityContract[] response = await devkitConnector.GetQuantities(); + + Assert.IsInstanceOfType(response, typeof(QuantityContract[])); + } + + [TestCategory("Quantities")] + [TestMethod] + public async Task AddQuantity_ShouldReturnQuantityContract() + { + var bodyContent = TestData.Quantities.GetQuantity(); + + server.Given(Request.Create().WithPath(PATH_BASE + QUANTITIES).UsingPost()) + .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); + + QuantityContract response = await devkitConnector.AddQuantity(bodyContent); + Assert.IsInstanceOfType(response, typeof(QuantityContract)); + } + + [TestCategory("Quantities")] + [TestMethod] + public async Task UpdateQuantity() + { + var bodyContent = TestData.Quantities.GetQuantity(); + + server.Given(Request.Create().WithPath(PATH_BASE + QUANTITIES + "/" + bodyContent.Id).UsingPatch()) + .RespondWith(Response.Create().WithStatusCode(200)); + + await devkitConnector.UpdateQuantity(bodyContent); + Assert.IsTrue(true); + } + + [TestCategory("Quantities")] + [TestMethod] + public async Task DeleteQuantity() + { + const int Id = 1; + server.Given(Request.Create().WithPath(PATH_BASE + QUANTITIES + "/" + Id).UsingDelete()) + .RespondWith(Response.Create().WithStatusCode(200)); + + await devkitConnector.DeleteQuantity(Id); + Assert.IsTrue(true); + } + } +} diff --git a/Test/Test/V3/Sectors.cs b/Test/Test/V3/Sectors.cs index 5b782ab29c3eb61fe9fe15a70d18b67f6b4d8269..e90e871c9f76c43c1f35969feee2064abc7290dc 100644 --- a/Test/Test/V3/Sectors.cs +++ b/Test/Test/V3/Sectors.cs @@ -16,11 +16,7 @@ namespace Test.V3 [TestMethod] public async Task GetSector_GetDeviceByLogin_ShouldReturn200() { - var bodyContent = new SectorContract() - { - Id = 1, - Guid = Guid.NewGuid(), - }; + var bodyContent = TestData.Sectors.GetSector(); server.Given(Request.Create().WithPath(PATH_BASE + SECTORS).UsingGet()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(new SectorContract[] { bodyContent })); diff --git a/Test/Test/V3/Shifts.cs b/Test/Test/V3/Shifts.cs index 84866186e8fddd7b451c1da64239f08cbde63324..9388b0d27ba2c5782d54ccda2967d1860f0c362c 100644 --- a/Test/Test/V3/Shifts.cs +++ b/Test/Test/V3/Shifts.cs @@ -16,14 +16,7 @@ namespace Test.V3 public async Task GetShift_ShouldReturnShiftContract() { const int Id = 1; - var bodyContent = new ShiftContract() - { - Id = 1, - BranchId = 1, - StartTime = 1599644652178, - StopTime = 1599644652178, - Title = "shift1" - }; + var bodyContent = TestData.Shifts.GetShift(); server.Given(Request.Create().WithPath(PATH_BASE + SHIFTS + "/" + Id).UsingGet()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); @@ -36,25 +29,7 @@ namespace Test.V3 [TestMethod] public async Task GetShifts_ShouldReturnShiftContracts() { - var bodyContent = new ShiftContract[] - { - new ShiftContract - { - Id = 1, - BranchId = 1, - StartTime = 1599644652178, - StopTime = 1599644652178, - Title = "shift1" - }, - new ShiftContract - { - Id = 2, - BranchId = 1, - StartTime = 1599644652178, - StopTime = 1599644652178, - Title = "shift2" - } - }; + var bodyContent = TestData.Shifts.GetShifts(); server.Given(Request.Create().WithPath(PATH_BASE + SHIFTS).UsingGet()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); @@ -68,14 +43,7 @@ namespace Test.V3 [TestMethod] public async Task AddShift_ShouldReturnShiftContract() { - var bodyContent = new ShiftContract - { - Id = 1, - BranchId = 1, - StartTime = 1599644652178, - StopTime = 1599644652178, - Title = "shift1" - }; + var bodyContent = TestData.Shifts.GetShift(); server.Given(Request.Create().WithPath(PATH_BASE + SHIFTS).UsingPost()) .RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent)); @@ -88,14 +56,7 @@ namespace Test.V3 [TestMethod] public async Task UpdateShift() { - var bodyContent = new ShiftContract - { - Id = 1, - BranchId = 1, - StartTime = 1599644652178, - StopTime = 1599644652178, - Title = "shift1" - }; + var bodyContent = TestData.Shifts.GetShift(); server.Given(Request.Create().WithPath(PATH_BASE + SHIFTS + "/" + bodyContent.Id).UsingPatch()) .RespondWith(Response.Create().WithStatusCode(200));