55 lines
2.9 KiB
C#
55 lines
2.9 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using TBF.Rig.RegisterReaders.PoseidonCmdStartStop;
|
|
using CmdPoseidonReader = TBF.Rig.RegisterReaders.PoseidonCmdStartStop.PoseidonReader;
|
|
|
|
namespace TBFTests.Rig.RegisterReaders.PoseidonCmdStartStop
|
|
{
|
|
/// <summary>
|
|
/// Regression fixtures extracted from PT50 customer CliRunner responses.
|
|
/// </summary>
|
|
[TestClass]
|
|
public class PoseidonCustomerCliResponseTest
|
|
{
|
|
// Independently calculated fixtures can differ by insignificant
|
|
// IEEE-754 rounding during gallons-to-litres conversion.
|
|
private const double DialogValueToleranceLitres = 0.0001;
|
|
|
|
private const string Com43InitialResponse =
|
|
"{\"Reading\":\"002780.99\",\"DeviceId\":\"1000000219\",\"ProductType\":74,\"ReadingComplete\":true,\"NfcTagDetected\":true,\"CliVersion\":\"2.0.0.2\"}";
|
|
private const string Com45InitialResponse =
|
|
"{\"Reading\":\"002316.63\",\"DeviceId\":\"1000000279\",\"ProductType\":74,\"ReadingComplete\":true,\"NfcTagDetected\":true,\"CliVersion\":\"2.0.0.2\"}";
|
|
private const string Com43LaterResponse =
|
|
"{\"Reading\":\"002898.60\",\"DeviceId\":\"1000000219\",\"ProductType\":74,\"ReadingComplete\":true,\"NfcTagDetected\":true,\"CliVersion\":\"2.0.0.2\"}";
|
|
private const string Com45LaterResponse =
|
|
"{\"Reading\":\"002433.50\",\"DeviceId\":\"1000000279\",\"ProductType\":74,\"ReadingComplete\":true,\"NfcTagDetected\":true,\"CliVersion\":\"2.0.0.2\"}";
|
|
|
|
[TestMethod]
|
|
public void CustomerCliResponses_AreDeserializedAndConvertedToDialogValues()
|
|
{
|
|
AssertDialogValue(Com43InitialResponse, "1000000219", "002780.99", 10527.1923171862);
|
|
AssertDialogValue(Com45InitialResponse, "1000000279", "002316.63", 8769.39850116792);
|
|
AssertDialogValue(Com43LaterResponse, "1000000219", "002898.60", 10972.3945971024);
|
|
AssertDialogValue(Com45LaterResponse, "1000000279", "002433.50", 9211.799576364);
|
|
}
|
|
|
|
private static void AssertDialogValue(string json, string expectedDeviceId,
|
|
string expectedReading, double expectedLitres)
|
|
{
|
|
var cliRunner = new CliRunner(false);
|
|
JsonDataFromPoseidon response;
|
|
|
|
Assert.IsTrue(cliRunner.TryJsonStringDeserialize(json, out response));
|
|
Assert.IsNotNull(response);
|
|
Assert.AreEqual(expectedDeviceId, response.DeviceId);
|
|
Assert.AreEqual(expectedReading, response.Reading);
|
|
|
|
double dialogValue;
|
|
string failureReason;
|
|
Assert.IsTrue(CmdPoseidonReader.TryGetDialogValue(response, out dialogValue, out failureReason), failureReason);
|
|
Assert.AreEqual(expectedLitres, dialogValue, DialogValueToleranceLitres,
|
|
"The value assigned to the START/END dialog must come from the CLI response.");
|
|
Assert.AreNotEqual(0d, dialogValue);
|
|
}
|
|
}
|
|
}
|