Skip to content
Snippets Groups Projects
Commit f18cce21 authored by Daniel Andrášik's avatar Daniel Andrášik
Browse files

- added man-down batch request

- added wiremock server
parent 91dc5649
No related branches found
No related tags found
No related merge requests found
using Flurl;
using Core.Enum;
using Flurl;
using SDK.Contracts.Communication;
using SDK.Contracts.Data;
using SDK.Exceptions;
using SDK.Models;
using System;
......@@ -21,6 +23,7 @@ namespace tDevkit
return response;
}
public async Task<DeviceContract> GetDevice(int id, string queryString = "")
{
string subUrl = Url.Combine(Address.Devices, Convert.ToString(id), queryString);
......@@ -28,6 +31,7 @@ namespace tDevkit
return response;
}
public async Task<DeviceContract> GetDevice(string login, string queryString = "")
{
string subUrl = Url.Combine(Address.DevicesLogin, login, queryString);
......@@ -35,6 +39,7 @@ namespace tDevkit
return response;
}
public async Task<DynamicDeviceContract[]> GetDynamicDevices(string queryString = "")
{
string subUrl = Url.Combine(Address.DevicesDynamicLocations, queryString);
......@@ -42,6 +47,7 @@ namespace tDevkit
return response;
}
public async Task<DynamicDeviceContract[]> GetDynamicDevicesShort(string queryString = "")
{
string subUrl = Url.Combine(Address.DevicesDynamicLocationsShort, queryString);
......@@ -49,6 +55,7 @@ namespace tDevkit
return response;
}
public async Task<DeviceContract> AddDevice(DeviceContract deviceContract)
{
string subUrl = Address.Devices;
......@@ -59,6 +66,7 @@ namespace tDevkit
return (DeviceContract)response;
}
public async Task<PatchResponseContract> UpdateDevice(DeviceContract deviceContract)
{
if (deviceContract.Id == 0)
......@@ -73,6 +81,7 @@ namespace tDevkit
return response;
}
public async Task<HttpResponseMessage> DeleteDevice(int id)
{
string subUrl = Address.Devices + id;
......@@ -80,6 +89,15 @@ namespace tDevkit
return response;
}
public async Task<ManDownBatchContract[]> ManDownBatch(ManDownBatchContract[] manDownBatchContracts)
{
string subUrl = Address.Devices + "man-down/batch";
var response = await PostRequest<ManDownBatchContract[]>(subUrl, manDownBatchContracts);
return response;
}
public async Task<HttpResponseMessage> RegisterDevice()
{
return null;
......
using SDK.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SDK.Contracts.Communication
{
public class ManDownBatchResponseContract
{
public string Login { get; set; }
public long Timestamp { get; set; }
public ActionType Action { get; set; }
public bool Success { get; set; }
public string ErrorMessage { get; set; }
}
}
using Core.Enum;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace SDK.Contracts.Data
{
[DataContract]
public class ManDownBatchContract
{
[Required]
[StringLength(255)]
[DataMember(Order = 1)]
public string Login { get; set; }
[Required]
[DataMember(Order = 2)]
public long Timestamp { get; set; }
[Required]
[DataMember(Order = 3)]
public FallType FallType { get; set; }
}
}
......@@ -15,6 +15,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
<PackageReference Include="WireMock.Net" Version="1.4.20" />
</ItemGroup>
<ItemGroup>
......
using Main;
using Core.Enum;
using Main;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SDK.Contracts.Communication;
using SDK.Contracts.Data;
using SDK.Enum;
using SDK.Exceptions;
using SDK.Models;
using System;
......@@ -8,12 +12,48 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using tDevkit;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Settings;
namespace Test
{
//(8/9)
public partial class TestClass
[TestClass]
public class DeviceTest
{
private const string URL = "http://localhost:8000";
private static DevkitConnectorV3 devkitConnector;
private static WireMockServer server;
[ClassInitialize]
public static void Init(TestContext context)
{
ConnectionOptionsBuilder optionsBuilder = new ConnectionOptionsBuilder();
ConnectionOptions connectionOptions = optionsBuilder
.Url(URL)
.Client("Infotech")
.ClientGuid("00000000-0000-0000-0000-000000000001")
.BranchGuid("00000000-0000-0000-0000-000000000003")
.Timeout(1000)
.ApiKey("X1fprPtlkvolW1Bl47UQV4SoW8siY3n8QDQkDsGJ")
.Version(ConnectionOptions.VERSION_3)
.Build();
devkitConnector = (DevkitConnectorV3)DevkitFactory.CreateDevkitConnector(connectionOptions);
server = WireMockServer.Start(new WireMockServerSettings()
{
Urls = new[] { URL }
});
}
[ClassCleanup]
public static void Cleanup()
{
server.Stop();
}
[TestMethod]
public async Task Devices1()
{
......@@ -49,19 +89,19 @@ namespace Test
Assert.IsNull(device2);
}
[TestMethod]
public async Task Devices4()
{
DynamicDeviceContract[] device = await devkitConnector.GetDynamicDevices();
Assert.IsNotNull(device[0]);
}
//[TestMethod]
//public async Task Devices4()
//{
// DynamicDeviceContract[] device = await devkitConnector.GetDynamicDevices();
// Assert.IsNotNull(device[0]);
//}
[TestMethod]
public async Task Devices5()
{
DynamicDeviceContract[] device = await devkitConnector.GetDynamicDevicesShort();
Assert.IsNotNull(device[0]);
}
//[TestMethod]
//public async Task Devices5()
//{
// DynamicDeviceContract[] device = await devkitConnector.GetDynamicDevicesShort();
// Assert.IsNotNull(device[0]);
//}
[TestMethod]
public async Task Devices6()
......@@ -122,5 +162,35 @@ namespace Test
{
//Register
}
[TestMethod]
public async Task ManDownBatch()
{
const string device = "Device1";
const long ts = 1000;
var bodyContent = new ManDownBatchResponseContract[] {
new ManDownBatchResponseContract()
{
Login = device,
Timestamp = ts,
Action = ActionType.Create,
Success = true
}
};
server.Given(Request.Create().WithPath("/v3/devices/man-down/batch").UsingPost())
.RespondWith(Response.Create().WithStatusCode(200).WithBodyAsJson(bodyContent));
var response = await devkitConnector.ManDownBatch(new ManDownBatchContract[] {
new ManDownBatchContract()
{
Login = device,
Timestamp = ts,
FallType = FallType.ManDown
}
});
Assert.IsInstanceOfType(response, typeof(ManDownBatchContract[]));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment