init
This commit is contained in:
1
DataPRO/UnitTest/.svn/entries
Normal file
1
DataPRO/UnitTest/.svn/entries
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
1
DataPRO/UnitTest/.svn/format
Normal file
1
DataPRO/UnitTest/.svn/format
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
@@ -0,0 +1,94 @@
|
||||
using DTS.Common.Classes.Channels;
|
||||
using DTS.Common.Interface.Channels;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
[Test]
|
||||
public void TestChannelsInsert()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var channel = CreateFakeChannel();
|
||||
//var hr = DbAPI.DbAPI.Channels.ChannelsInsert();
|
||||
//Assert.AreEqual(0, hr, "ChannelsInsert should return 0");
|
||||
//Assert.IsTrue(channel.Id > 0, "Inserted channel Id should be > 0");
|
||||
var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out var channels);
|
||||
Assert.AreEqual(0, hr, "ChannelsGet should return 0 for inserted channel");
|
||||
Assert.IsTrue(null != channels && 1 == channels.Length, "ChannelsGet should return 1 channel");
|
||||
|
||||
//hr = DbAPI.DbAPI.Channels.ChannelsDelete();
|
||||
//Assert.AreEqual(0, hr, "ChannelsDelete should return 0 for inserted channel");
|
||||
hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out channels);
|
||||
Assert.IsTrue(0 == hr && (null == channels || 0 == channels.Length), "Channel should no longer return 0 from ChannelsGet");
|
||||
}
|
||||
[Test]
|
||||
public void TestChannelsUpdate()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var channel = CreateFakeChannel();
|
||||
//var hr = DbAPI.DbAPI.Channels.ChannelsUpdate();
|
||||
//Assert.AreEqual(0, hr, "ChannelsUpdate should return 0");
|
||||
//Assert.IsTrue(channel.Id > 0, "Updated channel Id should be > 0");
|
||||
var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out var channels);
|
||||
Assert.AreEqual(0, hr, "ChannelsGet should return 0 for updated channel");
|
||||
Assert.IsTrue(null != channels && 1 == channels.Length, "ChannelsGet should return 1 channel");
|
||||
|
||||
//hr = DbAPI.DbAPI.Channels.ChannelsDelete();
|
||||
//Assert.AreEqual(0, hr, "ChannelsDelete should return 0 for inserted channel");
|
||||
hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out channels);
|
||||
Assert.IsTrue(0 == hr && (null == channels || 0 == channels.Length), "Channel should no longer return 0 from ChannelsGet");
|
||||
}
|
||||
[Test]
|
||||
public void TestChannelsGet()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var channel = CreateFakeChannel();
|
||||
//var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), channel);
|
||||
//Assert.AreEqual(0, hr, "ChannelsGet should return 0");
|
||||
//Assert.IsTrue(channel.Id > 0, "Channel Id should be > 0");
|
||||
var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out var channels);
|
||||
Assert.AreEqual(0, hr, "ChannelsGet should return 0 for inserted channel");
|
||||
Assert.IsTrue(null != channels && 1 == channels.Length, "ChannelsGet should return 1 channel");
|
||||
|
||||
//hr = DbAPI.DbAPI.Channels.ChannelsDelete();
|
||||
//Assert.AreEqual(0, hr, "ChannelsDelete should return 0 for inserted channel");
|
||||
hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out channels);
|
||||
Assert.IsTrue(0 == hr && (null == channels || 0 == channels.Length), "Channel should no longer return 0 from ChannelsGet");
|
||||
}
|
||||
[Test]
|
||||
public void TestChannelsDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var channel = CreateFakeChannel();
|
||||
//var hr = DbAPI.DbAPI.Channels.ChannelsDelete();
|
||||
//Assert.AreEqual(0, hr, "ChannelsDelete should return 0");
|
||||
//Assert.IsTrue(channel.Id > 0, "Updated channel Id should be > 0");
|
||||
var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out var channels);
|
||||
Assert.IsTrue(0 == hr, "ChannelsGet should return 0");
|
||||
Assert.IsTrue(null == channels || 0 == channels.Length, "ChannelsGet should return no channel");
|
||||
}
|
||||
|
||||
private IChannelDbRecord CreateFakeChannel()
|
||||
{
|
||||
//var group = CreateFakeGroup();
|
||||
|
||||
var channel = new ChannelDbRecord();
|
||||
//channel.GroupId = group.Id;
|
||||
channel.LastModified = DateTime.Now;
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using DTS.Common.Classes.Hardware;
|
||||
using DTS.Common.Classes.Sensors;
|
||||
using DTS.Common.Enums.Sensors;
|
||||
using DTS.Common.Interface.Sensors;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
[Test]
|
||||
public void TestSensorsDeleteAll()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var sensor = CreateFakeSensor();
|
||||
var hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogUpdateInsert should return 0");
|
||||
Assert.IsTrue(sensor.Id > 0, "Inserted sensor Id should be > 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out var records);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogGet should return 0 for inserted sensor");
|
||||
Assert.IsTrue(null != records && 1 == records.Length, "SensorsAnalogGet should return 1 sensor");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDeleteAll(_user, connections.First());
|
||||
Assert.AreEqual(0, hr, "SensorsDeleteAll should return 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, null, null, out records);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogGet should return 0");
|
||||
Assert.IsTrue(null != records && records.Any(), "After SensorsAnalogDelete test specific A and C should exist");
|
||||
Assert.IsTrue(records.Any(record => record.SerialNumber == SensorConstants.TEST_SPECIFIC_ANALOG_SERIAL)
|
||||
&& records.Any(record => record.SerialNumber == SensorConstants.TEST_SPECIFIC_CLOCK_SERIAL),
|
||||
"TSA and TSC should still exist after delete");
|
||||
}
|
||||
[Test]
|
||||
public void TestSensorsAnalogInsertAndDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var sensor = CreateFakeSensor();
|
||||
var hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogUpdateInsert should return 0");
|
||||
Assert.IsTrue(sensor.Id > 0, "Inserted sensor Id should be > 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out var records);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogGet should return 0 for inserted sensor");
|
||||
Assert.IsTrue(null != records && 1 == records.Length, "SensorsAnalogGet should return 1 sensor");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, connections.First(), sensor.Id, 0);
|
||||
Assert.AreEqual(0, hr, "SensorsDelete should return 0 for inserted sensor");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out records);
|
||||
Assert.IsTrue(0 == hr && (null == records || 0 == records.Length), "Sensor should no longer return from SensorsAnalogGet");
|
||||
}
|
||||
[Test]
|
||||
public void TestSensorAnalogInsertAndDeleteShouldFail()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var sensor = CreateFakeSensor();
|
||||
var hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(null, connections.First(), sensor);
|
||||
Assert.AreNotEqual(0, hr, "SensorsAnalogUpdateInsert should fail without user");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, null, sensor);
|
||||
Assert.AreNotEqual(0, hr, "SensorsAnalogUpdateInsert should fail without connect");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogUpdateInsert should return 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(null, connections.First(), sensor.Id, 0);
|
||||
Assert.AreNotEqual(0, hr, "SensorsDelete should fail without user");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, null, sensor.Id, 0);
|
||||
Assert.AreNotEqual(0, hr, "SensorsDelete should fail without connection");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, connections.First(), sensor.Id, 0);
|
||||
}
|
||||
[Test]
|
||||
public void TestSensorsAnalogBridgeResistanceGet()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var sensor = CreateFakeSensor();
|
||||
var hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogUpdateInsert should return 0");
|
||||
Assert.IsTrue(sensor.Id > 0, "Inserted sensor Id should be > 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out var records);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogGet should return 0 for inserted sensor");
|
||||
Assert.IsTrue(null != records && 1 == records.Length, "SensorsAnalogGet should return 1 sensor");
|
||||
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogBridgeResistanceGet(_user, connections.First(), sensor.SerialNumber, out var resistance);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogBridgeResistanceGet returns 0");
|
||||
Assert.AreEqual(resistance, FAKE_BRIDGE_RESISTANCE_OMS, "BridgeResistance returns the same as was set");
|
||||
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, connections.First(), sensor.Id, 0);
|
||||
Assert.AreEqual(0, hr, "SensorsDelete should return 0 for inserted sensor");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out records);
|
||||
Assert.IsTrue(0 == hr && (null == records || 0 == records.Length), "Sensor should no longer return from SensorsAnalogGet");
|
||||
}
|
||||
|
||||
|
||||
private const double FAKE_BRIDGE_RESISTANCE_OMS = 350;
|
||||
private IAnalogDbRecord CreateFakeSensor()
|
||||
{
|
||||
var sensor = new AnalogDbRecord();
|
||||
sensor.Created = DateTime.Now;
|
||||
sensor.LastModified = DateTime.Now;
|
||||
sensor.EId = "";
|
||||
sensor.SerialNumber = new Guid().ToString();
|
||||
sensor.BridgeResistance = FAKE_BRIDGE_RESISTANCE_OMS;
|
||||
return sensor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
using DTS.Common.Classes.TestSetups;
|
||||
using DTS.Common.Interface.RegionOfInterest;
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
using DTS.Common.Storage;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public ITestSetupRecord CreateFakeTestSetupWithROIs(int numberOfROIs)
|
||||
{
|
||||
var record = new TestSetupRecord();
|
||||
record.Id = -1;
|
||||
record.Name = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.TestEngineerDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.Settings = "";
|
||||
|
||||
var regionsOfInterestList = new System.ComponentModel.BindingList<IRegionOfInterest>();
|
||||
|
||||
var start = 0D;
|
||||
var end = 0D;
|
||||
for (int i = 0; i < numberOfROIs; i++)
|
||||
{
|
||||
var channelNameList = new List<string>();
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
start = -1D;
|
||||
end = 1D;
|
||||
channelNameList.Add("an1");
|
||||
channelNameList.Add("an2");
|
||||
channelNameList.Add("an3");
|
||||
break;
|
||||
case 1:
|
||||
start = -0.9D;
|
||||
end = 0.9D;
|
||||
channelNameList.Add("an1");
|
||||
channelNameList.Add("an2");
|
||||
break;
|
||||
}
|
||||
var regionOfInterest = CreateRegionOfInterest($"_ROI Period {i + 1}", start, end, true, true);
|
||||
regionOfInterest.ChannelNames = channelNameList.ToArray();
|
||||
regionsOfInterestList.Add(regionOfInterest);
|
||||
}
|
||||
|
||||
record.RegionsOfInterest = regionsOfInterestList;
|
||||
|
||||
return record;
|
||||
}
|
||||
public IRegionOfInterest CreateRegionOfInterest(string suffix, double start, double end, bool isEnabled, bool isDefault)
|
||||
{
|
||||
var record = new RegionOfInterest();
|
||||
record.Suffix = suffix;
|
||||
record.Start = start;
|
||||
record.End = end;
|
||||
record.IsEnabled = isEnabled;
|
||||
record.IsDefault = isDefault;
|
||||
|
||||
return record;
|
||||
}
|
||||
/// <summary>
|
||||
/// Tests included:
|
||||
/// sp_TestSetupsUpdateInsert_92 (and sp_TestSetupsInsert_92)
|
||||
/// sp_TestSetupROIsInsert
|
||||
/// sp_TestSetupROIsGet
|
||||
/// sp_TestSetupsDeleteManyById
|
||||
/// sp_TestSetupsGet_92
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetupROIsGetOneROI()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//***Testing*** sp_TestSetupsUpdateInsert_92
|
||||
var testSetupRecordToInsert = CreateFakeTestSetupWithROIs(1);
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 92, ref testSetupRecordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
|
||||
DbAPI.DbAPI.GetDatabaseVersion(connections[0], out int serverDbVersion);
|
||||
if (serverDbVersion <= 91)
|
||||
{
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out var testSetupROIId);
|
||||
Assert.IsTrue(0 != hr, "RegionsOfInterestInsert should not work if database Version is 91 or less");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
//***Testing*** sp_TestSetupROIsInsert
|
||||
var regionOfInterest = CreateRegionOfInterest("", -1, 1, true, true);
|
||||
var testSetupROIId = -1;
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out testSetupROIId);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a record in the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIId > 0, "A TestSetupROIId should have been generated and returned");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsGet
|
||||
var testSetupROIRecords = new DTS.Common.Interface.TestSetups.ITestSetupROIRecord[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, connections[0], testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 == hr, "Should be able to get a record from the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIRecords.Length == 1, "Should get one and only one record from the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIRecords[0].Suffix == "", "Suffix in record from the TestSetupROIs table should be empty");
|
||||
Assert.IsTrue(testSetupROIRecords[0].ROIStart == -1, "ROIStart in record from the TestSetupROIs table should be -1");
|
||||
Assert.IsTrue(testSetupROIRecords[0].ROIEnd == 1, "ROIEnd in record from the TestSetupROIs table should be 1");
|
||||
Assert.IsTrue(testSetupROIRecords[0].IsEnabled, "IsEnabled in record from the TestSetupROIs table should be 'true'");
|
||||
Assert.IsTrue(testSetupROIRecords[0].IsDefault, "IsDefault in record from the TestSetupROIs table should be 'true'");
|
||||
|
||||
//***Testing*** sp_ROIPeriodChannelsGet
|
||||
var roiPeriodChannelRecords = new DTS.Common.Interface.TestSetups.IROIPeriodChannelRecord[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIRecords[0].TestSetupROIId, out roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr, "Should not fail when getting zero records from the ROIPeriodChannels table based on the TestSetupROIId in the TestSetupROIs table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords.Length == 0, "Should get zero records from the ROIPeriodChannels table");
|
||||
}
|
||||
|
||||
//***Testing*** sp_TestSetupsDeleteManyById
|
||||
//Ensure that deleting a Test Setup will delete related record(s) in the TestSetupROIs and ROIPeriodChannels tables
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections[0], new int[] { testSetupRecordToInsert.Id });
|
||||
//Since hr will be 0 in this case, check by doing a Get
|
||||
|
||||
//***Testing*** sp_TestSetupsGet_92
|
||||
//Make sure the Test Setup was deleted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out var records, out var errors);
|
||||
Assert.IsTrue(null == records || records.Length == 0, "TestSetupsGet should not have retrieved records");
|
||||
Assert.IsFalse(records.Any(r => r.Name == testSetupRecordToInsert.Name), "TestSetupsGet should not have retrieved our record");
|
||||
|
||||
if (serverDbVersion <= 91)
|
||||
{
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out var testSetupROIId);
|
||||
Assert.IsTrue(0 != hr, "RegionsOfInterestInsert should not work if database Version is 91 or less");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
//Make sure the record in the TestSetupROIs table was deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, connections[0], testSetupRecordToInsert.Id, out var testSetupROIRecords);
|
||||
Assert.IsTrue(0 == hr && testSetupROIRecords.Length == 0, "Record in TestSetupROIs table should have been deleted");
|
||||
|
||||
//Make sure the record in the ROIPeriodChannels table was deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupRecordToInsert.Id, out var roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr && testSetupROIRecords.Length == 0, "Record in ROIPeriodChannels table should have been deleted");
|
||||
|
||||
//test that it fails when no user provided
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(null, connections[0], testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when user is invalid");
|
||||
|
||||
//test that it fails when no connection provided
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, null, testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when connection is invalid");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Tests included:
|
||||
/// sp_TestSetupsUpdateInsert_92 (and sp_TestSetupsInsert_92)
|
||||
/// sp_TestSetupROIsInsert
|
||||
/// sp_TestSetupROIsGet
|
||||
/// sp_TestSetupsDeleteManyById
|
||||
/// sp_TestSetupsGet_92
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetupROIsGetMultipleROIs()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//***Testing*** sp_TestSetupsUpdateInsert_92
|
||||
var testSetupRecordToInsert = CreateFakeTestSetupWithROIs(2);
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 92, ref testSetupRecordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
|
||||
DbAPI.DbAPI.GetDatabaseVersion(connections[0], out int serverDbVersion);
|
||||
if (serverDbVersion <= 91)
|
||||
{
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out var testSetupROIId);
|
||||
Assert.IsTrue(0 != hr, "RegionsOfInterestInsert should not work if database Version is 91 or less");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
//***Testing*** sp_TestSetupROIsInsert
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest[0];
|
||||
var testSetupROIId = -1;
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out testSetupROIId);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the first ROI record in the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIId > 0, "A TestSetupROIId should have been generated and returned (1)");
|
||||
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[0], regionOfInterest.ChannelIds[0]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the first record in the ROIPeriodChannels table");
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[1], regionOfInterest.ChannelIds[1]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the second record in the ROIPeriodChannels table");
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[2], regionOfInterest.ChannelIds[2]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the third record in the ROIPeriodChannels table");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsInsert
|
||||
regionOfInterest = testSetupRecordToInsert.RegionsOfInterest.Last();
|
||||
testSetupROIId = -1;
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out testSetupROIId);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the last ROI record in the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIId > 0, "A TestSetupROIId should have been generated and returned (2)");
|
||||
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[0], regionOfInterest.ChannelIds[0]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the fourth record in the ROIPeriodChannels table");
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[1], regionOfInterest.ChannelIds[1]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the fifth record in the ROIPeriodChannels table");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsGet
|
||||
var testSetupROIRecords = new DTS.Common.Interface.TestSetups.ITestSetupROIRecord[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, connections[0], testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 == hr, "Should be able to get a record from the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIRecords.Length == 2, "Should get two and only two records from the TestSetupROIs table");
|
||||
|
||||
Assert.IsTrue(testSetupROIRecords[0].Suffix == "_ROI Period 1", "Suffix in first record from the TestSetupROIs table should be empty");
|
||||
Assert.IsTrue(testSetupROIRecords[0].ROIStart == -1, "ROIStart in first record from the TestSetupROIs table should be -1");
|
||||
Assert.IsTrue(testSetupROIRecords[0].ROIEnd == 1, "ROIEnd in first record from the TestSetupROIs table should be 1");
|
||||
Assert.IsTrue(testSetupROIRecords[0].IsEnabled, "IsEnabled in first record from the TestSetupROIs table should be 'true'");
|
||||
Assert.IsTrue(testSetupROIRecords[0].IsDefault, "IsDefault in first record from the TestSetupROIs table should be 'true'");
|
||||
|
||||
Assert.IsTrue(testSetupROIRecords[1].Suffix == "_ROI Period 2", "Suffix in second record from the TestSetupROIs table should be empty");
|
||||
Assert.IsTrue(testSetupROIRecords[1].ROIStart == -0.9D, "ROIStart in second record from the TestSetupROIs table should be -1");
|
||||
Assert.IsTrue(testSetupROIRecords[1].ROIEnd == 0.9D, "ROIEnd in second record from the TestSetupROIs table should be 1");
|
||||
Assert.IsTrue(testSetupROIRecords[1].IsEnabled, "IsEnabled in second record from the TestSetupROIs table should be 'true'");
|
||||
Assert.IsTrue(testSetupROIRecords[1].IsDefault, "IsDefault in second record from the TestSetupROIs table should be 'true'");
|
||||
|
||||
//***Testing*** sp_ROIPeriodChannelsGet
|
||||
var roiPeriodChannelRecords = new DTS.Common.Interface.TestSetups.IROIPeriodChannelRecord[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIRecords[0].TestSetupROIId, out roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr, "Should be able to get three records from the ROIPeriodChannels table based on the TestSetupROIId in the TestSetupROIs table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords.Length == 3, "Should get three and only three records from the ROIPeriodChannels table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[0].ChannelName == "an1", "ChannelName[0] in record 0 should be 'an1'");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[1].ChannelName == "an2", "ChannelName[1] in record 0 should be 'an2'");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[2].ChannelName == "an3", "ChannelName[2] in record 0 should be 'an3'");
|
||||
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIRecords[1].TestSetupROIId, out roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr, "Should be able to get two records from the ROIPeriodChannels table based on the TestSetupROIId in the TestSetupROIs table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords.Length == 2, "Should get two and only two records from the ROIPeriodChannels table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[0].ChannelName == "an1", "ChannelName[0] in record 1 should be 'an1'");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[1].ChannelName == "an2", "ChannelName[1] in record 1 should be 'an2'");
|
||||
}
|
||||
|
||||
//***Testing*** sp_TestSetupsDeleteManyById
|
||||
//Ensure that deleting a Test Setup will delete related record(s) in the TestSetupROIs table
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections[0], new int[] { testSetupRecordToInsert.Id });
|
||||
//Since hr will be 0 in this case, check by doing a Get
|
||||
//Assert.IsTrue(0 != hr, $"Test Setup should not be able to be deleted before all related records in the TestSetupROIs table. hr={hr}");
|
||||
|
||||
//***Testing*** sp_TestSetupsGet_92
|
||||
//Make sure the Test Setup was deleted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out var records, out var errors);
|
||||
Assert.IsTrue(null == records || records.Length == 0, "TestSetupsGet should not have retrieved records");
|
||||
Assert.IsFalse(records.Any(r => r.Name == testSetupRecordToInsert.Name), "TestSetupsGet should not have retrieved our record");
|
||||
|
||||
if (serverDbVersion >= 92)
|
||||
{
|
||||
//Make sure that both records in the TestSetupROIs table were deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, connections[0], testSetupRecordToInsert.Id, out var testSetupROIRecords);
|
||||
Assert.IsTrue(0 == hr && testSetupROIRecords.Length == 0, "Record in TestSetupROIs table should have been deleted");
|
||||
|
||||
//Make sure the record in the ROIPeriodChannels table was deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupRecordToInsert.Id, out var roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr && testSetupROIRecords.Length == 0, "Record in ROIPeriodChannels table should have been deleted");
|
||||
|
||||
//test that it fails when no user provided
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(null, connections[0], testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when user is invalid");
|
||||
|
||||
//test that it fails when no connection provided
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, null, testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when connection is invalid");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using DatabaseUnitTesting.Utilities.Results;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
public class ResultSetTester
|
||||
{
|
||||
private readonly SqlCommand _command;
|
||||
|
||||
public ResultSetTester(SqlConnection connection, string procedureName)
|
||||
{
|
||||
_command = new SqlCommand(procedureName, connection);
|
||||
_command.CommandType = CommandType.StoredProcedure;
|
||||
}
|
||||
|
||||
public ResultSetTester(SqlCommand command)
|
||||
{
|
||||
_command = command;
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<string, object>> PrintOuputParameterValues()
|
||||
{
|
||||
Dictionary<string, object> outputParams = new Dictionary<string, object>();
|
||||
foreach (SqlParameter p in _command.Parameters)
|
||||
if (p.Direction == ParameterDirection.Output)
|
||||
outputParams.Add(p.ParameterName, p.Value);
|
||||
|
||||
return outputParams;
|
||||
}
|
||||
|
||||
public bool CompareToFile(string filename)
|
||||
{
|
||||
Database procedureResults = ResultSetParser.Parse(_command);
|
||||
Database fileResults = XmlFileAdapter.Read(filename);
|
||||
|
||||
if (!procedureResults.Equals(fileResults))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
public void OutputToFile(string filename)
|
||||
{
|
||||
|
||||
Database results = ResultSetParser.Parse(_command);
|
||||
XmlFileAdapter.Write(filename, results);
|
||||
}
|
||||
|
||||
public void SetInputParameter(string parameterName, object parameterValue)
|
||||
{
|
||||
if (_command.Parameters.Contains(parameterName))
|
||||
_command.Parameters[parameterName] =
|
||||
new SqlParameter(parameterName, parameterValue);
|
||||
else
|
||||
_command.Parameters.AddWithValue(parameterName, parameterValue);
|
||||
}
|
||||
|
||||
public void SetOutputParameter(string parameterName, SqlDbType type, int size)
|
||||
{
|
||||
if (_command.Parameters.Contains(parameterName))
|
||||
_command.Parameters.RemoveAt(parameterName);
|
||||
|
||||
_command.Parameters.Add(parameterName, type);
|
||||
_command.Parameters[parameterName].Direction = ParameterDirection.Output;
|
||||
if (size != 0)
|
||||
_command.Parameters[parameterName].Size = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using DatabaseUnitTesting.Utilities;
|
||||
using DatabaseUnitTesting.Utilities.Results;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
public class DatabaseModificationTester : IDisposable
|
||||
{
|
||||
|
||||
private readonly DatabaseComparer _dataComparer;
|
||||
private SqlTransaction _transaction;
|
||||
private SqlConnection _connection;
|
||||
private readonly string _snapshotName;
|
||||
private readonly DatabaseAdapter _databaseAdapter;
|
||||
private bool _activeSnapshot = false;
|
||||
/// <summary>
|
||||
/// Used to establish the objects required to create a unit test running compares between a stored XML database file and an SQL transaction.
|
||||
/// </summary>
|
||||
/// <param name="connection"></param>
|
||||
/// <param name="databaseName"></param>
|
||||
/// <param name="snapshotName"></param>
|
||||
public DatabaseModificationTester(SqlConnection connection, string databaseName, string snapshotName)
|
||||
{
|
||||
_connection = connection;
|
||||
_snapshotName = snapshotName;
|
||||
_dataComparer = new DatabaseComparer(connection, databaseName, snapshotName);
|
||||
_databaseAdapter = new DatabaseAdapter(connection);
|
||||
_databaseAdapter.CreateSnapshot(databaseName, snapshotName);
|
||||
_activeSnapshot = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// establishes the command transaction to be compared and rolled back on end
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SqlTransaction BeginTestTransaction()
|
||||
{
|
||||
if (_transaction != null)
|
||||
EndTestTransaction();
|
||||
|
||||
return (_transaction = _connection.BeginTransaction());
|
||||
}
|
||||
/// <summary>
|
||||
/// Once the compare is complete this method cleans up, rollsback, and disposes the transaction
|
||||
/// </summary>
|
||||
public void EndTestTransaction()
|
||||
{
|
||||
if (_transaction == null)
|
||||
throw new InvalidOperationException("Transaction does not exist");
|
||||
|
||||
_dataComparer.CleanUp();
|
||||
_transaction.Rollback();
|
||||
_transaction.Dispose();
|
||||
_transaction = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Method to write XML file to use during unit testing. Writes differences between current database and the completed transaction.
|
||||
/// The file generated here should be manually verified
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
public void WriteDiffsToXml(string filename)
|
||||
{
|
||||
XmlFileAdapter.Write(filename, _dataComparer.GenerateDifferences(_transaction));
|
||||
}
|
||||
/// <summary>
|
||||
/// Return true/false based on compare of transaction and stored XML expected test results.
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public bool CompareDiffsToXml(string filename)
|
||||
{
|
||||
return XmlFileAdapter.Read(filename).Equals(_dataComparer.GenerateDifferences(_transaction));
|
||||
}
|
||||
|
||||
public bool AreEqual()
|
||||
{
|
||||
return _dataComparer.GenerateDifferences(_transaction).TableCount == 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Enables test to ignore defined columns in database tables
|
||||
/// </summary>
|
||||
/// <param name="schemaName"></param>
|
||||
/// <param name="objectName"></param>
|
||||
/// <param name="columnName"></param>
|
||||
public void AddColumnToIgnore(string schemaName, string objectName, string columnName)
|
||||
{
|
||||
_dataComparer.AddColumnToIgnore(schemaName, objectName, columnName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Enables test to ignore defined columns in database tables
|
||||
/// </summary>
|
||||
/// <param name="schema1"></param>
|
||||
/// <param name="name1"></param>
|
||||
/// <param name="columnNames"></param>
|
||||
public void AddColumnsToIgnore(string schema1, string name1, List<string> columnNames)
|
||||
{
|
||||
_dataComparer.AddColumnsToIgnore(schema1, name1, columnNames);
|
||||
}
|
||||
|
||||
public void AddObjectComparison(string schemaName, string tableName)
|
||||
{
|
||||
_dataComparer.AddObjectComparison(schemaName, tableName, schemaName, tableName);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_activeSnapshot)
|
||||
{
|
||||
_activeSnapshot = false;
|
||||
_databaseAdapter.DropSnapshot(_snapshotName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
|
||||
namespace DatabaseUnitTesting.Utilities.Results
|
||||
{
|
||||
internal class Column
|
||||
{
|
||||
private readonly string _name;
|
||||
private readonly string _value;
|
||||
private readonly string _sortString;
|
||||
public const string DELIMITER = "\x1f;;";
|
||||
|
||||
public Column(string name, object value)
|
||||
{
|
||||
_name = name;
|
||||
_value = Convert(value);
|
||||
_sortString = String.Concat(_name.ToLower(), DELIMITER, _value);
|
||||
}
|
||||
|
||||
public static string Convert(object value)
|
||||
{
|
||||
if (value is byte[])
|
||||
{
|
||||
string[] binary = new string[((byte[])value).Length + 1];
|
||||
binary[0] = "0x";
|
||||
for (int i = 1; i < binary.Length; i++)
|
||||
binary[i] = ((byte[])value)[i - 1].ToString("X1");
|
||||
|
||||
return String.Join("", binary);
|
||||
}
|
||||
|
||||
if (value is DateTime)
|
||||
{
|
||||
string time = ((DateTime)value).ToShortDateString() + " ";
|
||||
time += ((DateTime)value).TimeOfDay;
|
||||
return time.TrimEnd('0').TrimEnd(':');
|
||||
}
|
||||
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
}
|
||||
|
||||
public string Value
|
||||
{
|
||||
get { return _value; }
|
||||
}
|
||||
|
||||
public string SortString
|
||||
{
|
||||
get { return _sortString; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DatabaseUnitTesting.Utilities.Results
|
||||
{
|
||||
internal class Table
|
||||
{
|
||||
private readonly string _name1;
|
||||
private readonly string _name2;
|
||||
private Row _schema = new Row("schema");
|
||||
private readonly Dictionary<string, int> rows = new Dictionary<string, int>();
|
||||
|
||||
private int _hashCode;
|
||||
private int _rowCount;
|
||||
private int _fieldCount;
|
||||
|
||||
public Table(string name1) : this(name1, String.Empty)
|
||||
{ }
|
||||
|
||||
public Table(string name1, string name2)
|
||||
{
|
||||
_name1 = name1.ToLower();
|
||||
_name2 = name2.ToLower();
|
||||
}
|
||||
|
||||
|
||||
public override bool Equals(object otherObject)
|
||||
{
|
||||
if (!(otherObject is Table))
|
||||
return false;
|
||||
|
||||
Table other = (Table)otherObject;
|
||||
|
||||
if (GetHashCode() != other.GetHashCode())
|
||||
return false;
|
||||
|
||||
if (RowCount != other.RowCount ||
|
||||
FieldCount != other.FieldCount ||
|
||||
!Schema.KeyString.Equals(other.Schema.KeyString))
|
||||
return false;
|
||||
|
||||
int otherCount;
|
||||
|
||||
foreach (string row in rows.Keys)
|
||||
if (!other.LookupRow(row, out otherCount) ||
|
||||
otherCount != rows[row])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _hashCode;
|
||||
}
|
||||
|
||||
public string Name1
|
||||
{
|
||||
get { return _name1; }
|
||||
}
|
||||
|
||||
public string Name2
|
||||
{
|
||||
get { return _name2; }
|
||||
}
|
||||
|
||||
public void AddRow(Row row)
|
||||
{
|
||||
string key = row.KeyString;
|
||||
if (rows.ContainsKey(key))
|
||||
rows[key]++;
|
||||
else
|
||||
rows.Add(key, 1);
|
||||
|
||||
_rowCount = _rowCount + 1;
|
||||
_hashCode = _hashCode + key.GetHashCode();
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<string, int>> Rows
|
||||
{
|
||||
get { return rows; }
|
||||
}
|
||||
|
||||
public int RowCount
|
||||
{
|
||||
get { return _rowCount; }
|
||||
}
|
||||
|
||||
public int FieldCount
|
||||
{
|
||||
get { return _fieldCount; }
|
||||
}
|
||||
|
||||
public Row Schema
|
||||
{
|
||||
get { return _schema; }
|
||||
set
|
||||
{
|
||||
_schema = value;
|
||||
_fieldCount = _schema.ColumnCount;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddField(string name, string type)
|
||||
{
|
||||
Column c = new Column(name, type.ToLower());
|
||||
_schema.AddColumn(c);
|
||||
_fieldCount++;
|
||||
// _hashCode = _hashCode + c.SortString.GetHashCode();
|
||||
}
|
||||
|
||||
public bool LookupRow(string key, out int other)
|
||||
{
|
||||
return rows.TryGetValue(key, out other);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using DTS.Common.Interface.TestMetaData;
|
||||
using DTS.Common.Classes.CustomerDetails;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public CustomerDetailsDbRecord CreateFakeCustomerDetails(string name)
|
||||
{
|
||||
var record = new CustomerDetailsDbRecord();
|
||||
record.CustomerId = -1;
|
||||
record.Name = name;
|
||||
record.CustomerName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerTestRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.ProjectRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerOrderNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerCostUnit = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LocalOnly = true;
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.Version = 1;
|
||||
return record;
|
||||
}
|
||||
[Test]
|
||||
public void CustomerDetails()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//Delete all to start with a blank table
|
||||
var hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsDelete(_user, connections.First(), null, out string errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsDelete");
|
||||
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var legitRecord = CreateFakeCustomerDetails("legit");
|
||||
var decoyRecord = CreateFakeCustomerDetails("decoy");
|
||||
|
||||
//Insert
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsInsert(_user, connections.First(), legitRecord, out int newLegitId, out string legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate CustomerDetails record");
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsInsert(_user, connections.First(), decoyRecord, out int newFakeId, out string fakeErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy CustomerDetails record");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), legitRecord.Name, out ICustomerDetailsDbRecord[] customerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != customerDetailsDbRecords && customerDetailsDbRecords.Length == 1, "CustomerDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(customerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should have retrieved only one record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), null, out ICustomerDetailsDbRecord[] allCustomerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != allCustomerDetailsDbRecords && allCustomerDetailsDbRecords.Length == 2, "CustomerDetailsGet should have retrieved 2 records");
|
||||
Assert.IsTrue(allCustomerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should have retrieved our record");
|
||||
Assert.IsTrue(allCustomerDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "CustomerDetailsGet should have retrieved our record");
|
||||
|
||||
//Update
|
||||
var newCustomerTestRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
legitRecord.CustomerTestRefNumber = newCustomerTestRefNumber;
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsUpdate(_user, connections.First(), legitRecord, out legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate CustomerDetails record");
|
||||
Assert.IsTrue(legitErrorString == string.Empty, $"Error when inserting a legitimate CustomerDetails record: {legitErrorString}");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), legitRecord.Name, out customerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != customerDetailsDbRecords && customerDetailsDbRecords.Length == 1, "CustomerDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(customerDetailsDbRecords.Any(r => r.CustomerTestRefNumber == newCustomerTestRefNumber), "CustomerDetailsGet should have retrieved the updated record");
|
||||
|
||||
//Delete by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsDelete(_user, connections.First(), legitRecord.Name, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), legitRecord.Name, out customerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != customerDetailsDbRecords, "CustomerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(customerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should not have retrieved this record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), null, out allCustomerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != allCustomerDetailsDbRecords && allCustomerDetailsDbRecords.Length == 1, "CustomerDetailsGet should have retrieved only the decoy record");
|
||||
Assert.IsFalse(allCustomerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet not should have retrieved this record");
|
||||
Assert.IsTrue(allCustomerDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "CustomerDetailsGet should have retrieved this record");
|
||||
|
||||
//Delete all
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsDelete(_user, connections.First(), null, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), legitRecord.Name, out customerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != customerDetailsDbRecords, "CustomerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(customerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should not have retrieved any records");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), null, out allCustomerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != allCustomerDetailsDbRecords, "CustomerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(allCustomerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should not have retrieved any records");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class DASChannelsTests : TestSetups
|
||||
{
|
||||
|
||||
// NOTES:
|
||||
// Deletes DAS channels by DASId. IE: all channels associated with the given DAS hardware ID will be deleted.
|
||||
|
||||
// [Test]
|
||||
// ============================================================
|
||||
// DELETE DAS CHANNELS
|
||||
// Call sp_DASChannelsDelete with a known DAS hardware ID
|
||||
// Verify all DAS channels associated with the hardware ID no longer exists in dbo.DASChannels table.
|
||||
// ============================================================
|
||||
|
||||
|
||||
// [Test]
|
||||
// =============================================================
|
||||
// GET DAS CHANNELS
|
||||
// Start with a DAS hardware that has a known number of DAS channels included. Call sp_DASChannelsGet for the hardware.
|
||||
// Verify known number of DAS channels are returned
|
||||
// =============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT DAS CHANNELS
|
||||
// Starting with a known populated test setup call sp_DASChannelsUpdateInsert with parameters for a new valid
|
||||
// DAS channel and compare all fields.
|
||||
// Pass if all fields in dbo.DASChannels table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT DAS CHANNEL: VERIFY ONLY ONE NEW ROW IS ADDED
|
||||
// Call sp_DASChannelsUpdateInsert with parameters for a new valid
|
||||
// DAS channel and verify a new row is created in dbo.DASChannels table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE DAS CHANNEL
|
||||
// Send valid DAS channels parameters to sp_DASChannelsInUpdateInsert for a DAS
|
||||
// channel that already is in the database and compare all fields.
|
||||
// Pass if all fields in dbo.DASChannels table are entered.
|
||||
// ============================================================
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE DAS CHANNEL: VERIFY NO NEW ROW IS ADDED
|
||||
// Send valid DAS channels parameters to sp_DASChannelsInUpdateInsert for a DAS
|
||||
// channel that already is in the database and verify no new row is created in dbo.DASChannels table.
|
||||
//
|
||||
// ============================================================
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<results>
|
||||
<object name1="dbo.sensorsanalog" name2="dbo.sensorsanalog">
|
||||
<row type="schema" />
|
||||
<row type="in first">
|
||||
<column name="serialnumber" value="CubicSensor_18" />
|
||||
<column name="userserialnumber" value="" />
|
||||
<column name="model" value="" />
|
||||
<column name="sensormodelid" value="0" />
|
||||
<column name="manufacturer" value="DTS" />
|
||||
<column name="status" value="0" />
|
||||
<column name="measurementunit" value="mm" />
|
||||
<column name="offsettolerancelow" value="-100" />
|
||||
<column name="offsettolerancehigh" value="100" />
|
||||
<column name="eid" value="AABBCCDD" />
|
||||
<column name="capacity" value="2000" />
|
||||
<column name="comment" value="" />
|
||||
<column name="bridgetype" value="3" />
|
||||
<column name="bridgelegmode" value="0" />
|
||||
<column name="shunt" value="1" />
|
||||
<column name="invert" value="False" />
|
||||
<column name="uservalue1" value="" />
|
||||
<column name="uservalue2" value="" />
|
||||
<column name="uservalue3" value="" />
|
||||
<column name="filterclass" value="None" />
|
||||
<column name="bridgeresistance" value="349" />
|
||||
<column name="isocode" value="???????????????P" />
|
||||
<column name="checkoffset" value="True" />
|
||||
<column name="supportedexcitation" value="Volt5" />
|
||||
<column name="initialeu" value="0.501" />
|
||||
<column name="calinterval" value="365" />
|
||||
<column name="calibrationsignal" value="False" />
|
||||
<column name="internalshuntresistance" value="0" />
|
||||
<column name="externalshuntresistance" value="0" />
|
||||
<column name="unipolar" value="False" />
|
||||
<column name="rangelow" value="10" />
|
||||
<column name="rangeave" value="100" />
|
||||
<column name="rangehigh" value="1000" />
|
||||
<column name="timesused" value="0" />
|
||||
<column name="sensorcategory" value="0" />
|
||||
<column name="bypassfilter" value="False" />
|
||||
<column name="couplingmode" value="0" />
|
||||
<column name="version" value="1" />
|
||||
<column name="modifiedby" value="TestUser" />
|
||||
<column name="localonly" value="False" />
|
||||
<column name="axisnumber" value="0" />
|
||||
<column name="numberofaxes" value="1" />
|
||||
<column name="usertags" value="0x0000000000000000000000000000000000000000" />
|
||||
<column name="donotuse" value="False" />
|
||||
<column name="broken" value="False" />
|
||||
</row>
|
||||
</object>
|
||||
</results>
|
||||
@@ -0,0 +1,133 @@
|
||||
using DTS.Common.Classes.Groups;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using DTS.Common.Interface.Groups;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void TestTestSetupGroupPositive()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections()[0];
|
||||
|
||||
var test = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref test);
|
||||
var group = CreateFakeGroup("TestGroup", null);
|
||||
_ = DbAPI.DbAPI.Groups.GroupsInsert(_user, con, ref group);
|
||||
|
||||
var insertGroupRecord = new TestSetupGroupRecord()
|
||||
{
|
||||
DisplayOrder = 0,
|
||||
GroupId = group.Id,
|
||||
Position = "?",
|
||||
TestObjectType = "X",
|
||||
TestSetupId = test.Id
|
||||
};
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, con, insertGroupRecord);
|
||||
Assert.IsTrue(0 == hr, "TestSetupGroupsInsert returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, null, null, out var groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(g, insertGroupRecord)),
|
||||
"TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, group.Id, null, null, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, test.Id, null, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, null, test.Name, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, group.Id, test.Id, null, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, group.Id, null, test.Name, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, test.Id, test.Name, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, group.Id, test.Id, test.Name, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
var updateGroupRecord = new TestSetupGroupRecord(insertGroupRecord);
|
||||
updateGroupRecord.Position = "Y";
|
||||
updateGroupRecord.TestObjectType = "Z";
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsUpdate(_user, con, updateGroupRecord);
|
||||
Assert.IsTrue(0 == hr, "TestSetupGroupsUpdate returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, test.Id, null, out groups);
|
||||
Assert.IsTrue(0 == hr && 1 == groups.Length && TestSetupGroupRecordEqual(groups[0], updateGroupRecord),
|
||||
"TestSetupGroupsGet returns updated group");
|
||||
|
||||
hr = DbAPI.DbAPI.Groups.GroupsDelete(_user, con, group.Id, out var error);
|
||||
Assert.IsTrue(0 == hr, "Groups can delete a group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, con, new[] { test.Id });
|
||||
Assert.IsTrue(0 == hr, "Test setup can be deleted");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, null, null, out groups);
|
||||
Assert.IsTrue(0 == hr && null == groups || 0 == groups.Length || !groups.Any(g => TestSetupGroupRecordEqual(g, updateGroupRecord)),
|
||||
"TestSetupsDelete removed any group record");
|
||||
}
|
||||
|
||||
private bool TestSetupGroupRecordEqual(ITestSetupGroupRecord left, ITestSetupGroupRecord right)
|
||||
{
|
||||
return left.DisplayOrder == right.DisplayOrder
|
||||
&& left.GroupId == right.GroupId
|
||||
&& left.Position == right.Position
|
||||
&& left.TestObjectType == right.TestObjectType
|
||||
&& left.TestSetupId == right.TestSetupId;
|
||||
}
|
||||
[Test]
|
||||
public void TestTestSetupGroupNegative()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections()[0];
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, null, null, null, null, out var groups);
|
||||
Assert.IsTrue(0 != hr && (null == groups || 0 == groups.Length), "TestSetups should not work without a connection");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(null, con, null, null, null, out groups);
|
||||
Assert.IsTrue(0 != hr && (null == groups || 0 == groups.Length), "TestSetups should not work without a user");
|
||||
|
||||
var test = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref test);
|
||||
var group = CreateFakeGroup("FakeGroup", null);
|
||||
_ = DbAPI.DbAPI.Groups.GroupsInsert(_user, con, ref group);
|
||||
|
||||
var groupToInsert = new TestSetupGroupRecord() { DisplayOrder = 0, GroupId = group.Id, Position = "?", TestObjectType = "?", TestSetupId = test.Id };
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(null, con, groupToInsert);
|
||||
Assert.IsTrue(0 != hr, "TestSetupsGroupsInsert should not work without user");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, null, groupToInsert);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsInsert should not work without connection");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, con, null);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsInsert should not work without record to insert");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsUpdate(null, con, groupToInsert);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsUpdate should not work without user");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, null, groupToInsert);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsUpdate should not work without connection");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, con, null);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsUpdate should not work without record to insert");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using DTS.Common.Classes.Channels;
|
||||
using DTS.Common.Classes.TestSetups;
|
||||
using DTS.Common.Interface.Channels;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using DTS.Common.Storage;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
/// <summary>
|
||||
/// Testing of version created for the replacement of the string RegionsOfInterest field in the
|
||||
/// TestSetups table with the TestSetupROIs and ROIPeriodChannels tables.
|
||||
/// This should only work with a Version 92 or later database, but should handle Version 91 databases gracefully.
|
||||
/// Tests included:
|
||||
/// sp_TestSetupsUpdateInsert_92 (and sp_TestSetupsInsert_92)
|
||||
/// sp_TestSetupROIsInsert
|
||||
/// sp_ROIPeriodChannelsInsert
|
||||
/// sp_TestSetupROIsGet
|
||||
/// sp_ROIPeriodChannelsGet
|
||||
/// sp_TestSetupROIsDelete
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void RegionsOfInterest()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//***Testing*** sp_TestSetupsUpdateInsert_92
|
||||
var testSetupRecordToInsert = CreateFakeTestSetupWithROIs(2);
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections.First(), 92, ref testSetupRecordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
|
||||
DbAPI.DbAPI.GetDatabaseVersion(connections.First(), out int serverDbVersion);
|
||||
if (serverDbVersion <= 91)
|
||||
{
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest.First();
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestInsert(_user, connections.First(), 91, testSetupRecordToInsert.Id, regionOfInterest);
|
||||
Assert.IsTrue(0 != hr, "RegionsOfInterestInsert should not work if database Version is 91 or less");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
//***Testing*** sp_TestSetupROIsInsert and sp_ROIPeriodChannelsInsert
|
||||
//valid Insert Regions of Interest
|
||||
foreach (var regionOfInterest in testSetupRecordToInsert.RegionsOfInterest)
|
||||
{
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestInsert(_user, connections.First(), 97, testSetupRecordToInsert.Id, regionOfInterest);
|
||||
}
|
||||
|
||||
//***Testing*** sp_TestSetupROIsGet and sp_ROIPeriodChannelsGet
|
||||
//valid get the RegionsOfInterest for this Test Setup
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestGet(_user, connections.First(), DbOperations.CURRENT_DB_VERSION, testSetupRecordToInsert.Id, out var roiRecords);
|
||||
Assert.IsTrue(0 == hr && null != roiRecords && roiRecords.Length == 2 && roiRecords.Any(r => r.Suffix == testSetupRecordToInsert.RegionsOfInterest.First().Suffix),
|
||||
"First suffix test failed");
|
||||
Assert.IsTrue(0 == hr && null != roiRecords && roiRecords.Length == 2 && roiRecords.Any(r => r.Suffix == testSetupRecordToInsert.RegionsOfInterest.Last().Suffix),
|
||||
"Last suffix test failed");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsDelete
|
||||
//Delete all of the RegionsOfInterest for this Test Setup
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestDelete(_user, connections.First(), testSetupRecordToInsert.Id);
|
||||
Assert.IsTrue(0 == hr, "Should be able to delete all ROIs in a Test Setup");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsGet and sp_ROIPeriodChannelsGet
|
||||
//Make sure they were deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestGet(_user, connections.First(), DbOperations.CURRENT_DB_VERSION, testSetupRecordToInsert.Id, out roiRecords);
|
||||
Assert.IsTrue(0 == hr && (null == roiRecords || roiRecords.Length == 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NUnit" version="3.12.0" targetFramework="net45" />
|
||||
<package id="NUnit3TestAdapter" version="3.14.0" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace DatabaseUnitTesting.Utilities.Results
|
||||
{
|
||||
internal static class XmlFileAdapter
|
||||
{
|
||||
private const string LEFT = "\0L;;";
|
||||
private const string RIGHT = "\0R;;";
|
||||
|
||||
internal static Database Read(string filename)
|
||||
{
|
||||
XmlDocument document = new XmlDocument();
|
||||
Database database = new Database();
|
||||
|
||||
document.Load(filename);
|
||||
XmlNode xmlRoot = document.LastChild;
|
||||
|
||||
if (xmlRoot == null)
|
||||
return database;
|
||||
|
||||
foreach (Table diff in ReadTables(xmlRoot))
|
||||
database.AddTable(diff);
|
||||
|
||||
return database;
|
||||
}
|
||||
|
||||
internal static List<Table> ReadTables(XmlNode xmlRoot)
|
||||
{
|
||||
List<Table> tableDiffs = new List<Table>();
|
||||
for (XmlNode xmlObject = xmlRoot.FirstChild; xmlObject != null; xmlObject = xmlObject.NextSibling)
|
||||
{
|
||||
XmlAttribute name1Attribute = xmlObject.Attributes["name1"];
|
||||
XmlAttribute name2Attribute = xmlObject.Attributes["name2"];
|
||||
|
||||
if (name1Attribute == null || name2Attribute == null)
|
||||
throw new XmlSyntaxException("Tables must have name1 and name2 attributes");
|
||||
|
||||
Table tableDiff = new Table(name1Attribute.Value, name2Attribute.Value);
|
||||
|
||||
Row schema = new Row("schema");
|
||||
ReadColumns(xmlObject.FirstChild, schema);
|
||||
|
||||
tableDiff.Schema = schema;
|
||||
|
||||
foreach (Row row in ReadRows(xmlObject))
|
||||
{
|
||||
tableDiff.AddRow(row);
|
||||
}
|
||||
|
||||
tableDiffs.Add(tableDiff);
|
||||
}
|
||||
return tableDiffs;
|
||||
}
|
||||
|
||||
internal static List<Row> ReadRows(XmlNode xmlTable)
|
||||
{
|
||||
List<Row> rowDiffs = new List<Row>();
|
||||
for (XmlNode xmlRow = xmlTable.FirstChild.NextSibling; xmlRow != null; xmlRow = xmlRow.NextSibling)
|
||||
{
|
||||
XmlAttribute typeAttribute = xmlRow.Attributes["type"];
|
||||
|
||||
if (typeAttribute == null)
|
||||
throw new XmlSyntaxException("Row does not have a 'type' attribute");
|
||||
|
||||
Row row = new Row(typeAttribute.Value);
|
||||
ReadColumns(xmlRow, row);
|
||||
rowDiffs.Add(row);
|
||||
}
|
||||
return rowDiffs;
|
||||
}
|
||||
|
||||
internal static void ReadColumns(XmlNode xmlRow, Row row)
|
||||
{
|
||||
for (XmlNode column = xmlRow.FirstChild; column != null; column = column.NextSibling)
|
||||
{
|
||||
XmlAttribute nameAttribute = column.Attributes["name"];
|
||||
|
||||
if (nameAttribute == null)
|
||||
throw new XmlSyntaxException("Fields and Keys must have 'name' attributes");
|
||||
|
||||
string name = nameAttribute.Value.ToLower();
|
||||
|
||||
if (column.Name.ToLower().Equals("column"))
|
||||
{
|
||||
XmlAttribute valueAttribute = column.Attributes["value"];
|
||||
if (valueAttribute == null)
|
||||
throw new XmlSyntaxException("Columns must have 'value' attribute");
|
||||
|
||||
row.AddColumn(new Column(name, valueAttribute.Value.Replace(LEFT, "<").Replace(RIGHT, ">")));
|
||||
}
|
||||
else
|
||||
throw new XmlSyntaxException("Rows may only contain 'column' children");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Write(string filename, Database diffs)
|
||||
{
|
||||
using (XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8))
|
||||
{
|
||||
writer.Formatting = Formatting.Indented;
|
||||
writer.WriteStartDocument();
|
||||
writer.WriteStartElement("results");
|
||||
|
||||
foreach (KeyValuePair<Table, int> table in diffs.Tables)
|
||||
for (int i = 0; i < table.Value; i++)
|
||||
WriteTable(writer, table.Key);
|
||||
|
||||
writer.WriteEndDocument();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void WriteTable(XmlTextWriter writer, Table tableDiff)
|
||||
{
|
||||
writer.WriteStartElement("object");
|
||||
|
||||
writer.WriteAttributeString("name1", tableDiff.Name1);
|
||||
writer.WriteAttributeString("name2", tableDiff.Name2);
|
||||
|
||||
|
||||
WriteRow(writer, tableDiff.Schema.KeyString);
|
||||
|
||||
foreach (KeyValuePair<string, int> row in tableDiff.Rows)
|
||||
{
|
||||
for (int i = 0; i < row.Value; i++)
|
||||
WriteRow(writer, row.Key);
|
||||
}
|
||||
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
internal static void WriteRow(XmlTextWriter writer, string rowDiff)
|
||||
{
|
||||
writer.WriteStartElement("row");
|
||||
string[] columns = rowDiff.Split(new string[] { Row.DELIMITER }, StringSplitOptions.None);
|
||||
|
||||
writer.WriteAttributeString("type", columns[0]);
|
||||
for (int i = 1; i < columns.Length; i++)
|
||||
WriteColumn(writer, columns[i]);
|
||||
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
internal static void WriteColumn(XmlTextWriter writer, string column)
|
||||
{
|
||||
string[] definition = column.Split(new string[] { Column.DELIMITER }, StringSplitOptions.None);
|
||||
|
||||
writer.WriteStartElement("column");
|
||||
writer.WriteAttributeString("name", definition[0]);
|
||||
writer.WriteAttributeString("value", definition[1].Replace("<", LEFT).Replace(">", RIGHT));
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using DTS.Common.Classes.Groups;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using DTS.Common.Interface.Groups;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="staticGroupId">Call with null or the id of a corresponding static Group</param>
|
||||
/// <returns></returns>
|
||||
public IGroupDbRecord CreateFakeGroup(string displayName, int? staticGroupId)
|
||||
{
|
||||
var group = new GroupDbRecord();
|
||||
group.SerialNumber = Guid.NewGuid().ToString().Substring(0, 10);
|
||||
group.Picture = "";
|
||||
group.DisplayName = displayName;
|
||||
group.Description = "";
|
||||
group.Embedded = false;
|
||||
group.LastModified = DateTime.Now;
|
||||
group.LastModifiedBy = "";
|
||||
group.StaticGroupId = staticGroupId;
|
||||
return group;
|
||||
}
|
||||
public GroupHardwareDbRecord CreateGroupHardwareDbRecord(int groupId, int dasId)
|
||||
{
|
||||
var groupHardwareDbRecord = new GroupHardwareDbRecord();
|
||||
groupHardwareDbRecord.GroupId = groupId;
|
||||
groupHardwareDbRecord.DASId = dasId;
|
||||
return groupHardwareDbRecord;
|
||||
}
|
||||
[Test]
|
||||
public void TestGroupHardwareInsertGetAndDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//Delete all records from the DAS and Groups tables - either of which should delete all records from the GroupHardware table also.
|
||||
var hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), connections.First().ClientDbVersion, null, null, out IDASDBRecord[] dasRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for DASGet");
|
||||
foreach (var dasRecord in dasRecords)
|
||||
{
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), dasRecord.DASId, dasRecord.SerialNumber, false);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for DASDelete");
|
||||
}
|
||||
hr = DbAPI.DbAPI.Groups.GroupsGet(_user, connections.First(), null, null, null, null, null, out IGroupDbRecord[] groups);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupsGet");
|
||||
foreach (var group in groups)
|
||||
{
|
||||
hr = DbAPI.DbAPI.Groups.GroupsDelete(_user, connections.First(), group.Id, out string deleteErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupsDelete");
|
||||
}
|
||||
|
||||
//Insert one legit and one bogus DAS
|
||||
var legitDas = CreateFakeDAS();
|
||||
legitDas.SerialNumber = "legit";
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), legitDas);
|
||||
Assert.AreEqual(0, hr, "DASInsert legit executed");
|
||||
|
||||
var bogusDas = CreateFakeDAS();
|
||||
bogusDas.SerialNumber = "bogus";
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), bogusDas);
|
||||
Assert.AreEqual(0, hr, "DASInsert bogus executed");
|
||||
|
||||
//Insert a legit static Group
|
||||
var legitGroup = CreateFakeGroup("legit", null);
|
||||
hr = DbAPI.DbAPI.Groups.GroupsInsert(_user, connections.First(), ref legitGroup);
|
||||
Assert.AreEqual(0, hr, "Legit GroupInsert executed");
|
||||
|
||||
//Insert a bogus static Group
|
||||
var bogusGroup = CreateFakeGroup("bogus", null);
|
||||
hr = DbAPI.DbAPI.Groups.GroupsInsert(_user, connections.First(), ref bogusGroup);
|
||||
Assert.AreEqual(0, hr, "Bogus GroupInsert executed");
|
||||
|
||||
//**Insert GroupHardware records for the legit static Group with both DAS
|
||||
var groupHardwareDbRecord = CreateGroupHardwareDbRecord(legitGroup.Id, legitDas.DASId);
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareInsert(_user, connections.First(), groupHardwareDbRecord, out int newId, out string errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareInsert");
|
||||
|
||||
groupHardwareDbRecord = CreateGroupHardwareDbRecord(legitGroup.Id, bogusDas.DASId);
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareInsert(_user, connections.First(), groupHardwareDbRecord, out newId, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareInsert");
|
||||
|
||||
//**Insert a GroupHardware record for the bogus static Group with one bogus DAS
|
||||
groupHardwareDbRecord = CreateGroupHardwareDbRecord(bogusGroup.Id, bogusDas.DASId);
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareInsert(_user, connections.First(), groupHardwareDbRecord, out newId, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareInsert");
|
||||
|
||||
//**Get the GroupHardware record for the legit static Group only (1)
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareGet(_user, connections.First(), legitGroup.Id, legitDas.SerialNumber, legitGroup.Embedded, out GroupHardwareDbRecord[] groupHardwareRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareGet");
|
||||
Assert.IsTrue(null != groupHardwareRecords && groupHardwareRecords.Length == 2, "GroupHardwareGet should have retrieved 2 records");
|
||||
|
||||
//**Get all GroupHardware records (3)
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareGet(_user, connections.First(), null, null, null, out groupHardwareRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareGet");
|
||||
Assert.IsTrue(null != groupHardwareRecords && groupHardwareRecords.Length == 3, "GroupHardwareGet should have retrieved 3 records");
|
||||
|
||||
//**Delete the GroupHardware records for the bogus static Group
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareDelete(_user, connections.First(), bogusGroup.Id, bogusDas.DASId, out string errorString);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareDelete");
|
||||
|
||||
//**Get the deleted GroupHardware record (fail) (0)
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareGet(_user, connections.First(), bogusGroup.Id, bogusDas.SerialNumber, false, out groupHardwareRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareGet of deleted record");
|
||||
Assert.IsTrue(null != groupHardwareRecords && groupHardwareRecords.Length == 0, "GroupHardwareGet should have retrieved 0 records");
|
||||
|
||||
//**Get all GroupHardware records (2)
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareGet(_user, connections.First(), legitGroup.Id, bogusDas.SerialNumber, false, out groupHardwareRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareGet");
|
||||
Assert.IsTrue(null != groupHardwareRecords && groupHardwareRecords.Length == 2, "GroupHardwareGet should have retrieved 2 records");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
using DTS.Common.Classes.Channels;
|
||||
using DTS.Common.Classes.TestSetups;
|
||||
using DTS.Common.Interface.Channels;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public ITestSetupRecord CreateFakeTestSetup()
|
||||
{
|
||||
var record = new TestSetupRecord();
|
||||
record.Id = -1;
|
||||
record.Name = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.TestEngineerDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.Settings = "";
|
||||
return record;
|
||||
}
|
||||
/// <summary>
|
||||
/// As of database Version 92, TestSetupGet() can now be used to test
|
||||
/// Version 91 databases, as well as interoperability with Version 92 databases,
|
||||
/// depending on which is database is present at "...\db\DataPRO.mdf.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetupGet()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var recordToInsert = CreateFakeTestSetup();
|
||||
var decoyRecord = CreateFakeTestSetup();
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 0, ref recordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 0, ref decoyRecord);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy test setup");
|
||||
|
||||
//valid get all tests, should return the test we inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 0, null, null, double.NaN, double.NaN, false, false, out var records, out var errors);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestSetupsGet");
|
||||
Assert.IsTrue(null != records && records.Length > 0, "TestSetupsGet should have retrieved records");
|
||||
Assert.IsTrue(Array.Exists(records, r => r.Name == recordToInsert.Name), "TestSetupsGet should have retrieved our record");
|
||||
|
||||
//valid get all tests by id, should only return 1 of the 2 inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 0, recordToInsert.Id, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(!records.Any(r => r.Id != recordToInsert.Id), "TestSetupsGet should only return ids requested");
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the id");
|
||||
|
||||
//valid get all tests by name, should only return 1 of the 2 inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 0, null, recordToInsert.Name, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the name");
|
||||
Assert.IsTrue(!records.Any(r => !r.Name.Equals(recordToInsert.Name)), "TestSetupsGet should only return names requested");
|
||||
Assert.IsTrue(TestSetupsEqual(recordToInsert, records[0]), "TestSetupsGet should return untouched record");
|
||||
|
||||
//delete both - part of of cleanup
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections[0], new[] { recordToInsert.Id, decoyRecord.Id });
|
||||
Assert.IsTrue(0 == hr, "TestSetupsDeleteById should return 0");
|
||||
|
||||
//testing get, it should not return either of the two records we inserted because they should no longer be around
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 0, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr);
|
||||
Assert.IsTrue(null == records || 0 == records.Length || !Array.Exists(records, r => r.Id == recordToInsert.Id || r.Id == decoyRecord.Id));
|
||||
|
||||
//test that it fails when no user provided
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(null, connections[0], 0, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when user is invalid");
|
||||
|
||||
//test that it fails when no connection provided
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, null, 0, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when connection is invalid");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// As of database Version 92, TestSetupGet_92() can now be used to test
|
||||
/// Version 92 databases, as well as interoperability with Version 91 databases,
|
||||
/// depending on which is database is present at "...\db\DataPRO.mdf.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetupGet_92()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var recordToInsert = CreateFakeTestSetupWithROIs(2);
|
||||
var decoyRecord = CreateFakeTestSetup();
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 92, ref recordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 92, ref decoyRecord);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy test setup");
|
||||
|
||||
//valid get all tests, should return the test we inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out var records, out var errors);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestSetupsGet");
|
||||
Assert.IsTrue(null != records && records.Length > 0, "TestSetupsGet should have retrieved records");
|
||||
Assert.IsTrue(records.Any(r => r.Name == recordToInsert.Name), "TestSetupsGet should have retrieved our record");
|
||||
|
||||
//valid get all tests by id, should only return 1 of the 2 inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, recordToInsert.Id, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(!records.Any(r => r.Id != recordToInsert.Id), "TestSetupsGet should only return ids requested");
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the id");
|
||||
|
||||
//valid get all tests by name, should only return 1 of the 2 inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, recordToInsert.Name, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the name");
|
||||
Assert.IsTrue(!records.Any(r => !r.Name.Equals(recordToInsert.Name)), "TestSetupsGet should only return names requested");
|
||||
Assert.IsTrue(TestSetupsEqual(recordToInsert, records[0]), "TestSetupsGet should return untouched record");
|
||||
|
||||
//valid get the Test Setup, should only have something in the RegionsOfInterest if Version 91 database is used -
|
||||
//(in DataPRO, when using a Version 92 database, a later Load will read from the new tables)
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, recordToInsert.Name, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the name");
|
||||
Assert.IsTrue(!Array.Exists(records, r => !r.Name.Equals(recordToInsert.Name)), "TestSetupsGet should only return names requested");
|
||||
Assert.IsTrue(TestSetupsEqual(recordToInsert, records[0]), "TestSetupsGet should return untouched record");
|
||||
|
||||
DbAPI.DbAPI.GetDatabaseVersion(connections[0], out int serverDbVersion);
|
||||
if (serverDbVersion == 91)
|
||||
{
|
||||
Assert.IsTrue(records[0].RegionsOfInterest.Count == 2, "TestSetupsGet should have returned a RegionsOfInterest structure");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
Assert.IsTrue(records[0].RegionsOfInterest.Count == 0, "TestSetupsGet_92 should not have returned a RegionsOfInterest structure, but a later Load will read from the new tables");
|
||||
}
|
||||
|
||||
//delete both - part of of cleanup
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections[0], new[] { recordToInsert.Id, decoyRecord.Id });
|
||||
Assert.IsTrue(0 == hr, "TestSetupsDeleteById should return 0");
|
||||
|
||||
//testing get, it should not return either of the two records we inserted because they should no longer be around
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr);
|
||||
Assert.IsTrue(null == records || 0 == records.Length || !Array.Exists(records, r => r.Id == recordToInsert.Id || r.Id == decoyRecord.Id));
|
||||
|
||||
//test that it fails when no user provided
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(null, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when user is invalid");
|
||||
|
||||
//test that it fails when no connection provided
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, null, 92, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when connection is invalid");
|
||||
}
|
||||
private bool TestSetupsEqual(ITestSetupRecord left, ITestSetupRecord right)
|
||||
{
|
||||
return left.Id == right.Id
|
||||
&& left.AllowMissingSensors == right.AllowMissingSensors
|
||||
&& left.AllowSensorIdToBlankChannel == right.AllowSensorIdToBlankChannel
|
||||
&& left.AngularAccelLevelTriggerOn == right.AngularAccelLevelTriggerOn
|
||||
&& left.AngularAccelLevelTriggerOnX == right.AngularAccelLevelTriggerOnX
|
||||
&& left.AngularAccelLevelTriggerOnY == right.AngularAccelLevelTriggerOnY
|
||||
&& left.AngularAccelLevelTriggerOnZ == right.AngularAccelLevelTriggerOnZ
|
||||
&& left.AngularAccelLevelTriggerX == right.AngularAccelLevelTriggerX
|
||||
&& left.AngularAccelLevelTriggerY == right.AngularAccelLevelTriggerY
|
||||
&& left.AngularAccelLevelTriggerZ == right.AngularAccelLevelTriggerZ
|
||||
&& left.AngularRate == right.AngularRate
|
||||
&& left.AngularRateLevelTriggerOn == right.AngularRateLevelTriggerOn
|
||||
&& left.AngularRateLevelTriggerOnX == right.AngularRateLevelTriggerOnX
|
||||
&& left.AngularRateLevelTriggerOnY == right.AngularRateLevelTriggerOnY
|
||||
&& left.AngularRateLevelTriggerOnZ == right.AngularRateLevelTriggerOnZ
|
||||
&& left.AngularRateLevelTriggerX == right.AngularRateLevelTriggerX
|
||||
&& left.AngularRateLevelTriggerY == right.AngularRateLevelTriggerY
|
||||
&& left.AngularRateLevelTriggerZ == right.AngularRateLevelTriggerZ
|
||||
&& left.AutomaticProgression == right.AutomaticProgression
|
||||
&& left.AutomaticProgressionDelayMS == right.AutomaticProgressionDelayMS
|
||||
&& left.AutoVerifyChannels == right.AutoVerifyChannels
|
||||
&& left.AutoVerifyDelaySeconds == right.AutoVerifyDelaySeconds
|
||||
&& left.CalibrationBehavior == right.CalibrationBehavior
|
||||
&& left.CheckoutMode == right.CheckoutMode
|
||||
&& left.ClockSyncProfileMaster == right.ClockSyncProfileMaster
|
||||
&& left.ClockSyncProfileSlave == right.ClockSyncProfileSlave
|
||||
&& left.CommonStatusLine == right.CommonStatusLine
|
||||
&& left.CustomerDetails == right.CustomerDetails
|
||||
&& left.DefaultNumberRealtimeGraphs == right.DefaultNumberRealtimeGraphs
|
||||
&& left.Description == right.Description
|
||||
&& left.Dirty == right.Dirty
|
||||
&& left.DoAutoArm == right.DoAutoArm
|
||||
&& left.DoROIDownload == right.DoROIDownload
|
||||
&& left.DoStreaming == right.DoStreaming
|
||||
&& left.DownloadAll == right.DownloadAll
|
||||
&& left.ErrorMessage.Equals(right.ErrorMessage)
|
||||
&& left.ExportFormats == right.ExportFormats
|
||||
//&& left.ExtraProperties
|
||||
&& left.HighgLevelTriggerOn == right.HighgLevelTriggerOn
|
||||
&& left.HighgLevelTriggerOnX == right.HighgLevelTriggerOnX
|
||||
&& left.HighgLevelTriggerOnY == right.HighgLevelTriggerOnY
|
||||
&& left.HighgLevelTriggerOnZ == right.HighgLevelTriggerOnZ
|
||||
&& left.HighgLinearAccRate == right.HighgLinearAccRate
|
||||
&& left.HighgLinearLevelTriggerX == right.HighgLinearLevelTriggerX
|
||||
&& left.HighgLinearLevelTriggerY == right.HighgLinearLevelTriggerY
|
||||
&& left.HighgLinearLevelTriggerZ == right.HighgLinearLevelTriggerZ
|
||||
&& left.HumidityLevelTriggerAbove == right.HumidityLevelTriggerAbove
|
||||
&& left.HumidityLevelTriggerBelow == right.HumidityLevelTriggerBelow
|
||||
&& left.HumidityLevelTriggerOn == right.HumidityLevelTriggerOn
|
||||
&& left.InvertStartRecordCompletion == right.InvertStartRecordCompletion
|
||||
&& left.InvertTriggerCompletion == right.InvertTriggerCompletion
|
||||
&& left.IsComplete == right.IsComplete
|
||||
// can be modified
|
||||
//&& left.ISFFile.Equals(right.ISFFile)
|
||||
&& left.LabDetails.Equals(right.LabDetails)
|
||||
&& left.LastModified.Equals(right.LastModified)
|
||||
&& left.LastModifiedBy.Equals(right.LastModifiedBy)
|
||||
&& left.LocalOnly == right.LocalOnly
|
||||
&& left.LowgLevelTriggerOn == right.LowgLevelTriggerOn
|
||||
&& left.LowgLevelTriggerOnX == right.LowgLevelTriggerOnX
|
||||
&& left.LowgLevelTriggerOnY == right.LowgLevelTriggerOnY
|
||||
&& left.LowgLevelTriggerOnZ == right.LowgLevelTriggerOnZ
|
||||
&& left.LowgLinearAccRate == right.LowgLinearAccRate
|
||||
&& left.LowgLinearLevelTriggerX == right.LowgLinearLevelTriggerX
|
||||
&& left.LowgLinearLevelTriggerY == right.LowgLinearLevelTriggerY
|
||||
&& left.LowgLinearLevelTriggerZ == right.LowgLinearLevelTriggerZ
|
||||
&& left.MeasureSquibResistancesStep == right.MeasureSquibResistancesStep
|
||||
&& left.Name.Equals(right.Name)
|
||||
&& left.NotAllChannelsRealTime == right.NotAllChannelsRealTime
|
||||
&& left.NotAllChannelsViewer == right.NotAllChannelsViewer
|
||||
&& left.NumberOfEvents == right.NumberOfEvents
|
||||
&& left.WakeUpMotionTimeout == right.WakeUpMotionTimeout
|
||||
&& left.PostTestDiagnosticsLevel == right.PostTestDiagnosticsLevel
|
||||
&& left.PostTriggerSeconds == right.PostTriggerSeconds
|
||||
&& left.PressureLevelTriggerAbove == right.PressureLevelTriggerAbove
|
||||
&& left.PressureLevelTriggerBelow == right.PressureLevelTriggerBelow
|
||||
&& left.PressureLevelTriggerOn == right.PressureLevelTriggerOn
|
||||
&& left.PreTriggerSeconds == right.PreTriggerSeconds
|
||||
&& left.QuitTestWithoutWarning == right.QuitTestWithoutWarning
|
||||
&& left.QuitTestWithoutWarning == right.QuitTestWithoutWarning
|
||||
&& left.RecordingMode == right.RecordingMode
|
||||
//&& left.RegionsOfInterest
|
||||
&& left.RequireUserConfirmationOnErrors == right.RequireUserConfirmationOnErrors
|
||||
&& left.ROIEnd == right.ROIEnd
|
||||
&& left.ROIStart == right.ROIStart
|
||||
&& left.RTCScheduleDuration.Equals(right.RTCScheduleDuration)
|
||||
//can be modified on insert if invalid
|
||||
//&& left.RTCScheduleStartDateTime.Equals(right.RTCScheduleStartDateTime)
|
||||
&& left.RTCScheduleTriggerOn == right.RTCScheduleTriggerOn
|
||||
&& left.SameAsDownloadFolder == right.SameAsDownloadFolder
|
||||
&& left.SamplesPerSecondAggregate.Equals(right.SamplesPerSecondAggregate)
|
||||
&& left.Settings.Equals(right.Settings)
|
||||
&& left.StrictDiagnostics == right.StrictDiagnostics
|
||||
&& left.SuppressMissingSensorsWarning == right.SuppressMissingSensorsWarning
|
||||
&& left.TemperatureHumidityPressureRate == right.TemperatureHumidityPressureRate
|
||||
&& left.TemperatureLevelTriggerAbove == right.TemperatureLevelTriggerAbove
|
||||
&& left.TemperatureLevelTriggerBelow == right.TemperatureLevelTriggerBelow
|
||||
&& left.TemperatureLevelTriggerOn == right.TemperatureLevelTriggerOn
|
||||
&& left.TestEngineerDetails == right.TestEngineerDetails
|
||||
&& left.TestSetupUniqueId == right.TestSetupUniqueId
|
||||
&& left.TimedIntervalDuration == right.TimedIntervalDuration
|
||||
&& left.TimedIntervalEvents == right.TimedIntervalEvents
|
||||
&& left.IntervalBetweenEventStartsMinutes == right.IntervalBetweenEventStartsMinutes
|
||||
&& left.TimedIntervalTriggerOn == right.TimedIntervalTriggerOn
|
||||
&& left.TimedIntervalUnits == right.TimedIntervalUnits
|
||||
&& left.TriggerCheckRealtime == right.TriggerCheckRealtime
|
||||
&& left.TriggerCheckStep == right.TriggerCheckStep
|
||||
&& left.TurnOffExcitation == right.TurnOffExcitation
|
||||
&& left.UploadData == right.UploadData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class SensorsAnalogTests : TestSetups
|
||||
{
|
||||
|
||||
|
||||
[Test]
|
||||
// ============================================================
|
||||
// Send new valid analog sensor parameters to sp_SensorsAnalogUpdateInsert and
|
||||
// compare all fields except LastModified and new ID. Pass if all fields in SensorsAnalog
|
||||
// table are entered.
|
||||
// ============================================================
|
||||
[Category("sp_SensorsAnalogUpdateInsert")]
|
||||
public void VerifyWriteToAnalogTable_sp_SensorsAnalogUpdateInsertTest()
|
||||
{
|
||||
string filename = TestResultPath + "AnalogSensorInsertTest.xml";
|
||||
// only data in SensorsAnalog table will be compared
|
||||
UnitTests.AddObjectComparison("dbo", "SensorsAnalog");
|
||||
// But the LastModified column is excluded from comparison,
|
||||
// just to demonstrate how we do it.
|
||||
UnitTests.AddColumnToIgnore("dbo", "SensorsAnalog", "LastModified");
|
||||
UnitTests.AddColumnToIgnore("dbo", "SensorsAnalog", "Id");
|
||||
UnitTests.AddColumnToIgnore("dbo", "SensorsAnalog", "Created");
|
||||
|
||||
|
||||
|
||||
Command.CommandType = CommandType.StoredProcedure;
|
||||
Command.CommandText = "sp_SensorsAnalogUpdateInsert";
|
||||
|
||||
Command.Parameters.Add(new SqlParameter("@SerialNumber", SqlDbType.NVarChar, 50) { Value = "CubicSensor_18" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserSerialNumber", SqlDbType.NVarChar, 50) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@Model", SqlDbType.NVarChar, 50) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@Manufacturer", SqlDbType.NVarChar, 50) { Value = "DTS" });
|
||||
Command.Parameters.Add(new SqlParameter("@Status", SqlDbType.SmallInt) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@MeasurementUnit", SqlDbType.NVarChar, 50) { Value = "mm" });
|
||||
Command.Parameters.Add(new SqlParameter("@OffsetToleranceLow", SqlDbType.Float) { Value = -100 });
|
||||
Command.Parameters.Add(new SqlParameter("@OffsetToleranceHigh", SqlDbType.Float) { Value = 100 });
|
||||
Command.Parameters.Add(new SqlParameter("@eId", SqlDbType.NVarChar, 50) { Value = "AABBCCDD" });
|
||||
Command.Parameters.Add(new SqlParameter("@Capacity", SqlDbType.Float) { Value = 2000 });
|
||||
Command.Parameters.Add(new SqlParameter("@Comment", SqlDbType.NVarChar, 255) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@BridgeType", SqlDbType.SmallInt) { Value = 3 });
|
||||
Command.Parameters.Add(new SqlParameter("@BridgeLegMode", SqlDbType.SmallInt) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@Shunt", SqlDbType.SmallInt) { Value = 1 });
|
||||
Command.Parameters.Add(new SqlParameter("@Invert", SqlDbType.Bit) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@UserValue1", SqlDbType.NVarChar, 50) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserValue2", SqlDbType.NVarChar, 50) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserValue3", SqlDbType.NVarChar, 50) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@FilterClass", SqlDbType.NVarChar, 50) { Value = "None" });
|
||||
Command.Parameters.Add(new SqlParameter("@BridgeResistance", SqlDbType.Float) { Value = 349 });
|
||||
Command.Parameters.Add(new SqlParameter("@IsoCode", SqlDbType.NVarChar, 50) { Value = "???????????????P" });
|
||||
Command.Parameters.Add(new SqlParameter("@CheckOffset", SqlDbType.Bit) { Value = 1 });
|
||||
Command.Parameters.Add(new SqlParameter("@SupportedExcitation", SqlDbType.NVarChar, 50) { Value = "Volt5" });
|
||||
Command.Parameters.Add(new SqlParameter("@InitialEU", SqlDbType.Float) { Value = .501 });
|
||||
Command.Parameters.Add(new SqlParameter("@CalInterval", SqlDbType.Int) { Value = 365 });
|
||||
Command.Parameters.Add(new SqlParameter("@CalibrationSignal", SqlDbType.Bit) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@InternalShuntResistance", SqlDbType.Float) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@ExternalShuntResistance", SqlDbType.Float) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@UniPolar", SqlDbType.Bit) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@RangeLow", SqlDbType.Float) { Value = 10 });
|
||||
Command.Parameters.Add(new SqlParameter("@RangeAve", SqlDbType.Float) { Value = 100 });
|
||||
Command.Parameters.Add(new SqlParameter("@RangeHigh", SqlDbType.Float) { Value = 1000 });
|
||||
Command.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime) { Value = DateTime.Now });
|
||||
Command.Parameters.Add(new SqlParameter("@TimesUsed", SqlDbType.BigInt) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@SensorCategory", SqlDbType.Int) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@BypassFilter", SqlDbType.Bit) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@CouplingMode", SqlDbType.SmallInt) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@Version", SqlDbType.Int) { Value = 1 });
|
||||
Command.Parameters.Add(new SqlParameter("@LastModified", SqlDbType.DateTime) { Value = DateTime.Now });
|
||||
Command.Parameters.Add(new SqlParameter("@ModifiedBy", SqlDbType.NVarChar, 50) { Value = "TestUser" });
|
||||
Command.Parameters.Add(new SqlParameter("@LocalOnly", SqlDbType.Bit) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@AxisNumber", SqlDbType.SmallInt) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@NumberOfAxes", SqlDbType.SmallInt) { Value = 1 });
|
||||
Command.Parameters.Add(new SqlParameter("@UserTags", SqlDbType.VarBinary) { Value = new byte[10 * sizeof(int)] });
|
||||
Command.Parameters.Add(new SqlParameter("@DoNotUse", SqlDbType.Bit) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@Broken", SqlDbType.Bit) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@DiagnosticsMode", SqlDbType.Bit) { Value = 0 });
|
||||
Command.Parameters.Add(new SqlParameter("@FirstUseDate", SqlDbType.DateTime) { Value = DBNull.Value });
|
||||
Command.Parameters.Add(new SqlParameter("@LatestCalibrationId", SqlDbType.Int) { Value = DBNull.Value });
|
||||
var newIdParam = new SqlParameter("@new_id", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
Command.Parameters.Add(newIdParam);
|
||||
var errorNumberParam = new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
Command.Parameters.Add(errorNumberParam);
|
||||
var errorMessageParam = new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250) { Direction = ParameterDirection.Output };
|
||||
Command.Parameters.Add(errorMessageParam);
|
||||
|
||||
Command.ExecuteNonQuery();
|
||||
if (BSETUPMODE)
|
||||
UnitTests.WriteDiffsToXml(filename);
|
||||
else
|
||||
Assert.IsTrue(UnitTests.CompareDiffsToXml(filename));
|
||||
}
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Send valid analog sensor parameters to sp_SensorsAnalogUpdateInsert for a sensor
|
||||
// already in the database and compare all fields except LastModified, new ID, and Created.
|
||||
// Pass if all fields in SensorsAnalog table are entered.
|
||||
// ============================================================
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Send valid analog sensor parameters to sp_SensorsAnalogUpdateInsert for a sensor
|
||||
// already in the database and verify no new row is created in dbo.Sensors.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Send valid analog sensor parameters to sp_SensorsAnalogUpdateInsert for a new sensor
|
||||
// to be entered into the db and verify a new row is created in dbo.Sensors.
|
||||
//
|
||||
// ============================================================
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using DTS.Common.Interface.Database;
|
||||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
private const string INSTANCE_NAME = "DataPROInstance";
|
||||
private const string LOCAL_SERVER = @"(localdb)\DataPROInstance";
|
||||
private const string SCRIPTS_FOLDER = "SQL Server Scripts";
|
||||
private const string LOCAL_DB_FOLDER = "db";
|
||||
private const string ISO = "ISO";
|
||||
private const string ATTACH_DBS_BAT = "AttachDBs.bat";
|
||||
private bool _setup = false;
|
||||
private IUserDbRecord _user = null;
|
||||
private const int SettingsDefaultMaxLogFileSize = 4194304;
|
||||
private const int SettingsDefaultDBLoggingLevel = 783;
|
||||
private int clientDbVersion = DTS.Common.Storage.DbOperations.MINIMUM_LTS_DB_VERSION;
|
||||
[OneTimeSetUp]
|
||||
public void Setup()
|
||||
{
|
||||
if (!DbAPI.DbAPI._loggerInitialized)
|
||||
{
|
||||
DbAPI.DbAPI.InitializeLogger(SettingsDefaultMaxLogFileSize, "Logs", SettingsDefaultDBLoggingLevel);
|
||||
}
|
||||
|
||||
var dllLocation = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
var debugOrRelease = dllLocation.Directory.Name;
|
||||
var architecture = dllLocation.Directory.Parent.Name;
|
||||
var curDir = System.Environment.CurrentDirectory;
|
||||
if (curDir.Contains("Common"))
|
||||
{
|
||||
curDir = curDir.Substring(0, curDir.IndexOf("Common"));
|
||||
curDir = Path.Combine(curDir, "DataPRO");
|
||||
}
|
||||
else
|
||||
{
|
||||
var tokens = curDir.Split(new[] { Path.DirectorySeparatorChar });
|
||||
var count = tokens.Count(d => d.Equals("DataPRO"));
|
||||
if (1 == count)
|
||||
{
|
||||
tokens[0] = $"{tokens[0]}{Path.DirectorySeparatorChar}";
|
||||
var index = tokens.ToList().IndexOf("DataPRO");
|
||||
tokens = tokens.Take(index + 1).ToArray();
|
||||
curDir = Path.Combine(tokens);
|
||||
}
|
||||
else if (0 == count)
|
||||
{
|
||||
curDir = Path.Combine(curDir, "DataPRO");
|
||||
}
|
||||
}
|
||||
var exeOutputLocation = Path.Combine(curDir, "DataPRO", "bin", architecture, debugOrRelease);
|
||||
var details = new DbAPI.Connections.ConnectionDetails();
|
||||
|
||||
details.AttachDbsBatPath = Path.Combine(exeOutputLocation, SCRIPTS_FOLDER, ATTACH_DBS_BAT);
|
||||
details.DbFolderPath = Path.Combine(exeOutputLocation, LOCAL_DB_FOLDER);
|
||||
details.DbName = "DataPRO";
|
||||
details.UsingCentralizedDb = false;
|
||||
details.DbServer = LOCAL_SERVER;
|
||||
details.InstanceName = INSTANCE_NAME;
|
||||
details.UseNTLMAuthentication = true;
|
||||
details.SqlDbPath = DTS.Common.Utils.Database.GetSqlServerLocalDbPath();
|
||||
details.ODBCToolsPath = DTS.Common.Utils.Database.GetODBCToolsPath(null);
|
||||
var res = DbAPI.DbAPI.Connections.ConnectToDb(details);
|
||||
_setup = true;
|
||||
}
|
||||
[Test]
|
||||
public void TestConnect()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
Assert.IsTrue(connections.Any(), $"Db connected");
|
||||
}
|
||||
private void Login()
|
||||
{
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var hr = DbAPI.DbAPI.Connections.LoginUser(connections.First(), "Admin", "DTSAdmin", out var user);
|
||||
if (0 == hr)
|
||||
{
|
||||
_user = user;
|
||||
clientDbVersion = connections.FirstOrDefault().ClientDbVersion;
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public void TestLogin()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestConnect();
|
||||
if (null == _user) { Login(); }
|
||||
Assert.IsNotNull(_user, "User logged in");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using DTS.Common.Interface.TestMetaData;
|
||||
using DTS.Common.Classes.LabratoryDetails;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public LabratoryDetailsDbRecord CreateFakeLabratoryDetails(string name)
|
||||
{
|
||||
var record = new LabratoryDetailsDbRecord();
|
||||
record.LabratoryId = -1;
|
||||
record.Name = name;
|
||||
record.LabratoryName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryContactName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryContactPhone = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryContactFax = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryContactEmail = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryTestRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryProjectRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.LocalOnly = true;
|
||||
record.Version = 1;
|
||||
return record;
|
||||
}
|
||||
[Test]
|
||||
public void LaboratoryDetails()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//Delete all to start with a blank table
|
||||
var hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsDelete(_user, connections.First(), null, out string errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsDelete");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), null, out ILabratoryDetailsDbRecord[] allLabratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != allLabratoryDetailsDbRecords && allLabratoryDetailsDbRecords.Length == 0, "LabratoryDetailsGet should have retrieved 0 records");
|
||||
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var legitRecord = CreateFakeLabratoryDetails("legit");
|
||||
var decoyRecord = CreateFakeLabratoryDetails("decoy");
|
||||
|
||||
//Insert
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsInsert(_user, connections.First(), legitRecord, out int newLegitId, out string legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate LabratoryDetails record");
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsInsert(_user, connections.First(), decoyRecord, out int newFakeId, out string fakeErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy LabratoryDetails record");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), legitRecord.Name, out ILabratoryDetailsDbRecord[] labratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != labratoryDetailsDbRecords && labratoryDetailsDbRecords.Length == 1, "LabratoryDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(labratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should have retrieved only one record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), null, out allLabratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != allLabratoryDetailsDbRecords && allLabratoryDetailsDbRecords.Length == 2, "LabratoryDetailsGet should have retrieved 2 records");
|
||||
Assert.IsTrue(allLabratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should have retrieved our record");
|
||||
Assert.IsTrue(allLabratoryDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "LabratoryDetailsGet should have retrieved our record");
|
||||
|
||||
//Update
|
||||
var newLabratoryTestRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
legitRecord.LabratoryTestRefNumber = newLabratoryTestRefNumber;
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsUpdate(_user, connections.First(), legitRecord, out legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate LabratoryDetails record");
|
||||
Assert.IsTrue(legitErrorString == string.Empty, $"Error when inserting a legitimate LabratoryDetails record: {legitErrorString}");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), legitRecord.Name, out labratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != labratoryDetailsDbRecords && labratoryDetailsDbRecords.Length == 1, "LabratoryDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(labratoryDetailsDbRecords.Any(r => r.LabratoryTestRefNumber == newLabratoryTestRefNumber), "LabratoryDetailsGet should have retrieved the updated record");
|
||||
|
||||
//Delete by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsDelete(_user, connections.First(), legitRecord.Name, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), legitRecord.Name, out labratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != labratoryDetailsDbRecords, "LabratoryDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(labratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should not have retrieved this record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), null, out allLabratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != allLabratoryDetailsDbRecords && allLabratoryDetailsDbRecords.Length == 1, "LabratoryDetailsGet should have retrieved only the decoy record");
|
||||
Assert.IsFalse(allLabratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet not should have retrieved this record");
|
||||
Assert.IsTrue(allLabratoryDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "LabratoryDetailsGet should have retrieved this record");
|
||||
|
||||
//Delete all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsDelete(_user, connections.First(), null, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), legitRecord.Name, out labratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != labratoryDetailsDbRecords, "LabratoryDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(labratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should not have retrieved any records");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), null, out allLabratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != allLabratoryDetailsDbRecords, "LabratoryDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(allLabratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should not have retrieved any records");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class CalculatedChannelsTests : TestSetups
|
||||
{
|
||||
|
||||
// Notes:
|
||||
// Operation
|
||||
// SUM = 1,
|
||||
// AVERAGE = 2,
|
||||
// IRTRACC3D =3,
|
||||
// IRTRACC3D_ABDOMEN =4,
|
||||
// IRTRACC3D_LOWERTHORAX = 5
|
||||
|
||||
|
||||
// [Test]
|
||||
// ============================================================
|
||||
// DELETE CALCULATED CHANNEL
|
||||
// Call sp_CalculatedChannelsDelete with a known calculated channel
|
||||
// Verify Calculated channel no longer exists in dbo.CalculatedChannels table.
|
||||
// ============================================================
|
||||
|
||||
|
||||
// [Test]
|
||||
// =============================================================
|
||||
// GET CALCULATED CHANNEL
|
||||
// Start with a test setup that has a known number of calculated channels included. Call sp_CalculatedChannelsGet for test setup
|
||||
// Verify known calculated channels are returned
|
||||
// =============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT CALCULATED CHANNEL: VERIFY FIELDS
|
||||
// Starting with a known populated test setup call sp_CalculatedChannelsUpdateInsert with parameters for a new valid
|
||||
// calculated channel and compare all fields.
|
||||
// Pass if all fields in dbo.CalculatedChannels table are entered.
|
||||
// ============================================================
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT CALCULATED CHANNEL: VERIFY ONLY ONE NEW ROW IS ADDED
|
||||
// Starting with a known populated test setup call sp_CalculatedChannelsUpdateInsert with parameters for a new valid
|
||||
// calculated channel and verify a new row is created in dbo.CalcualtedChannels table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE CALCULATED CHANNEL
|
||||
// Send valid calculated channels parameters to sp_CalculatedChannelsInUpdateInsert for a calculated
|
||||
// channel that already is in the database and compare all fields.
|
||||
// Pass if all fields in dbo.CalculatedChannels table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE CALCULATED CHANNEL: VERIFY NO NEW ROW IS ADDED
|
||||
// Send valid calculated channels parameters to sp_CalculatedChannelsInUpdateInsert for a calculated
|
||||
// channel that already is in the database and verify no new row is created in dbo.CalculatedChannels table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DatabaseUnitTesting.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="ConnectionString" Type="(Connection string)" Scope="Application">
|
||||
<DesignTimeValue Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
|
||||
<SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<ConnectionString>Data Source=FAJITA\DEV_SQL;Initial Catalog=DataPRO_UnitTest;Integrated Security=False;Persist Security Info=True;User ID=sa;Password=!!QQAAZZxxssww22;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False</ConnectionString>
|
||||
<ProviderName>System.Data.SqlClient</ProviderName>
|
||||
</SerializableConnectionString></DesignTimeValue>
|
||||
<Value Profile="(Default)">Data Source=FAJITA\DEV_SQL;Initial Catalog=DataPRO_UnitTest;Integrated Security=False;Persist Security Info=True;User ID=sa;Password=!!QQAAZZxxssww22;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False</Value>
|
||||
</Setting>
|
||||
<Setting Name="DBName" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)">DataPRO_UnitTest</Value>
|
||||
</Setting>
|
||||
<Setting Name="DBSnapshot" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)">DataPRO_UnitTestSnapshot</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DatabaseUnitTesting.Utilities
|
||||
{
|
||||
internal class ObjectsToCompare
|
||||
{
|
||||
private readonly string _schema1Name;
|
||||
private readonly string _object1Name;
|
||||
private readonly string _schema2Name;
|
||||
private readonly string _object2Name;
|
||||
|
||||
private readonly List<string> _columnsToIgnore = new List<string>();
|
||||
|
||||
public ObjectsToCompare(string schema1Name, string object1Name, string schema2Name,
|
||||
string object2Name)
|
||||
{
|
||||
_schema1Name = schema1Name;
|
||||
_object1Name = object1Name;
|
||||
_schema2Name = schema2Name;
|
||||
_object2Name = object2Name;
|
||||
}
|
||||
|
||||
public IEnumerable<string> ColumnsToIgnore
|
||||
{
|
||||
get { return _columnsToIgnore; }
|
||||
}
|
||||
|
||||
public string Object1Name
|
||||
{
|
||||
get { return _object1Name; }
|
||||
}
|
||||
|
||||
public string Schema1Name
|
||||
{
|
||||
get { return _schema1Name; }
|
||||
}
|
||||
|
||||
public string Object2Name
|
||||
{
|
||||
get { return _object2Name; }
|
||||
}
|
||||
|
||||
public string Schema2Name
|
||||
{
|
||||
get { return _schema2Name; }
|
||||
}
|
||||
|
||||
public string Qualified1
|
||||
{
|
||||
get { return _schema1Name + "." + _object1Name; }
|
||||
}
|
||||
|
||||
public string Qualified2
|
||||
{
|
||||
get { return _schema2Name + "." + _object2Name; }
|
||||
}
|
||||
|
||||
public void AddColumnToIgnore(string columnName)
|
||||
{
|
||||
_columnsToIgnore.Add(columnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class SensorsDigitalInUnitTests : TestSetups
|
||||
{
|
||||
|
||||
[Test]
|
||||
// ============================================================
|
||||
// Send new valid digital in sensor parameters to sp_SensorsDigitalInUpdateInsert and
|
||||
// compare all fields except LastModified and new ID. Pass if all fields in SensorsDigitalIn
|
||||
// table are entered.
|
||||
// ============================================================
|
||||
[Category("sp_SensorsDigitalInUpdateInsert")]
|
||||
public void VerifyWriteToDigitalInTable_sp_SensorsDigitalInUpdateInsertTest()
|
||||
{
|
||||
string filename = TestResultPath + "DigitalInSensorInsertTest.xml";
|
||||
// only data in SensorsDigitalIn table will be compared
|
||||
UnitTests.AddObjectComparison("dbo", "SensorsDigitalIn");
|
||||
// But the LastModified column is excluded from comparison,
|
||||
// just to demonstrate how we do it.
|
||||
UnitTests.AddColumnToIgnore("dbo", "SensorsDigitalIn", "LastModified");
|
||||
UnitTests.AddColumnToIgnore("dbo", "SensorsDigitalIn", "Id");
|
||||
Command.CommandType = CommandType.StoredProcedure;
|
||||
Command.CommandText = "sp_SensorsDigitalInUpdateInsert";
|
||||
|
||||
Command.Parameters.Add(new SqlParameter("@SerialNumber", SqlDbType.NVarChar) { Value = "DigiInSerialNum" });
|
||||
Command.Parameters.Add(new SqlParameter("@SettingMode", SqlDbType.Int) { Value = 8 });
|
||||
Command.Parameters.Add(new SqlParameter("@ScaleMultiplier", SqlDbType.NVarChar) { Value = "ArbitraryHighAndLow,1,2" });
|
||||
Command.Parameters.Add(new SqlParameter("@LastModified", SqlDbType.DateTime) { Value = DateTime.Now });
|
||||
Command.Parameters.Add(new SqlParameter("@LastModifiedBy", SqlDbType.NVarChar) { Value = "TestUser" });
|
||||
Command.Parameters.Add(new SqlParameter("@eId", SqlDbType.NVarChar) { Value = "EID" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserValue1", SqlDbType.NVarChar) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserValue2", SqlDbType.NVarChar) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserValue3", SqlDbType.NVarChar) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserTags", SqlDbType.VarBinary) { Value = new byte[10 * sizeof(int)] });
|
||||
|
||||
var newIdParam = new SqlParameter("@new_id", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output };
|
||||
Command.Parameters.Add(newIdParam);
|
||||
var errorNumberParam = new SqlParameter("@errorNumber", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output };
|
||||
Command.Parameters.Add(errorNumberParam);
|
||||
var errorMessageParam = new SqlParameter("@errorMessage", System.Data.SqlDbType.NVarChar, 250) { Direction = System.Data.ParameterDirection.Output };
|
||||
Command.Parameters.Add(errorMessageParam);
|
||||
|
||||
Command.ExecuteNonQuery();
|
||||
if (BSETUPMODE)
|
||||
UnitTests.WriteDiffsToXml(filename);
|
||||
else
|
||||
Assert.IsTrue(UnitTests.CompareDiffsToXml(filename));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
// ============================================================
|
||||
// Send valid digital in sensor parameters to sp_SensorsDigitalInUpdateInsert for a sensor
|
||||
// already in the database and compare all fields except LastModified and new ID.
|
||||
// Pass if all fields in SensorsDigitalIn table are entered.
|
||||
// ============================================================
|
||||
[Category("sp_SensorsDigitalInUpdateInsert")]
|
||||
public void VerifyUpdateToDigitalIn_sp_SensorsDigitalInUpdateInsertTest()
|
||||
{
|
||||
string filename = TestResultPath + "DigitalInSensorUpdateTest.xml";
|
||||
// only data in SensorsDigitalIn table will be compared
|
||||
UnitTests.AddObjectComparison("dbo", "SensorsDigitalIn");
|
||||
// But the LastModified column is excluded from comparison,
|
||||
// just to demonstrate how we do it.
|
||||
UnitTests.AddColumnToIgnore("dbo", "SensorsDigitalIn", "LastModified");
|
||||
UnitTests.AddColumnToIgnore("dbo", "SensorsDigitalIn", "Id");
|
||||
|
||||
//SqlCommand command = connection.CreateCommand();
|
||||
//command.Transaction = transaction;
|
||||
Command.CommandType = CommandType.StoredProcedure;
|
||||
Command.CommandText = "sp_SensorsDigitalInUpdateInsert";
|
||||
|
||||
Command.Parameters.Add(new SqlParameter("@SerialNumber", SqlDbType.NVarChar) { Value = "DigiInSerialNum" });
|
||||
Command.Parameters.Add(new SqlParameter("@SettingMode", SqlDbType.Int) { Value = 8 });
|
||||
Command.Parameters.Add(new SqlParameter("@ScaleMultiplier", SqlDbType.NVarChar) { Value = "ArbitraryHighAndLow,1,2" });
|
||||
Command.Parameters.Add(new SqlParameter("@LastModified", SqlDbType.DateTime) { Value = DateTime.Now });
|
||||
Command.Parameters.Add(new SqlParameter("@LastModifiedBy", SqlDbType.NVarChar) { Value = "TestUser" });
|
||||
Command.Parameters.Add(new SqlParameter("@eId", SqlDbType.NVarChar) { Value = "EID" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserValue1", SqlDbType.NVarChar) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserValue2", SqlDbType.NVarChar) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserValue3", SqlDbType.NVarChar) { Value = "" });
|
||||
Command.Parameters.Add(new SqlParameter("@UserTags", SqlDbType.VarBinary) { Value = new byte[10 * sizeof(int)] });
|
||||
|
||||
var newIdParam = new SqlParameter("@new_id", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output };
|
||||
Command.Parameters.Add(newIdParam);
|
||||
var errorNumberParam = new SqlParameter("@errorNumber", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output };
|
||||
Command.Parameters.Add(errorNumberParam);
|
||||
var errorMessageParam = new SqlParameter("@errorMessage", System.Data.SqlDbType.NVarChar, 250) { Direction = System.Data.ParameterDirection.Output };
|
||||
Command.Parameters.Add(errorMessageParam);
|
||||
|
||||
Command.ExecuteNonQuery();
|
||||
|
||||
//Now that the sensor is saved, make a change so "update" is called
|
||||
Command.Parameters[5].Value = "EID_Modified";
|
||||
Command.ExecuteNonQuery();
|
||||
|
||||
|
||||
if (BSETUPMODE)
|
||||
UnitTests.WriteDiffsToXml(filename);
|
||||
else
|
||||
Assert.IsTrue(UnitTests.CompareDiffsToXml(filename));
|
||||
}
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Send valid digital in sensor parameters to sp_SensorsDigitalInUpdateInsert for a sensor
|
||||
// already in the database and verify no new row is created in dbo.Sensors.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Send valid digital in sensor parameters to sp_SensorsDigitalInUpdateInsert for a new sensor
|
||||
// to be entered into the db and verify a new row is created in dbo.Sensors.
|
||||
//
|
||||
// ============================================================
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
using DTS.Common.Classes.Tags;
|
||||
using DTS.Common.Interface.Sensors;
|
||||
using DTS.Common.Interface.Tags;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
[Test]
|
||||
public void TagsTestGetNegatives()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var tag = CreateFakeTag();
|
||||
|
||||
//insert a tag just so that we have something that _might_ be returned
|
||||
var hr = DbAPI.DbAPI.Tags.TagsInsert(_user, connections.First(), ref tag);
|
||||
Assert.IsTrue(0 == hr, "TagsInsert returned 0");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(null, connections.First(), null, out var records);
|
||||
Assert.IsTrue(0 != hr && (null == records || 0 == records.Length), "TagsGet should not allow null user");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(_user, null, null, out records);
|
||||
Assert.IsTrue(0 != hr && (null == records || 0 == records.Length), "TagsGet should not allow null connection");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGetId(null, connections.First(), tag.Text, out var id);
|
||||
Assert.IsTrue(0 != hr && null == id, "TagsGetId should not allow null user");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGetId(_user, null, tag.Text, out id);
|
||||
Assert.IsTrue(0 != hr && null == id, "TagsGetId should not allow null connection");
|
||||
|
||||
ITag tag2 = null;
|
||||
hr = DbAPI.DbAPI.Tags.TagsInsert(_user, connections.First(), ref tag2);
|
||||
Assert.IsTrue(DbAPI.Errors.ErrorCodes.ERROR_MISSING_PARAMETER == hr, "TagsInsert with null does return missing parameter");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(null, connections.First(), tag.ID);
|
||||
Assert.IsTrue(0 != hr, "TagsDelete should not allow null user");
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(_user, null, tag.ID);
|
||||
Assert.IsTrue(0 != hr, "TagsDelete should not allow null connection");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(_user, connections.First(), tag.ID);
|
||||
Assert.IsTrue(0 == hr, "TagsDelete returns 0");
|
||||
}
|
||||
[Test]
|
||||
public void TagsTestGetPositives()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var tag = CreateFakeTag();
|
||||
var hr = DbAPI.DbAPI.Tags.TagsGet(_user, connections.First(), null, out var records);
|
||||
Assert.IsTrue(0 == hr && (null == records || !records.Any(r => r.Text == tag.Text)),
|
||||
"TagsGet returns 0 and GUID text not already found");
|
||||
hr = DbAPI.DbAPI.Tags.TagsInsert(_user, connections.First(), ref tag);
|
||||
Assert.IsTrue(0 == hr && -1 != tag.ID, "TagsInsert returns 0 and modifies id");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(_user, connections.First(), null, out records);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Any(r => r.Text == tag.Text && r.ID == tag.ID),
|
||||
"TagsGet returns 0 and finds the tag");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(_user, connections.First(), tag.ID, out records);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length == 1 && TagIsEqual(records[0], tag)
|
||||
, "TagsGet returns 0, and returns the tag [when passing in id]");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGetId(_user, connections.First(), tag.Text, out var id);
|
||||
Assert.IsTrue(0 == hr && null != id && (int)id == tag.ID, "TagsGetId returns 0 and retrieves right id");
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(_user, connections.First(), tag.ID);
|
||||
Assert.IsTrue(0 == hr, "TagsDelete returns 0");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(_user, connections.First(), null, out records);
|
||||
Assert.IsTrue(0 == hr && null == records || !records.Any(r => r.Text == tag.Text), "TagsDelete returns 0");
|
||||
}
|
||||
private bool TagIsEqual(ITag left, ITag right)
|
||||
{
|
||||
return left.ID == right.ID &&
|
||||
left.IsObsolete == right.IsObsolete &&
|
||||
left.Text.Equals(right.Text);
|
||||
}
|
||||
public static ITag CreateFakeTag()
|
||||
{
|
||||
var tag = new Tag();
|
||||
tag.ID = -1;
|
||||
tag.Text = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
return tag;
|
||||
}
|
||||
[Test]
|
||||
public void TagAssignmentsPositives()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var tag = CreateFakeTag();
|
||||
|
||||
_ = DbAPI.DbAPI.Tags.TagsInsert(_user, connections.First(), ref tag);
|
||||
|
||||
var testSetup = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections.First(), 0, ref testSetup);
|
||||
var sensor = CreateFakeSensor();
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
|
||||
var hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), null, out var tagAssignments);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsGet returns 0");
|
||||
|
||||
var taTestSetup = CreateTagAssignment(tag, testSetup);
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, connections.First(), taTestSetup);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsInsert returns 0");
|
||||
|
||||
var taSensor = CreateTagAssignment(tag, sensor);
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, connections.First(), taSensor);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsInsert returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), null, out tagAssignments);
|
||||
Assert.IsTrue(0 == hr && null != tagAssignments &&
|
||||
tagAssignments.Any(t => IsTagAssignmentEqual(t, taTestSetup)) &&
|
||||
tagAssignments.Any(t => IsTagAssignmentEqual(t, taSensor)),
|
||||
"TagAssignmentsGet returns tag assignments");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), TagTypes.TestSetup, out tagAssignments);
|
||||
Assert.IsTrue(0 == hr && null != tagAssignments && tagAssignments.Any(t => IsTagAssignmentEqual(t, taTestSetup)),
|
||||
"TagAssignmentsGet returns taTestSetup");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), TagTypes.Sensors, out tagAssignments);
|
||||
Assert.IsTrue(0 == hr && null != tagAssignments && tagAssignments.Any(t => IsTagAssignmentEqual(t, taSensor)),
|
||||
"TagAssignmentsGet returns taSensor");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsDelete(_user, connections.First(), taSensor.ObjectID, TagTypes.Sensors);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsDelete returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsDelete(_user, connections.First(), taTestSetup.ObjectID, TagTypes.TestSetup);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsDelete returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), null, out tagAssignments);
|
||||
Assert.IsTrue(0 == hr && !tagAssignments.Any(t => IsTagAssignmentEqual(t, taSensor))
|
||||
&& !tagAssignments.Any(t => IsTagAssignmentEqual(t, taTestSetup)), "TagAssignments deleted");
|
||||
_ = DbAPI.DbAPI.Tags.TagsDelete(_user, connections.First(), tag.ID);
|
||||
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsDelete(_user, connections.First(), sensor.Id, 0);
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections.First(), new[] { testSetup.Id });
|
||||
}
|
||||
|
||||
private bool IsTagAssignmentEqual(ITagAssignment left, ITagAssignment right)
|
||||
{
|
||||
return left.ObjectID == right.ObjectID
|
||||
&& left.ObjectType == right.ObjectType
|
||||
&& left.TagID == right.TagID;
|
||||
}
|
||||
private ITagAssignment CreateTagAssignment(ITag tag, IAnalogDbRecord sensor)
|
||||
{
|
||||
var ta = new TagAssignment() { ObjectType = TagTypes.Sensors, TagID = tag.ID, ObjectID = sensor.Id };
|
||||
return ta;
|
||||
}
|
||||
private ITagAssignment CreateTagAssignment(ITag tag, ITestSetupRecord test)
|
||||
{
|
||||
var ta = new TagAssignment() { ObjectID = test.Id, ObjectType = TagTypes.TestSetup, TagID = tag.ID };
|
||||
return ta;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TagAssignmentsNegatives()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections().First();
|
||||
var tag = CreateFakeTag();
|
||||
|
||||
_ = DbAPI.DbAPI.Tags.TagsInsert(_user, con, ref tag);
|
||||
|
||||
var hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(null, con, null, out var tagAssignments);
|
||||
Assert.IsTrue(0 != hr, "TagAssignmentsGet should not work with null user");
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, null, null, out tagAssignments);
|
||||
Assert.IsTrue(0 != hr, "TagAssignmentsGet should not work with null connection");
|
||||
var sensor = CreateFakeSensor();
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, con, sensor);
|
||||
var testSetup = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref testSetup);
|
||||
|
||||
var taSetup = CreateTagAssignment(tag, testSetup);
|
||||
var taSensor = CreateTagAssignment(tag, sensor);
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(null, con, taSetup);
|
||||
Assert.IsTrue(0 != hr, "TagAssignmentsInsert should not work with null user");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, null, taSetup);
|
||||
Assert.IsTrue(0 != hr, "TagAssignmentsInsert should not work with null connection");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, con, null);
|
||||
Assert.IsTrue(DbAPI.Errors.ErrorCodes.ERROR_MISSING_PARAMETER == hr, "TagAssignmentsInsert should not work with null tagassignment");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, con, new[] { testSetup.Id });
|
||||
Assert.IsTrue(0 == hr, "TestSetupsDelete should work when tag assignments exist");
|
||||
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, con, sensor.Id, 0);
|
||||
Assert.IsTrue(0 == hr, "SensorsDelete should work when tag assignments exist");
|
||||
|
||||
var sensor2 = CreateFakeSensor();
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, con, sensor);
|
||||
var taSensor2 = CreateTagAssignment(tag, sensor2);
|
||||
_ = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, con, taSensor2);
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(_user, con, tag.ID);
|
||||
Assert.IsTrue(0 == hr, "TagsDelete should work when tag assignments exist");
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsDelete(_user, con, sensor2.Id, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0">
|
||||
<Import Project="..\..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props')" />
|
||||
<Import Project="..\..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\..\packages\NUnit.3.12.0\build\NUnit.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F5BA4B68-A059-4A1A-8286-490462D4F29A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DatabaseUnitTesting</RootNamespace>
|
||||
<AssemblyName>DatabaseUnitTesting</AssemblyName>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>
|
||||
</AssemblyOriginatorKeyFile>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>2.0</OldToolsVersion>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NUnit3.TestAdapter">
|
||||
<HintPath>..\..\..\Common\DTS.Common\lib\NUnitTestAdapter\NUnit3.TestAdapter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CalculatedChannelsTests.cs" />
|
||||
<Compile Include="CustomerDetailsTests.cs" />
|
||||
<Compile Include="DASChannelsTests.cs" />
|
||||
<Compile Include="DASTests.cs" />
|
||||
<Compile Include="DatabaseModificationTester.cs" />
|
||||
<Compile Include="DBAPITests.cs" />
|
||||
<Compile Include="DbAPITestsRegionsOfInterest.cs" />
|
||||
<Compile Include="DbAPITestsTestSetupGroup.cs" />
|
||||
<Compile Include="DbAPITestsGroupHardware.cs" />
|
||||
<Compile Include="DbAPITestsTestEngineerDetails.cs" />
|
||||
<Compile Include="DbAPITestsLaboratoryDetails.cs" />
|
||||
<Compile Include="DbAPITestsCustomerDetails.cs" />
|
||||
<Compile Include="DbAPITestsTags.cs" />
|
||||
<Compile Include="DbAPITestsTestSetupHardware.cs" />
|
||||
<Compile Include="DbAPITestsTestSetupROIs.cs" />
|
||||
<Compile Include="DbAPITestsTestSetups.cs" />
|
||||
<Compile Include="DbAPITestsChannels.cs" />
|
||||
<Compile Include="DbAPITestsSensorsAnalog.cs" />
|
||||
<Compile Include="DbAPITestsDAS.cs" />
|
||||
<Compile Include="DefaultPropertiesTests.cs" />
|
||||
<Compile Include="LaboratoryDetailsTests.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ResultSetTester.cs" />
|
||||
<Compile Include="SensorsAnalogTests.cs" />
|
||||
<Compile Include="SensorsDigitalInTests.cs" />
|
||||
<Compile Include="TestSetups.cs" />
|
||||
<Compile Include="Utilities\DatabaseAdapter.cs" />
|
||||
<Compile Include="Utilities\ObjectsToCompare.cs" />
|
||||
<Compile Include="Utilities\Results\Column.cs" />
|
||||
<Compile Include="Utilities\Results\Database.cs" />
|
||||
<Compile Include="Utilities\DatabaseComparer.cs" />
|
||||
<Compile Include="Utilities\Results\Row.cs" />
|
||||
<Compile Include="Utilities\Results\XmlFileAdapter.cs" />
|
||||
<Compile Include="Utilities\Results\Table.cs" />
|
||||
<Compile Include="Utilities\Results\ResultSetParser.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common.Storage\DTS.Common.Storage.csproj">
|
||||
<Project>{e3be457c-0ac7-4a9c-bc81-eafeb3217878}</Project>
|
||||
<Name>DTS.Common.Storage</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common\DTS.Common.csproj">
|
||||
<Project>{F7A0804F-61A4-40AE-83D0-F1137622B592}</Project>
|
||||
<Name>DTS.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\DbAPI\DbAPI.csproj">
|
||||
<Project>{c356fb81-3177-4a42-b3c2-afa619335e3f}</Project>
|
||||
<Name>DbAPI</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="Design\DatabaseUnitTestingClassDiagram.cd" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="TestResults\DigitalInSensorInsertTest.xml" />
|
||||
<Content Include="TestResults\DigitalInSensorUpdateTest.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class CustomerDetailsTests : TestSetups
|
||||
{
|
||||
|
||||
// NOTES
|
||||
// Name cannot be null as that is the identifying field for insert or update.
|
||||
|
||||
|
||||
// [Test]
|
||||
// ============================================================
|
||||
// DELETE CUSTOMER DETAILS
|
||||
// Call sp_CustomerDetailsDelete with a known details
|
||||
// Verify customer detials no longer exists in dbo.CustomerDetails table.
|
||||
// ============================================================
|
||||
|
||||
|
||||
// [Test]
|
||||
// =============================================================
|
||||
// GET CUSTOMER DETAILS
|
||||
// Start with a known customer details in the database. Call sp_CustomerDetailsGet with name
|
||||
// Verify known customer details are returned
|
||||
// =============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT CUSTOMER DETAILS
|
||||
// call sp_CustomerDetailsUpdateInsert with parameters for a new valid
|
||||
// customer details record and compare all fields.
|
||||
// Pass if all fields in dbo.CustomerDetails table are entered.
|
||||
// ============================================================
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// call sp_CustomerDetailsUpdateInsert with parameters for a new valid
|
||||
// customer details and verify a new row is created in dbo.CustomerDetails table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE CUSTOMER DETAILS
|
||||
// Send valid customer details parameters to sp_CustomerDetailsInUpdateInsert for a
|
||||
// customer detail record that already is in the database and compare all fields.
|
||||
// Pass if all fields in dbo.CustomerDetails table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// UPDATE CUSTOMER DETAILS
|
||||
// ============================================================
|
||||
// Send valid customer details parameters to sp_CustomerDetailsInUpdateInsert for a
|
||||
// customer details record that already is in the database.
|
||||
// pass if no new row is created in dbo.CustomerDetails table.
|
||||
// ============================================================
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text;
|
||||
using DatabaseUnitTesting.Utilities.Results;
|
||||
|
||||
namespace DatabaseUnitTesting.Utilities
|
||||
{
|
||||
internal class DatabaseComparer
|
||||
{
|
||||
private readonly SqlConnection _connection;
|
||||
private readonly DatabaseAdapter _databaseAdapter;
|
||||
private readonly string _databaseOne;
|
||||
private readonly string _databaseTwo;
|
||||
private readonly List<ObjectsToCompare> _objectsToCompare = new List<ObjectsToCompare>();
|
||||
|
||||
internal DatabaseComparer(SqlConnection connection, string databaseOneName, string databaseTwoName)
|
||||
{
|
||||
_connection = connection;
|
||||
_databaseAdapter = new DatabaseAdapter(connection);
|
||||
_databaseAdapter.UseDatabase(databaseOneName);
|
||||
_databaseOne = databaseOneName;
|
||||
_databaseTwo = databaseTwoName;
|
||||
}
|
||||
|
||||
internal void CleanUp()
|
||||
{
|
||||
_objectsToCompare.Clear();
|
||||
}
|
||||
|
||||
internal Database GenerateDifferences(SqlTransaction transaction)
|
||||
{
|
||||
Database tables = new Database();
|
||||
|
||||
foreach (ObjectsToCompare objects in _objectsToCompare)
|
||||
{
|
||||
Table table = RunCompare(transaction, objects);
|
||||
if (table.RowCount > 0)
|
||||
tables.AddTable(table);
|
||||
}
|
||||
|
||||
return tables;
|
||||
}
|
||||
|
||||
internal string GetAllColumns(SqlTransaction transaction, ObjectsToCompare objects)
|
||||
{
|
||||
SqlCommand command = _connection.CreateCommand();
|
||||
command.CommandText =
|
||||
"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = @table AND" +
|
||||
" table_schema = @schema AND table_catalog = @database";
|
||||
command.Transaction = transaction;
|
||||
command.Parameters.AddWithValue("@table", objects.Object1Name);
|
||||
command.Parameters.AddWithValue("@schema", objects.Schema1Name);
|
||||
command.Parameters.AddWithValue("@database", _databaseOne);
|
||||
|
||||
List<string> allColumns = new List<string>();
|
||||
|
||||
using (SqlDataReader result = command.ExecuteReader())
|
||||
{
|
||||
while (result.Read())
|
||||
allColumns.Add(result.GetString(0));
|
||||
}
|
||||
|
||||
if (allColumns.Count == 0)
|
||||
throw new ArgumentException("Object " + objects.Qualified1 + " does not exist");
|
||||
|
||||
foreach (string victim in objects.ColumnsToIgnore)
|
||||
{
|
||||
if (!allColumns.Remove(victim))
|
||||
throw new ArgumentException("Specified column " + victim + " was not in table " +
|
||||
objects.Qualified1);
|
||||
if (allColumns.Count == 0)
|
||||
throw new ArgumentException("User cannot ignore all columns in a table.");
|
||||
}
|
||||
|
||||
return String.Join(",", allColumns.ToArray());
|
||||
}
|
||||
|
||||
internal Table RunCompare(SqlTransaction transaction, ObjectsToCompare objectComparison)
|
||||
{
|
||||
Table table =
|
||||
new Table(objectComparison.Qualified1, objectComparison.Qualified2);
|
||||
|
||||
string columns = GetAllColumns(transaction, objectComparison);
|
||||
|
||||
StringBuilder select = new StringBuilder("SELECT ", 1000);
|
||||
select.Append(columns);
|
||||
select.Append(", ROW_NUMBER() OVER(PARTITION BY ");
|
||||
select.Append(columns);
|
||||
select.Append(" ORDER BY @@SPID) AS 'TempRowNumber' FROM ");
|
||||
string select1 = select + _databaseOne + "." + objectComparison.Qualified1;
|
||||
string select2 = select + _databaseTwo + "." + objectComparison.Qualified2;
|
||||
string commandText = "--Data Comparison\n" + select1 + "\nEXCEPT\n" + select2 + "\n" +
|
||||
select2 + "\nEXCEPT\n" + select1;
|
||||
SqlCommand command = _connection.CreateCommand();
|
||||
command.CommandText = commandText;
|
||||
command.Transaction = transaction;
|
||||
|
||||
using (SqlDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
string type = "In First";
|
||||
string[] columnNames = columns.Split(',');
|
||||
do
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
Row row = new Row(type);
|
||||
for (int i = 0; i < (reader.FieldCount - 1); i++)
|
||||
{
|
||||
object value = reader.GetValue(i);
|
||||
if (!(value is DBNull))
|
||||
row.AddColumn(new Column(columnNames[i].ToLower(), value));
|
||||
}
|
||||
table.AddRow(row);
|
||||
}
|
||||
type = "In Second";
|
||||
} while (reader.NextResult());
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
internal void AddObjectComparison(string schema1, string object1, string schema2, string object2)
|
||||
{
|
||||
_objectsToCompare.Add(new ObjectsToCompare(schema1, object1, schema2, object2));
|
||||
}
|
||||
|
||||
internal void AddColumnToIgnore(string schemaName, string objectName, string columnName)
|
||||
{
|
||||
_objectsToCompare.Find(
|
||||
delegate (ObjectsToCompare item) { return item.Schema1Name == schemaName && item.Object1Name == objectName; }
|
||||
).AddColumnToIgnore(columnName);
|
||||
}
|
||||
|
||||
internal void AddColumnsToIgnore(string schemaName, string tableName, List<string> columnNames)
|
||||
{
|
||||
foreach (string columnName in columnNames)
|
||||
AddColumnToIgnore(schemaName, tableName, columnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class DefaultPropertiesTests : TestSetups
|
||||
{
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Verify update a default property
|
||||
//
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Verify retrieval of a default property
|
||||
//
|
||||
//
|
||||
// ============================================================
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text;
|
||||
|
||||
namespace DatabaseUnitTesting.Utilities.Results
|
||||
{
|
||||
internal static class ResultSetParser
|
||||
{
|
||||
private const int NAME = 0;
|
||||
private const int WIDTH = 2;
|
||||
private const int PRECISION = 3;
|
||||
private const int SCALE = 4;
|
||||
private const int TYPE = 24;
|
||||
|
||||
internal static Database Parse(SqlCommand command)
|
||||
{
|
||||
using (SqlDataReader sqlReader = command.ExecuteReader())
|
||||
{
|
||||
Database results = new Database();
|
||||
|
||||
if (!sqlReader.HasRows)
|
||||
return results;
|
||||
|
||||
do
|
||||
{
|
||||
Table table = new Table("Result Set");
|
||||
List<string> fieldNames = SetFields(table, sqlReader.GetSchemaTable());
|
||||
while (sqlReader.Read())
|
||||
{
|
||||
Row row = new Row("datarow");
|
||||
for (int i = 0; i < sqlReader.FieldCount; i++)
|
||||
{
|
||||
object value = sqlReader.GetValue(i);
|
||||
if (!(value is DBNull))
|
||||
row.AddColumn(new Column(fieldNames[i], sqlReader.GetValue(i)));
|
||||
}
|
||||
table.AddRow(row);
|
||||
}
|
||||
results.AddTable(table);
|
||||
} while (sqlReader.NextResult());
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
internal static List<string> SetFields(Table table, DataTable schema)
|
||||
{
|
||||
List<string> fieldNames = new List<string>();
|
||||
foreach (DataRow dataRow in schema.Rows)
|
||||
{
|
||||
string name = dataRow[NAME].ToString();
|
||||
string type = dataRow[TYPE].ToString().ToLower();
|
||||
string precision = dataRow[PRECISION].ToString();
|
||||
string scale = dataRow[SCALE].ToString();
|
||||
string width = dataRow[WIDTH].ToString();
|
||||
|
||||
StringBuilder typeString = new StringBuilder(type);
|
||||
|
||||
if (type.Equals("decimal") || type.Equals("numeric"))
|
||||
{
|
||||
typeString.Append("(");
|
||||
typeString.Append(precision);
|
||||
typeString.Append(",");
|
||||
typeString.Append(scale);
|
||||
typeString.Append(")");
|
||||
}
|
||||
else if (type.Contains("char") || type.Contains("binary"))
|
||||
{
|
||||
if (int.Parse(width) > 8000)
|
||||
width = "max";
|
||||
|
||||
typeString.Append("(");
|
||||
typeString.Append(width);
|
||||
typeString.Append(")");
|
||||
}
|
||||
|
||||
fieldNames.Add(name);
|
||||
table.AddField(name, typeString.ToString());
|
||||
}
|
||||
return fieldNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text;
|
||||
|
||||
namespace DatabaseUnitTesting.Utilities
|
||||
{
|
||||
internal class DatabaseAdapter
|
||||
{
|
||||
private readonly SqlConnection _connection;
|
||||
|
||||
internal DatabaseAdapter(SqlConnection connection)
|
||||
{
|
||||
_connection = connection;
|
||||
|
||||
if (_connection.State == ConnectionState.Closed)
|
||||
_connection.Open();
|
||||
}
|
||||
|
||||
internal bool IsSnapshot(string name)
|
||||
{
|
||||
SqlCommand command = _connection.CreateCommand();
|
||||
command.CommandText =
|
||||
"--Testing Existence Type\nSELECT source_database_id FROM sys.databases WHERE name = @name";
|
||||
|
||||
command.Parameters.AddWithValue("@name", name);
|
||||
|
||||
object objResult = command.ExecuteScalar();
|
||||
|
||||
if (objResult != null && !(objResult is DBNull))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void UseDatabase(string databaseName)
|
||||
{
|
||||
SqlCommand command = _connection.CreateCommand();
|
||||
command.CommandText = "USE " + databaseName;
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
internal void CreateSnapshot(string databaseName, string snapshotName)
|
||||
{
|
||||
SqlCommand command = _connection.CreateCommand();
|
||||
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder("-- Creating Snapshot \nCREATE DATABASE ");
|
||||
stringBuilder.Append(snapshotName);
|
||||
stringBuilder.Append(" ON ( NAME = ");
|
||||
stringBuilder.Append(databaseName);
|
||||
stringBuilder.Append(", FILENAME = 'C:\\Temp\\");
|
||||
stringBuilder.Append(snapshotName);
|
||||
stringBuilder.Append("') AS SNAPSHOT OF ");
|
||||
stringBuilder.Append(databaseName);
|
||||
command.CommandText = stringBuilder.ToString();
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
internal void DropSnapshot(string snapshotName)
|
||||
{
|
||||
if (!IsSnapshot(snapshotName))
|
||||
throw new ArgumentException("A snapshot of name " + snapshotName + " does not exist.");
|
||||
|
||||
SqlCommand command = _connection.CreateCommand();
|
||||
command.CommandText = "DROP DATABASE " + snapshotName;
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<section name="DatabaseUnitTesting.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<connectionStrings>
|
||||
<add name="DatabaseUnitTesting.Properties.Settings.ConnectionString" connectionString="Data Source=FAJITA\DEV_SQL;Initial Catalog=DataPRO_UnitTest;Integrated Security=False;Persist Security Info=True;User ID=sa;Password=!!QQAAZZxxssww22;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" providerName="System.Data.SqlClient"/>
|
||||
</connectionStrings>
|
||||
<userSettings>
|
||||
<DatabaseUnitTesting.Properties.Settings>
|
||||
<setting name="DBName" serializeAs="String">
|
||||
<value>DataPRO_UnitTest</value>
|
||||
</setting>
|
||||
<setting name="DBSnapshot" serializeAs="String">
|
||||
<value>DataPRO_UnitTestSnapshot</value>
|
||||
</setting>
|
||||
</DatabaseUnitTesting.Properties.Settings>
|
||||
</userSettings>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
public class TestSetups
|
||||
{
|
||||
private SqlConnection _connection;
|
||||
private SqlTransaction _transaction;
|
||||
private DatabaseModificationTester _unitTests;
|
||||
private const bool _BSETUPMODE = false;
|
||||
private SqlCommand _command;
|
||||
private string _testResultsInitialPath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\TestResults\";
|
||||
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void TFSetup()
|
||||
{
|
||||
//Define the connection string
|
||||
string connectionString = Properties.Settings.Default["ConnectionString"].ToString();
|
||||
_connection = new SqlConnection(connectionString);
|
||||
|
||||
_connection.Open();
|
||||
//a database snapshot is created under the hood in this constructor
|
||||
|
||||
_unitTests = new DatabaseModificationTester(_connection, Properties.Settings.Default.DBName, Properties.Settings.Default.DBSnapshot);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void TFTearDown()
|
||||
{
|
||||
//a database snapshot is dropped under the hood in this method
|
||||
_unitTests.Dispose();
|
||||
// deleting test data is skipped
|
||||
_connection.Close();
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_transaction = _unitTests.BeginTestTransaction();
|
||||
_command = _connection.CreateCommand();
|
||||
_command.Transaction = _transaction;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_unitTests.EndTestTransaction();
|
||||
}
|
||||
|
||||
public String TestResultPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return _testResultsInitialPath;
|
||||
}
|
||||
}
|
||||
public DatabaseModificationTester UnitTests
|
||||
{
|
||||
get
|
||||
{
|
||||
return _unitTests;
|
||||
}
|
||||
}
|
||||
public bool BSETUPMODE
|
||||
{
|
||||
get
|
||||
{
|
||||
return _BSETUPMODE;
|
||||
}
|
||||
}
|
||||
public SqlCommand Command
|
||||
{
|
||||
get
|
||||
{
|
||||
return _command;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using DTS.Common.Interface.TestMetaData;
|
||||
using DTS.Common.Classes.TestEngineerDetails;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public TestEngineerDetailsDbRecord CreateFakeTestEngineerDetails(string name)
|
||||
{
|
||||
var record = new TestEngineerDetailsDbRecord();
|
||||
record.TestEngineerId = -1;
|
||||
record.Name = name;
|
||||
record.TestEngineerName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.TestEngineerName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.TestEngineerPhone = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.TestEngineerFax = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.TestEngineerEmail = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LocalOnly = true;
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.Version = 1;
|
||||
return record;
|
||||
}
|
||||
[Test]
|
||||
public void TestEngineerDetails()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//Delete all to start with a blank table
|
||||
var hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsDelete(_user, connections.First(), null, out string errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsDelete");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), null, out ITestEngineerDetailsDbRecord[] allTestEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != allTestEngineerDetailsDbRecords && allTestEngineerDetailsDbRecords.Length == 0, "TestEngineerDetailsGet should have retrieved 0 records");
|
||||
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var legitRecord = CreateFakeTestEngineerDetails("legit");
|
||||
var decoyRecord = CreateFakeTestEngineerDetails("decoy");
|
||||
|
||||
//Insert
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsInsert(_user, connections.First(), legitRecord, out int newLegitId, out string legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate TestEngineerDetails record");
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsInsert(_user, connections.First(), decoyRecord, out int newFakeId, out string fakeErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy TestEngineerDetails record");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), legitRecord.Name, out ITestEngineerDetailsDbRecord[] testEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != testEngineerDetailsDbRecords && testEngineerDetailsDbRecords.Length == 1, "TestEngineerDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(testEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should have retrieved only one record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), null, out allTestEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != allTestEngineerDetailsDbRecords && allTestEngineerDetailsDbRecords.Length == 2, "TestEngineerDetailsGet should have retrieved 2 records");
|
||||
Assert.IsTrue(allTestEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should have retrieved our record");
|
||||
Assert.IsTrue(allTestEngineerDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "TestEngineerDetailsGet should have retrieved our record");
|
||||
|
||||
//Update
|
||||
var newTestEngineerPhone = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
legitRecord.TestEngineerPhone = newTestEngineerPhone;
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsUpdate(_user, connections.First(), legitRecord, out legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate TestEngineerDetails record");
|
||||
Assert.IsTrue(legitErrorString == string.Empty, $"Error when inserting a legitimate TestEngineerDetails record: {legitErrorString}");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), legitRecord.Name, out testEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != testEngineerDetailsDbRecords && testEngineerDetailsDbRecords.Length == 1, "TestEngineerDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(testEngineerDetailsDbRecords.Any(r => r.TestEngineerPhone == newTestEngineerPhone), "TestEngineerDetailsGet should have retrieved the updated record");
|
||||
|
||||
//Delete by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsDelete(_user, connections.First(), legitRecord.Name, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), legitRecord.Name, out testEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != testEngineerDetailsDbRecords, "TestEngineerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(testEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should not have retrieved this record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), null, out allTestEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != allTestEngineerDetailsDbRecords && allTestEngineerDetailsDbRecords.Length == 1, "TestEngineerDetailsGet should have retrieved only the decoy record");
|
||||
Assert.IsFalse(allTestEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet not should have retrieved this record");
|
||||
Assert.IsTrue(allTestEngineerDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "TestEngineerDetailsGet should have retrieved this record");
|
||||
|
||||
//Delete all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsDelete(_user, connections.First(), null, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), legitRecord.Name, out testEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != testEngineerDetailsDbRecords, "TestEngineerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(testEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should not have retrieved any records");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), null, out allTestEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != allTestEngineerDetailsDbRecords, "TestEngineerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(allTestEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should not have retrieved any records");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
using DTS.Common.Classes.Hardware;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
[Test]
|
||||
public void TestDASGetPrototypesShouldFail()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var hr = DbAPI.DbAPI.DAS.DASGet(null, connections.First(), clientDbVersion, null, "Prototype", out var dbDAS);
|
||||
Assert.AreNotEqual(0, hr, "DASGet with no user should not return 0");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length == 0, "No das should be returned when calling DASGet with no user");
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, null, clientDbVersion, null, "Prototype", out dbDAS);
|
||||
Assert.AreNotEqual(0, hr, "DASGet with no connection should not return 0");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length == 0, "No das should be returned when calling DASGet with no connection");
|
||||
}
|
||||
[Test]
|
||||
public void TestDASGetPrototypes()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, null, "Prototype", out var das);
|
||||
Assert.AreEqual(0, hr, "DASGet Executed");
|
||||
Assert.IsNotNull(das, "DAS not null");
|
||||
Assert.IsTrue(das.Length > 0, "DAS prototypes in db");
|
||||
}
|
||||
[Test]
|
||||
public void TestDASInsertAndDeleteShouldFail()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var das = CreateFakeDAS();
|
||||
//test that insert fails properly
|
||||
var hr = DbAPI.DbAPI.DAS.DASInsert(null, connections.First(), das);
|
||||
Assert.AreNotEqual(0, hr, "DASInsert should not return 0 with no user");
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, null, das);
|
||||
Assert.AreNotEqual(0, hr, "DASInsert should not return 0 with no connection");
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), null);
|
||||
Assert.AreNotEqual(0, hr, "DASInsert should not return 0 with no DAS");
|
||||
|
||||
//insert so that we can test that delete fails properly
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), das);
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, das.SerialNumber, null, out var dbRecord);
|
||||
|
||||
//test that delete fails properly
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(null, connections.First(), dbRecord[0].DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreNotEqual(0, hr, "DAS delete without a user should not return 0");
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, null, dbRecord[0].DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreNotEqual(0, hr, "DAS delete without a connection should not return 0");
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), -1, null, false);
|
||||
Assert.AreNotEqual(0, hr, "DAS delete without a DAS should not return 0");
|
||||
|
||||
//now finally cleanup
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), dbRecord[0].DASId, dbRecord[0].SerialNumber, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDASInsertAndDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var das = CreateFakeDAS();
|
||||
var hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), das);
|
||||
Assert.AreEqual(0, hr, "DASInsert Executed");
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, das.SerialNumber, null, out var dbRecord);
|
||||
Assert.AreEqual(0, hr, "DASGet Inserted DAS");
|
||||
Assert.IsNotNull(dbRecord, "Retrieved das not null");
|
||||
Assert.AreEqual(1, dbRecord.Length, "1 das was retrieved");
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), das.DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreEqual(0, hr, "DASDelete executed");
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, dbRecord[0].SerialNumber, null, out var dbDAS);
|
||||
Assert.AreEqual(0, hr, "DASGet executed after delete");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length < 1, "DAS no longer in db afer delete");
|
||||
}
|
||||
[Test]
|
||||
public void TestDASChannelInsertAndDASDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var das = CreateFakeDAS();
|
||||
|
||||
var hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), das);
|
||||
Assert.AreEqual(0, hr, "DASInsert Executed");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, das.SerialNumber, null, out var dbRecord);
|
||||
Assert.AreEqual(0, hr, "DASGet Inserted DAS");
|
||||
Assert.IsNotNull(dbRecord, "Retrieved das not null");
|
||||
Assert.AreEqual(1, dbRecord.Length, "1 das was retrieved");
|
||||
|
||||
var channels = CreateFakeChannels(das);
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
IDASChannelDBRecord iCh = channel;
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsInsert(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", ref iCh);
|
||||
Assert.AreEqual(0, hr, "DASChannelsInsert executed");
|
||||
}
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsGet(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", out var dbChannels);
|
||||
Assert.AreEqual(0, hr, "DASChannelsGet executed");
|
||||
|
||||
Assert.IsNotNull(dbChannels, "Channels retrieved after insertion");
|
||||
Assert.AreEqual(dbChannels.Length, channels.Length, "Same # of channels retrieved as inserted");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), das.DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreEqual(0, hr, "DASDelete executed");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, dbRecord[0].SerialNumber, null, out var dbDAS);
|
||||
Assert.AreEqual(0, hr, "DASGet executed after delete");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length < 1, "DAS no longer in db after delete");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsGet(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", out var dbChannelsAfterDelete);
|
||||
Assert.AreEqual(0, hr, "DASChannelsGet after delete das executes");
|
||||
Assert.IsTrue(null == dbChannelsAfterDelete || 0 == dbChannelsAfterDelete.Length, "No channels remain after das delete");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDASChannelsDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var das = CreateFakeDAS();
|
||||
|
||||
var hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), das);
|
||||
Assert.AreEqual(0, hr, "DASInsert Executed");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, das.SerialNumber, null, out var dbRecord);
|
||||
Assert.AreEqual(0, hr, "DASGet Inserted DAS");
|
||||
Assert.IsNotNull(dbRecord, "Retrieved das not null");
|
||||
Assert.AreEqual(1, dbRecord.Length, "1 das was retrieved");
|
||||
|
||||
var channels = CreateFakeChannels(das);
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
IDASChannelDBRecord iCh = channel;
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsInsert(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", ref iCh);
|
||||
Assert.AreEqual(0, hr, "DASChannelsInsert executed");
|
||||
}
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsGet(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", out var dbChannels);
|
||||
Assert.AreEqual(0, hr, "DASChannelsGet executed");
|
||||
|
||||
Assert.IsNotNull(dbChannels, "Channels retrieved after insertion");
|
||||
Assert.AreEqual(dbChannels.Length, channels.Length, "Same # of channels retrieved as inserted");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsDelete(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}");
|
||||
Assert.AreEqual(0, hr, "DASChannelsDelete executes");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsGet(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", out var dbChannelsAfterDelete);
|
||||
Assert.AreEqual(0, hr, "DASChannelsGet after daschannelsdelete executes");
|
||||
Assert.IsTrue(null == dbChannelsAfterDelete || 0 == dbChannelsAfterDelete.Length, "No channels remain after daschannelsdelete");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), das.DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreEqual(0, hr, "DASDelete executed");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, dbRecord[0].SerialNumber, null, out var dbDAS);
|
||||
Assert.AreEqual(0, hr, "DASGet executed after delete");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length < 1, "DAS no longer in db after delete");
|
||||
}
|
||||
private DASChannelDBRecord[] CreateFakeChannels(DASDBRecord das)
|
||||
{
|
||||
var list = new List<DASChannelDBRecord>();
|
||||
|
||||
for (var i = 0; i < das.Channels; i++)
|
||||
{
|
||||
var channel = new DASChannelDBRecord();
|
||||
channel.ChannelIdx = i;
|
||||
channel.DaschannelId = i;
|
||||
channel.DASDisplayOrder = i;
|
||||
channel.Dasid = das.DASId;
|
||||
channel.HardwareId = $"{das.SerialNumber}_{das.DASType}";
|
||||
channel.LocalOnly = false;
|
||||
channel.ModuleArrayIndex = 0;
|
||||
channel.ModuleSerialNumber = "FakeMod0";
|
||||
list.Add(channel);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
private DASDBRecord CreateFakeDAS()
|
||||
{
|
||||
var das = new DASDBRecord();
|
||||
das.SerialNumber = Guid.NewGuid().ToString().Substring(0, 10);
|
||||
das.Position = "";
|
||||
das.LastModifiedBy = "";
|
||||
das.LastModified = DateTime.Now;
|
||||
das.LastUsed = DateTime.Now;
|
||||
das.LastUsedBy = "NUNIT";
|
||||
das.DASType = 18;
|
||||
das.ChannelTypes = new[] { 1, 2, 3 };
|
||||
das.Channels = 3;
|
||||
das.Position = "";
|
||||
return das;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
using DbAPI.Errors;
|
||||
using DTS.Common.Classes.Groups;
|
||||
using DTS.Common.Classes.TestSetups;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using DTS.Common.Interface.Groups;
|
||||
using DTS.Common.Interface.TestSetups;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void TestTestSetupHardwarePositive()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections()[0];
|
||||
|
||||
var test = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref test);
|
||||
|
||||
var group = CreateFakeGroup("Fake Test Group", null);
|
||||
var channel = CreateFakeChannel();
|
||||
var hardware = CreateFakeDAS();
|
||||
var hwChannels = CreateFakeChannels(hardware);
|
||||
|
||||
_ = DbAPI.DbAPI.DAS.DASInsert(_user, con, hardware);
|
||||
var chIdx = 0;
|
||||
foreach (var hwCh in hwChannels)
|
||||
{
|
||||
IDASChannelDBRecord iCh = hwCh;
|
||||
_ = DbAPI.DbAPI.DAS.DASChannelsInsert(_user, con, $"{hardware.SerialNumber}_{hardware.DASType}", ref iCh);
|
||||
chIdx++;
|
||||
}
|
||||
|
||||
var hwRecord = new TestSetupHardwareRecord()
|
||||
{
|
||||
AddDAS = true,
|
||||
DASId = hardware.DASId,
|
||||
AntiAliasFilterRate = 2000,
|
||||
IsClockMaster = false,
|
||||
SamplesPerSecond = 20000,
|
||||
TestSetupId = test.Id,
|
||||
PTPDomainId = 0
|
||||
};
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(_user, con, hwRecord);
|
||||
Assert.IsTrue(0 == hr, "TestSetupHardwareInsert returns 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, con, con.ClientDbVersion, null, out var hwRecords);
|
||||
Assert.IsTrue(0 == hr && null != hwRecords && 0 != hwRecords.Length &&
|
||||
hwRecords.Any(h => IsTestSetupHardwareRecordsEqual(h, hwRecord)),
|
||||
"TestSetupHardwareGet returns 0 and has record inserted");
|
||||
|
||||
var hwRecordToUpdate = new TestSetupHardwareRecord(hwRecord);
|
||||
hwRecordToUpdate.SamplesPerSecond = 10000;
|
||||
hwRecordToUpdate.AddDAS = false;
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareUpdate(_user, con, hwRecordToUpdate);
|
||||
Assert.IsTrue(0 == hr, "TestSetupHardwareUpdate returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, con, con.ClientDbVersion, null, out hwRecords);
|
||||
Assert.IsTrue(0 == hr && null != hwRecords && 0 != hwRecords.Length &&
|
||||
hwRecords.Any(h => IsTestSetupHardwareRecordsEqual(h, hwRecordToUpdate))
|
||||
&& !hwRecords.Any(h => IsTestSetupHardwareRecordsEqual(h, hwRecord)),
|
||||
$"TestSetupHardwareGet returned updated record and not previous inserted record");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(_user, con, null, hwRecord.DASId, null);
|
||||
Assert.IsTrue(0 == hr, "TestSetupHardwareDelete returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, con, con.ClientDbVersion, null, out hwRecords);
|
||||
Assert.IsTrue(0 == hr && (null == hwRecords || 0 == hwRecords.Length || !hwRecords.Any(h => h.DASId == hwRecord.DASId)),
|
||||
"TestSetupHardwareDelete deletes records");
|
||||
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, con, new[] { test.Id });
|
||||
_ = DbAPI.DbAPI.DAS.DASDelete(_user, con, hardware.DASId, hardware.SerialNumber, false);
|
||||
}
|
||||
private bool IsTestSetupHardwareRecordsEqual(ITestSetupHardwareRecord left, ITestSetupHardwareRecord right)
|
||||
{
|
||||
return left.AddDAS == right.AddDAS &&
|
||||
left.AntiAliasFilterRate == right.AntiAliasFilterRate &&
|
||||
left.DASId == right.DASId &&
|
||||
left.IsClockMaster == right.IsClockMaster &&
|
||||
left.SamplesPerSecond == right.SamplesPerSecond &&
|
||||
left.TestSetupId == right.TestSetupId &&
|
||||
left.PTPDomainId == right.PTPDomainId;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTestSetupHardwareNegative()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections()[0];
|
||||
|
||||
var test = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref test);
|
||||
|
||||
var group = CreateFakeGroup("Fake Test Group", null);
|
||||
var channel = CreateFakeChannel();
|
||||
var hardware = CreateFakeDAS();
|
||||
var hwChannels = CreateFakeChannels(hardware);
|
||||
|
||||
_ = DbAPI.DbAPI.DAS.DASInsert(_user, con, hardware);
|
||||
var chIdx = 0;
|
||||
foreach (var hwCh in hwChannels)
|
||||
{
|
||||
IDASChannelDBRecord iCh = hwCh;
|
||||
_ = DbAPI.DbAPI.DAS.DASChannelsInsert(_user, con, $"{hardware.SerialNumber}_{hardware.DASType}", ref iCh);
|
||||
chIdx++;
|
||||
}
|
||||
|
||||
var hwRecord = new TestSetupHardwareRecord()
|
||||
{
|
||||
AddDAS = true,
|
||||
DASId = hardware.DASId,
|
||||
AntiAliasFilterRate = 2000,
|
||||
IsClockMaster = false,
|
||||
SamplesPerSecond = 20000,
|
||||
TestSetupId = test.Id,
|
||||
PTPDomainId = 0
|
||||
};
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(_user, null, hwRecord);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareInsert should not return 0 without a user");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(null, con, hwRecord);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareInsert should not return 0 without a connection");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(_user, con, null);
|
||||
Assert.IsTrue(ErrorCodes.ERROR_MISSING_PARAMETER == hr,
|
||||
"TestSetupHardwareInsert should return missing parameter with empty hardware");
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(_user, con, hwRecord);
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(null, con, con.ClientDbVersion, null, out var hardwareRecords);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareGet with null user should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, null, clientDbVersion, null, out hardwareRecords);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareGet with null connection should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, con, con.ClientDbVersion, test.Id + 1, out hardwareRecords);
|
||||
Assert.IsTrue(0 != hr || null == hardwareRecords || 0 == hardwareRecords.Length,
|
||||
"TestSetupHardwareGet with a different test id should not return the hardware record");
|
||||
|
||||
|
||||
var hwRecordToUpdate = new TestSetupHardwareRecord(hwRecord);
|
||||
hwRecordToUpdate.SamplesPerSecond = 10000;
|
||||
hwRecordToUpdate.AddDAS = false;
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareUpdate(null, con, hwRecordToUpdate);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareUpdate with null user should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareUpdate(_user, null, hwRecordToUpdate);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareUpdate with null connection should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareUpdate(_user, con, null);
|
||||
Assert.IsTrue(ErrorCodes.ERROR_MISSING_PARAMETER == hr,
|
||||
"TestSetupHardwareUpdate with null hardware should return missing parameter");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(null, con, null, hwRecord.DASId, null);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareDelete with null user should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(_user, null, null, hwRecord.DASId, null);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareDelete with null connection should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(_user, con, null, null, null);
|
||||
Assert.IsTrue(ErrorCodes.ERROR_MISSING_PARAMETER == hr,
|
||||
"TestSetupHardwareDelete with no parameters should return missing parameter");
|
||||
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(_user, con, null, hwRecord.DASId, null);
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, con, new[] { test.Id });
|
||||
_ = DbAPI.DbAPI.DAS.DASDelete(_user, con, hardware.DASId, hardware.SerialNumber, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class DASTests : TestSetups
|
||||
{
|
||||
// NOTES:
|
||||
// DAS must have serial number
|
||||
|
||||
// [Test]
|
||||
// ============================================================
|
||||
// DELETE DAS
|
||||
// Call sp_DASDelete with a known DAS hardware ID
|
||||
// Verify all DAS channels associated with the hardware ID no longer exists in dbo.DAS table.
|
||||
// ============================================================
|
||||
|
||||
|
||||
// [Test]
|
||||
// =============================================================
|
||||
// GET DAS
|
||||
// Start with a known already entered DAS. Call sp_DASGet for the hardware.
|
||||
// Verify known DAS is returned
|
||||
// =============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT DAS
|
||||
// Call sp_CalculatedChannelsUpdateInsert with parameters for a new valid
|
||||
// DAS and compare all fields.
|
||||
// Pass if all fields in dbo.DAS table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT DAS: VERIFY ONLY ONE NEW ROW IS ADDED
|
||||
// Call sp_DASCUpdateInsert with parameters for a new valid
|
||||
// DAS and verify a new row is created in dbo.DAS table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE DAS
|
||||
// Send valid DAS parameters to sp_DASInUpdateInsert for a DAS
|
||||
// that already is in the database and compare all fields.
|
||||
// Pass if all fields in dbo.DAS table are entered.
|
||||
// ============================================================
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE DAS: VERIFY NO NEW ROW IS ADDED
|
||||
// Send valid DAS parameters to sp_DASInUpdateInsert for a DAS
|
||||
// that already is in the database and verify no new row is created in dbo.DAS table.
|
||||
//
|
||||
// ============================================================
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DatabaseUnitTesting.Utilities.Results
|
||||
{
|
||||
internal class Row
|
||||
{
|
||||
private readonly string _type;
|
||||
private readonly List<Column> _columns = new List<Column>();
|
||||
private string _keyString;
|
||||
private bool _keyValid = false;
|
||||
public const string DELIMITER = "\x1e;;";
|
||||
|
||||
public Row(string type)
|
||||
{
|
||||
_type = type.ToLower();
|
||||
}
|
||||
|
||||
public void AddColumn(Column column)
|
||||
{
|
||||
_columns.Add(column);
|
||||
_keyValid = false;
|
||||
}
|
||||
|
||||
public string KeyString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_keyValid)
|
||||
{
|
||||
string[] keyString = new string[_columns.Count + 1];
|
||||
keyString[0] = _type;
|
||||
for (int i = 1; i < keyString.Length; i++)
|
||||
keyString[i] = _columns[i - 1].SortString;
|
||||
|
||||
_keyString = String.Join(DELIMITER, keyString);
|
||||
_keyValid = true;
|
||||
}
|
||||
return _keyString;
|
||||
}
|
||||
}
|
||||
|
||||
public int ColumnCount
|
||||
{
|
||||
get { return _columns.Count; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<results>
|
||||
<object name1="dbo.sensorsdigitalin" name2="dbo.sensorsdigitalin">
|
||||
<row type="schema" />
|
||||
<row type="in first">
|
||||
<column name="serialnumber" value="DigiInSerialNum" />
|
||||
<column name="settingmode" value="8" />
|
||||
<column name="scalemultiplier" value="ArbitraryHighAndLow,1,2" />
|
||||
<column name="lastmodifiedby" value="TestUser" />
|
||||
<column name="eid" value="EID_Modified" />
|
||||
<column name="uservalue1" value="" />
|
||||
<column name="uservalue2" value="" />
|
||||
<column name="uservalue3" value="" />
|
||||
<column name="usertags" value="0x0000000000000000000000000000000000000000" />
|
||||
</row>
|
||||
</object>
|
||||
</results>
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class LaboratoryDetailsTests : TestSetups
|
||||
{
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Send new valid laboratory details parameters sp_LabratoryDetailsUpdateInsert and
|
||||
// compare all fields except LastModified and new ID. Pass if all fields in LabratoryDetails
|
||||
// table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Send valid laboratory details parameters to sp_LabratoryDetailsUpdateInsert for an entry
|
||||
// already in the database and compare all fields except LastModified, new ID.
|
||||
// Pass if all fields in LabratoryDetails table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Verify that updating laboratory details does not create a new row in the
|
||||
// LabratoryDetails table.
|
||||
//
|
||||
// ============================================================
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DatabaseUnitTesting.Utilities.Results
|
||||
{
|
||||
internal class Database
|
||||
{
|
||||
private int _tableCount = 0;
|
||||
private int _hashCode = 0;
|
||||
private readonly Dictionary<Table, int> _tables = new Dictionary<Table, int>();
|
||||
|
||||
public int TableCount
|
||||
{
|
||||
get { return _tableCount; }
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<Table, int>> Tables
|
||||
{
|
||||
get { return _tables; }
|
||||
}
|
||||
|
||||
public void AddTable(Table table)
|
||||
{
|
||||
if (_tables.ContainsKey(table))
|
||||
_tables[table]++;
|
||||
else
|
||||
_tables.Add(table, 1);
|
||||
|
||||
_tableCount++;
|
||||
_hashCode = _hashCode + table.GetHashCode();
|
||||
}
|
||||
|
||||
public bool ContainsTable(Table table)
|
||||
{
|
||||
return _tables.ContainsKey(table);
|
||||
}
|
||||
|
||||
public int GetCount(Table table)
|
||||
{
|
||||
return _tables[table];
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _hashCode;
|
||||
}
|
||||
|
||||
public override bool Equals(object otherObject)
|
||||
{
|
||||
if (!(otherObject is Database))
|
||||
return false;
|
||||
|
||||
Database other = (Database)otherObject;
|
||||
|
||||
if (TableCount != other.TableCount ||
|
||||
GetHashCode() != other.GetHashCode())
|
||||
return false;
|
||||
|
||||
foreach (KeyValuePair<Table, int> pair in _tables)
|
||||
if (!other.ContainsTable(pair.Key) ||
|
||||
other.GetCount(pair.Key) != pair.Value)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace DatabaseUnitTesting.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute(@"Data Source=FAJITA\DEV_SQL;Initial Catalog=DataPRO_UnitTest;Integrated Security=False;Persist Security Info=True;User ID=sa;Password=!!QQAAZZxxssww22;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")]
|
||||
public string ConnectionString {
|
||||
get {
|
||||
return ((string)(this["ConnectionString"]));
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("DataPRO_UnitTest")]
|
||||
public string DBName {
|
||||
get {
|
||||
return ((string)(this["DBName"]));
|
||||
}
|
||||
set {
|
||||
this["DBName"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("DataPRO_UnitTestSnapshot")]
|
||||
public string DBSnapshot {
|
||||
get {
|
||||
return ((string)(this["DBSnapshot"]));
|
||||
}
|
||||
set {
|
||||
this["DBSnapshot"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ClassDiagram MajorVersion="1" MinorVersion="1">
|
||||
<Class Name="DatabaseUnitTesting.CalculatedChannelsTests" Collapsed="true">
|
||||
<Position X="0.5" Y="1.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>CalculatedChannelsTests.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.CustomerDetailsTests" Collapsed="true">
|
||||
<Position X="5" Y="1.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>CustomerDetailsTests.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.DASChannelsTests" Collapsed="true">
|
||||
<Position X="9.5" Y="1.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>DASChannelsTests.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.DASTests" Collapsed="true">
|
||||
<Position X="11.75" Y="1.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>DASTests.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.DatabaseModificationTester" Collapsed="true" BaseTypeListCollapsed="true">
|
||||
<Position X="18.75" Y="1.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAgACACgAQABAAAAABIAAIAAAAAIAAAACEARAg=</HashCode>
|
||||
<FileName>DatabaseModificationTester.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<Lollipop Position="0.2" Collapsed="true" />
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.DefaultPropertiesTests" Collapsed="true">
|
||||
<Position X="2.75" Y="1.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>DefaultPropertiesTests.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.LaboratoryDetailsTests" Collapsed="true">
|
||||
<Position X="7.25" Y="1.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>LaboratoryDetailsTests.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.ResultSetTester" Collapsed="true">
|
||||
<Position X="24" Y="1.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAACAAAAAAAAAAAAQAAAAAAAAAAIAAAAQhAAAAA=</HashCode>
|
||||
<FileName>ResultSetTester.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.SensorsAnalogTests" Collapsed="true">
|
||||
<Position X="14" Y="1.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>SensorsAnalogTests.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.SensorsDigitalInUnitTests" Collapsed="true">
|
||||
<Position X="16.25" Y="1.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAA=</HashCode>
|
||||
<FileName>SensorsDigitalInTests.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.TestSetups" Collapsed="true">
|
||||
<Position X="8.25" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAwAAEAABAAAAAAAAAAAAANAABAAhoA=</HashCode>
|
||||
<FileName>TestSetups.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Properties.Settings" Collapsed="true">
|
||||
<Position X="20.5" Y="2.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAQAAAAAAAIABAAAABAAAAACAAAAAAAAA=</HashCode>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Utilities.DatabaseAdapter" Collapsed="true">
|
||||
<Position X="22.25" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAABAAAkAAIAAAAAAAAAAAAAABAA=</HashCode>
|
||||
<FileName>Utilities\DatabaseAdapter.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Utilities.DatabaseComparer" Collapsed="true">
|
||||
<Position X="24" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAACAAAQAAAAggAAAAAAAAAIAAAAAAAAQAAAAGQARAA=</HashCode>
|
||||
<FileName>Utilities\DatabaseComparer.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Utilities.ObjectsToCompare" Collapsed="true">
|
||||
<Position X="20.5" Y="1.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>EAACAAAAAEAAAAAIQAAAEAAAAAAAAAQAAJAAIAAAcAA=</HashCode>
|
||||
<FileName>Utilities\ObjectsToCompare.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Utilities.Results.Column" Collapsed="true">
|
||||
<Position X="18.75" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>ABAAIAAAAAAAAAAAgIAAACQAAAAAAAAQAAAgAAAAAAA=</HashCode>
|
||||
<FileName>Utilities\Results\Column.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Utilities.Results.Database" Collapsed="true">
|
||||
<Position X="20.5" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAQAEAAgAAAAAAAAgAAAQAAAAABAAOAAAAAgAAAAAAA=</HashCode>
|
||||
<FileName>Utilities\Results\Database.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Utilities.Results.ResultSetParser" Collapsed="true">
|
||||
<Position X="22.25" Y="1.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAgAAgAAAABAAAAAACAAAAAEAQAAAAAAAAAAAAAAEA=</HashCode>
|
||||
<FileName>Utilities\Results\ResultSetParser.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Utilities.Results.Row" Collapsed="true">
|
||||
<Position X="18.75" Y="2.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAQAAAAACAAQAAABAAEAAQAAQAAAQAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Utilities\Results\Row.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Utilities.Results.Table" Collapsed="true">
|
||||
<Position X="22.25" Y="2.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AABAIEBEAAAQAMAAgABAAAAEAAAAAIAAMAAgAAEAAgA=</HashCode>
|
||||
<FileName>Utilities\Results\Table.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="DatabaseUnitTesting.Utilities.Results.XmlFileAdapter" Collapsed="true">
|
||||
<Position X="24" Y="2.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAQAQAAgQAAAAAAAAwAAAAAABgAAAAAAECAAA=</HashCode>
|
||||
<FileName>Utilities\Results\XmlFileAdapter.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Font Name="Segoe UI" Size="9" />
|
||||
</ClassDiagram>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<results>
|
||||
<object name1="dbo.sensorsdigitalin" name2="dbo.sensorsdigitalin">
|
||||
<row type="schema" />
|
||||
<row type="in first">
|
||||
<column name="serialnumber" value="DigiInSerialNum" />
|
||||
<column name="settingmode" value="8" />
|
||||
<column name="scalemultiplier" value="ArbitraryHighAndLow,1,2" />
|
||||
<column name="lastmodifiedby" value="TestUser" />
|
||||
<column name="eid" value="EID" />
|
||||
<column name="uservalue1" value="" />
|
||||
<column name="uservalue2" value="" />
|
||||
<column name="uservalue3" value="" />
|
||||
<column name="usertags" value="0x0000000000000000000000000000000000000000" />
|
||||
</row>
|
||||
</object>
|
||||
</results>
|
||||
BIN
DataPRO/UnitTest/.svn/wc.db
Normal file
BIN
DataPRO/UnitTest/.svn/wc.db
Normal file
Binary file not shown.
0
DataPRO/UnitTest/.svn/wc.db-journal
Normal file
0
DataPRO/UnitTest/.svn/wc.db-journal
Normal file
1
DataPRO/UnitTest/DTS.Common.DataModel.Tests/.svn/entries
Normal file
1
DataPRO/UnitTest/DTS.Common.DataModel.Tests/.svn/entries
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
1
DataPRO/UnitTest/DTS.Common.DataModel.Tests/.svn/format
Normal file
1
DataPRO/UnitTest/DTS.Common.DataModel.Tests/.svn/format
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
@@ -0,0 +1,104 @@
|
||||
using GroupList.Model;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTS.Common.DataModel.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class GroupShould
|
||||
{
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueOnEmptyTerm()
|
||||
{
|
||||
Group sut = new Group();
|
||||
var res = sut.Filter("");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueOnNullTerm()
|
||||
{
|
||||
Group sut = new Group();
|
||||
var res = sut.Filter(null);
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenAssociatedTestSetupsIsNull()
|
||||
{
|
||||
Group sut = new Group();
|
||||
var res = sut.Filter("abc");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTerm()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.DisplayName = "defabchy";
|
||||
var res = sut.Filter("abc");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermDescription()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.Description = "defabchy";
|
||||
var res = sut.Filter("abc");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermChannelCount()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.AssociatedTestSetups = new List<Interface.Groups.GroupList.TestSetupParentHelper>();
|
||||
sut.ChannelCount = 3;
|
||||
var res = sut.Filter("3");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermNotfound()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.AssociatedTestSetups = new List<Interface.Groups.GroupList.TestSetupParentHelper>();
|
||||
var res = sut.Filter("178");
|
||||
Assert.That(res, Is.False);
|
||||
}
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermLastModifiedfound()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.AssociatedTestSetups = new List<Interface.Groups.GroupList.TestSetupParentHelper>();
|
||||
var now = DateTime.Now;
|
||||
sut.LastModified = now;
|
||||
var res = sut.Filter(now.ToString());
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermLastModifiedNotfound()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.AssociatedTestSetups = new List<Interface.Groups.GroupList.TestSetupParentHelper>();
|
||||
var now = DateTime.Now;
|
||||
sut.LastModified = now.AddMonths(5);
|
||||
var res = sut.Filter(now.ToString());
|
||||
Assert.That(res, Is.False);
|
||||
}
|
||||
[Test]
|
||||
public void ConvertToEmbedded_ShouldThrowNoExceptionIfEmbeddedAlready()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.Embedded = true;
|
||||
sut.ConvertToEmbedded(new List<Interface.Channels.IGroupChannel>().ToArray());
|
||||
Assert.That(sut.Embedded, Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{1FFCA92D-A1B0-4425-9074-7A1B91C04CB9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DTS.Common.DataModel.Tests</RootNamespace>
|
||||
<AssemblyName>DTS.Common.DataModel.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NUnit3.TestAdapter">
|
||||
<HintPath>..\..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3.TestAdapter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GroupShould.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common.DataModel\DTS.Common.DataModel.csproj">
|
||||
<Project>{2a2f03a9-bf85-4360-a06a-cf3016d2633b}</Project>
|
||||
<Name>DTS.Common.DataModel</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common\DTS.Common.csproj">
|
||||
<Project>{f7a0804f-61a4-40ae-83d0-f1137622b592}</Project>
|
||||
<Name>DTS.Common</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DTS.Common.DataModel.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("DTS.Common.DataModel.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1ffca92d-a1b0-4425-9074-7a1b91c04cb9")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
BIN
DataPRO/UnitTest/DTS.Common.DataModel.Tests/.svn/wc.db
Normal file
BIN
DataPRO/UnitTest/DTS.Common.DataModel.Tests/.svn/wc.db
Normal file
Binary file not shown.
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{1FFCA92D-A1B0-4425-9074-7A1B91C04CB9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DTS.Common.DataModel.Tests</RootNamespace>
|
||||
<AssemblyName>DTS.Common.DataModel.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NUnit3.TestAdapter">
|
||||
<HintPath>..\..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3.TestAdapter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GroupShould.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common.DataModel\DTS.Common.DataModel.csproj">
|
||||
<Project>{2a2f03a9-bf85-4360-a06a-cf3016d2633b}</Project>
|
||||
<Name>DTS.Common.DataModel</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common\DTS.Common.csproj">
|
||||
<Project>{f7a0804f-61a4-40ae-83d0-f1137622b592}</Project>
|
||||
<Name>DTS.Common</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
104
DataPRO/UnitTest/DTS.Common.DataModel.Tests/GroupShould.cs
Normal file
104
DataPRO/UnitTest/DTS.Common.DataModel.Tests/GroupShould.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using GroupList.Model;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTS.Common.DataModel.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class GroupShould
|
||||
{
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueOnEmptyTerm()
|
||||
{
|
||||
Group sut = new Group();
|
||||
var res = sut.Filter("");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueOnNullTerm()
|
||||
{
|
||||
Group sut = new Group();
|
||||
var res = sut.Filter(null);
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenAssociatedTestSetupsIsNull()
|
||||
{
|
||||
Group sut = new Group();
|
||||
var res = sut.Filter("abc");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTerm()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.DisplayName = "defabchy";
|
||||
var res = sut.Filter("abc");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermDescription()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.Description = "defabchy";
|
||||
var res = sut.Filter("abc");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermChannelCount()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.AssociatedTestSetups = new List<Interface.Groups.GroupList.TestSetupParentHelper>();
|
||||
sut.ChannelCount = 3;
|
||||
var res = sut.Filter("3");
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermNotfound()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.AssociatedTestSetups = new List<Interface.Groups.GroupList.TestSetupParentHelper>();
|
||||
var res = sut.Filter("178");
|
||||
Assert.That(res, Is.False);
|
||||
}
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermLastModifiedfound()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.AssociatedTestSetups = new List<Interface.Groups.GroupList.TestSetupParentHelper>();
|
||||
var now = DateTime.Now;
|
||||
sut.LastModified = now;
|
||||
var res = sut.Filter(now.ToString());
|
||||
Assert.That(res, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Filter_ShouldReturnTrueWhenfindTermLastModifiedNotfound()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.AssociatedTestSetups = new List<Interface.Groups.GroupList.TestSetupParentHelper>();
|
||||
var now = DateTime.Now;
|
||||
sut.LastModified = now.AddMonths(5);
|
||||
var res = sut.Filter(now.ToString());
|
||||
Assert.That(res, Is.False);
|
||||
}
|
||||
[Test]
|
||||
public void ConvertToEmbedded_ShouldThrowNoExceptionIfEmbeddedAlready()
|
||||
{
|
||||
Group sut = new Group();
|
||||
sut.Embedded = true;
|
||||
sut.ConvertToEmbedded(new List<Interface.Channels.IGroupChannel>().ToArray());
|
||||
Assert.That(sut.Embedded, Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DTS.Common.DataModel.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("DTS.Common.DataModel.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1ffca92d-a1b0-4425-9074-7a1b91c04cb9")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
e66b2b2bbd82ccd73fa03b4bc269003c474e9b85
|
||||
@@ -0,0 +1,2 @@
|
||||
D:\DTS\Code\DP\BRANCH_MAINT_4_04\DataPRO\UnitTest\DTS.Common.DataModel.Tests\obj\Debug\DTS.Common.DataModel.Tests.csproj.AssemblyReference.cache
|
||||
D:\DTS\Code\DP\BRANCH_MAINT_4_04\DataPRO\UnitTest\DTS.Common.DataModel.Tests\obj\Debug\DTS.Common.DataModel.Tests.csproj.CoreCompileInputs.cache
|
||||
Binary file not shown.
1
DataPRO/UnitTest/DTS.Common.Import.Tests/.svn/entries
Normal file
1
DataPRO/UnitTest/DTS.Common.Import.Tests/.svn/entries
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
1
DataPRO/UnitTest/DTS.Common.Import.Tests/.svn/format
Normal file
1
DataPRO/UnitTest/DTS.Common.Import.Tests/.svn/format
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
@@ -0,0 +1,134 @@
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DTS.Common.Import.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("DTS.Common.Import.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("38a471f6-c94f-4ae1-8ef5-d49f309bb3c2")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{38A471F6-C94F-4AE1-8EF5-D49F309BB3C2}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DTS.Common.Import.Tests</RootNamespace>
|
||||
<AssemblyName>DTS.Common.Import.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Castle.Core">
|
||||
<HintPath>..\..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NSubstitute">
|
||||
<HintPath>..\..\packages\NSubstitute.4.2.1\lib\net46\NSubstitute.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CalibrationImportShould.cs" />
|
||||
<Compile Include="GroupHelperShould.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common.DataModel\DTS.Common.DataModel.csproj">
|
||||
<Project>{2a2f03a9-bf85-4360-a06a-cf3016d2633b}</Project>
|
||||
<Name>DTS.Common.DataModel</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common.Import\DTS.Common.Import.csproj">
|
||||
<Project>{c1bc06f4-8657-4892-bc4d-1064da01c4c7}</Project>
|
||||
<Name>DTS.Common.Import</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common\DTS.Common.csproj">
|
||||
<Project>{f7a0804f-61a4-40ae-83d0-f1137622b592}</Project>
|
||||
<Name>DTS.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\SensorDB\SensorDB.csproj">
|
||||
<Project>{444ef10c-046e-47ad-a9a5-17318d488723}</Project>
|
||||
<Name>SensorDB</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Users\Users.csproj">
|
||||
<Project>{be8d217d-6da9-4bca-b62a-a82325b33979}</Project>
|
||||
<Name>Users</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
using DataPROWin7.DataModel;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
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
|
||||
{
|
||||
class GroupHelperShould
|
||||
{
|
||||
[Test]
|
||||
public void CreateEmptyGroup_ShouldCreateNewGroup()
|
||||
{
|
||||
var res = GroupHelper.CreateEmptyGroup();
|
||||
Assert.That(res.LastModifiedBy, Is.EqualTo("---"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReverseChannelOrder_ShouldNotThorwExceptionOnNullTestTemplate()
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
dict.Add("1", "a");
|
||||
var sens = NSubstitute.Substitute.For<SensorData>();
|
||||
var res = GroupHelper.ReverseChannelOrder(null, dict, new List<SensorDB.SensorData> { sens });
|
||||
Assert.That(res.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReverseChannelOrder_ShouldNotThorwExceptionOnNullSensors()
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
dict.Add("1", "a");
|
||||
|
||||
var res = GroupHelper.ReverseChannelOrder(null, dict,null);
|
||||
Assert.That(res.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NormalizeSensorIds_ShouldNotThorwExceptionOnNullSensors()
|
||||
{
|
||||
var res = GroupHelper.NormalizeSensorIds(null);
|
||||
Assert.That(res.Count, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DataPRO/UnitTest/DTS.Common.Import.Tests/.svn/wc.db
Normal file
BIN
DataPRO/UnitTest/DTS.Common.Import.Tests/.svn/wc.db
Normal file
Binary file not shown.
@@ -0,0 +1,134 @@
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{38A471F6-C94F-4AE1-8EF5-D49F309BB3C2}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DTS.Common.Import.Tests</RootNamespace>
|
||||
<AssemblyName>DTS.Common.Import.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Castle.Core">
|
||||
<HintPath>..\..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NSubstitute">
|
||||
<HintPath>..\..\packages\NSubstitute.4.2.1\lib\net46\NSubstitute.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CalibrationImportShould.cs" />
|
||||
<Compile Include="GroupHelperShould.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common.DataModel\DTS.Common.DataModel.csproj">
|
||||
<Project>{2a2f03a9-bf85-4360-a06a-cf3016d2633b}</Project>
|
||||
<Name>DTS.Common.DataModel</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common.Import\DTS.Common.Import.csproj">
|
||||
<Project>{c1bc06f4-8657-4892-bc4d-1064da01c4c7}</Project>
|
||||
<Name>DTS.Common.Import</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common\DTS.Common.csproj">
|
||||
<Project>{f7a0804f-61a4-40ae-83d0-f1137622b592}</Project>
|
||||
<Name>DTS.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\SensorDB\SensorDB.csproj">
|
||||
<Project>{444ef10c-046e-47ad-a9a5-17318d488723}</Project>
|
||||
<Name>SensorDB</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Users\Users.csproj">
|
||||
<Project>{be8d217d-6da9-4bca-b62a-a82325b33979}</Project>
|
||||
<Name>Users</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
using DataPROWin7.DataModel;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
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
|
||||
{
|
||||
class GroupHelperShould
|
||||
{
|
||||
[Test]
|
||||
public void CreateEmptyGroup_ShouldCreateNewGroup()
|
||||
{
|
||||
var res = GroupHelper.CreateEmptyGroup();
|
||||
Assert.That(res.LastModifiedBy, Is.EqualTo("---"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReverseChannelOrder_ShouldNotThorwExceptionOnNullTestTemplate()
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
dict.Add("1", "a");
|
||||
var sens = NSubstitute.Substitute.For<SensorData>();
|
||||
var res = GroupHelper.ReverseChannelOrder(null, dict, new List<SensorDB.SensorData> { sens });
|
||||
Assert.That(res.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReverseChannelOrder_ShouldNotThorwExceptionOnNullSensors()
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
dict.Add("1", "a");
|
||||
|
||||
var res = GroupHelper.ReverseChannelOrder(null, dict,null);
|
||||
Assert.That(res.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NormalizeSensorIds_ShouldNotThorwExceptionOnNullSensors()
|
||||
{
|
||||
var res = GroupHelper.NormalizeSensorIds(null);
|
||||
Assert.That(res.Count, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DTS.Common.Import.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("DTS.Common.Import.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("38a471f6-c94f-4ae1-8ef5-d49f309bb3c2")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
f8502a9d2c5c989efd146c062830cc7b4b1ea490
|
||||
@@ -0,0 +1,2 @@
|
||||
D:\DTS\Code\DP\BRANCH_MAINT_4_04\DataPRO\UnitTest\DTS.Common.Import.Tests\obj\Debug\DTS.Common.Import.Tests.csproj.AssemblyReference.cache
|
||||
D:\DTS\Code\DP\BRANCH_MAINT_4_04\DataPRO\UnitTest\DTS.Common.Import.Tests\obj\Debug\DTS.Common.Import.Tests.csproj.CoreCompileInputs.cache
|
||||
Binary file not shown.
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class CalculatedChannelsTests : TestSetups
|
||||
{
|
||||
|
||||
// Notes:
|
||||
// Operation
|
||||
// SUM = 1,
|
||||
// AVERAGE = 2,
|
||||
// IRTRACC3D =3,
|
||||
// IRTRACC3D_ABDOMEN =4,
|
||||
// IRTRACC3D_LOWERTHORAX = 5
|
||||
|
||||
|
||||
// [Test]
|
||||
// ============================================================
|
||||
// DELETE CALCULATED CHANNEL
|
||||
// Call sp_CalculatedChannelsDelete with a known calculated channel
|
||||
// Verify Calculated channel no longer exists in dbo.CalculatedChannels table.
|
||||
// ============================================================
|
||||
|
||||
|
||||
// [Test]
|
||||
// =============================================================
|
||||
// GET CALCULATED CHANNEL
|
||||
// Start with a test setup that has a known number of calculated channels included. Call sp_CalculatedChannelsGet for test setup
|
||||
// Verify known calculated channels are returned
|
||||
// =============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT CALCULATED CHANNEL: VERIFY FIELDS
|
||||
// Starting with a known populated test setup call sp_CalculatedChannelsUpdateInsert with parameters for a new valid
|
||||
// calculated channel and compare all fields.
|
||||
// Pass if all fields in dbo.CalculatedChannels table are entered.
|
||||
// ============================================================
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT CALCULATED CHANNEL: VERIFY ONLY ONE NEW ROW IS ADDED
|
||||
// Starting with a known populated test setup call sp_CalculatedChannelsUpdateInsert with parameters for a new valid
|
||||
// calculated channel and verify a new row is created in dbo.CalcualtedChannels table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE CALCULATED CHANNEL
|
||||
// Send valid calculated channels parameters to sp_CalculatedChannelsInUpdateInsert for a calculated
|
||||
// channel that already is in the database and compare all fields.
|
||||
// Pass if all fields in dbo.CalculatedChannels table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE CALCULATED CHANNEL: VERIFY NO NEW ROW IS ADDED
|
||||
// Send valid calculated channels parameters to sp_CalculatedChannelsInUpdateInsert for a calculated
|
||||
// channel that already is in the database and verify no new row is created in dbo.CalculatedChannels table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
}
|
||||
}
|
||||
68
DataPRO/UnitTest/DatabaseUnitTesting/CustomerDetailsTests.cs
Normal file
68
DataPRO/UnitTest/DatabaseUnitTesting/CustomerDetailsTests.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class CustomerDetailsTests : TestSetups
|
||||
{
|
||||
|
||||
// NOTES
|
||||
// Name cannot be null as that is the identifying field for insert or update.
|
||||
|
||||
|
||||
// [Test]
|
||||
// ============================================================
|
||||
// DELETE CUSTOMER DETAILS
|
||||
// Call sp_CustomerDetailsDelete with a known details
|
||||
// Verify customer detials no longer exists in dbo.CustomerDetails table.
|
||||
// ============================================================
|
||||
|
||||
|
||||
// [Test]
|
||||
// =============================================================
|
||||
// GET CUSTOMER DETAILS
|
||||
// Start with a known customer details in the database. Call sp_CustomerDetailsGet with name
|
||||
// Verify known customer details are returned
|
||||
// =============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT CUSTOMER DETAILS
|
||||
// call sp_CustomerDetailsUpdateInsert with parameters for a new valid
|
||||
// customer details record and compare all fields.
|
||||
// Pass if all fields in dbo.CustomerDetails table are entered.
|
||||
// ============================================================
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// call sp_CustomerDetailsUpdateInsert with parameters for a new valid
|
||||
// customer details and verify a new row is created in dbo.CustomerDetails table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE CUSTOMER DETAILS
|
||||
// Send valid customer details parameters to sp_CustomerDetailsInUpdateInsert for a
|
||||
// customer detail record that already is in the database and compare all fields.
|
||||
// Pass if all fields in dbo.CustomerDetails table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// UPDATE CUSTOMER DETAILS
|
||||
// ============================================================
|
||||
// Send valid customer details parameters to sp_CustomerDetailsInUpdateInsert for a
|
||||
// customer details record that already is in the database.
|
||||
// pass if no new row is created in dbo.CustomerDetails table.
|
||||
// ============================================================
|
||||
|
||||
}
|
||||
}
|
||||
67
DataPRO/UnitTest/DatabaseUnitTesting/DASChannelsTests.cs
Normal file
67
DataPRO/UnitTest/DatabaseUnitTesting/DASChannelsTests.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class DASChannelsTests : TestSetups
|
||||
{
|
||||
|
||||
// NOTES:
|
||||
// Deletes DAS channels by DASId. IE: all channels associated with the given DAS hardware ID will be deleted.
|
||||
|
||||
// [Test]
|
||||
// ============================================================
|
||||
// DELETE DAS CHANNELS
|
||||
// Call sp_DASChannelsDelete with a known DAS hardware ID
|
||||
// Verify all DAS channels associated with the hardware ID no longer exists in dbo.DASChannels table.
|
||||
// ============================================================
|
||||
|
||||
|
||||
// [Test]
|
||||
// =============================================================
|
||||
// GET DAS CHANNELS
|
||||
// Start with a DAS hardware that has a known number of DAS channels included. Call sp_DASChannelsGet for the hardware.
|
||||
// Verify known number of DAS channels are returned
|
||||
// =============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT DAS CHANNELS
|
||||
// Starting with a known populated test setup call sp_DASChannelsUpdateInsert with parameters for a new valid
|
||||
// DAS channel and compare all fields.
|
||||
// Pass if all fields in dbo.DASChannels table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT DAS CHANNEL: VERIFY ONLY ONE NEW ROW IS ADDED
|
||||
// Call sp_DASChannelsUpdateInsert with parameters for a new valid
|
||||
// DAS channel and verify a new row is created in dbo.DASChannels table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE DAS CHANNEL
|
||||
// Send valid DAS channels parameters to sp_DASChannelsInUpdateInsert for a DAS
|
||||
// channel that already is in the database and compare all fields.
|
||||
// Pass if all fields in dbo.DASChannels table are entered.
|
||||
// ============================================================
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE DAS CHANNEL: VERIFY NO NEW ROW IS ADDED
|
||||
// Send valid DAS channels parameters to sp_DASChannelsInUpdateInsert for a DAS
|
||||
// channel that already is in the database and verify no new row is created in dbo.DASChannels table.
|
||||
//
|
||||
// ============================================================
|
||||
}
|
||||
}
|
||||
66
DataPRO/UnitTest/DatabaseUnitTesting/DASTests.cs
Normal file
66
DataPRO/UnitTest/DatabaseUnitTesting/DASTests.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class DASTests : TestSetups
|
||||
{
|
||||
// NOTES:
|
||||
// DAS must have serial number
|
||||
|
||||
// [Test]
|
||||
// ============================================================
|
||||
// DELETE DAS
|
||||
// Call sp_DASDelete with a known DAS hardware ID
|
||||
// Verify all DAS channels associated with the hardware ID no longer exists in dbo.DAS table.
|
||||
// ============================================================
|
||||
|
||||
|
||||
// [Test]
|
||||
// =============================================================
|
||||
// GET DAS
|
||||
// Start with a known already entered DAS. Call sp_DASGet for the hardware.
|
||||
// Verify known DAS is returned
|
||||
// =============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT DAS
|
||||
// Call sp_CalculatedChannelsUpdateInsert with parameters for a new valid
|
||||
// DAS and compare all fields.
|
||||
// Pass if all fields in dbo.DAS table are entered.
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// INSERT DAS: VERIFY ONLY ONE NEW ROW IS ADDED
|
||||
// Call sp_DASCUpdateInsert with parameters for a new valid
|
||||
// DAS and verify a new row is created in dbo.DAS table.
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE DAS
|
||||
// Send valid DAS parameters to sp_DASInUpdateInsert for a DAS
|
||||
// that already is in the database and compare all fields.
|
||||
// Pass if all fields in dbo.DAS table are entered.
|
||||
// ============================================================
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// UPDATE DAS: VERIFY NO NEW ROW IS ADDED
|
||||
// Send valid DAS parameters to sp_DASInUpdateInsert for a DAS
|
||||
// that already is in the database and verify no new row is created in dbo.DAS table.
|
||||
//
|
||||
// ============================================================
|
||||
}
|
||||
}
|
||||
96
DataPRO/UnitTest/DatabaseUnitTesting/DBAPITests.cs
Normal file
96
DataPRO/UnitTest/DatabaseUnitTesting/DBAPITests.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using DTS.Common.Interface.Database;
|
||||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
private const string INSTANCE_NAME = "DataPROInstance";
|
||||
private const string LOCAL_SERVER = @"(localdb)\DataPROInstance";
|
||||
private const string SCRIPTS_FOLDER = "SQL Server Scripts";
|
||||
private const string LOCAL_DB_FOLDER = "db";
|
||||
private const string ISO = "ISO";
|
||||
private const string ATTACH_DBS_BAT = "AttachDBs.bat";
|
||||
private bool _setup = false;
|
||||
private IUserDbRecord _user = null;
|
||||
private const int SettingsDefaultMaxLogFileSize = 4194304;
|
||||
private const int SettingsDefaultDBLoggingLevel = 783;
|
||||
private int clientDbVersion = DTS.Common.Storage.DbOperations.MINIMUM_LTS_DB_VERSION;
|
||||
[OneTimeSetUp]
|
||||
public void Setup()
|
||||
{
|
||||
if (!DbAPI.DbAPI._loggerInitialized)
|
||||
{
|
||||
DbAPI.DbAPI.InitializeLogger(SettingsDefaultMaxLogFileSize, "Logs", SettingsDefaultDBLoggingLevel);
|
||||
}
|
||||
|
||||
var dllLocation = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
var debugOrRelease = dllLocation.Directory.Name;
|
||||
var architecture = dllLocation.Directory.Parent.Name;
|
||||
var curDir = System.Environment.CurrentDirectory;
|
||||
if (curDir.Contains("Common"))
|
||||
{
|
||||
curDir = curDir.Substring(0, curDir.IndexOf("Common"));
|
||||
curDir = Path.Combine(curDir, "DataPRO");
|
||||
}
|
||||
else
|
||||
{
|
||||
var tokens = curDir.Split(new[] { Path.DirectorySeparatorChar });
|
||||
var count = tokens.Count(d => d.Equals("DataPRO"));
|
||||
if (1 == count)
|
||||
{
|
||||
tokens[0] = $"{tokens[0]}{Path.DirectorySeparatorChar}";
|
||||
var index = tokens.ToList().IndexOf("DataPRO");
|
||||
tokens = tokens.Take(index + 1).ToArray();
|
||||
curDir = Path.Combine(tokens);
|
||||
}
|
||||
else if (0 == count)
|
||||
{
|
||||
curDir = Path.Combine(curDir, "DataPRO");
|
||||
}
|
||||
}
|
||||
var exeOutputLocation = Path.Combine(curDir, "DataPRO", "bin", architecture, debugOrRelease);
|
||||
var details = new DbAPI.Connections.ConnectionDetails();
|
||||
|
||||
details.AttachDbsBatPath = Path.Combine(exeOutputLocation, SCRIPTS_FOLDER, ATTACH_DBS_BAT);
|
||||
details.DbFolderPath = Path.Combine(exeOutputLocation, LOCAL_DB_FOLDER);
|
||||
details.DbName = "DataPRO";
|
||||
details.UsingCentralizedDb = false;
|
||||
details.DbServer = LOCAL_SERVER;
|
||||
details.InstanceName = INSTANCE_NAME;
|
||||
details.UseNTLMAuthentication = true;
|
||||
details.SqlDbPath = DTS.Common.Utils.Database.GetSqlServerLocalDbPath();
|
||||
details.ODBCToolsPath = DTS.Common.Utils.Database.GetODBCToolsPath(null);
|
||||
var res = DbAPI.DbAPI.Connections.ConnectToDb(details);
|
||||
_setup = true;
|
||||
}
|
||||
[Test]
|
||||
public void TestConnect()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
Assert.IsTrue(connections.Any(), $"Db connected");
|
||||
}
|
||||
private void Login()
|
||||
{
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var hr = DbAPI.DbAPI.Connections.LoginUser(connections.First(), "Admin", "DTSAdmin", out var user);
|
||||
if (0 == hr)
|
||||
{
|
||||
_user = user;
|
||||
clientDbVersion = connections.FirstOrDefault().ClientDbVersion;
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public void TestLogin()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestConnect();
|
||||
if (null == _user) { Login(); }
|
||||
Assert.IsNotNull(_user, "User logged in");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using DatabaseUnitTesting.Utilities;
|
||||
using DatabaseUnitTesting.Utilities.Results;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
public class DatabaseModificationTester : IDisposable
|
||||
{
|
||||
|
||||
private readonly DatabaseComparer _dataComparer;
|
||||
private SqlTransaction _transaction;
|
||||
private SqlConnection _connection;
|
||||
private readonly string _snapshotName;
|
||||
private readonly DatabaseAdapter _databaseAdapter;
|
||||
private bool _activeSnapshot = false;
|
||||
/// <summary>
|
||||
/// Used to establish the objects required to create a unit test running compares between a stored XML database file and an SQL transaction.
|
||||
/// </summary>
|
||||
/// <param name="connection"></param>
|
||||
/// <param name="databaseName"></param>
|
||||
/// <param name="snapshotName"></param>
|
||||
public DatabaseModificationTester(SqlConnection connection, string databaseName, string snapshotName)
|
||||
{
|
||||
_connection = connection;
|
||||
_snapshotName = snapshotName;
|
||||
_dataComparer = new DatabaseComparer(connection, databaseName, snapshotName);
|
||||
_databaseAdapter = new DatabaseAdapter(connection);
|
||||
_databaseAdapter.CreateSnapshot(databaseName, snapshotName);
|
||||
_activeSnapshot = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// establishes the command transaction to be compared and rolled back on end
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SqlTransaction BeginTestTransaction()
|
||||
{
|
||||
if (_transaction != null)
|
||||
EndTestTransaction();
|
||||
|
||||
return (_transaction = _connection.BeginTransaction());
|
||||
}
|
||||
/// <summary>
|
||||
/// Once the compare is complete this method cleans up, rollsback, and disposes the transaction
|
||||
/// </summary>
|
||||
public void EndTestTransaction()
|
||||
{
|
||||
if (_transaction == null)
|
||||
throw new InvalidOperationException("Transaction does not exist");
|
||||
|
||||
_dataComparer.CleanUp();
|
||||
_transaction.Rollback();
|
||||
_transaction.Dispose();
|
||||
_transaction = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Method to write XML file to use during unit testing. Writes differences between current database and the completed transaction.
|
||||
/// The file generated here should be manually verified
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
public void WriteDiffsToXml(string filename)
|
||||
{
|
||||
XmlFileAdapter.Write(filename, _dataComparer.GenerateDifferences(_transaction));
|
||||
}
|
||||
/// <summary>
|
||||
/// Return true/false based on compare of transaction and stored XML expected test results.
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public bool CompareDiffsToXml(string filename)
|
||||
{
|
||||
return XmlFileAdapter.Read(filename).Equals(_dataComparer.GenerateDifferences(_transaction));
|
||||
}
|
||||
|
||||
public bool AreEqual()
|
||||
{
|
||||
return _dataComparer.GenerateDifferences(_transaction).TableCount == 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Enables test to ignore defined columns in database tables
|
||||
/// </summary>
|
||||
/// <param name="schemaName"></param>
|
||||
/// <param name="objectName"></param>
|
||||
/// <param name="columnName"></param>
|
||||
public void AddColumnToIgnore(string schemaName, string objectName, string columnName)
|
||||
{
|
||||
_dataComparer.AddColumnToIgnore(schemaName, objectName, columnName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Enables test to ignore defined columns in database tables
|
||||
/// </summary>
|
||||
/// <param name="schema1"></param>
|
||||
/// <param name="name1"></param>
|
||||
/// <param name="columnNames"></param>
|
||||
public void AddColumnsToIgnore(string schema1, string name1, List<string> columnNames)
|
||||
{
|
||||
_dataComparer.AddColumnsToIgnore(schema1, name1, columnNames);
|
||||
}
|
||||
|
||||
public void AddObjectComparison(string schemaName, string tableName)
|
||||
{
|
||||
_dataComparer.AddObjectComparison(schemaName, tableName, schemaName, tableName);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_activeSnapshot)
|
||||
{
|
||||
_activeSnapshot = false;
|
||||
_databaseAdapter.DropSnapshot(_snapshotName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
184
DataPRO/UnitTest/DatabaseUnitTesting/DatabaseUnitTesting.csproj
Normal file
184
DataPRO/UnitTest/DatabaseUnitTesting/DatabaseUnitTesting.csproj
Normal file
@@ -0,0 +1,184 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0">
|
||||
<Import Project="..\..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props')" />
|
||||
<Import Project="..\..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\..\packages\NUnit.3.12.0\build\NUnit.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F5BA4B68-A059-4A1A-8286-490462D4F29A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DatabaseUnitTesting</RootNamespace>
|
||||
<AssemblyName>DatabaseUnitTesting</AssemblyName>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>
|
||||
</AssemblyOriginatorKeyFile>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>2.0</OldToolsVersion>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NUnit3.TestAdapter">
|
||||
<HintPath>..\..\..\Common\DTS.Common\lib\NUnitTestAdapter\NUnit3.TestAdapter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CalculatedChannelsTests.cs" />
|
||||
<Compile Include="CustomerDetailsTests.cs" />
|
||||
<Compile Include="DASChannelsTests.cs" />
|
||||
<Compile Include="DASTests.cs" />
|
||||
<Compile Include="DatabaseModificationTester.cs" />
|
||||
<Compile Include="DBAPITests.cs" />
|
||||
<Compile Include="DbAPITestsRegionsOfInterest.cs" />
|
||||
<Compile Include="DbAPITestsTestSetupGroup.cs" />
|
||||
<Compile Include="DbAPITestsGroupHardware.cs" />
|
||||
<Compile Include="DbAPITestsTestEngineerDetails.cs" />
|
||||
<Compile Include="DbAPITestsLaboratoryDetails.cs" />
|
||||
<Compile Include="DbAPITestsCustomerDetails.cs" />
|
||||
<Compile Include="DbAPITestsTags.cs" />
|
||||
<Compile Include="DbAPITestsTestSetupHardware.cs" />
|
||||
<Compile Include="DbAPITestsTestSetupROIs.cs" />
|
||||
<Compile Include="DbAPITestsTestSetups.cs" />
|
||||
<Compile Include="DbAPITestsChannels.cs" />
|
||||
<Compile Include="DbAPITestsSensorsAnalog.cs" />
|
||||
<Compile Include="DbAPITestsDAS.cs" />
|
||||
<Compile Include="DefaultPropertiesTests.cs" />
|
||||
<Compile Include="LaboratoryDetailsTests.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ResultSetTester.cs" />
|
||||
<Compile Include="SensorsAnalogTests.cs" />
|
||||
<Compile Include="SensorsDigitalInTests.cs" />
|
||||
<Compile Include="TestSetups.cs" />
|
||||
<Compile Include="Utilities\DatabaseAdapter.cs" />
|
||||
<Compile Include="Utilities\ObjectsToCompare.cs" />
|
||||
<Compile Include="Utilities\Results\Column.cs" />
|
||||
<Compile Include="Utilities\Results\Database.cs" />
|
||||
<Compile Include="Utilities\DatabaseComparer.cs" />
|
||||
<Compile Include="Utilities\Results\Row.cs" />
|
||||
<Compile Include="Utilities\Results\XmlFileAdapter.cs" />
|
||||
<Compile Include="Utilities\Results\Table.cs" />
|
||||
<Compile Include="Utilities\Results\ResultSetParser.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common.Storage\DTS.Common.Storage.csproj">
|
||||
<Project>{e3be457c-0ac7-4a9c-bc81-eafeb3217878}</Project>
|
||||
<Name>DTS.Common.Storage</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Common\DTS.Common\DTS.Common.csproj">
|
||||
<Project>{F7A0804F-61A4-40AE-83D0-F1137622B592}</Project>
|
||||
<Name>DTS.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\DbAPI\DbAPI.csproj">
|
||||
<Project>{c356fb81-3177-4a42-b3c2-afa619335e3f}</Project>
|
||||
<Name>DbAPI</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="Design\DatabaseUnitTestingClassDiagram.cd" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="TestResults\DigitalInSensorInsertTest.xml" />
|
||||
<Content Include="TestResults\DigitalInSensorUpdateTest.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
94
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsChannels.cs
Normal file
94
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsChannels.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using DTS.Common.Classes.Channels;
|
||||
using DTS.Common.Interface.Channels;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
[Test]
|
||||
public void TestChannelsInsert()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var channel = CreateFakeChannel();
|
||||
//var hr = DbAPI.DbAPI.Channels.ChannelsInsert();
|
||||
//Assert.AreEqual(0, hr, "ChannelsInsert should return 0");
|
||||
//Assert.IsTrue(channel.Id > 0, "Inserted channel Id should be > 0");
|
||||
var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out var channels);
|
||||
Assert.AreEqual(0, hr, "ChannelsGet should return 0 for inserted channel");
|
||||
Assert.IsTrue(null != channels && 1 == channels.Length, "ChannelsGet should return 1 channel");
|
||||
|
||||
//hr = DbAPI.DbAPI.Channels.ChannelsDelete();
|
||||
//Assert.AreEqual(0, hr, "ChannelsDelete should return 0 for inserted channel");
|
||||
hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out channels);
|
||||
Assert.IsTrue(0 == hr && (null == channels || 0 == channels.Length), "Channel should no longer return 0 from ChannelsGet");
|
||||
}
|
||||
[Test]
|
||||
public void TestChannelsUpdate()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var channel = CreateFakeChannel();
|
||||
//var hr = DbAPI.DbAPI.Channels.ChannelsUpdate();
|
||||
//Assert.AreEqual(0, hr, "ChannelsUpdate should return 0");
|
||||
//Assert.IsTrue(channel.Id > 0, "Updated channel Id should be > 0");
|
||||
var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out var channels);
|
||||
Assert.AreEqual(0, hr, "ChannelsGet should return 0 for updated channel");
|
||||
Assert.IsTrue(null != channels && 1 == channels.Length, "ChannelsGet should return 1 channel");
|
||||
|
||||
//hr = DbAPI.DbAPI.Channels.ChannelsDelete();
|
||||
//Assert.AreEqual(0, hr, "ChannelsDelete should return 0 for inserted channel");
|
||||
hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out channels);
|
||||
Assert.IsTrue(0 == hr && (null == channels || 0 == channels.Length), "Channel should no longer return 0 from ChannelsGet");
|
||||
}
|
||||
[Test]
|
||||
public void TestChannelsGet()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var channel = CreateFakeChannel();
|
||||
//var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), channel);
|
||||
//Assert.AreEqual(0, hr, "ChannelsGet should return 0");
|
||||
//Assert.IsTrue(channel.Id > 0, "Channel Id should be > 0");
|
||||
var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out var channels);
|
||||
Assert.AreEqual(0, hr, "ChannelsGet should return 0 for inserted channel");
|
||||
Assert.IsTrue(null != channels && 1 == channels.Length, "ChannelsGet should return 1 channel");
|
||||
|
||||
//hr = DbAPI.DbAPI.Channels.ChannelsDelete();
|
||||
//Assert.AreEqual(0, hr, "ChannelsDelete should return 0 for inserted channel");
|
||||
hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out channels);
|
||||
Assert.IsTrue(0 == hr && (null == channels || 0 == channels.Length), "Channel should no longer return 0 from ChannelsGet");
|
||||
}
|
||||
[Test]
|
||||
public void TestChannelsDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var channel = CreateFakeChannel();
|
||||
//var hr = DbAPI.DbAPI.Channels.ChannelsDelete();
|
||||
//Assert.AreEqual(0, hr, "ChannelsDelete should return 0");
|
||||
//Assert.IsTrue(channel.Id > 0, "Updated channel Id should be > 0");
|
||||
var hr = DbAPI.DbAPI.Channels.ChannelsGet(_user, connections.First(), clientDbVersion, channel.Id, null, null, null, null, null, out var channels);
|
||||
Assert.IsTrue(0 == hr, "ChannelsGet should return 0");
|
||||
Assert.IsTrue(null == channels || 0 == channels.Length, "ChannelsGet should return no channel");
|
||||
}
|
||||
|
||||
private IChannelDbRecord CreateFakeChannel()
|
||||
{
|
||||
//var group = CreateFakeGroup();
|
||||
|
||||
var channel = new ChannelDbRecord();
|
||||
//channel.GroupId = group.Id;
|
||||
channel.LastModified = DateTime.Now;
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using DTS.Common.Interface.TestMetaData;
|
||||
using DTS.Common.Classes.CustomerDetails;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public CustomerDetailsDbRecord CreateFakeCustomerDetails(string name)
|
||||
{
|
||||
var record = new CustomerDetailsDbRecord();
|
||||
record.CustomerId = -1;
|
||||
record.Name = name;
|
||||
record.CustomerName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerTestRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.ProjectRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerOrderNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerCostUnit = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LocalOnly = true;
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.Version = 1;
|
||||
return record;
|
||||
}
|
||||
[Test]
|
||||
public void CustomerDetails()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//Delete all to start with a blank table
|
||||
var hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsDelete(_user, connections.First(), null, out string errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsDelete");
|
||||
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var legitRecord = CreateFakeCustomerDetails("legit");
|
||||
var decoyRecord = CreateFakeCustomerDetails("decoy");
|
||||
|
||||
//Insert
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsInsert(_user, connections.First(), legitRecord, out int newLegitId, out string legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate CustomerDetails record");
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsInsert(_user, connections.First(), decoyRecord, out int newFakeId, out string fakeErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy CustomerDetails record");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), legitRecord.Name, out ICustomerDetailsDbRecord[] customerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != customerDetailsDbRecords && customerDetailsDbRecords.Length == 1, "CustomerDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(customerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should have retrieved only one record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), null, out ICustomerDetailsDbRecord[] allCustomerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != allCustomerDetailsDbRecords && allCustomerDetailsDbRecords.Length == 2, "CustomerDetailsGet should have retrieved 2 records");
|
||||
Assert.IsTrue(allCustomerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should have retrieved our record");
|
||||
Assert.IsTrue(allCustomerDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "CustomerDetailsGet should have retrieved our record");
|
||||
|
||||
//Update
|
||||
var newCustomerTestRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
legitRecord.CustomerTestRefNumber = newCustomerTestRefNumber;
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsUpdate(_user, connections.First(), legitRecord, out legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate CustomerDetails record");
|
||||
Assert.IsTrue(legitErrorString == string.Empty, $"Error when inserting a legitimate CustomerDetails record: {legitErrorString}");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), legitRecord.Name, out customerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != customerDetailsDbRecords && customerDetailsDbRecords.Length == 1, "CustomerDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(customerDetailsDbRecords.Any(r => r.CustomerTestRefNumber == newCustomerTestRefNumber), "CustomerDetailsGet should have retrieved the updated record");
|
||||
|
||||
//Delete by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsDelete(_user, connections.First(), legitRecord.Name, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), legitRecord.Name, out customerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != customerDetailsDbRecords, "CustomerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(customerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should not have retrieved this record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), null, out allCustomerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != allCustomerDetailsDbRecords && allCustomerDetailsDbRecords.Length == 1, "CustomerDetailsGet should have retrieved only the decoy record");
|
||||
Assert.IsFalse(allCustomerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet not should have retrieved this record");
|
||||
Assert.IsTrue(allCustomerDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "CustomerDetailsGet should have retrieved this record");
|
||||
|
||||
//Delete all
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsDelete(_user, connections.First(), null, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), legitRecord.Name, out customerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != customerDetailsDbRecords, "CustomerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(customerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should not have retrieved any records");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.CustomerDetails.CustomerDetailsGet(_user, connections.First(), null, out allCustomerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for CustomerDetailsGet");
|
||||
Assert.IsTrue(null != allCustomerDetailsDbRecords, "CustomerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(allCustomerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "CustomerDetailsGet should not have retrieved any records");
|
||||
}
|
||||
}
|
||||
}
|
||||
209
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsDAS.cs
Normal file
209
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsDAS.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
using DTS.Common.Classes.Hardware;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
[Test]
|
||||
public void TestDASGetPrototypesShouldFail()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var hr = DbAPI.DbAPI.DAS.DASGet(null, connections.First(), clientDbVersion, null, "Prototype", out var dbDAS);
|
||||
Assert.AreNotEqual(0, hr, "DASGet with no user should not return 0");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length == 0, "No das should be returned when calling DASGet with no user");
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, null, clientDbVersion, null, "Prototype", out dbDAS);
|
||||
Assert.AreNotEqual(0, hr, "DASGet with no connection should not return 0");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length == 0, "No das should be returned when calling DASGet with no connection");
|
||||
}
|
||||
[Test]
|
||||
public void TestDASGetPrototypes()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, null, "Prototype", out var das);
|
||||
Assert.AreEqual(0, hr, "DASGet Executed");
|
||||
Assert.IsNotNull(das, "DAS not null");
|
||||
Assert.IsTrue(das.Length > 0, "DAS prototypes in db");
|
||||
}
|
||||
[Test]
|
||||
public void TestDASInsertAndDeleteShouldFail()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var das = CreateFakeDAS();
|
||||
//test that insert fails properly
|
||||
var hr = DbAPI.DbAPI.DAS.DASInsert(null, connections.First(), das);
|
||||
Assert.AreNotEqual(0, hr, "DASInsert should not return 0 with no user");
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, null, das);
|
||||
Assert.AreNotEqual(0, hr, "DASInsert should not return 0 with no connection");
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), null);
|
||||
Assert.AreNotEqual(0, hr, "DASInsert should not return 0 with no DAS");
|
||||
|
||||
//insert so that we can test that delete fails properly
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), das);
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, das.SerialNumber, null, out var dbRecord);
|
||||
|
||||
//test that delete fails properly
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(null, connections.First(), dbRecord[0].DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreNotEqual(0, hr, "DAS delete without a user should not return 0");
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, null, dbRecord[0].DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreNotEqual(0, hr, "DAS delete without a connection should not return 0");
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), -1, null, false);
|
||||
Assert.AreNotEqual(0, hr, "DAS delete without a DAS should not return 0");
|
||||
|
||||
//now finally cleanup
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), dbRecord[0].DASId, dbRecord[0].SerialNumber, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDASInsertAndDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var das = CreateFakeDAS();
|
||||
var hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), das);
|
||||
Assert.AreEqual(0, hr, "DASInsert Executed");
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, das.SerialNumber, null, out var dbRecord);
|
||||
Assert.AreEqual(0, hr, "DASGet Inserted DAS");
|
||||
Assert.IsNotNull(dbRecord, "Retrieved das not null");
|
||||
Assert.AreEqual(1, dbRecord.Length, "1 das was retrieved");
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), das.DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreEqual(0, hr, "DASDelete executed");
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, dbRecord[0].SerialNumber, null, out var dbDAS);
|
||||
Assert.AreEqual(0, hr, "DASGet executed after delete");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length < 1, "DAS no longer in db afer delete");
|
||||
}
|
||||
[Test]
|
||||
public void TestDASChannelInsertAndDASDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var das = CreateFakeDAS();
|
||||
|
||||
var hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), das);
|
||||
Assert.AreEqual(0, hr, "DASInsert Executed");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, das.SerialNumber, null, out var dbRecord);
|
||||
Assert.AreEqual(0, hr, "DASGet Inserted DAS");
|
||||
Assert.IsNotNull(dbRecord, "Retrieved das not null");
|
||||
Assert.AreEqual(1, dbRecord.Length, "1 das was retrieved");
|
||||
|
||||
var channels = CreateFakeChannels(das);
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
IDASChannelDBRecord iCh = channel;
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsInsert(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", ref iCh);
|
||||
Assert.AreEqual(0, hr, "DASChannelsInsert executed");
|
||||
}
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsGet(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", out var dbChannels);
|
||||
Assert.AreEqual(0, hr, "DASChannelsGet executed");
|
||||
|
||||
Assert.IsNotNull(dbChannels, "Channels retrieved after insertion");
|
||||
Assert.AreEqual(dbChannels.Length, channels.Length, "Same # of channels retrieved as inserted");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), das.DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreEqual(0, hr, "DASDelete executed");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, dbRecord[0].SerialNumber, null, out var dbDAS);
|
||||
Assert.AreEqual(0, hr, "DASGet executed after delete");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length < 1, "DAS no longer in db after delete");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsGet(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", out var dbChannelsAfterDelete);
|
||||
Assert.AreEqual(0, hr, "DASChannelsGet after delete das executes");
|
||||
Assert.IsTrue(null == dbChannelsAfterDelete || 0 == dbChannelsAfterDelete.Length, "No channels remain after das delete");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDASChannelsDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var das = CreateFakeDAS();
|
||||
|
||||
var hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), das);
|
||||
Assert.AreEqual(0, hr, "DASInsert Executed");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, das.SerialNumber, null, out var dbRecord);
|
||||
Assert.AreEqual(0, hr, "DASGet Inserted DAS");
|
||||
Assert.IsNotNull(dbRecord, "Retrieved das not null");
|
||||
Assert.AreEqual(1, dbRecord.Length, "1 das was retrieved");
|
||||
|
||||
var channels = CreateFakeChannels(das);
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
IDASChannelDBRecord iCh = channel;
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsInsert(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", ref iCh);
|
||||
Assert.AreEqual(0, hr, "DASChannelsInsert executed");
|
||||
}
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsGet(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", out var dbChannels);
|
||||
Assert.AreEqual(0, hr, "DASChannelsGet executed");
|
||||
|
||||
Assert.IsNotNull(dbChannels, "Channels retrieved after insertion");
|
||||
Assert.AreEqual(dbChannels.Length, channels.Length, "Same # of channels retrieved as inserted");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsDelete(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}");
|
||||
Assert.AreEqual(0, hr, "DASChannelsDelete executes");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASChannelsGet(_user, connections.First(), $"{das.SerialNumber}_{das.DASType}", out var dbChannelsAfterDelete);
|
||||
Assert.AreEqual(0, hr, "DASChannelsGet after daschannelsdelete executes");
|
||||
Assert.IsTrue(null == dbChannelsAfterDelete || 0 == dbChannelsAfterDelete.Length, "No channels remain after daschannelsdelete");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), das.DASId, dbRecord[0].SerialNumber, false);
|
||||
Assert.AreEqual(0, hr, "DASDelete executed");
|
||||
|
||||
hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), clientDbVersion, dbRecord[0].SerialNumber, null, out var dbDAS);
|
||||
Assert.AreEqual(0, hr, "DASGet executed after delete");
|
||||
Assert.IsTrue(null == dbDAS || dbDAS.Length < 1, "DAS no longer in db after delete");
|
||||
}
|
||||
private DASChannelDBRecord[] CreateFakeChannels(DASDBRecord das)
|
||||
{
|
||||
var list = new List<DASChannelDBRecord>();
|
||||
|
||||
for (var i = 0; i < das.Channels; i++)
|
||||
{
|
||||
var channel = new DASChannelDBRecord();
|
||||
channel.ChannelIdx = i;
|
||||
channel.DaschannelId = i;
|
||||
channel.DASDisplayOrder = i;
|
||||
channel.Dasid = das.DASId;
|
||||
channel.HardwareId = $"{das.SerialNumber}_{das.DASType}";
|
||||
channel.LocalOnly = false;
|
||||
channel.ModuleArrayIndex = 0;
|
||||
channel.ModuleSerialNumber = "FakeMod0";
|
||||
list.Add(channel);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
private DASDBRecord CreateFakeDAS()
|
||||
{
|
||||
var das = new DASDBRecord();
|
||||
das.SerialNumber = Guid.NewGuid().ToString().Substring(0, 10);
|
||||
das.Position = "";
|
||||
das.LastModifiedBy = "";
|
||||
das.LastModified = DateTime.Now;
|
||||
das.LastUsed = DateTime.Now;
|
||||
das.LastUsedBy = "NUNIT";
|
||||
das.DASType = 18;
|
||||
das.ChannelTypes = new[] { 1, 2, 3 };
|
||||
das.Channels = 3;
|
||||
das.Position = "";
|
||||
return das;
|
||||
}
|
||||
}
|
||||
}
|
||||
121
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsGroupHardware.cs
Normal file
121
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsGroupHardware.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using DTS.Common.Classes.Groups;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using DTS.Common.Interface.Groups;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="staticGroupId">Call with null or the id of a corresponding static Group</param>
|
||||
/// <returns></returns>
|
||||
public IGroupDbRecord CreateFakeGroup(string displayName, int? staticGroupId)
|
||||
{
|
||||
var group = new GroupDbRecord();
|
||||
group.SerialNumber = Guid.NewGuid().ToString().Substring(0, 10);
|
||||
group.Picture = "";
|
||||
group.DisplayName = displayName;
|
||||
group.Description = "";
|
||||
group.Embedded = false;
|
||||
group.LastModified = DateTime.Now;
|
||||
group.LastModifiedBy = "";
|
||||
group.StaticGroupId = staticGroupId;
|
||||
return group;
|
||||
}
|
||||
public GroupHardwareDbRecord CreateGroupHardwareDbRecord(int groupId, int dasId)
|
||||
{
|
||||
var groupHardwareDbRecord = new GroupHardwareDbRecord();
|
||||
groupHardwareDbRecord.GroupId = groupId;
|
||||
groupHardwareDbRecord.DASId = dasId;
|
||||
return groupHardwareDbRecord;
|
||||
}
|
||||
[Test]
|
||||
public void TestGroupHardwareInsertGetAndDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//Delete all records from the DAS and Groups tables - either of which should delete all records from the GroupHardware table also.
|
||||
var hr = DbAPI.DbAPI.DAS.DASGet(_user, connections.First(), connections.First().ClientDbVersion, null, null, out IDASDBRecord[] dasRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for DASGet");
|
||||
foreach (var dasRecord in dasRecords)
|
||||
{
|
||||
hr = DbAPI.DbAPI.DAS.DASDelete(_user, connections.First(), dasRecord.DASId, dasRecord.SerialNumber, false);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for DASDelete");
|
||||
}
|
||||
hr = DbAPI.DbAPI.Groups.GroupsGet(_user, connections.First(), null, null, null, null, null, out IGroupDbRecord[] groups);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupsGet");
|
||||
foreach (var group in groups)
|
||||
{
|
||||
hr = DbAPI.DbAPI.Groups.GroupsDelete(_user, connections.First(), group.Id, out string deleteErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupsDelete");
|
||||
}
|
||||
|
||||
//Insert one legit and one bogus DAS
|
||||
var legitDas = CreateFakeDAS();
|
||||
legitDas.SerialNumber = "legit";
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), legitDas);
|
||||
Assert.AreEqual(0, hr, "DASInsert legit executed");
|
||||
|
||||
var bogusDas = CreateFakeDAS();
|
||||
bogusDas.SerialNumber = "bogus";
|
||||
hr = DbAPI.DbAPI.DAS.DASInsert(_user, connections.First(), bogusDas);
|
||||
Assert.AreEqual(0, hr, "DASInsert bogus executed");
|
||||
|
||||
//Insert a legit static Group
|
||||
var legitGroup = CreateFakeGroup("legit", null);
|
||||
hr = DbAPI.DbAPI.Groups.GroupsInsert(_user, connections.First(), ref legitGroup);
|
||||
Assert.AreEqual(0, hr, "Legit GroupInsert executed");
|
||||
|
||||
//Insert a bogus static Group
|
||||
var bogusGroup = CreateFakeGroup("bogus", null);
|
||||
hr = DbAPI.DbAPI.Groups.GroupsInsert(_user, connections.First(), ref bogusGroup);
|
||||
Assert.AreEqual(0, hr, "Bogus GroupInsert executed");
|
||||
|
||||
//**Insert GroupHardware records for the legit static Group with both DAS
|
||||
var groupHardwareDbRecord = CreateGroupHardwareDbRecord(legitGroup.Id, legitDas.DASId);
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareInsert(_user, connections.First(), groupHardwareDbRecord, out int newId, out string errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareInsert");
|
||||
|
||||
groupHardwareDbRecord = CreateGroupHardwareDbRecord(legitGroup.Id, bogusDas.DASId);
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareInsert(_user, connections.First(), groupHardwareDbRecord, out newId, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareInsert");
|
||||
|
||||
//**Insert a GroupHardware record for the bogus static Group with one bogus DAS
|
||||
groupHardwareDbRecord = CreateGroupHardwareDbRecord(bogusGroup.Id, bogusDas.DASId);
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareInsert(_user, connections.First(), groupHardwareDbRecord, out newId, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareInsert");
|
||||
|
||||
//**Get the GroupHardware record for the legit static Group only (1)
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareGet(_user, connections.First(), legitGroup.Id, legitDas.SerialNumber, legitGroup.Embedded, out GroupHardwareDbRecord[] groupHardwareRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareGet");
|
||||
Assert.IsTrue(null != groupHardwareRecords && groupHardwareRecords.Length == 2, "GroupHardwareGet should have retrieved 2 records");
|
||||
|
||||
//**Get all GroupHardware records (3)
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareGet(_user, connections.First(), null, null, null, out groupHardwareRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareGet");
|
||||
Assert.IsTrue(null != groupHardwareRecords && groupHardwareRecords.Length == 3, "GroupHardwareGet should have retrieved 3 records");
|
||||
|
||||
//**Delete the GroupHardware records for the bogus static Group
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareDelete(_user, connections.First(), bogusGroup.Id, bogusDas.DASId, out string errorString);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareDelete");
|
||||
|
||||
//**Get the deleted GroupHardware record (fail) (0)
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareGet(_user, connections.First(), bogusGroup.Id, bogusDas.SerialNumber, false, out groupHardwareRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareGet of deleted record");
|
||||
Assert.IsTrue(null != groupHardwareRecords && groupHardwareRecords.Length == 0, "GroupHardwareGet should have retrieved 0 records");
|
||||
|
||||
//**Get all GroupHardware records (2)
|
||||
hr = DbAPI.DbAPI.GroupHardware.GroupHardwareGet(_user, connections.First(), legitGroup.Id, bogusDas.SerialNumber, false, out groupHardwareRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for GroupHardwareGet");
|
||||
Assert.IsTrue(null != groupHardwareRecords && groupHardwareRecords.Length == 2, "GroupHardwareGet should have retrieved 2 records");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using DTS.Common.Interface.TestMetaData;
|
||||
using DTS.Common.Classes.LabratoryDetails;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public LabratoryDetailsDbRecord CreateFakeLabratoryDetails(string name)
|
||||
{
|
||||
var record = new LabratoryDetailsDbRecord();
|
||||
record.LabratoryId = -1;
|
||||
record.Name = name;
|
||||
record.LabratoryName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryContactName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryContactPhone = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryContactFax = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryContactEmail = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryTestRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabratoryProjectRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.LocalOnly = true;
|
||||
record.Version = 1;
|
||||
return record;
|
||||
}
|
||||
[Test]
|
||||
public void LaboratoryDetails()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//Delete all to start with a blank table
|
||||
var hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsDelete(_user, connections.First(), null, out string errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsDelete");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), null, out ILabratoryDetailsDbRecord[] allLabratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != allLabratoryDetailsDbRecords && allLabratoryDetailsDbRecords.Length == 0, "LabratoryDetailsGet should have retrieved 0 records");
|
||||
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var legitRecord = CreateFakeLabratoryDetails("legit");
|
||||
var decoyRecord = CreateFakeLabratoryDetails("decoy");
|
||||
|
||||
//Insert
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsInsert(_user, connections.First(), legitRecord, out int newLegitId, out string legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate LabratoryDetails record");
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsInsert(_user, connections.First(), decoyRecord, out int newFakeId, out string fakeErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy LabratoryDetails record");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), legitRecord.Name, out ILabratoryDetailsDbRecord[] labratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != labratoryDetailsDbRecords && labratoryDetailsDbRecords.Length == 1, "LabratoryDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(labratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should have retrieved only one record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), null, out allLabratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != allLabratoryDetailsDbRecords && allLabratoryDetailsDbRecords.Length == 2, "LabratoryDetailsGet should have retrieved 2 records");
|
||||
Assert.IsTrue(allLabratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should have retrieved our record");
|
||||
Assert.IsTrue(allLabratoryDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "LabratoryDetailsGet should have retrieved our record");
|
||||
|
||||
//Update
|
||||
var newLabratoryTestRefNumber = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
legitRecord.LabratoryTestRefNumber = newLabratoryTestRefNumber;
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsUpdate(_user, connections.First(), legitRecord, out legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate LabratoryDetails record");
|
||||
Assert.IsTrue(legitErrorString == string.Empty, $"Error when inserting a legitimate LabratoryDetails record: {legitErrorString}");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), legitRecord.Name, out labratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != labratoryDetailsDbRecords && labratoryDetailsDbRecords.Length == 1, "LabratoryDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(labratoryDetailsDbRecords.Any(r => r.LabratoryTestRefNumber == newLabratoryTestRefNumber), "LabratoryDetailsGet should have retrieved the updated record");
|
||||
|
||||
//Delete by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsDelete(_user, connections.First(), legitRecord.Name, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), legitRecord.Name, out labratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != labratoryDetailsDbRecords, "LabratoryDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(labratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should not have retrieved this record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), null, out allLabratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != allLabratoryDetailsDbRecords && allLabratoryDetailsDbRecords.Length == 1, "LabratoryDetailsGet should have retrieved only the decoy record");
|
||||
Assert.IsFalse(allLabratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet not should have retrieved this record");
|
||||
Assert.IsTrue(allLabratoryDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "LabratoryDetailsGet should have retrieved this record");
|
||||
|
||||
//Delete all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsDelete(_user, connections.First(), null, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), legitRecord.Name, out labratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != labratoryDetailsDbRecords, "LabratoryDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(labratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should not have retrieved any records");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.LabratoryDetails.LabratoryDetailsGet(_user, connections.First(), null, out allLabratoryDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for LabratoryDetailsGet");
|
||||
Assert.IsTrue(null != allLabratoryDetailsDbRecords, "LabratoryDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(allLabratoryDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "LabratoryDetailsGet should not have retrieved any records");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using DTS.Common.Classes.Channels;
|
||||
using DTS.Common.Classes.TestSetups;
|
||||
using DTS.Common.Interface.Channels;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using DTS.Common.Storage;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
/// <summary>
|
||||
/// Testing of version created for the replacement of the string RegionsOfInterest field in the
|
||||
/// TestSetups table with the TestSetupROIs and ROIPeriodChannels tables.
|
||||
/// This should only work with a Version 92 or later database, but should handle Version 91 databases gracefully.
|
||||
/// Tests included:
|
||||
/// sp_TestSetupsUpdateInsert_92 (and sp_TestSetupsInsert_92)
|
||||
/// sp_TestSetupROIsInsert
|
||||
/// sp_ROIPeriodChannelsInsert
|
||||
/// sp_TestSetupROIsGet
|
||||
/// sp_ROIPeriodChannelsGet
|
||||
/// sp_TestSetupROIsDelete
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void RegionsOfInterest()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//***Testing*** sp_TestSetupsUpdateInsert_92
|
||||
var testSetupRecordToInsert = CreateFakeTestSetupWithROIs(2);
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections.First(), 92, ref testSetupRecordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
|
||||
DbAPI.DbAPI.GetDatabaseVersion(connections.First(), out int serverDbVersion);
|
||||
if (serverDbVersion <= 91)
|
||||
{
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest.First();
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestInsert(_user, connections.First(), 91, testSetupRecordToInsert.Id, regionOfInterest);
|
||||
Assert.IsTrue(0 != hr, "RegionsOfInterestInsert should not work if database Version is 91 or less");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
//***Testing*** sp_TestSetupROIsInsert and sp_ROIPeriodChannelsInsert
|
||||
//valid Insert Regions of Interest
|
||||
foreach (var regionOfInterest in testSetupRecordToInsert.RegionsOfInterest)
|
||||
{
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestInsert(_user, connections.First(), 97, testSetupRecordToInsert.Id, regionOfInterest);
|
||||
}
|
||||
|
||||
//***Testing*** sp_TestSetupROIsGet and sp_ROIPeriodChannelsGet
|
||||
//valid get the RegionsOfInterest for this Test Setup
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestGet(_user, connections.First(), DbOperations.CURRENT_DB_VERSION, testSetupRecordToInsert.Id, out var roiRecords);
|
||||
Assert.IsTrue(0 == hr && null != roiRecords && roiRecords.Length == 2 && roiRecords.Any(r => r.Suffix == testSetupRecordToInsert.RegionsOfInterest.First().Suffix),
|
||||
"First suffix test failed");
|
||||
Assert.IsTrue(0 == hr && null != roiRecords && roiRecords.Length == 2 && roiRecords.Any(r => r.Suffix == testSetupRecordToInsert.RegionsOfInterest.Last().Suffix),
|
||||
"Last suffix test failed");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsDelete
|
||||
//Delete all of the RegionsOfInterest for this Test Setup
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestDelete(_user, connections.First(), testSetupRecordToInsert.Id);
|
||||
Assert.IsTrue(0 == hr, "Should be able to delete all ROIs in a Test Setup");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsGet and sp_ROIPeriodChannelsGet
|
||||
//Make sure they were deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.RegionsOfInterestGet(_user, connections.First(), DbOperations.CURRENT_DB_VERSION, testSetupRecordToInsert.Id, out roiRecords);
|
||||
Assert.IsTrue(0 == hr && (null == roiRecords || roiRecords.Length == 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
111
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsSensorsAnalog.cs
Normal file
111
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsSensorsAnalog.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using DTS.Common.Classes.Hardware;
|
||||
using DTS.Common.Classes.Sensors;
|
||||
using DTS.Common.Enums.Sensors;
|
||||
using DTS.Common.Interface.Sensors;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
[Test]
|
||||
public void TestSensorsDeleteAll()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var sensor = CreateFakeSensor();
|
||||
var hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogUpdateInsert should return 0");
|
||||
Assert.IsTrue(sensor.Id > 0, "Inserted sensor Id should be > 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out var records);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogGet should return 0 for inserted sensor");
|
||||
Assert.IsTrue(null != records && 1 == records.Length, "SensorsAnalogGet should return 1 sensor");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDeleteAll(_user, connections.First());
|
||||
Assert.AreEqual(0, hr, "SensorsDeleteAll should return 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, null, null, out records);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogGet should return 0");
|
||||
Assert.IsTrue(null != records && records.Any(), "After SensorsAnalogDelete test specific A and C should exist");
|
||||
Assert.IsTrue(records.Any(record => record.SerialNumber == SensorConstants.TEST_SPECIFIC_ANALOG_SERIAL)
|
||||
&& records.Any(record => record.SerialNumber == SensorConstants.TEST_SPECIFIC_CLOCK_SERIAL),
|
||||
"TSA and TSC should still exist after delete");
|
||||
}
|
||||
[Test]
|
||||
public void TestSensorsAnalogInsertAndDelete()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var sensor = CreateFakeSensor();
|
||||
var hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogUpdateInsert should return 0");
|
||||
Assert.IsTrue(sensor.Id > 0, "Inserted sensor Id should be > 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out var records);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogGet should return 0 for inserted sensor");
|
||||
Assert.IsTrue(null != records && 1 == records.Length, "SensorsAnalogGet should return 1 sensor");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, connections.First(), sensor.Id, 0);
|
||||
Assert.AreEqual(0, hr, "SensorsDelete should return 0 for inserted sensor");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out records);
|
||||
Assert.IsTrue(0 == hr && (null == records || 0 == records.Length), "Sensor should no longer return from SensorsAnalogGet");
|
||||
}
|
||||
[Test]
|
||||
public void TestSensorAnalogInsertAndDeleteShouldFail()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var sensor = CreateFakeSensor();
|
||||
var hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(null, connections.First(), sensor);
|
||||
Assert.AreNotEqual(0, hr, "SensorsAnalogUpdateInsert should fail without user");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, null, sensor);
|
||||
Assert.AreNotEqual(0, hr, "SensorsAnalogUpdateInsert should fail without connect");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogUpdateInsert should return 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(null, connections.First(), sensor.Id, 0);
|
||||
Assert.AreNotEqual(0, hr, "SensorsDelete should fail without user");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, null, sensor.Id, 0);
|
||||
Assert.AreNotEqual(0, hr, "SensorsDelete should fail without connection");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, connections.First(), sensor.Id, 0);
|
||||
}
|
||||
[Test]
|
||||
public void TestSensorsAnalogBridgeResistanceGet()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var sensor = CreateFakeSensor();
|
||||
var hr = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogUpdateInsert should return 0");
|
||||
Assert.IsTrue(sensor.Id > 0, "Inserted sensor Id should be > 0");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out var records);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogGet should return 0 for inserted sensor");
|
||||
Assert.IsTrue(null != records && 1 == records.Length, "SensorsAnalogGet should return 1 sensor");
|
||||
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogBridgeResistanceGet(_user, connections.First(), sensor.SerialNumber, out var resistance);
|
||||
Assert.AreEqual(0, hr, "SensorsAnalogBridgeResistanceGet returns 0");
|
||||
Assert.AreEqual(resistance, FAKE_BRIDGE_RESISTANCE_OMS, "BridgeResistance returns the same as was set");
|
||||
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, connections.First(), sensor.Id, 0);
|
||||
Assert.AreEqual(0, hr, "SensorsDelete should return 0 for inserted sensor");
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsAnalogGet(_user, connections.First(), null, sensor.SerialNumber, null, out records);
|
||||
Assert.IsTrue(0 == hr && (null == records || 0 == records.Length), "Sensor should no longer return from SensorsAnalogGet");
|
||||
}
|
||||
|
||||
|
||||
private const double FAKE_BRIDGE_RESISTANCE_OMS = 350;
|
||||
private IAnalogDbRecord CreateFakeSensor()
|
||||
{
|
||||
var sensor = new AnalogDbRecord();
|
||||
sensor.Created = DateTime.Now;
|
||||
sensor.LastModified = DateTime.Now;
|
||||
sensor.EId = "";
|
||||
sensor.SerialNumber = new Guid().ToString();
|
||||
sensor.BridgeResistance = FAKE_BRIDGE_RESISTANCE_OMS;
|
||||
return sensor;
|
||||
}
|
||||
}
|
||||
}
|
||||
204
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsTags.cs
Normal file
204
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsTags.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using DTS.Common.Classes.Tags;
|
||||
using DTS.Common.Interface.Sensors;
|
||||
using DTS.Common.Interface.Tags;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
[Test]
|
||||
public void TagsTestGetNegatives()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var tag = CreateFakeTag();
|
||||
|
||||
//insert a tag just so that we have something that _might_ be returned
|
||||
var hr = DbAPI.DbAPI.Tags.TagsInsert(_user, connections.First(), ref tag);
|
||||
Assert.IsTrue(0 == hr, "TagsInsert returned 0");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(null, connections.First(), null, out var records);
|
||||
Assert.IsTrue(0 != hr && (null == records || 0 == records.Length), "TagsGet should not allow null user");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(_user, null, null, out records);
|
||||
Assert.IsTrue(0 != hr && (null == records || 0 == records.Length), "TagsGet should not allow null connection");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGetId(null, connections.First(), tag.Text, out var id);
|
||||
Assert.IsTrue(0 != hr && null == id, "TagsGetId should not allow null user");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGetId(_user, null, tag.Text, out id);
|
||||
Assert.IsTrue(0 != hr && null == id, "TagsGetId should not allow null connection");
|
||||
|
||||
ITag tag2 = null;
|
||||
hr = DbAPI.DbAPI.Tags.TagsInsert(_user, connections.First(), ref tag2);
|
||||
Assert.IsTrue(DbAPI.Errors.ErrorCodes.ERROR_MISSING_PARAMETER == hr, "TagsInsert with null does return missing parameter");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(null, connections.First(), tag.ID);
|
||||
Assert.IsTrue(0 != hr, "TagsDelete should not allow null user");
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(_user, null, tag.ID);
|
||||
Assert.IsTrue(0 != hr, "TagsDelete should not allow null connection");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(_user, connections.First(), tag.ID);
|
||||
Assert.IsTrue(0 == hr, "TagsDelete returns 0");
|
||||
}
|
||||
[Test]
|
||||
public void TagsTestGetPositives()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var tag = CreateFakeTag();
|
||||
var hr = DbAPI.DbAPI.Tags.TagsGet(_user, connections.First(), null, out var records);
|
||||
Assert.IsTrue(0 == hr && (null == records || !records.Any(r => r.Text == tag.Text)),
|
||||
"TagsGet returns 0 and GUID text not already found");
|
||||
hr = DbAPI.DbAPI.Tags.TagsInsert(_user, connections.First(), ref tag);
|
||||
Assert.IsTrue(0 == hr && -1 != tag.ID, "TagsInsert returns 0 and modifies id");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(_user, connections.First(), null, out records);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Any(r => r.Text == tag.Text && r.ID == tag.ID),
|
||||
"TagsGet returns 0 and finds the tag");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(_user, connections.First(), tag.ID, out records);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length == 1 && TagIsEqual(records[0], tag)
|
||||
, "TagsGet returns 0, and returns the tag [when passing in id]");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGetId(_user, connections.First(), tag.Text, out var id);
|
||||
Assert.IsTrue(0 == hr && null != id && (int)id == tag.ID, "TagsGetId returns 0 and retrieves right id");
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(_user, connections.First(), tag.ID);
|
||||
Assert.IsTrue(0 == hr, "TagsDelete returns 0");
|
||||
hr = DbAPI.DbAPI.Tags.TagsGet(_user, connections.First(), null, out records);
|
||||
Assert.IsTrue(0 == hr && null == records || !records.Any(r => r.Text == tag.Text), "TagsDelete returns 0");
|
||||
}
|
||||
private bool TagIsEqual(ITag left, ITag right)
|
||||
{
|
||||
return left.ID == right.ID &&
|
||||
left.IsObsolete == right.IsObsolete &&
|
||||
left.Text.Equals(right.Text);
|
||||
}
|
||||
public static ITag CreateFakeTag()
|
||||
{
|
||||
var tag = new Tag();
|
||||
tag.ID = -1;
|
||||
tag.Text = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
return tag;
|
||||
}
|
||||
[Test]
|
||||
public void TagAssignmentsPositives()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
var tag = CreateFakeTag();
|
||||
|
||||
_ = DbAPI.DbAPI.Tags.TagsInsert(_user, connections.First(), ref tag);
|
||||
|
||||
var testSetup = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections.First(), 0, ref testSetup);
|
||||
var sensor = CreateFakeSensor();
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, connections.First(), sensor);
|
||||
|
||||
var hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), null, out var tagAssignments);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsGet returns 0");
|
||||
|
||||
var taTestSetup = CreateTagAssignment(tag, testSetup);
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, connections.First(), taTestSetup);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsInsert returns 0");
|
||||
|
||||
var taSensor = CreateTagAssignment(tag, sensor);
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, connections.First(), taSensor);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsInsert returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), null, out tagAssignments);
|
||||
Assert.IsTrue(0 == hr && null != tagAssignments &&
|
||||
tagAssignments.Any(t => IsTagAssignmentEqual(t, taTestSetup)) &&
|
||||
tagAssignments.Any(t => IsTagAssignmentEqual(t, taSensor)),
|
||||
"TagAssignmentsGet returns tag assignments");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), TagTypes.TestSetup, out tagAssignments);
|
||||
Assert.IsTrue(0 == hr && null != tagAssignments && tagAssignments.Any(t => IsTagAssignmentEqual(t, taTestSetup)),
|
||||
"TagAssignmentsGet returns taTestSetup");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), TagTypes.Sensors, out tagAssignments);
|
||||
Assert.IsTrue(0 == hr && null != tagAssignments && tagAssignments.Any(t => IsTagAssignmentEqual(t, taSensor)),
|
||||
"TagAssignmentsGet returns taSensor");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsDelete(_user, connections.First(), taSensor.ObjectID, TagTypes.Sensors);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsDelete returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsDelete(_user, connections.First(), taTestSetup.ObjectID, TagTypes.TestSetup);
|
||||
Assert.IsTrue(0 == hr, "TagAssignmentsDelete returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, connections.First(), null, out tagAssignments);
|
||||
Assert.IsTrue(0 == hr && !tagAssignments.Any(t => IsTagAssignmentEqual(t, taSensor))
|
||||
&& !tagAssignments.Any(t => IsTagAssignmentEqual(t, taTestSetup)), "TagAssignments deleted");
|
||||
_ = DbAPI.DbAPI.Tags.TagsDelete(_user, connections.First(), tag.ID);
|
||||
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsDelete(_user, connections.First(), sensor.Id, 0);
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections.First(), new[] { testSetup.Id });
|
||||
}
|
||||
|
||||
private bool IsTagAssignmentEqual(ITagAssignment left, ITagAssignment right)
|
||||
{
|
||||
return left.ObjectID == right.ObjectID
|
||||
&& left.ObjectType == right.ObjectType
|
||||
&& left.TagID == right.TagID;
|
||||
}
|
||||
private ITagAssignment CreateTagAssignment(ITag tag, IAnalogDbRecord sensor)
|
||||
{
|
||||
var ta = new TagAssignment() { ObjectType = TagTypes.Sensors, TagID = tag.ID, ObjectID = sensor.Id };
|
||||
return ta;
|
||||
}
|
||||
private ITagAssignment CreateTagAssignment(ITag tag, ITestSetupRecord test)
|
||||
{
|
||||
var ta = new TagAssignment() { ObjectID = test.Id, ObjectType = TagTypes.TestSetup, TagID = tag.ID };
|
||||
return ta;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TagAssignmentsNegatives()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections().First();
|
||||
var tag = CreateFakeTag();
|
||||
|
||||
_ = DbAPI.DbAPI.Tags.TagsInsert(_user, con, ref tag);
|
||||
|
||||
var hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(null, con, null, out var tagAssignments);
|
||||
Assert.IsTrue(0 != hr, "TagAssignmentsGet should not work with null user");
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsGet(_user, null, null, out tagAssignments);
|
||||
Assert.IsTrue(0 != hr, "TagAssignmentsGet should not work with null connection");
|
||||
var sensor = CreateFakeSensor();
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, con, sensor);
|
||||
var testSetup = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref testSetup);
|
||||
|
||||
var taSetup = CreateTagAssignment(tag, testSetup);
|
||||
var taSensor = CreateTagAssignment(tag, sensor);
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(null, con, taSetup);
|
||||
Assert.IsTrue(0 != hr, "TagAssignmentsInsert should not work with null user");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, null, taSetup);
|
||||
Assert.IsTrue(0 != hr, "TagAssignmentsInsert should not work with null connection");
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, con, null);
|
||||
Assert.IsTrue(DbAPI.Errors.ErrorCodes.ERROR_MISSING_PARAMETER == hr, "TagAssignmentsInsert should not work with null tagassignment");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, con, new[] { testSetup.Id });
|
||||
Assert.IsTrue(0 == hr, "TestSetupsDelete should work when tag assignments exist");
|
||||
|
||||
hr = DbAPI.DbAPI.Sensors.SensorsDelete(_user, con, sensor.Id, 0);
|
||||
Assert.IsTrue(0 == hr, "SensorsDelete should work when tag assignments exist");
|
||||
|
||||
var sensor2 = CreateFakeSensor();
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsAnalogUpdateInsert(_user, con, sensor);
|
||||
var taSensor2 = CreateTagAssignment(tag, sensor2);
|
||||
_ = DbAPI.DbAPI.Tags.TagAssignmentsInsert(_user, con, taSensor2);
|
||||
|
||||
hr = DbAPI.DbAPI.Tags.TagsDelete(_user, con, tag.ID);
|
||||
Assert.IsTrue(0 == hr, "TagsDelete should work when tag assignments exist");
|
||||
_ = DbAPI.DbAPI.Sensors.SensorsDelete(_user, con, sensor2.Id, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using DTS.Common.Interface.TestMetaData;
|
||||
using DTS.Common.Classes.TestEngineerDetails;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public TestEngineerDetailsDbRecord CreateFakeTestEngineerDetails(string name)
|
||||
{
|
||||
var record = new TestEngineerDetailsDbRecord();
|
||||
record.TestEngineerId = -1;
|
||||
record.Name = name;
|
||||
record.TestEngineerName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.TestEngineerName = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.TestEngineerPhone = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.TestEngineerFax = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.TestEngineerEmail = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LocalOnly = true;
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.Version = 1;
|
||||
return record;
|
||||
}
|
||||
[Test]
|
||||
public void TestEngineerDetails()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//Delete all to start with a blank table
|
||||
var hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsDelete(_user, connections.First(), null, out string errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsDelete");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), null, out ITestEngineerDetailsDbRecord[] allTestEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != allTestEngineerDetailsDbRecords && allTestEngineerDetailsDbRecords.Length == 0, "TestEngineerDetailsGet should have retrieved 0 records");
|
||||
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var legitRecord = CreateFakeTestEngineerDetails("legit");
|
||||
var decoyRecord = CreateFakeTestEngineerDetails("decoy");
|
||||
|
||||
//Insert
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsInsert(_user, connections.First(), legitRecord, out int newLegitId, out string legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate TestEngineerDetails record");
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsInsert(_user, connections.First(), decoyRecord, out int newFakeId, out string fakeErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy TestEngineerDetails record");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), legitRecord.Name, out ITestEngineerDetailsDbRecord[] testEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != testEngineerDetailsDbRecords && testEngineerDetailsDbRecords.Length == 1, "TestEngineerDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(testEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should have retrieved only one record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), null, out allTestEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != allTestEngineerDetailsDbRecords && allTestEngineerDetailsDbRecords.Length == 2, "TestEngineerDetailsGet should have retrieved 2 records");
|
||||
Assert.IsTrue(allTestEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should have retrieved our record");
|
||||
Assert.IsTrue(allTestEngineerDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "TestEngineerDetailsGet should have retrieved our record");
|
||||
|
||||
//Update
|
||||
var newTestEngineerPhone = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
legitRecord.TestEngineerPhone = newTestEngineerPhone;
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsUpdate(_user, connections.First(), legitRecord, out legitErrorString);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a legitimate TestEngineerDetails record");
|
||||
Assert.IsTrue(legitErrorString == string.Empty, $"Error when inserting a legitimate TestEngineerDetails record: {legitErrorString}");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), legitRecord.Name, out testEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != testEngineerDetailsDbRecords && testEngineerDetailsDbRecords.Length == 1, "TestEngineerDetailsGet should have retrieved 1 record");
|
||||
Assert.IsTrue(testEngineerDetailsDbRecords.Any(r => r.TestEngineerPhone == newTestEngineerPhone), "TestEngineerDetailsGet should have retrieved the updated record");
|
||||
|
||||
//Delete by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsDelete(_user, connections.First(), legitRecord.Name, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), legitRecord.Name, out testEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != testEngineerDetailsDbRecords, "TestEngineerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(testEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should not have retrieved this record");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), null, out allTestEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != allTestEngineerDetailsDbRecords && allTestEngineerDetailsDbRecords.Length == 1, "TestEngineerDetailsGet should have retrieved only the decoy record");
|
||||
Assert.IsFalse(allTestEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet not should have retrieved this record");
|
||||
Assert.IsTrue(allTestEngineerDetailsDbRecords.Any(r => r.Name == decoyRecord.Name), "TestEngineerDetailsGet should have retrieved this record");
|
||||
|
||||
//Delete all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsDelete(_user, connections.First(), null, out errorMessage);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsDelete");
|
||||
//Get by Name
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), legitRecord.Name, out testEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != testEngineerDetailsDbRecords, "TestEngineerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(testEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should not have retrieved any records");
|
||||
//Get all
|
||||
hr = DbAPI.DbAPI.TestEngineerDetails.TestEngineerDetailsGet(_user, connections.First(), null, out allTestEngineerDetailsDbRecords);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestEngineerDetailsGet");
|
||||
Assert.IsTrue(null != allTestEngineerDetailsDbRecords, "TestEngineerDetailsGet should not have retrieved this record");
|
||||
Assert.IsFalse(allTestEngineerDetailsDbRecords.Any(r => r.Name == legitRecord.Name), "TestEngineerDetailsGet should not have retrieved any records");
|
||||
}
|
||||
}
|
||||
}
|
||||
133
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsTestSetupGroup.cs
Normal file
133
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsTestSetupGroup.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using DTS.Common.Classes.Groups;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using DTS.Common.Interface.Groups;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void TestTestSetupGroupPositive()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections()[0];
|
||||
|
||||
var test = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref test);
|
||||
var group = CreateFakeGroup("TestGroup", null);
|
||||
_ = DbAPI.DbAPI.Groups.GroupsInsert(_user, con, ref group);
|
||||
|
||||
var insertGroupRecord = new TestSetupGroupRecord()
|
||||
{
|
||||
DisplayOrder = 0,
|
||||
GroupId = group.Id,
|
||||
Position = "?",
|
||||
TestObjectType = "X",
|
||||
TestSetupId = test.Id
|
||||
};
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, con, insertGroupRecord);
|
||||
Assert.IsTrue(0 == hr, "TestSetupGroupsInsert returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, null, null, out var groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(g, insertGroupRecord)),
|
||||
"TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, group.Id, null, null, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, test.Id, null, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, null, test.Name, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, group.Id, test.Id, null, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, group.Id, null, test.Name, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, test.Id, test.Name, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, group.Id, test.Id, test.Name, out groups);
|
||||
Assert.IsTrue(0 == hr && null != groups && groups.Any(g => TestSetupGroupRecordEqual(insertGroupRecord, g))
|
||||
&& 1 == groups.Length, "TestSetupGroupsGet returns inserted group");
|
||||
|
||||
var updateGroupRecord = new TestSetupGroupRecord(insertGroupRecord);
|
||||
updateGroupRecord.Position = "Y";
|
||||
updateGroupRecord.TestObjectType = "Z";
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsUpdate(_user, con, updateGroupRecord);
|
||||
Assert.IsTrue(0 == hr, "TestSetupGroupsUpdate returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, test.Id, null, out groups);
|
||||
Assert.IsTrue(0 == hr && 1 == groups.Length && TestSetupGroupRecordEqual(groups[0], updateGroupRecord),
|
||||
"TestSetupGroupsGet returns updated group");
|
||||
|
||||
hr = DbAPI.DbAPI.Groups.GroupsDelete(_user, con, group.Id, out var error);
|
||||
Assert.IsTrue(0 == hr, "Groups can delete a group");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, con, new[] { test.Id });
|
||||
Assert.IsTrue(0 == hr, "Test setup can be deleted");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, con, null, null, null, out groups);
|
||||
Assert.IsTrue(0 == hr && null == groups || 0 == groups.Length || !groups.Any(g => TestSetupGroupRecordEqual(g, updateGroupRecord)),
|
||||
"TestSetupsDelete removed any group record");
|
||||
}
|
||||
|
||||
private bool TestSetupGroupRecordEqual(ITestSetupGroupRecord left, ITestSetupGroupRecord right)
|
||||
{
|
||||
return left.DisplayOrder == right.DisplayOrder
|
||||
&& left.GroupId == right.GroupId
|
||||
&& left.Position == right.Position
|
||||
&& left.TestObjectType == right.TestObjectType
|
||||
&& left.TestSetupId == right.TestSetupId;
|
||||
}
|
||||
[Test]
|
||||
public void TestTestSetupGroupNegative()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections()[0];
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(_user, null, null, null, null, out var groups);
|
||||
Assert.IsTrue(0 != hr && (null == groups || 0 == groups.Length), "TestSetups should not work without a connection");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsGet(null, con, null, null, null, out groups);
|
||||
Assert.IsTrue(0 != hr && (null == groups || 0 == groups.Length), "TestSetups should not work without a user");
|
||||
|
||||
var test = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref test);
|
||||
var group = CreateFakeGroup("FakeGroup", null);
|
||||
_ = DbAPI.DbAPI.Groups.GroupsInsert(_user, con, ref group);
|
||||
|
||||
var groupToInsert = new TestSetupGroupRecord() { DisplayOrder = 0, GroupId = group.Id, Position = "?", TestObjectType = "?", TestSetupId = test.Id };
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(null, con, groupToInsert);
|
||||
Assert.IsTrue(0 != hr, "TestSetupsGroupsInsert should not work without user");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, null, groupToInsert);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsInsert should not work without connection");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, con, null);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsInsert should not work without record to insert");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsUpdate(null, con, groupToInsert);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsUpdate should not work without user");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, null, groupToInsert);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsUpdate should not work without connection");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupGroupsInsert(_user, con, null);
|
||||
Assert.IsTrue(0 != hr, "TestSetupGroupsUpdate should not work without record to insert");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
using DbAPI.Errors;
|
||||
using DTS.Common.Classes.Groups;
|
||||
using DTS.Common.Classes.TestSetups;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using DTS.Common.Interface.Groups;
|
||||
using DTS.Common.Interface.TestSetups;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void TestTestSetupHardwarePositive()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections()[0];
|
||||
|
||||
var test = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref test);
|
||||
|
||||
var group = CreateFakeGroup("Fake Test Group", null);
|
||||
var channel = CreateFakeChannel();
|
||||
var hardware = CreateFakeDAS();
|
||||
var hwChannels = CreateFakeChannels(hardware);
|
||||
|
||||
_ = DbAPI.DbAPI.DAS.DASInsert(_user, con, hardware);
|
||||
var chIdx = 0;
|
||||
foreach (var hwCh in hwChannels)
|
||||
{
|
||||
IDASChannelDBRecord iCh = hwCh;
|
||||
_ = DbAPI.DbAPI.DAS.DASChannelsInsert(_user, con, $"{hardware.SerialNumber}_{hardware.DASType}", ref iCh);
|
||||
chIdx++;
|
||||
}
|
||||
|
||||
var hwRecord = new TestSetupHardwareRecord()
|
||||
{
|
||||
AddDAS = true,
|
||||
DASId = hardware.DASId,
|
||||
AntiAliasFilterRate = 2000,
|
||||
IsClockMaster = false,
|
||||
SamplesPerSecond = 20000,
|
||||
TestSetupId = test.Id,
|
||||
PTPDomainId = 0
|
||||
};
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(_user, con, hwRecord);
|
||||
Assert.IsTrue(0 == hr, "TestSetupHardwareInsert returns 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, con, con.ClientDbVersion, null, out var hwRecords);
|
||||
Assert.IsTrue(0 == hr && null != hwRecords && 0 != hwRecords.Length &&
|
||||
hwRecords.Any(h => IsTestSetupHardwareRecordsEqual(h, hwRecord)),
|
||||
"TestSetupHardwareGet returns 0 and has record inserted");
|
||||
|
||||
var hwRecordToUpdate = new TestSetupHardwareRecord(hwRecord);
|
||||
hwRecordToUpdate.SamplesPerSecond = 10000;
|
||||
hwRecordToUpdate.AddDAS = false;
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareUpdate(_user, con, hwRecordToUpdate);
|
||||
Assert.IsTrue(0 == hr, "TestSetupHardwareUpdate returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, con, con.ClientDbVersion, null, out hwRecords);
|
||||
Assert.IsTrue(0 == hr && null != hwRecords && 0 != hwRecords.Length &&
|
||||
hwRecords.Any(h => IsTestSetupHardwareRecordsEqual(h, hwRecordToUpdate))
|
||||
&& !hwRecords.Any(h => IsTestSetupHardwareRecordsEqual(h, hwRecord)),
|
||||
$"TestSetupHardwareGet returned updated record and not previous inserted record");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(_user, con, null, hwRecord.DASId, null);
|
||||
Assert.IsTrue(0 == hr, "TestSetupHardwareDelete returns 0");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, con, con.ClientDbVersion, null, out hwRecords);
|
||||
Assert.IsTrue(0 == hr && (null == hwRecords || 0 == hwRecords.Length || !hwRecords.Any(h => h.DASId == hwRecord.DASId)),
|
||||
"TestSetupHardwareDelete deletes records");
|
||||
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, con, new[] { test.Id });
|
||||
_ = DbAPI.DbAPI.DAS.DASDelete(_user, con, hardware.DASId, hardware.SerialNumber, false);
|
||||
}
|
||||
private bool IsTestSetupHardwareRecordsEqual(ITestSetupHardwareRecord left, ITestSetupHardwareRecord right)
|
||||
{
|
||||
return left.AddDAS == right.AddDAS &&
|
||||
left.AntiAliasFilterRate == right.AntiAliasFilterRate &&
|
||||
left.DASId == right.DASId &&
|
||||
left.IsClockMaster == right.IsClockMaster &&
|
||||
left.SamplesPerSecond == right.SamplesPerSecond &&
|
||||
left.TestSetupId == right.TestSetupId &&
|
||||
left.PTPDomainId == right.PTPDomainId;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTestSetupHardwareNegative()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var con = DbAPI.DbAPI.Connections.GetActiveConnections()[0];
|
||||
|
||||
var test = CreateFakeTestSetup();
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, con, 0, ref test);
|
||||
|
||||
var group = CreateFakeGroup("Fake Test Group", null);
|
||||
var channel = CreateFakeChannel();
|
||||
var hardware = CreateFakeDAS();
|
||||
var hwChannels = CreateFakeChannels(hardware);
|
||||
|
||||
_ = DbAPI.DbAPI.DAS.DASInsert(_user, con, hardware);
|
||||
var chIdx = 0;
|
||||
foreach (var hwCh in hwChannels)
|
||||
{
|
||||
IDASChannelDBRecord iCh = hwCh;
|
||||
_ = DbAPI.DbAPI.DAS.DASChannelsInsert(_user, con, $"{hardware.SerialNumber}_{hardware.DASType}", ref iCh);
|
||||
chIdx++;
|
||||
}
|
||||
|
||||
var hwRecord = new TestSetupHardwareRecord()
|
||||
{
|
||||
AddDAS = true,
|
||||
DASId = hardware.DASId,
|
||||
AntiAliasFilterRate = 2000,
|
||||
IsClockMaster = false,
|
||||
SamplesPerSecond = 20000,
|
||||
TestSetupId = test.Id,
|
||||
PTPDomainId = 0
|
||||
};
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(_user, null, hwRecord);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareInsert should not return 0 without a user");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(null, con, hwRecord);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareInsert should not return 0 without a connection");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(_user, con, null);
|
||||
Assert.IsTrue(ErrorCodes.ERROR_MISSING_PARAMETER == hr,
|
||||
"TestSetupHardwareInsert should return missing parameter with empty hardware");
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupHardwareInsert(_user, con, hwRecord);
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(null, con, con.ClientDbVersion, null, out var hardwareRecords);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareGet with null user should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, null, clientDbVersion, null, out hardwareRecords);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareGet with null connection should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareGet(_user, con, con.ClientDbVersion, test.Id + 1, out hardwareRecords);
|
||||
Assert.IsTrue(0 != hr || null == hardwareRecords || 0 == hardwareRecords.Length,
|
||||
"TestSetupHardwareGet with a different test id should not return the hardware record");
|
||||
|
||||
|
||||
var hwRecordToUpdate = new TestSetupHardwareRecord(hwRecord);
|
||||
hwRecordToUpdate.SamplesPerSecond = 10000;
|
||||
hwRecordToUpdate.AddDAS = false;
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareUpdate(null, con, hwRecordToUpdate);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareUpdate with null user should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareUpdate(_user, null, hwRecordToUpdate);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareUpdate with null connection should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareUpdate(_user, con, null);
|
||||
Assert.IsTrue(ErrorCodes.ERROR_MISSING_PARAMETER == hr,
|
||||
"TestSetupHardwareUpdate with null hardware should return missing parameter");
|
||||
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(null, con, null, hwRecord.DASId, null);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareDelete with null user should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(_user, null, null, hwRecord.DASId, null);
|
||||
Assert.IsTrue(0 != hr, "TestSetupHardwareDelete with null connection should not return 0");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(_user, con, null, null, null);
|
||||
Assert.IsTrue(ErrorCodes.ERROR_MISSING_PARAMETER == hr,
|
||||
"TestSetupHardwareDelete with no parameters should return missing parameter");
|
||||
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupHardwareDelete(_user, con, null, hwRecord.DASId, null);
|
||||
_ = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, con, new[] { test.Id });
|
||||
_ = DbAPI.DbAPI.DAS.DASDelete(_user, con, hardware.DASId, hardware.SerialNumber, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
282
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsTestSetupROIs.cs
Normal file
282
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsTestSetupROIs.cs
Normal file
@@ -0,0 +1,282 @@
|
||||
using DTS.Common.Classes.TestSetups;
|
||||
using DTS.Common.Interface.RegionOfInterest;
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
using DTS.Common.Storage;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public ITestSetupRecord CreateFakeTestSetupWithROIs(int numberOfROIs)
|
||||
{
|
||||
var record = new TestSetupRecord();
|
||||
record.Id = -1;
|
||||
record.Name = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.TestEngineerDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.Settings = "";
|
||||
|
||||
var regionsOfInterestList = new System.ComponentModel.BindingList<IRegionOfInterest>();
|
||||
|
||||
var start = 0D;
|
||||
var end = 0D;
|
||||
for (int i = 0; i < numberOfROIs; i++)
|
||||
{
|
||||
var channelNameList = new List<string>();
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
start = -1D;
|
||||
end = 1D;
|
||||
channelNameList.Add("an1");
|
||||
channelNameList.Add("an2");
|
||||
channelNameList.Add("an3");
|
||||
break;
|
||||
case 1:
|
||||
start = -0.9D;
|
||||
end = 0.9D;
|
||||
channelNameList.Add("an1");
|
||||
channelNameList.Add("an2");
|
||||
break;
|
||||
}
|
||||
var regionOfInterest = CreateRegionOfInterest($"_ROI Period {i + 1}", start, end, true, true);
|
||||
regionOfInterest.ChannelNames = channelNameList.ToArray();
|
||||
regionsOfInterestList.Add(regionOfInterest);
|
||||
}
|
||||
|
||||
record.RegionsOfInterest = regionsOfInterestList;
|
||||
|
||||
return record;
|
||||
}
|
||||
public IRegionOfInterest CreateRegionOfInterest(string suffix, double start, double end, bool isEnabled, bool isDefault)
|
||||
{
|
||||
var record = new RegionOfInterest();
|
||||
record.Suffix = suffix;
|
||||
record.Start = start;
|
||||
record.End = end;
|
||||
record.IsEnabled = isEnabled;
|
||||
record.IsDefault = isDefault;
|
||||
|
||||
return record;
|
||||
}
|
||||
/// <summary>
|
||||
/// Tests included:
|
||||
/// sp_TestSetupsUpdateInsert_92 (and sp_TestSetupsInsert_92)
|
||||
/// sp_TestSetupROIsInsert
|
||||
/// sp_TestSetupROIsGet
|
||||
/// sp_TestSetupsDeleteManyById
|
||||
/// sp_TestSetupsGet_92
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetupROIsGetOneROI()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//***Testing*** sp_TestSetupsUpdateInsert_92
|
||||
var testSetupRecordToInsert = CreateFakeTestSetupWithROIs(1);
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 92, ref testSetupRecordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
|
||||
DbAPI.DbAPI.GetDatabaseVersion(connections[0], out int serverDbVersion);
|
||||
if (serverDbVersion <= 91)
|
||||
{
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out var testSetupROIId);
|
||||
Assert.IsTrue(0 != hr, "RegionsOfInterestInsert should not work if database Version is 91 or less");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
//***Testing*** sp_TestSetupROIsInsert
|
||||
var regionOfInterest = CreateRegionOfInterest("", -1, 1, true, true);
|
||||
var testSetupROIId = -1;
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out testSetupROIId);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a record in the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIId > 0, "A TestSetupROIId should have been generated and returned");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsGet
|
||||
var testSetupROIRecords = new DTS.Common.Interface.TestSetups.ITestSetupROIRecord[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, connections[0], testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 == hr, "Should be able to get a record from the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIRecords.Length == 1, "Should get one and only one record from the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIRecords[0].Suffix == "", "Suffix in record from the TestSetupROIs table should be empty");
|
||||
Assert.IsTrue(testSetupROIRecords[0].ROIStart == -1, "ROIStart in record from the TestSetupROIs table should be -1");
|
||||
Assert.IsTrue(testSetupROIRecords[0].ROIEnd == 1, "ROIEnd in record from the TestSetupROIs table should be 1");
|
||||
Assert.IsTrue(testSetupROIRecords[0].IsEnabled, "IsEnabled in record from the TestSetupROIs table should be 'true'");
|
||||
Assert.IsTrue(testSetupROIRecords[0].IsDefault, "IsDefault in record from the TestSetupROIs table should be 'true'");
|
||||
|
||||
//***Testing*** sp_ROIPeriodChannelsGet
|
||||
var roiPeriodChannelRecords = new DTS.Common.Interface.TestSetups.IROIPeriodChannelRecord[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIRecords[0].TestSetupROIId, out roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr, "Should not fail when getting zero records from the ROIPeriodChannels table based on the TestSetupROIId in the TestSetupROIs table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords.Length == 0, "Should get zero records from the ROIPeriodChannels table");
|
||||
}
|
||||
|
||||
//***Testing*** sp_TestSetupsDeleteManyById
|
||||
//Ensure that deleting a Test Setup will delete related record(s) in the TestSetupROIs and ROIPeriodChannels tables
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections[0], new int[] { testSetupRecordToInsert.Id });
|
||||
//Since hr will be 0 in this case, check by doing a Get
|
||||
|
||||
//***Testing*** sp_TestSetupsGet_92
|
||||
//Make sure the Test Setup was deleted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out var records, out var errors);
|
||||
Assert.IsTrue(null == records || records.Length == 0, "TestSetupsGet should not have retrieved records");
|
||||
Assert.IsFalse(records.Any(r => r.Name == testSetupRecordToInsert.Name), "TestSetupsGet should not have retrieved our record");
|
||||
|
||||
if (serverDbVersion <= 91)
|
||||
{
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out var testSetupROIId);
|
||||
Assert.IsTrue(0 != hr, "RegionsOfInterestInsert should not work if database Version is 91 or less");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
//Make sure the record in the TestSetupROIs table was deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, connections[0], testSetupRecordToInsert.Id, out var testSetupROIRecords);
|
||||
Assert.IsTrue(0 == hr && testSetupROIRecords.Length == 0, "Record in TestSetupROIs table should have been deleted");
|
||||
|
||||
//Make sure the record in the ROIPeriodChannels table was deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupRecordToInsert.Id, out var roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr && testSetupROIRecords.Length == 0, "Record in ROIPeriodChannels table should have been deleted");
|
||||
|
||||
//test that it fails when no user provided
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(null, connections[0], testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when user is invalid");
|
||||
|
||||
//test that it fails when no connection provided
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, null, testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when connection is invalid");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Tests included:
|
||||
/// sp_TestSetupsUpdateInsert_92 (and sp_TestSetupsInsert_92)
|
||||
/// sp_TestSetupROIsInsert
|
||||
/// sp_TestSetupROIsGet
|
||||
/// sp_TestSetupsDeleteManyById
|
||||
/// sp_TestSetupsGet_92
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetupROIsGetMultipleROIs()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
|
||||
//***Testing*** sp_TestSetupsUpdateInsert_92
|
||||
var testSetupRecordToInsert = CreateFakeTestSetupWithROIs(2);
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 92, ref testSetupRecordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
|
||||
DbAPI.DbAPI.GetDatabaseVersion(connections[0], out int serverDbVersion);
|
||||
if (serverDbVersion <= 91)
|
||||
{
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out var testSetupROIId);
|
||||
Assert.IsTrue(0 != hr, "RegionsOfInterestInsert should not work if database Version is 91 or less");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
//***Testing*** sp_TestSetupROIsInsert
|
||||
var regionOfInterest = testSetupRecordToInsert.RegionsOfInterest[0];
|
||||
var testSetupROIId = -1;
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out testSetupROIId);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the first ROI record in the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIId > 0, "A TestSetupROIId should have been generated and returned (1)");
|
||||
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[0], regionOfInterest.ChannelIds[0]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the first record in the ROIPeriodChannels table");
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[1], regionOfInterest.ChannelIds[1]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the second record in the ROIPeriodChannels table");
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[2], regionOfInterest.ChannelIds[2]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the third record in the ROIPeriodChannels table");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsInsert
|
||||
regionOfInterest = testSetupRecordToInsert.RegionsOfInterest.Last();
|
||||
testSetupROIId = -1;
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsInsert(_user, connections[0], testSetupRecordToInsert.Id, regionOfInterest, out testSetupROIId);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the last ROI record in the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIId > 0, "A TestSetupROIId should have been generated and returned (2)");
|
||||
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[0], regionOfInterest.ChannelIds[0]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the fourth record in the ROIPeriodChannels table");
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsInsert(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIId, regionOfInterest.ChannelNames[1], regionOfInterest.ChannelIds[1]);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert the fifth record in the ROIPeriodChannels table");
|
||||
|
||||
//***Testing*** sp_TestSetupROIsGet
|
||||
var testSetupROIRecords = new DTS.Common.Interface.TestSetups.ITestSetupROIRecord[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, connections[0], testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 == hr, "Should be able to get a record from the TestSetupROIs table");
|
||||
Assert.IsTrue(testSetupROIRecords.Length == 2, "Should get two and only two records from the TestSetupROIs table");
|
||||
|
||||
Assert.IsTrue(testSetupROIRecords[0].Suffix == "_ROI Period 1", "Suffix in first record from the TestSetupROIs table should be empty");
|
||||
Assert.IsTrue(testSetupROIRecords[0].ROIStart == -1, "ROIStart in first record from the TestSetupROIs table should be -1");
|
||||
Assert.IsTrue(testSetupROIRecords[0].ROIEnd == 1, "ROIEnd in first record from the TestSetupROIs table should be 1");
|
||||
Assert.IsTrue(testSetupROIRecords[0].IsEnabled, "IsEnabled in first record from the TestSetupROIs table should be 'true'");
|
||||
Assert.IsTrue(testSetupROIRecords[0].IsDefault, "IsDefault in first record from the TestSetupROIs table should be 'true'");
|
||||
|
||||
Assert.IsTrue(testSetupROIRecords[1].Suffix == "_ROI Period 2", "Suffix in second record from the TestSetupROIs table should be empty");
|
||||
Assert.IsTrue(testSetupROIRecords[1].ROIStart == -0.9D, "ROIStart in second record from the TestSetupROIs table should be -1");
|
||||
Assert.IsTrue(testSetupROIRecords[1].ROIEnd == 0.9D, "ROIEnd in second record from the TestSetupROIs table should be 1");
|
||||
Assert.IsTrue(testSetupROIRecords[1].IsEnabled, "IsEnabled in second record from the TestSetupROIs table should be 'true'");
|
||||
Assert.IsTrue(testSetupROIRecords[1].IsDefault, "IsDefault in second record from the TestSetupROIs table should be 'true'");
|
||||
|
||||
//***Testing*** sp_ROIPeriodChannelsGet
|
||||
var roiPeriodChannelRecords = new DTS.Common.Interface.TestSetups.IROIPeriodChannelRecord[0];
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIRecords[0].TestSetupROIId, out roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr, "Should be able to get three records from the ROIPeriodChannels table based on the TestSetupROIId in the TestSetupROIs table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords.Length == 3, "Should get three and only three records from the ROIPeriodChannels table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[0].ChannelName == "an1", "ChannelName[0] in record 0 should be 'an1'");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[1].ChannelName == "an2", "ChannelName[1] in record 0 should be 'an2'");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[2].ChannelName == "an3", "ChannelName[2] in record 0 should be 'an3'");
|
||||
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupROIRecords[1].TestSetupROIId, out roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr, "Should be able to get two records from the ROIPeriodChannels table based on the TestSetupROIId in the TestSetupROIs table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords.Length == 2, "Should get two and only two records from the ROIPeriodChannels table");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[0].ChannelName == "an1", "ChannelName[0] in record 1 should be 'an1'");
|
||||
Assert.IsTrue(roiPeriodChannelRecords[1].ChannelName == "an2", "ChannelName[1] in record 1 should be 'an2'");
|
||||
}
|
||||
|
||||
//***Testing*** sp_TestSetupsDeleteManyById
|
||||
//Ensure that deleting a Test Setup will delete related record(s) in the TestSetupROIs table
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections[0], new int[] { testSetupRecordToInsert.Id });
|
||||
//Since hr will be 0 in this case, check by doing a Get
|
||||
//Assert.IsTrue(0 != hr, $"Test Setup should not be able to be deleted before all related records in the TestSetupROIs table. hr={hr}");
|
||||
|
||||
//***Testing*** sp_TestSetupsGet_92
|
||||
//Make sure the Test Setup was deleted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out var records, out var errors);
|
||||
Assert.IsTrue(null == records || records.Length == 0, "TestSetupsGet should not have retrieved records");
|
||||
Assert.IsFalse(records.Any(r => r.Name == testSetupRecordToInsert.Name), "TestSetupsGet should not have retrieved our record");
|
||||
|
||||
if (serverDbVersion >= 92)
|
||||
{
|
||||
//Make sure that both records in the TestSetupROIs table were deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, connections[0], testSetupRecordToInsert.Id, out var testSetupROIRecords);
|
||||
Assert.IsTrue(0 == hr && testSetupROIRecords.Length == 0, "Record in TestSetupROIs table should have been deleted");
|
||||
|
||||
//Make sure the record in the ROIPeriodChannels table was deleted
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.ROIPeriodChannelsGet(_user, connections[0], DbOperations.CURRENT_DB_VERSION, testSetupRecordToInsert.Id, out var roiPeriodChannelRecords);
|
||||
Assert.IsTrue(0 == hr && testSetupROIRecords.Length == 0, "Record in ROIPeriodChannels table should have been deleted");
|
||||
|
||||
//test that it fails when no user provided
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(null, connections[0], testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when user is invalid");
|
||||
|
||||
//test that it fails when no connection provided
|
||||
hr = DbAPI.DbAPI.RegionsOfInterest.TestSetupROIsGet(_user, null, testSetupRecordToInsert.Id, out testSetupROIRecords);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when connection is invalid");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
274
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsTestSetups.cs
Normal file
274
DataPRO/UnitTest/DatabaseUnitTesting/DbAPITestsTestSetups.cs
Normal file
@@ -0,0 +1,274 @@
|
||||
using DTS.Common.Classes.Channels;
|
||||
using DTS.Common.Classes.TestSetups;
|
||||
using DTS.Common.Interface.Channels;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DBAPITests
|
||||
{
|
||||
public ITestSetupRecord CreateFakeTestSetup()
|
||||
{
|
||||
var record = new TestSetupRecord();
|
||||
record.Id = -1;
|
||||
record.Name = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LastModified = DateTime.Today;
|
||||
record.LastModifiedBy = "NUNIT";
|
||||
record.TestEngineerDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.CustomerDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.LabDetails = Guid.NewGuid().ToString().Substring(0, 15);
|
||||
record.Settings = "";
|
||||
return record;
|
||||
}
|
||||
/// <summary>
|
||||
/// As of database Version 92, TestSetupGet() can now be used to test
|
||||
/// Version 91 databases, as well as interoperability with Version 92 databases,
|
||||
/// depending on which is database is present at "...\db\DataPRO.mdf.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetupGet()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var recordToInsert = CreateFakeTestSetup();
|
||||
var decoyRecord = CreateFakeTestSetup();
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 0, ref recordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 0, ref decoyRecord);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy test setup");
|
||||
|
||||
//valid get all tests, should return the test we inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 0, null, null, double.NaN, double.NaN, false, false, out var records, out var errors);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestSetupsGet");
|
||||
Assert.IsTrue(null != records && records.Length > 0, "TestSetupsGet should have retrieved records");
|
||||
Assert.IsTrue(Array.Exists(records, r => r.Name == recordToInsert.Name), "TestSetupsGet should have retrieved our record");
|
||||
|
||||
//valid get all tests by id, should only return 1 of the 2 inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 0, recordToInsert.Id, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(!records.Any(r => r.Id != recordToInsert.Id), "TestSetupsGet should only return ids requested");
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the id");
|
||||
|
||||
//valid get all tests by name, should only return 1 of the 2 inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 0, null, recordToInsert.Name, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the name");
|
||||
Assert.IsTrue(!records.Any(r => !r.Name.Equals(recordToInsert.Name)), "TestSetupsGet should only return names requested");
|
||||
Assert.IsTrue(TestSetupsEqual(recordToInsert, records[0]), "TestSetupsGet should return untouched record");
|
||||
|
||||
//delete both - part of of cleanup
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections[0], new[] { recordToInsert.Id, decoyRecord.Id });
|
||||
Assert.IsTrue(0 == hr, "TestSetupsDeleteById should return 0");
|
||||
|
||||
//testing get, it should not return either of the two records we inserted because they should no longer be around
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 0, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr);
|
||||
Assert.IsTrue(null == records || 0 == records.Length || !Array.Exists(records, r => r.Id == recordToInsert.Id || r.Id == decoyRecord.Id));
|
||||
|
||||
//test that it fails when no user provided
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(null, connections[0], 0, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when user is invalid");
|
||||
|
||||
//test that it fails when no connection provided
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, null, 0, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when connection is invalid");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// As of database Version 92, TestSetupGet_92() can now be used to test
|
||||
/// Version 92 databases, as well as interoperability with Version 91 databases,
|
||||
/// depending on which is database is present at "...\db\DataPRO.mdf.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetupGet_92()
|
||||
{
|
||||
if (!_setup) { Setup(); }
|
||||
TestLogin();
|
||||
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
|
||||
//we'll insert two records, one which is the one we'll be testing with get, and one that is just a decoy
|
||||
//for tests which we do not expect to be returned, etc.
|
||||
var recordToInsert = CreateFakeTestSetupWithROIs(2);
|
||||
var decoyRecord = CreateFakeTestSetup();
|
||||
|
||||
var hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 92, ref recordToInsert);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a test setup");
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsUpdateInsert(_user, connections[0], 92, ref decoyRecord);
|
||||
Assert.IsTrue(0 == hr, "Should be able to insert a decoy test setup");
|
||||
|
||||
//valid get all tests, should return the test we inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out var records, out var errors);
|
||||
Assert.IsTrue(0 == hr, "Should return 0 for TestSetupsGet");
|
||||
Assert.IsTrue(null != records && records.Length > 0, "TestSetupsGet should have retrieved records");
|
||||
Assert.IsTrue(records.Any(r => r.Name == recordToInsert.Name), "TestSetupsGet should have retrieved our record");
|
||||
|
||||
//valid get all tests by id, should only return 1 of the 2 inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, recordToInsert.Id, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(!records.Any(r => r.Id != recordToInsert.Id), "TestSetupsGet should only return ids requested");
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the id");
|
||||
|
||||
//valid get all tests by name, should only return 1 of the 2 inserted
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, recordToInsert.Name, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the name");
|
||||
Assert.IsTrue(!records.Any(r => !r.Name.Equals(recordToInsert.Name)), "TestSetupsGet should only return names requested");
|
||||
Assert.IsTrue(TestSetupsEqual(recordToInsert, records[0]), "TestSetupsGet should return untouched record");
|
||||
|
||||
//valid get the Test Setup, should only have something in the RegionsOfInterest if Version 91 database is used -
|
||||
//(in DataPRO, when using a Version 92 database, a later Load will read from the new tables)
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, recordToInsert.Name, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr && null != records && records.Length > 0 && Array.Exists(records, r => r.Name == recordToInsert.Name),
|
||||
"TestSetupsGet should have retrieved our record using the name");
|
||||
Assert.IsTrue(!Array.Exists(records, r => !r.Name.Equals(recordToInsert.Name)), "TestSetupsGet should only return names requested");
|
||||
Assert.IsTrue(TestSetupsEqual(recordToInsert, records[0]), "TestSetupsGet should return untouched record");
|
||||
|
||||
DbAPI.DbAPI.GetDatabaseVersion(connections[0], out int serverDbVersion);
|
||||
if (serverDbVersion == 91)
|
||||
{
|
||||
Assert.IsTrue(records[0].RegionsOfInterest.Count == 2, "TestSetupsGet should have returned a RegionsOfInterest structure");
|
||||
}
|
||||
else if (serverDbVersion >= 92)
|
||||
{
|
||||
Assert.IsTrue(records[0].RegionsOfInterest.Count == 0, "TestSetupsGet_92 should not have returned a RegionsOfInterest structure, but a later Load will read from the new tables");
|
||||
}
|
||||
|
||||
//delete both - part of of cleanup
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsDeleteById(_user, connections[0], new[] { recordToInsert.Id, decoyRecord.Id });
|
||||
Assert.IsTrue(0 == hr, "TestSetupsDeleteById should return 0");
|
||||
|
||||
//testing get, it should not return either of the two records we inserted because they should no longer be around
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 == hr);
|
||||
Assert.IsTrue(null == records || 0 == records.Length || !Array.Exists(records, r => r.Id == recordToInsert.Id || r.Id == decoyRecord.Id));
|
||||
|
||||
//test that it fails when no user provided
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(null, connections[0], 92, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when user is invalid");
|
||||
|
||||
//test that it fails when no connection provided
|
||||
hr = DbAPI.DbAPI.TestSetups.TestSetupsGet(_user, null, 92, null, null, double.NaN, double.NaN, false, false, out records, out errors);
|
||||
Assert.IsTrue(0 != hr, "Should not return 0 when connection is invalid");
|
||||
}
|
||||
private bool TestSetupsEqual(ITestSetupRecord left, ITestSetupRecord right)
|
||||
{
|
||||
return left.Id == right.Id
|
||||
&& left.AllowMissingSensors == right.AllowMissingSensors
|
||||
&& left.AllowSensorIdToBlankChannel == right.AllowSensorIdToBlankChannel
|
||||
&& left.AngularAccelLevelTriggerOn == right.AngularAccelLevelTriggerOn
|
||||
&& left.AngularAccelLevelTriggerOnX == right.AngularAccelLevelTriggerOnX
|
||||
&& left.AngularAccelLevelTriggerOnY == right.AngularAccelLevelTriggerOnY
|
||||
&& left.AngularAccelLevelTriggerOnZ == right.AngularAccelLevelTriggerOnZ
|
||||
&& left.AngularAccelLevelTriggerX == right.AngularAccelLevelTriggerX
|
||||
&& left.AngularAccelLevelTriggerY == right.AngularAccelLevelTriggerY
|
||||
&& left.AngularAccelLevelTriggerZ == right.AngularAccelLevelTriggerZ
|
||||
&& left.AngularRate == right.AngularRate
|
||||
&& left.AngularRateLevelTriggerOn == right.AngularRateLevelTriggerOn
|
||||
&& left.AngularRateLevelTriggerOnX == right.AngularRateLevelTriggerOnX
|
||||
&& left.AngularRateLevelTriggerOnY == right.AngularRateLevelTriggerOnY
|
||||
&& left.AngularRateLevelTriggerOnZ == right.AngularRateLevelTriggerOnZ
|
||||
&& left.AngularRateLevelTriggerX == right.AngularRateLevelTriggerX
|
||||
&& left.AngularRateLevelTriggerY == right.AngularRateLevelTriggerY
|
||||
&& left.AngularRateLevelTriggerZ == right.AngularRateLevelTriggerZ
|
||||
&& left.AutomaticProgression == right.AutomaticProgression
|
||||
&& left.AutomaticProgressionDelayMS == right.AutomaticProgressionDelayMS
|
||||
&& left.AutoVerifyChannels == right.AutoVerifyChannels
|
||||
&& left.AutoVerifyDelaySeconds == right.AutoVerifyDelaySeconds
|
||||
&& left.CalibrationBehavior == right.CalibrationBehavior
|
||||
&& left.CheckoutMode == right.CheckoutMode
|
||||
&& left.ClockSyncProfileMaster == right.ClockSyncProfileMaster
|
||||
&& left.ClockSyncProfileSlave == right.ClockSyncProfileSlave
|
||||
&& left.CommonStatusLine == right.CommonStatusLine
|
||||
&& left.CustomerDetails == right.CustomerDetails
|
||||
&& left.DefaultNumberRealtimeGraphs == right.DefaultNumberRealtimeGraphs
|
||||
&& left.Description == right.Description
|
||||
&& left.Dirty == right.Dirty
|
||||
&& left.DoAutoArm == right.DoAutoArm
|
||||
&& left.DoROIDownload == right.DoROIDownload
|
||||
&& left.DoStreaming == right.DoStreaming
|
||||
&& left.DownloadAll == right.DownloadAll
|
||||
&& left.ErrorMessage.Equals(right.ErrorMessage)
|
||||
&& left.ExportFormats == right.ExportFormats
|
||||
//&& left.ExtraProperties
|
||||
&& left.HighgLevelTriggerOn == right.HighgLevelTriggerOn
|
||||
&& left.HighgLevelTriggerOnX == right.HighgLevelTriggerOnX
|
||||
&& left.HighgLevelTriggerOnY == right.HighgLevelTriggerOnY
|
||||
&& left.HighgLevelTriggerOnZ == right.HighgLevelTriggerOnZ
|
||||
&& left.HighgLinearAccRate == right.HighgLinearAccRate
|
||||
&& left.HighgLinearLevelTriggerX == right.HighgLinearLevelTriggerX
|
||||
&& left.HighgLinearLevelTriggerY == right.HighgLinearLevelTriggerY
|
||||
&& left.HighgLinearLevelTriggerZ == right.HighgLinearLevelTriggerZ
|
||||
&& left.HumidityLevelTriggerAbove == right.HumidityLevelTriggerAbove
|
||||
&& left.HumidityLevelTriggerBelow == right.HumidityLevelTriggerBelow
|
||||
&& left.HumidityLevelTriggerOn == right.HumidityLevelTriggerOn
|
||||
&& left.InvertStartRecordCompletion == right.InvertStartRecordCompletion
|
||||
&& left.InvertTriggerCompletion == right.InvertTriggerCompletion
|
||||
&& left.IsComplete == right.IsComplete
|
||||
// can be modified
|
||||
//&& left.ISFFile.Equals(right.ISFFile)
|
||||
&& left.LabDetails.Equals(right.LabDetails)
|
||||
&& left.LastModified.Equals(right.LastModified)
|
||||
&& left.LastModifiedBy.Equals(right.LastModifiedBy)
|
||||
&& left.LocalOnly == right.LocalOnly
|
||||
&& left.LowgLevelTriggerOn == right.LowgLevelTriggerOn
|
||||
&& left.LowgLevelTriggerOnX == right.LowgLevelTriggerOnX
|
||||
&& left.LowgLevelTriggerOnY == right.LowgLevelTriggerOnY
|
||||
&& left.LowgLevelTriggerOnZ == right.LowgLevelTriggerOnZ
|
||||
&& left.LowgLinearAccRate == right.LowgLinearAccRate
|
||||
&& left.LowgLinearLevelTriggerX == right.LowgLinearLevelTriggerX
|
||||
&& left.LowgLinearLevelTriggerY == right.LowgLinearLevelTriggerY
|
||||
&& left.LowgLinearLevelTriggerZ == right.LowgLinearLevelTriggerZ
|
||||
&& left.MeasureSquibResistancesStep == right.MeasureSquibResistancesStep
|
||||
&& left.Name.Equals(right.Name)
|
||||
&& left.NotAllChannelsRealTime == right.NotAllChannelsRealTime
|
||||
&& left.NotAllChannelsViewer == right.NotAllChannelsViewer
|
||||
&& left.NumberOfEvents == right.NumberOfEvents
|
||||
&& left.WakeUpMotionTimeout == right.WakeUpMotionTimeout
|
||||
&& left.PostTestDiagnosticsLevel == right.PostTestDiagnosticsLevel
|
||||
&& left.PostTriggerSeconds == right.PostTriggerSeconds
|
||||
&& left.PressureLevelTriggerAbove == right.PressureLevelTriggerAbove
|
||||
&& left.PressureLevelTriggerBelow == right.PressureLevelTriggerBelow
|
||||
&& left.PressureLevelTriggerOn == right.PressureLevelTriggerOn
|
||||
&& left.PreTriggerSeconds == right.PreTriggerSeconds
|
||||
&& left.QuitTestWithoutWarning == right.QuitTestWithoutWarning
|
||||
&& left.QuitTestWithoutWarning == right.QuitTestWithoutWarning
|
||||
&& left.RecordingMode == right.RecordingMode
|
||||
//&& left.RegionsOfInterest
|
||||
&& left.RequireUserConfirmationOnErrors == right.RequireUserConfirmationOnErrors
|
||||
&& left.ROIEnd == right.ROIEnd
|
||||
&& left.ROIStart == right.ROIStart
|
||||
&& left.RTCScheduleDuration.Equals(right.RTCScheduleDuration)
|
||||
//can be modified on insert if invalid
|
||||
//&& left.RTCScheduleStartDateTime.Equals(right.RTCScheduleStartDateTime)
|
||||
&& left.RTCScheduleTriggerOn == right.RTCScheduleTriggerOn
|
||||
&& left.SameAsDownloadFolder == right.SameAsDownloadFolder
|
||||
&& left.SamplesPerSecondAggregate.Equals(right.SamplesPerSecondAggregate)
|
||||
&& left.Settings.Equals(right.Settings)
|
||||
&& left.StrictDiagnostics == right.StrictDiagnostics
|
||||
&& left.SuppressMissingSensorsWarning == right.SuppressMissingSensorsWarning
|
||||
&& left.TemperatureHumidityPressureRate == right.TemperatureHumidityPressureRate
|
||||
&& left.TemperatureLevelTriggerAbove == right.TemperatureLevelTriggerAbove
|
||||
&& left.TemperatureLevelTriggerBelow == right.TemperatureLevelTriggerBelow
|
||||
&& left.TemperatureLevelTriggerOn == right.TemperatureLevelTriggerOn
|
||||
&& left.TestEngineerDetails == right.TestEngineerDetails
|
||||
&& left.TestSetupUniqueId == right.TestSetupUniqueId
|
||||
&& left.TimedIntervalDuration == right.TimedIntervalDuration
|
||||
&& left.TimedIntervalEvents == right.TimedIntervalEvents
|
||||
&& left.IntervalBetweenEventStartsMinutes == right.IntervalBetweenEventStartsMinutes
|
||||
&& left.TimedIntervalTriggerOn == right.TimedIntervalTriggerOn
|
||||
&& left.TimedIntervalUnits == right.TimedIntervalUnits
|
||||
&& left.TriggerCheckRealtime == right.TriggerCheckRealtime
|
||||
&& left.TriggerCheckStep == right.TriggerCheckStep
|
||||
&& left.TurnOffExcitation == right.TurnOffExcitation
|
||||
&& left.UploadData == right.UploadData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NUnit.Framework;
|
||||
using System.Data;
|
||||
|
||||
|
||||
namespace DatabaseUnitTesting
|
||||
{
|
||||
[TestFixture]
|
||||
public class DefaultPropertiesTests : TestSetups
|
||||
{
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Verify update a default property
|
||||
//
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
|
||||
//[Test]
|
||||
// ============================================================
|
||||
// Verify retrieval of a default property
|
||||
//
|
||||
//
|
||||
// ============================================================
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user