135 lines
6.1 KiB
C#
135 lines
6.1 KiB
C#
using DTS.Common.Enums;
|
|
using DTS.Common.Interface.Sensors;
|
|
using DTS.SensorDB;
|
|
using NUnit.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DTS.Common.Import.Tests
|
|
{
|
|
[TestFixture]
|
|
public class CalibrationImportShould
|
|
{
|
|
[Test]
|
|
public void CheckForExcitationCalibration_ShouldReturnSameSensorCalibration_OnEqualExcitation()
|
|
{
|
|
CalibrationImport sut = new CalibrationImport();
|
|
var sensorCalibration = new SensorCalibration();
|
|
var records= NSubstitute.Substitute.For<ICalibrationRecords>();
|
|
var record = NSubstitute.Substitute.For<ICalibrationRecord>();
|
|
record.Excitation = ExcitationVoltageOptions.ExcitationVoltageOption.Volt1;
|
|
records.Records = new List<ICalibrationRecord> { record }.ToArray();
|
|
sensorCalibration.Records = records;
|
|
|
|
var res = sut.CheckForExcitationCalibration(sensorCalibration, 0, ExcitationVoltageOptions.ExcitationVoltageOption.Volt1, "");
|
|
|
|
Assert.That(res, Is.EqualTo(sensorCalibration));
|
|
|
|
}
|
|
|
|
[Test]
|
|
public void CheckForExcitationCalibration_ShouldReturnSameSensorCalibration_OnNotEqualExcitation()
|
|
{
|
|
CalibrationImport sut = new CalibrationImport();
|
|
var sensorCalibration = new SensorCalibration();
|
|
var records = NSubstitute.Substitute.For<ICalibrationRecords>();
|
|
var record = NSubstitute.Substitute.For<ICalibrationRecord>();
|
|
record.Excitation = ExcitationVoltageOptions.ExcitationVoltageOption.Volt2;
|
|
records.Records = new List<ICalibrationRecord> { record }.ToArray();
|
|
sensorCalibration.Records = records;
|
|
|
|
var res = sut.CheckForExcitationCalibration(sensorCalibration, 0, ExcitationVoltageOptions.ExcitationVoltageOption.Volt1, "");
|
|
|
|
Assert.That(res.Records.Records.Count, Is.EqualTo(2));
|
|
|
|
}
|
|
|
|
[Test]
|
|
public void AddLinearCalRecordIfNeeded_ShouldReturnSameSensorCalibrationIfRecordsLengthNot1()
|
|
{
|
|
CalibrationImport sut = new CalibrationImport();
|
|
var sensorCalibration = new SensorCalibration();
|
|
var records = NSubstitute.Substitute.For<ICalibrationRecords>();
|
|
var record = NSubstitute.Substitute.For<ICalibrationRecord>();
|
|
record.Poly = new Classes.Sensors.LinearizationFormula();
|
|
record.Poly.MarkValid(true);
|
|
var record2 = NSubstitute.Substitute.For<ICalibrationRecord>();
|
|
record.Excitation = ExcitationVoltageOptions.ExcitationVoltageOption.Volt2;
|
|
records.Records = new List<ICalibrationRecord> { record,record2 }.ToArray();
|
|
sensorCalibration.Records = records;
|
|
|
|
var res = sut.AddLinearCalRecordIfNeeded(sensorCalibration, false, false);
|
|
|
|
Assert.That(res, Is.EqualTo(sensorCalibration));
|
|
Assert.That(res.Records.Records[0].Poly.IsValid,Is.True);
|
|
|
|
}
|
|
|
|
[Test]
|
|
public void AddLinearCalRecordIfNeeded_ShouldReturnNotValidPolySensorCalibrationIfRecordsLengthIs1()
|
|
{
|
|
CalibrationImport sut = new CalibrationImport();
|
|
var sensorCalibration = new SensorCalibration();
|
|
var records = NSubstitute.Substitute.For<ICalibrationRecords>();
|
|
var record = NSubstitute.Substitute.For<ICalibrationRecord>();
|
|
record.Poly = new Classes.Sensors.LinearizationFormula();
|
|
|
|
record.Excitation = ExcitationVoltageOptions.ExcitationVoltageOption.Volt2;
|
|
records.Records = new List<ICalibrationRecord> { record }.ToArray();
|
|
sensorCalibration.Records = records;
|
|
|
|
var res = sut.AddLinearCalRecordIfNeeded(sensorCalibration, false, false);
|
|
|
|
Assert.That(res, Is.EqualTo(sensorCalibration));
|
|
Assert.That(res.Records.Records[0].Poly.IsValid, Is.False);
|
|
Assert.That(res.Records.Records.Count, Is.EqualTo(2));
|
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void AddLinearZeroMethodIfNeeded_ShouldReturnSameSensorCalibrationIfRecordsLengthNot1()
|
|
{
|
|
CalibrationImport sut = new CalibrationImport();
|
|
var sensorCalibration = new SensorCalibration();
|
|
var records = NSubstitute.Substitute.For<ICalibrationRecords>();
|
|
var record = NSubstitute.Substitute.For<ICalibrationRecord>();
|
|
record.Poly = new Classes.Sensors.LinearizationFormula();
|
|
record.Poly.MarkValid(true);
|
|
var record2 = NSubstitute.Substitute.For<ICalibrationRecord>();
|
|
record.Excitation = ExcitationVoltageOptions.ExcitationVoltageOption.Volt2;
|
|
records.Records = new List<ICalibrationRecord> { record, record2 }.ToArray();
|
|
sensorCalibration.Records = records;
|
|
|
|
var res = sut.AddLinearZeroMethodIfNeeded(sensorCalibration, Common.Enums.Sensors.ZeroMethodType.None, 0,1);
|
|
|
|
Assert.That(res, Is.EqualTo(sensorCalibration));
|
|
Assert.That(res.Records.Records.Count, Is.EqualTo(2));
|
|
|
|
}
|
|
|
|
[Test]
|
|
public void AddLinearZeroMethodIfNeeded_ShouldReturnZeroMethodsMethodsAdded()
|
|
{
|
|
CalibrationImport sut = new CalibrationImport();
|
|
var sensorCalibration = new SensorCalibration();
|
|
var records = NSubstitute.Substitute.For<ICalibrationRecords>();
|
|
var record = NSubstitute.Substitute.For<ICalibrationRecord>();
|
|
record.Poly = new Classes.Sensors.LinearizationFormula();
|
|
|
|
record.Excitation = ExcitationVoltageOptions.ExcitationVoltageOption.Volt2;
|
|
records.Records = new List<ICalibrationRecord> { record }.ToArray();
|
|
sensorCalibration.Records = records;
|
|
|
|
var res = sut.AddLinearZeroMethodIfNeeded(sensorCalibration, Common.Enums.Sensors.ZeroMethodType.None, 0, 1);
|
|
|
|
Assert.That(res, Is.EqualTo(sensorCalibration));
|
|
Assert.That(res.ZeroMethods.Methods.Count, Is.EqualTo(2));
|
|
|
|
}
|
|
}
|
|
}
|