init
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user