Compare commits
21 Commits
gethistori
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2e1c90c16 | ||
|
|
86a8b2b789 | ||
|
|
aa2e16de89 | ||
|
|
b112fc131e | ||
|
|
6725f2ff85 | ||
|
|
89fe104418 | ||
|
|
2177f9bd19 | ||
|
|
28dc2c2f9c | ||
|
|
cd1a95ae85 | ||
|
|
cad1a508e6 | ||
|
|
06e1d1edee | ||
|
|
7c98aa6536 | ||
|
|
d6cf5902da | ||
|
|
c1ee84fd2e | ||
|
|
9f7a01170b | ||
|
|
4207eaefea | ||
|
|
acc2fddf82 | ||
|
|
a333d6cd8d | ||
|
|
c48e396e81 | ||
|
|
4af7b3bc44 | ||
|
|
3dc1709943 |
@@ -21,7 +21,7 @@ namespace ClientApp.Utils
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int totalBufferReceived = 0;
|
||||
public EngineConnection engineConnection;
|
||||
private bool sessionRunning = false;
|
||||
private bool sessionRunning = true;
|
||||
private IHandler handler = null;
|
||||
private LoginViewModel LoginViewModel;
|
||||
|
||||
@@ -146,6 +146,7 @@ namespace ClientApp.Utils
|
||||
case DataParser.STOP_SESSION:
|
||||
Console.WriteLine("Stop session identifier");
|
||||
this.sessionRunning = false;
|
||||
stopBikeInSimulation();
|
||||
Debug.WriteLine("stop");
|
||||
break;
|
||||
case DataParser.SET_RESISTANCE:
|
||||
@@ -230,14 +231,12 @@ namespace ClientApp.Utils
|
||||
}
|
||||
byte[] message = DataParser.GetRawBPMDataMessageServer(bytes);
|
||||
|
||||
if (engineConnection.Connected && engineConnection.FollowingRoute)
|
||||
if (engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute)
|
||||
{
|
||||
engineConnection.BikeBPM = bytes[1];
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
this.stream?.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -256,21 +255,29 @@ namespace ClientApp.Utils
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawBikeDataMessageServer(bytes);
|
||||
bool canSendToEngine = engineConnection.Connected && engineConnection.FollowingRoute;
|
||||
bool canSendToEngine = engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute && this.sessionRunning;
|
||||
switch (bytes[0])
|
||||
{
|
||||
|
||||
case 0x10:
|
||||
|
||||
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
||||
else if (engineConnection != null) engineConnection.BikeSpeed = 0;
|
||||
break;
|
||||
case 0x19:
|
||||
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||
else if (engineConnection != null) engineConnection.BikePower = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
this.stream?.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
private void stopBikeInSimulation()
|
||||
{
|
||||
engineConnection.BikeSpeed = 0;
|
||||
engineConnection.BikePower = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace ClientApp.Utils
|
||||
Write("Starting route follow...");
|
||||
FollowingRoute = true;
|
||||
|
||||
SendMessageAndOnResponse(mainCommand.AddBikeModelAnim("bikeID", 0.01f), "bikeID",
|
||||
SendMessageAndOnResponse(mainCommand.AddBikeModel("bikeID"), "bikeID",
|
||||
(message) =>
|
||||
{
|
||||
bikeId = JSONParser.GetResponseUuid(message);
|
||||
|
||||
@@ -99,13 +99,13 @@ namespace DoctorApp.ViewModels
|
||||
{
|
||||
//TODO
|
||||
//Parsen van de data you fuck
|
||||
PatientInfo.BPM = bytes[1];
|
||||
if (bytes[0] == 0x00)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
PatientInfo.BPM = bytes[1];
|
||||
if (MySelectedItem == "BPM")
|
||||
{
|
||||
Chart.NewValue(PatientInfo.BPM);
|
||||
|
||||
@@ -52,13 +52,15 @@ namespace DoctorApp.ViewModels
|
||||
public void TransferDataToClientBike(byte[] bytes)
|
||||
{
|
||||
string username = DataParser.getNameFromBytesBike(bytes);
|
||||
foreach(ClientInfoViewModel item in Tabs)
|
||||
foreach (ClientInfoViewModel item in Tabs)
|
||||
{
|
||||
if(item.PatientInfo.Username == username)
|
||||
if (item.PatientInfo.Username == username)
|
||||
{
|
||||
item.BikeData(DataParser.getDataWithoutName(bytes,0,8));
|
||||
item.BikeData(DataParser.getDataWithoutName(bytes, 0, 8));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Debug.WriteLine("[MainViewModel] did not find client (bike) username is " + username);
|
||||
}
|
||||
|
||||
public void TransferDataToClientBPM(byte[] bytes)
|
||||
@@ -68,9 +70,11 @@ namespace DoctorApp.ViewModels
|
||||
{
|
||||
if (item.PatientInfo.Username == username)
|
||||
{
|
||||
item.BikeData(DataParser.getDataWithoutName(bytes, 0,2));
|
||||
item.BPMData(DataParser.getDataWithoutName(bytes, 0, 2));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Debug.WriteLine("[MainViewModel] did not find client (bpm) username is " + username);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<UserControl x:Class="DoctorApp.Views.ClientInfoView"
|
||||
<UserControl x:Class="DoctorApp.Views.ClientInfoView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
@@ -44,7 +44,7 @@
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
|
||||
<TextBox Name="textBox_Resistance" Text="{Binding Path=PatientInfo.Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentSpeed" Text="{Binding Path=PatientInfo.Speed}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentSpeed" Text="{Binding Path=PatientInfo.Speed, StringFormat=N2}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentBPM" Text="{Binding Path=PatientInfo.BPM}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False">
|
||||
|
||||
@@ -298,7 +298,6 @@ namespace Util
|
||||
|
||||
private static byte[] GetRawDataDoctor(byte[] payload, string username, byte messageID)
|
||||
{
|
||||
Debug.WriteLine(BitConverter.ToString(Encoding.ASCII.GetBytes(username)));
|
||||
byte[] nameArray = Encoding.ASCII.GetBytes(username);
|
||||
byte[] total = new byte[nameArray.Length + payload.Length];
|
||||
Array.Copy(payload, 0, total, 0, payload.Length);
|
||||
@@ -422,7 +421,6 @@ namespace Util
|
||||
/// <returns>the response of the message, so wether it was successful or not.</returns>
|
||||
public static bool getResistanceFromResponseJson(byte[] json)
|
||||
{
|
||||
Debug.WriteLine("got message " + Encoding.ASCII.GetString(json));
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "..\Server\Server.
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DoctorApp", "..\DoctorApp\DoctorApp.csproj", "{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestRH", "..\UnitTestRH\UnitTestRH.csproj", "{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B} = {BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}
|
||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE} = {7D751284-17E8-434C-A7F6-2EB37572E7AE}
|
||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F} = {7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994} = {A232F2D5-AF98-4777-BF3A-FBDDFBC02994}
|
||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3} = {C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
..\Hashing\Hashing.projitems*{0b6ccc1d-5e76-420e-b54d-eb3e5ffea6cb}*SharedItemsImports = 5
|
||||
..\Hashing\Hashing.projitems*{70277749-d423-4871-b692-2efc5a6ed932}*SharedItemsImports = 13
|
||||
..\Hashing\Hashing.projitems*{7d751284-17e8-434c-a7f6-2eb37572e7ae}*SharedItemsImports = 5
|
||||
..\Hashing\Hashing.projitems*{7ef854c1-73eb-4099-a7d7-057cceee6f8f}*SharedItemsImports = 5
|
||||
@@ -47,6 +57,10 @@ Global
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace RH_Engine
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
|
||||
private string showOnPanel(string uuidPanel, string serialCode, string mText, int index)
|
||||
public string showOnPanel(string uuidPanel, string serialCode, string mText, int index)
|
||||
{
|
||||
dynamic payload = new
|
||||
{
|
||||
|
||||
@@ -129,7 +129,8 @@ namespace Server
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
this.communication.StartSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
||||
this.timer.Start();
|
||||
if (communication.Doctor != this)
|
||||
this.timer.Start();
|
||||
break;
|
||||
case DataParser.STOP_SESSION:
|
||||
this.communication.StopSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
||||
@@ -169,7 +170,9 @@ namespace Server
|
||||
Array.Copy(this.BikeDataBuffer, 0, this.BikeDataBuffer, 8, 8);
|
||||
Array.Copy(payloadbytes, 0, this.BikeDataBuffer, 0, 8);
|
||||
}
|
||||
//this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(payloadbytes, this.username));
|
||||
if (this.username != null)
|
||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(payloadbytes, this.username));
|
||||
|
||||
}
|
||||
else if (DataParser.isRawDataBPMServer(message))
|
||||
{
|
||||
@@ -179,8 +182,9 @@ namespace Server
|
||||
{
|
||||
Array.Copy(payloadbytes, 0, this.BPMDataBuffer, 0, 2);
|
||||
}
|
||||
//this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(payloadbytes, this.username));
|
||||
}
|
||||
if (this.username != null)
|
||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(payloadbytes, this.username));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -207,7 +211,7 @@ namespace Server
|
||||
Debug.WriteLine("[SERVER CLIENT] excetion while trying to get raw bike data: " + e.Message);
|
||||
}
|
||||
|
||||
Debug.WriteLine("[SERVER CLIENT] about to send " +sb.ToString());
|
||||
Debug.WriteLine("[SERVER CLIENT] about to send " + sb.ToString());
|
||||
communication.Doctor.sendMessage(DataParser.GetFileMessage(File.ReadAllBytes(path)));
|
||||
}
|
||||
|
||||
@@ -316,6 +320,7 @@ namespace Server
|
||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(this.BPMDataBuffer, this.username));
|
||||
}
|
||||
this.timer.Start();
|
||||
Debug.WriteLine("[serverclient] send bike and bpm data timer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
418
UnitTestRH/CommandTest.cs
Normal file
418
UnitTestRH/CommandTest.cs
Normal file
@@ -0,0 +1,418 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ProftaakRH;
|
||||
using RH_Engine;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace UnitTestRH
|
||||
{
|
||||
[TestClass]
|
||||
public class CommandTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void TerrainAdd_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/terrain/add";
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
|
||||
|
||||
int[] terrainSizeArray = new int[2] { 4, 4 };
|
||||
float[] terrainHeightsArray = new float[16] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
string terrainAddCommand = command.TerrainAdd(terrainSizeArray, terrainHeightsArray, testSerial);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test terrain
|
||||
JArray jArrayTerrainSize = (JArray)json.data.data.data.size;
|
||||
JArray jArrayTerrainHeights = (JArray)json.data.data.data.heights;
|
||||
|
||||
int[] outSizeArray = jArrayTerrainSize.Select(ja => (int)ja).ToArray();
|
||||
float[] outHeightsArray = jArrayTerrainHeights.Select(ja => (float)ja).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(terrainSizeArray, outSizeArray);
|
||||
CollectionAssert.AreEqual(terrainHeightsArray, json.data.data.data.heights.ToObject<float[]>());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddLayer_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/node/addlayer";
|
||||
|
||||
|
||||
string testUuid = "dummyUuid";
|
||||
string diffuseExpected = @"data\NetworkEngine\textures\terrain\grass_green_d.jpg";
|
||||
string normalExpected = @"data\NetworkEngine\textures\terrain\grass_green_n.jpg";
|
||||
int minHeightExpected = 0;
|
||||
int maxHeightExpected = 10;
|
||||
int fadeDistExpected = 1;
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.AddLayer(testUuid, testSerial);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test AddLayer
|
||||
Assert.AreEqual(testUuid, (string)json.data.data.data.id);
|
||||
Assert.AreEqual(diffuseExpected, (string)json.data.data.data.diffuse);
|
||||
Assert.AreEqual(normalExpected, (string)json.data.data.data.normal);
|
||||
Assert.AreEqual(minHeightExpected, (int)json.data.data.data.minHeight);
|
||||
Assert.AreEqual(maxHeightExpected, (int)json.data.data.data.maxHeight);
|
||||
Assert.AreEqual(fadeDistExpected, (int)json.data.data.data.fadeDist);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UpdateTerrain_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/terrain/update";
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.UpdateTerrain();
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void renderTerrain_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/node/add";
|
||||
|
||||
|
||||
string nameExpected = "newNode";
|
||||
int[] positionExpected = new int[] { -80, 0, -80 };
|
||||
float scaleExpected = 1f;
|
||||
int[] rotationExpected = new int[] { 0, 0, 0 };
|
||||
|
||||
bool smoothnormalsExpected = true;
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.renderTerrain(testSerial);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(nameExpected, (string)json.data.data.data.name);
|
||||
|
||||
//Test data components
|
||||
|
||||
//Test transform
|
||||
JArray jArrayPosition = (JArray)json.data.data.data.components.transform.position;
|
||||
JArray jArrayRotation = (JArray)json.data.data.data.components.transform.rotation;
|
||||
|
||||
int[] outPositionArray = jArrayPosition.Select(ja => (int)ja).ToArray();
|
||||
int[] outRotationArray = jArrayRotation.Select(ja => (int)ja).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(positionExpected, outPositionArray);
|
||||
CollectionAssert.AreEqual(rotationExpected, outRotationArray);
|
||||
|
||||
|
||||
//Test terrain
|
||||
Assert.AreEqual(smoothnormalsExpected, (bool)json.data.data.data.components.terrain.smoothnormals);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteNode_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/node/delete";
|
||||
|
||||
string uuid = "dummyUuid";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.DeleteNode(uuid, testSerial);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void addPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/node/add";
|
||||
|
||||
string uuidBike = "dummyUuidBike";
|
||||
|
||||
string nameExpected = "dashboard";
|
||||
|
||||
//components
|
||||
//transform
|
||||
float[] positionExpected = new float[] { -1.5f, 1f, 0f };
|
||||
int scaleExpected = 1;
|
||||
int[] rotationExpected = new int[] { -30, 90, 0 };
|
||||
|
||||
//panel
|
||||
int[] sizeExpected = new int[] { 1, 1 };
|
||||
int[] resolutionExpected = new int[] { 512, 512 };
|
||||
int[] backgroundExpected = new int[] { 1, 1, 1, 1 };
|
||||
bool castShadowExpected = false;
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.addPanel(testSerial, uuidBike);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(nameExpected, (string)json.data.data.data.name);
|
||||
Assert.AreEqual(uuidBike, (string)json.data.data.data.parent);
|
||||
|
||||
//Test components
|
||||
|
||||
//Test transform
|
||||
JArray jArrayPosition = (JArray)json.data.data.data.components.transform.position;
|
||||
JArray jArrayRotation = (JArray)json.data.data.data.components.transform.rotation;
|
||||
|
||||
float[] outPositionArray = jArrayPosition.Select(ja => (float)ja).ToArray();
|
||||
int[] outRotationArray = jArrayRotation.Select(ja => (int)ja).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(positionExpected, outPositionArray);
|
||||
CollectionAssert.AreEqual(rotationExpected, outRotationArray);
|
||||
|
||||
Assert.AreEqual(scaleExpected, (int)json.data.data.data.components.transform.scale);
|
||||
|
||||
//Test panel
|
||||
CollectionAssert.AreEqual(sizeExpected, ((JArray)json.data.data.data.components.panel.size).Select(ja => (int)ja).ToArray());
|
||||
CollectionAssert.AreEqual(resolutionExpected, ((JArray)json.data.data.data.components.panel.resolution).Select(ja => (int)ja).ToArray());
|
||||
CollectionAssert.AreEqual(backgroundExpected, ((JArray)json.data.data.data.components.panel.background).Select(ja => (int)ja).ToArray());
|
||||
Assert.AreEqual(castShadowExpected, (bool)json.data.data.data.components.panel.castShadow);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ColorPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/setclearcolor";
|
||||
|
||||
string uuidPanel = "dummyUuidPanel";
|
||||
|
||||
float[] colorExpected = new float[] { 0f, 0f, 0f, 0f };
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.ColorPanel(uuidPanel);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuidPanel, (string)json.data.data.data.id);
|
||||
CollectionAssert.AreEqual(colorExpected, ((JArray)json.data.data.data.color).Select(ja => (float)ja).ToArray());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SwapPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/swap";
|
||||
|
||||
string uuid = "dummyUuid";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.SwapPanel(uuid);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void showOnPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/drawtext";
|
||||
|
||||
string uuidPanel = "dummyUuidPanel";
|
||||
string text = "dummyText";
|
||||
int index = 3;
|
||||
int[] positionExpected = new int[] { 4, 24 + index * 32 };
|
||||
double sizeExpected = 32.0;
|
||||
int[] colorExpected = new int[] { 0, 0, 0, 1 };
|
||||
string fontExpected = "segoeui";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.showOnPanel(uuidPanel, testSerial, text, index);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuidPanel, (string)json.data.data.data.id);
|
||||
Assert.AreEqual(text, (string)json.data.data.data.text);
|
||||
CollectionAssert.AreEqual(positionExpected, ((JArray)json.data.data.data.position).Select(ja => (int)ja).ToArray());
|
||||
Assert.AreEqual(sizeExpected, (double)json.data.data.data.size);
|
||||
CollectionAssert.AreEqual(colorExpected, ((JArray)json.data.data.data.color).Select(ja => (int)ja).ToArray());
|
||||
Assert.AreEqual(fontExpected, (string)json.data.data.data.font);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SwapPanelCommand_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/swap";
|
||||
|
||||
string uuid = "dummyUuid";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.SwapPanelCommand(uuid);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClearPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/clear";
|
||||
|
||||
string uuid = "dummyUuid";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.ClearPanel(uuid);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test terrain
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
74
UnitTestRH/DataParserTest.cs
Normal file
74
UnitTestRH/DataParserTest.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json;
|
||||
using RH_Engine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Util;
|
||||
|
||||
namespace UnitTestRH
|
||||
{
|
||||
[TestClass]
|
||||
public class DataParserTest
|
||||
{
|
||||
|
||||
public byte[] GetPayload(byte[] message)
|
||||
{
|
||||
byte[] payload = new byte[message.Length - 5];
|
||||
Array.Copy(message, 5, payload, 0, message.Length - 5);
|
||||
return payload;
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestGetMessageToSend()
|
||||
{
|
||||
byte[] toTest = DataParser.GetMessageToSend("test");
|
||||
|
||||
dynamic res = JsonConvert.DeserializeObject(Encoding.ASCII.GetString((toTest)));
|
||||
Assert.AreEqual("MESSAGE", (string)res.identifier);
|
||||
Assert.AreEqual("test", (string)res.data.message);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestIsRawDataBikeServer()
|
||||
{
|
||||
byte[] testArr = { 0x34,0x00,0x00,0x00,0x02};
|
||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x02,0x49,0x65 };
|
||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBikeServer(testArr));
|
||||
Assert.IsTrue(DataParser.isRawDataBikeServer(testArr2));
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestIsRawDataBikeDoctor()
|
||||
{
|
||||
byte[] testArr = { 0x34, 0x00, 0x00, 0x00, 0x04 };
|
||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x04, 0x49, 0x65 };
|
||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBikeDoctor(testArr));
|
||||
Assert.IsTrue(DataParser.isRawDataBikeDoctor(testArr2));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestIsRawDataBPMServer()
|
||||
{
|
||||
byte[] testArr = { 0x34, 0x00, 0x00, 0x00, 0x03};
|
||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x03, 0x49, 0x65 };
|
||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBPMServer(testArr));
|
||||
Assert.IsTrue(DataParser.isRawDataBPMServer(testArr2));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestIsRawDataBPMDoctor()
|
||||
{
|
||||
byte[] testArr = { 0x34, 0x00, 0x00, 0x00, 0x05 };
|
||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x05, 0x49, 0x65 };
|
||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBPMDoctor(testArr));
|
||||
Assert.IsTrue(DataParser.isRawDataBPMDoctor(testArr2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
26
UnitTestRH/UnitTestRH.csproj
Normal file
26
UnitTestRH/UnitTestRH.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ClientApp\ClientApp.csproj" />
|
||||
<ProjectReference Include="..\DoctorApp\DoctorApp.csproj" />
|
||||
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
||||
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
|
||||
<ProjectReference Include="..\Server\Server.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user