Reputation: 665
I am testing my class. My method returns an array of insurance percentage paid and financial limit for the given policy id. For policy id 43 its financial limit is null and its percentage insurance paid is 95.75.I am trying to test this but my test keep failing. Could any one tell where am doing wrong?
here is my 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;
}
here is my test class
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);
}
}
}
Upvotes: 0
Views: 47
Reputation: 5348
The function returns an array containing null and "19.75".
You need to change the value assigned to expected to { null, "19.75"}
.
However if you are using .net 2 or later I would recommend that you change the method to return a tuple to prevent this sort of errors. It is probably also a good idea to store numbers in a numerical data type like decimal.
Upvotes: 1