I am using 3 tier architecture: Controller, Business, and Data Layer. In my Data Layer, I am making a call to an Sql Server Database by passing Connection String and other necessary parameters.
I have to write unit tests for the Controller layer and Business layer. I want to write a stub (fake repository) from which I would return the hard coded values/result. When I write a test for business layer, the logic should call this stub instead of the real database.
How can I write the code in the business layer to achieve this?
Business Layer:
public string GetValues(string xmlData)
{
DataObject do = new DataObject ();
string result = do.GetValues(xmlData);
return result;
}
Data access:
public static string GetValues(string xmlData)
{
return SqlHelper.ExecuteScalar(
ConfigurationManager.AppSettings["ConnectionString"].ToString(),
"DBO.usp_GetDetail",
xmlData
).ToString();
}