[ADD] test
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SharedClientServer;
|
using SharedClientServer;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Xunit.Sdk;
|
using Xunit.Sdk;
|
||||||
|
|
||||||
@@ -10,6 +12,18 @@ namespace Tests
|
|||||||
[TestClass]
|
[TestClass]
|
||||||
public class JSONConvertTest
|
public class JSONConvertTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private byte[] testArray1()
|
||||||
|
{
|
||||||
|
byte identifier = 0x01;
|
||||||
|
dynamic payload = new
|
||||||
|
{
|
||||||
|
value = "test"
|
||||||
|
};
|
||||||
|
|
||||||
|
byte[] result = JSONConvert.GetMessageToSend(identifier, payload);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestGetMessageToSendLength()
|
public void TestGetMessageToSendLength()
|
||||||
@@ -30,14 +44,34 @@ namespace Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestGetMessageToSendIdentifier()
|
public void TestGetMessageToSendIdentifier()
|
||||||
{
|
{
|
||||||
|
byte[] result = testArray1();
|
||||||
|
Assert.AreEqual(0x01, result[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestGetMessageToSendMessageLength()
|
||||||
|
{
|
||||||
|
|
||||||
byte identifier = 0x01;
|
byte identifier = 0x01;
|
||||||
dynamic payload = new
|
dynamic payload = new
|
||||||
{
|
{
|
||||||
value = "test"
|
value = "test"
|
||||||
};
|
};
|
||||||
|
|
||||||
byte[] result = JSONConvert.GetMessageToSend(identifier, payload);
|
string json = JsonConvert.SerializeObject(payload);
|
||||||
Assert.AreEqual(0x01, result[4]);
|
byte[] payloadBytes = Encoding.UTF8.GetBytes(json);
|
||||||
|
byte[] res = new byte[payloadBytes.Length + 5];
|
||||||
|
Array.Copy(payloadBytes, 0, res, 5, payloadBytes.Length);
|
||||||
|
res[4] = identifier;
|
||||||
|
Array.Copy(BitConverter.GetBytes(payloadBytes.Length + 5), 0, res, 0, 4);
|
||||||
|
int lengthTest = BitConverter.ToInt32(res, 0);
|
||||||
|
byte[] result = testArray1();
|
||||||
|
int lengthResult = BitConverter.ToInt32(result, 0);
|
||||||
|
|
||||||
|
Assert.AreEqual(lengthTest, lengthResult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user