149 lines
4.1 KiB
C#
149 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Common;
|
|
using JetBrains.Annotations;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Results;
|
|
using Results.Entities;
|
|
|
|
|
|
namespace TBFTests
|
|
{
|
|
[TestClass]
|
|
[TestSubject(typeof(DB))]
|
|
public class DBTests
|
|
{
|
|
private string _dbFile;
|
|
private string _dbName;
|
|
|
|
[TestInitialize]
|
|
public void Setup()
|
|
{
|
|
DB.DbType = DBType.MySql;
|
|
DB.ConnectionString =
|
|
"SERVER=localhost; DATABASE=tbf_test; UID=root; PASSWORD=; CHARSET=utf8;";
|
|
|
|
DB.SessionFactory = null;
|
|
|
|
Assert.IsTrue(DB.CreateEmptyDB());
|
|
}
|
|
|
|
[TestCleanup]
|
|
public void Cleanup()
|
|
{
|
|
DB.SessionFactory?.Dispose();
|
|
DB.SessionFactory = null;
|
|
|
|
if (File.Exists(_dbFile))
|
|
File.Delete(_dbFile);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LoadBatch_ExistingBatchNr_ReturnsBatch()
|
|
{
|
|
// ARRANGE
|
|
Batch batch = new Batch
|
|
{
|
|
BatchNr = 1234
|
|
};
|
|
|
|
bool saved = DB.SaveNewBatch(batch);
|
|
Assert.IsTrue(saved);
|
|
|
|
// ACT
|
|
Batch loaded = DB.LoadBatch(1234);
|
|
|
|
// ASSERT
|
|
Assert.IsNotNull(loaded);
|
|
Assert.AreEqual(1234, loaded.BatchNr);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LoadBatch_NotExistingBatchNr_ReturnsNull()
|
|
{
|
|
// ACT
|
|
Batch loaded = DB.LoadBatch(999999);
|
|
|
|
// ASSERT
|
|
Assert.IsNull(loaded);
|
|
}
|
|
|
|
|
|
|
|
[TestMethod]
|
|
public void LoadBatch_LoadsTestRsltCalibFactorResults()
|
|
{
|
|
Batch batch = new Batch
|
|
{
|
|
BatchNr = 2222,
|
|
TestRslts = new List<TestRslt>(),
|
|
WaterMeters = new List<WaterMeter>()
|
|
};
|
|
|
|
TestData testData = new TestData
|
|
{
|
|
Name = "Q3Channel",
|
|
Repeats = 1,
|
|
Method = "SmartCommunication"
|
|
};
|
|
|
|
Components components = new Components();
|
|
|
|
TestRslt testRslt = new TestRslt
|
|
{
|
|
Batch = batch,
|
|
TestData = testData,
|
|
Components = components,
|
|
Part = 1,
|
|
RepetitionNr = 1,
|
|
StartTime = DateTime.Now,
|
|
EndTime = DateTime.Now,
|
|
TestDone = true,
|
|
CalibFactorResultsToSave = new List<TestRsltCalibFactor>
|
|
{
|
|
new TestRsltCalibFactor
|
|
{
|
|
CalibFactorIndex = 1,
|
|
BaseCalibFactor = 15625,
|
|
CalculatedCalibFactor = 17969,
|
|
Stored = true,
|
|
ErrorStr = "OK",
|
|
TimeStart = 1.1,
|
|
TimeEnd = 2.2,
|
|
CalibRawStart = 100,
|
|
CalibRawEnd = 200,
|
|
Error = 0.12,
|
|
VolumeStart = 10,
|
|
VolumeEnd = 20
|
|
}
|
|
}
|
|
};
|
|
|
|
batch.TestRslts.Add(testRslt);
|
|
|
|
bool saved = DB.SaveNewBatch(batch);
|
|
Assert.IsTrue(saved);
|
|
|
|
Batch loaded = DB.LoadBatch(2222);
|
|
|
|
Assert.IsNotNull(loaded);
|
|
Assert.IsNotNull(loaded.TestRslts);
|
|
Assert.AreEqual(1, loaded.TestRslts.Count);
|
|
|
|
TestRslt loadedTestRslt = loaded.TestRslts[0];
|
|
|
|
Assert.IsNotNull(loadedTestRslt.CalibFactorResultsToSave);
|
|
Assert.AreEqual(1, loadedTestRslt.CalibFactorResultsToSave.Count);
|
|
|
|
TestRsltCalibFactor loadedCalib =
|
|
loadedTestRslt.CalibFactorResultsToSave[0];
|
|
|
|
Assert.AreEqual(1, loadedCalib.CalibFactorIndex);
|
|
Assert.AreEqual(15625, loadedCalib.BaseCalibFactor);
|
|
Assert.AreEqual(17969, loadedCalib.CalculatedCalibFactor);
|
|
Assert.IsTrue(loadedCalib.Stored);
|
|
Assert.AreEqual("OK", loadedCalib.ErrorStr);
|
|
}
|
|
}
|
|
} |