Hi,
lets see if i understood you correctly.
Is this more or less what you are doing?
public class BusinessObject
{
public int CustomerID {get;set;}
public string CompanyName { get; set; }
}
public class DAO
{
public static void Insert(BusinessObject data)
{
using (SqlConnection connection = new SqlConnection("Some connection string"))
{
connection.Open();
string queryString = String.Format("INSERT INTO Customers (CustomerID, CompanyName) Values('{0}', '{1}')",
data.CustomerID,data.CompanyName);
SqlCommand command = new SqlCommand(queryString, connection);
command.ExecuteNonQuery();
}
}
}
if this is the case then heres a way to check that the proper string is passed to the SqlCommand ctor.
(I would have done it in the AAA syntax but I'm not sure they have the ability to verify arguments on the constructor)
[TestMethod]
[VerifyMocks]
public void DaoExample()
{
string ExpectedSQLString = "INSERT INTO Customers" +
" (CustomerID, CompanyName) Values('6', 'yahoo')";
using (RecordExpectations rec = new RecordExpectations())
{
using (SqlConnection connection = new SqlConnection("Some connection string"))
{
connection.Open();
SqlCommand fake = new SqlCommand("", null);
rec.CheckArguments(ExpectedSQLString, Check.IsAny());
fake.ExecuteNonQuery();
rec.Return(6);
}
}
BusinessObject data = new BusinessObject();
data.CustomerID = 6;
data.CompanyName = "yahoo";
DAO.Insert(data);
}