2018-10-13 21:28:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using OmniLinkBridge;
|
2022-10-20 22:10:42 +00:00
|
|
|
|
using OmniLinkBridge.MQTT;
|
2018-10-13 21:28:47 +00:00
|
|
|
|
|
|
|
|
|
namespace OmniLinkBridgeTest
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ExtensionTest
|
|
|
|
|
{
|
2019-12-27 18:57:17 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestToCelsius()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(-40, ((double)-40).ToCelsius());
|
|
|
|
|
Assert.AreEqual(0, ((double)32).ToCelsius());
|
|
|
|
|
Assert.AreEqual(50, ((double)122).ToCelsius());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestToOmniTemp()
|
|
|
|
|
{
|
|
|
|
|
// -40C is 0
|
|
|
|
|
double min = -40;
|
|
|
|
|
Assert.AreEqual(0, min.ToOmniTemp());
|
|
|
|
|
|
|
|
|
|
// 87.5C is 255
|
|
|
|
|
double max = 87.5;
|
|
|
|
|
Assert.AreEqual(255, max.ToOmniTemp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestIsBitSet()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(true, ((byte)1).IsBitSet(0));
|
|
|
|
|
Assert.AreEqual(false, ((byte)2).IsBitSet(0));
|
|
|
|
|
Assert.AreEqual(true, ((byte)3).IsBitSet(0));
|
|
|
|
|
Assert.AreEqual(true, ((byte)3).IsBitSet(1));
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-29 00:33:06 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestToCommandCode()
|
|
|
|
|
{
|
2022-10-20 22:10:42 +00:00
|
|
|
|
string payload;
|
|
|
|
|
AreaCommandCode parser;
|
2021-07-29 00:33:06 +00:00
|
|
|
|
|
|
|
|
|
payload = "disarm";
|
2022-10-20 22:10:42 +00:00
|
|
|
|
parser = payload.ToCommandCode(supportValidate: true);
|
|
|
|
|
Assert.AreEqual(parser.Success, true);
|
|
|
|
|
Assert.AreEqual(parser.Command, "disarm");
|
|
|
|
|
Assert.AreEqual(parser.Validate, false);
|
|
|
|
|
Assert.AreEqual(parser.Code, 0);
|
2021-07-29 00:33:06 +00:00
|
|
|
|
|
|
|
|
|
payload = "disarm,1";
|
2022-10-20 22:10:42 +00:00
|
|
|
|
parser = payload.ToCommandCode(supportValidate: true);
|
|
|
|
|
Assert.AreEqual(parser.Success, true);
|
|
|
|
|
Assert.AreEqual(parser.Command, "disarm");
|
|
|
|
|
Assert.AreEqual(parser.Validate, false);
|
|
|
|
|
Assert.AreEqual(parser.Code, 1);
|
|
|
|
|
|
|
|
|
|
payload = "disarm,validate,1234";
|
|
|
|
|
parser = payload.ToCommandCode(supportValidate: true);
|
|
|
|
|
Assert.AreEqual(parser.Success, true);
|
|
|
|
|
Assert.AreEqual(parser.Command, "disarm");
|
|
|
|
|
Assert.AreEqual(parser.Validate, true);
|
|
|
|
|
Assert.AreEqual(parser.Code, 1234);
|
|
|
|
|
|
|
|
|
|
// Falures
|
|
|
|
|
payload = "disarm,1a";
|
|
|
|
|
parser = payload.ToCommandCode(supportValidate: true);
|
|
|
|
|
Assert.AreEqual(parser.Success, false);
|
|
|
|
|
Assert.AreEqual(parser.Command, "disarm");
|
|
|
|
|
Assert.AreEqual(parser.Validate, false);
|
|
|
|
|
Assert.AreEqual(parser.Code, 0);
|
|
|
|
|
|
|
|
|
|
payload = "disarm,validate,";
|
|
|
|
|
parser = payload.ToCommandCode(supportValidate: true);
|
|
|
|
|
Assert.AreEqual(parser.Success, false);
|
|
|
|
|
Assert.AreEqual(parser.Command, "disarm");
|
|
|
|
|
Assert.AreEqual(parser.Validate, true);
|
|
|
|
|
Assert.AreEqual(parser.Code, 0);
|
|
|
|
|
|
|
|
|
|
payload = "disarm,test,1234";
|
|
|
|
|
parser = payload.ToCommandCode(supportValidate: true);
|
|
|
|
|
Assert.AreEqual(parser.Success, false);
|
|
|
|
|
Assert.AreEqual(parser.Command, "disarm");
|
|
|
|
|
Assert.AreEqual(parser.Validate, false);
|
|
|
|
|
Assert.AreEqual(parser.Code, 0);
|
2021-07-29 00:33:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-13 21:28:47 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestParseRange()
|
|
|
|
|
{
|
2019-12-27 18:57:17 +00:00
|
|
|
|
List<int> empty = "".ParseRanges();
|
|
|
|
|
Assert.AreEqual(0, empty.Count);
|
2018-10-13 21:28:47 +00:00
|
|
|
|
|
|
|
|
|
List<int> range = "1-3,5,6".ParseRanges();
|
|
|
|
|
CollectionAssert.AreEqual(new List<int>(new int[] { 1, 2, 3, 5, 6 }), range);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-20 22:10:42 +00:00
|
|
|
|
}
|