137 lines
4.6 KiB
C#
137 lines
4.6 KiB
C#
using System.Reflection;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using JetBrains.Annotations;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Results.Entities;
|
|
using TBF.Rig.RegisterReaders.GenesisRegReader.communication;
|
|
using TBF.Rig.RegisterReaders.GenesisRegReader.implementations;
|
|
using TBF.Rig.TestMethods.GenesisCommunication;
|
|
|
|
namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.communication
|
|
{
|
|
|
|
[TestClass]
|
|
[TestSubject(typeof(OptoHeadTest))]
|
|
public class OptoHeadTestImpelementations
|
|
{
|
|
[TestMethod]
|
|
public void PrepareMeterSizeAndCalibration_CfgNull_SetsDefaultCalibration()
|
|
{
|
|
GenesisSmartReader reader = new GenesisSmartReader();
|
|
|
|
MethodInfo method = typeof(OptoHeadTest).GetMethod(
|
|
"PrepareMeterSizeAndCalibration",
|
|
BindingFlags.NonPublic | BindingFlags.Static);
|
|
|
|
Assert.IsNotNull(method);
|
|
|
|
var task = (Task<string>)method.Invoke(
|
|
null,
|
|
new object[]
|
|
{
|
|
reader,
|
|
null,
|
|
null,
|
|
CancellationToken.None
|
|
});
|
|
|
|
string result = task.GetAwaiter().GetResult();
|
|
|
|
Assert.AreEqual(OptoHeadTest.ResultOk, result);
|
|
Assert.IsNotNull(reader.Q3CalibValue);
|
|
Assert.AreEqual(3, reader.Q3CalibValue.Length);
|
|
|
|
Assert.AreEqual(15625, reader.Q3CalibValue[0]);
|
|
Assert.AreEqual(15625, reader.Q3CalibValue[1]);
|
|
Assert.AreEqual(15625, reader.Q3CalibValue[2]);
|
|
}
|
|
|
|
|
|
|
|
[TestMethod]
|
|
public void PrepareMeterSizeAndCalibration_MeterSize4_TakesCalibrationFromConfiguration()
|
|
{
|
|
GenesisSmartReader reader = new GenesisSmartReader();
|
|
|
|
TestMethodCfg cfg = new TestMethodCfg(null)
|
|
{
|
|
CalibFactor6InchCh1 = 17969,
|
|
CalibFactor6InchCh2 = 17969,
|
|
CalibFactor6InchCh3 = 17969
|
|
};
|
|
|
|
MethodInfo method = typeof(OptoHeadTest).GetMethod(
|
|
"PrepareCalibrationFromMeterSizeRawHex",
|
|
BindingFlags.NonPublic | BindingFlags.Static);
|
|
|
|
Assert.IsNotNull(method);
|
|
|
|
string result = (string)method.Invoke(
|
|
null,
|
|
new object[]
|
|
{
|
|
reader,
|
|
cfg,
|
|
"04"
|
|
});
|
|
|
|
Assert.AreEqual(OptoHeadTest.ResultOk, result);
|
|
Assert.IsNotNull(reader.Q3CalibValue);
|
|
Assert.AreEqual(3, reader.Q3CalibValue.Length);
|
|
|
|
Assert.AreEqual(17969, reader.Q3CalibValue[0]);
|
|
Assert.AreEqual(17969, reader.Q3CalibValue[1]);
|
|
Assert.AreEqual(17969, reader.Q3CalibValue[2]);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void PrepareQ3Calibration_SimulateMode_ReturnsOk()
|
|
{
|
|
Factory factory = new Factory();
|
|
GenesisSmartReader reader = new GenesisSmartReader(factory.DefaultConfig());
|
|
reader.DebugLevel = Common.DebugMode.Simulate;
|
|
|
|
OptoHeadTest optoHeadTest = new OptoHeadTest(reader);
|
|
|
|
string result = optoHeadTest.PrepareQ3Calibration(null, null, null);
|
|
|
|
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(
|
|
OptoHeadTest.ResultOk,
|
|
result);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void PrepareQ3Calibration_TestStoreDB()
|
|
{
|
|
GenesisSmartReader reader = new GenesisSmartReader();
|
|
|
|
Results.Entities.TestRslt tstRslt = new Results.Entities.TestRslt();
|
|
|
|
Assert.IsNotNull(tstRslt.CalibFactorResultsToSave);
|
|
tstRslt.CalibFactorResultsToSave.Clear();
|
|
|
|
Assert.AreEqual(0, tstRslt.CalibFactorResultsToSave.Count);
|
|
|
|
if (tstRslt?.CalibFactorResultsToSave?.Count == 0)
|
|
{
|
|
for (int i = 0; i < reader.ChannelsCount; i++)
|
|
{
|
|
tstRslt.CalibFactorResultsToSave.Add(new TestRsltCalibFactor()
|
|
{
|
|
Stored = false,
|
|
CalibFactorIndex = i
|
|
});
|
|
}
|
|
}
|
|
|
|
Assert.AreEqual(reader.ChannelsCount, tstRslt.CalibFactorResultsToSave.Count);
|
|
|
|
for (int i = 0; i < reader.ChannelsCount; i++)
|
|
{
|
|
Assert.IsFalse(tstRslt.CalibFactorResultsToSave[i].Stored);
|
|
Assert.AreEqual(i, tstRslt.CalibFactorResultsToSave[i].CalibFactorIndex);
|
|
}
|
|
}
|
|
}
|
|
} |