gpt4 book ai didi

c# - 测试比较数组方法失败

转载 作者:行者123 更新时间:2023-11-28 21:32:00 24 4
gpt4 key购买 nike

我正在测试我的类(class)。我的方法为给定的保单 ID 返回一组支付的保险百分比和财务限额。对于保单 ID 43,其财务限额为空,其支付的保险百分比为 95.75。我正在尝试对此进行测试,但我的测试一直失败。谁能告诉我哪里做错了?

这是我的类(class)

public class PatientInsuranceLimits : System.Web.UI.Page
{

String sqlConStr = ConfigurationManager.ConnectionStrings["connectionname"].ToString();


public String[] generalLimits(String policyID)
{
String []resultset = new String[2];
SqlConnection con = new SqlConnection(sqlConStr);
String sqlQuery1 = "Select InsurancePaidPercentage as iPP, FinancialLimit as fLimit from Policy where ID=@poid";

SqlCommand cmd1 = new SqlCommand(sqlQuery1, con);
cmd1.Parameters.AddWithValue("@poid", policyID);

try
{
con.Open();
SqlDataReader r = cmd1.ExecuteReader();
while(r.Read()){
resultset[0] = r[0].ToString();
resultset[1] = r[1].ToString();

}
r.Close();
}
catch(Exception ex){

}
finally{
con.Close();
}

return resultset;

}

这是我的测试类

namespace _10_06_13_test

{
[TestClass()]
public class PatientInsuranceLimitsTest
{
private TestContext testContextInstance;

public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}

[DataSource("System.Data.SqlClient", "Data Source=servername_lab;Initial Catalog=IDKit;User ID=userid;Password=password", "mytable", DataAccessMethod.Sequential), TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\Users", "/")]
[UrlToTest("http://localhost:51063/")]
public void generalLimitsTest()
{
SurvivalHealth.PatientInsuranceLimits target = new SurvivalHealth.PatientInsuranceLimits();
string policyID = "43";
string[] expected = new string[] {"95.75"};
string[] actual;
actual = target.generalLimits(policyID);
Assert.AreEqual(expected, actual);
}
}
}

最佳答案

该函数返回一个包含 null 和“19.75”的数组。您需要将分配给 expected 的值更改为 { null, "19.75"}

但是,如果您使用的是 .net 2 或更高版本,我建议您更改返回元组的方法以防止此类错误。以小数等数字数据类型存储数字可能也是一个好主意。

关于c# - 测试比较数组方法失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17048154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com