当我尝试在 db2 服务器中执行数据集时出现此异常。最奇怪的是单元测试代码不会抛出异常,但是当我尝试从网页中使用相同的参数调用它时,它会抛出异常。
这是我的单元测试代码:
[Test]
public void Get_the_car_details_via_the_chassisnumber_WVWZZZ1KZCW240208()
{
//Arrange
string chassisNumber = "WVWZZZ1KZCW240208";
string brand = "skoda";
//Act
Vehicle car = VehicleDA.GetVehicle(chassisNumber, "", brand).GetResult();
//Assert
Assert.IsNotNull(car);
car.Type.ShouldBe("VOLKSWAGEN GOLF");
}
这是我从页面中调用它的方式,如您所见,我对相同的参数进行了硬编码,但它仍然不起作用
public Vehicle GetVehicleInformation(string chassis, string commissionnumber, string brand)
{
Vehicle car = VehicleDA.GetVehicle("WVWZZZ1KZCW240208", commissionnumber, "skoda").GetResult();
这是dal中的DB代码
public class VehicleDA
{
public static ResultForType<Vehicle> GetVehicle(string chassisNumber, string commissionNumber, string brand)
{
if (chassisNumber.Length != 17 && chassisNumber.Length > 0)
{
chassisNumber = new ChassisNumberSearch().GetCompleteChassisNumber(chassisNumber);
if (chassisNumber == string.Empty)
{
return CreateReturnWithError("Unknown chassis number");
}
}
if (chassisNumber == string.Empty)
{
chassisNumber = GetTheLatestChassisNumberInCaseOfMultipleChassisNumbers(new ChassisNumberSearch().GetChassisNumber(commissionNumber));
if (chassisNumber == string.Empty)
{
return CreateReturnWithError("Unknown commision number");
}
}
var vehicleXMLString = new VehicleSearch().GetVehicle(chassisNumber);
if (GetDateTimeDataFor("DFACUSI", vehicleXMLString) < DateTime.Now.AddYears(-2))
{
return CreateReturnWithError("Vehicle is older then 2 years");
}
if ( GetDateTimeDataFor("DFACTUR", vehicleXMLString) == DateTime.MinValue)
{
return CreateReturnWithError("Invoice date is not filled in");
}
var vehicle = new Vehicle
{
Chassis = chassisNumber,
ComissionNumber = GetDataFor("NCOMMIS", vehicleXMLString),
Type = GetDataFor("LMAKTYP", vehicleXMLString),
Year = GetIntDataFor("CANNMOD", vehicleXMLString),
OrderDate = GetDateTimeDataFor("D705DAT", vehicleXMLString),
InvoiceDate = GetDateTimeDataFor("DFACTUR", vehicleXMLString),
InvoiceNumber = GetDataFor("NFACTUR", vehicleXMLString),
DeliveryDate = GetDateTimeDataFor("DLIVRAI", vehicleXMLString),
RegistrationDate = GetDateTimeDataFor("DIMMFIR", vehicleXMLString),
CataloguePrice = GetDecimalDataFor("VPRICAT", vehicleXMLString),
InvoicePrice = GetDecimalDataFor("VPRIFAC", vehicleXMLString),
Code = GetDataFor("CINTERM", vehicleXMLString)
};
var result = new ResultForType<Vehicle>(vehicle);
if (!vehicle.Type.ToLower().StartsWith(brand.ToLower()))
{
result.AddWarning("Brand of the dealer is different from the brand of the vehicle");
}
if (vehicle.RegistrationDate < DateTime.Now.AddMonths(-3))
{
result.AddWarning("Registration date is older then 3 months");
}
//"Registration date is older then 3 months"
return result;
}
public class VehicleSearch : DB2Base
{
public string GetVehicle(string chassisNumber)
{
const string procName = "CALL DBSP.xxx(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
var cmd = DB2Database.GetStoredProcCommand(procName);
cmd.CommandType = CommandType.Text;
if (chassisNumber.Length > 17)
{
chassisNumber = chassisNumber.Substring(0, 17);
}
CreateInputParameter("CFONCTI", cmd, "RB");
CreateInputParameter("CFORMAT", cmd, "X");
CreateInputParameter("CLANGUE", cmd, "E");
CreateInputParameter("FEXTEND", cmd, "Y");
CreateInputParameter("NCHASSI", cmd, chassisNumber);
CreateStringParameter("LLIGXML", cmd, 250);
CreateStringParameter("CIDFVAR", cmd, 10);
CreateStringParameter("LVALVAR", cmd, 250);
CreateStringParameter("CEQUIPE", cmd, 4);
CreateStringParameter("CEQUPAC", cmd, 4);
CreateStringParameter("LEQUCOUF", cmd, 30);
CreateStringParameter("LEQUCOUN", cmd, 30);
CreateStringParameter("LEQUCOUD", cmd, 30);
CreateStringParameter("LEQUCOUE", cmd, 30);
CreateStringParameter("LEQULONF", cmd, 120);
CreateStringParameter("LEQULONN", cmd, 120);
CreateStringParameter("LEQULOND", cmd, 120);
CreateStringParameter("LEQULONE", cmd, 120);
CreateStringParameter("CTYPOPT", cmd, 1);
CreateStringParameter("CCATOPT", cmd, 1);
CreateStringParameter("CEQUGEN", cmd, 4);
CreateDecimalParameter("VHTVAXX", cmd, 10);
CreateStringParameter("CRETOUR", cmd, 2);
CreateStringParameter("LMSGERR", cmd, 70);
CreateStringParameter("LSPPROG", cmd, 8);
CreateStringParameter("LSPPARG", cmd, 30);
CreateSmallIntParameter("CSPRETC", cmd, 2);
CreateIntParameter("CSQLAST", cmd, 4);
CreateStringParameter("LSQLMSG", cmd, 70);
var dataset = DB2Database.ExecuteDataSet(cmd);
var result = new StringBuilder();
if (dataset.HasRowsInTheFirstTable())
{
foreach (DataRow row in dataset.Tables[0].Rows)
{
result.Append(row[0]);
}
}
return result.ToString();
}