/ Published in: C#
Shows how to mock the Object["CollectionItemName"] syntax.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public class TransactionStore { public virtual IDataReader GetReader(SqlCommand cmd) { return cmd.ExecuteReader(); } public decimal GetAvailableBalance(int custNumb) { decimal retVal = 0.00M; { sqlConnection.Open(); using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandText = "dbo.GetCustomerBalance"; sqlCommand.Parameters.AddWithValue("CustomerID", custNumb); using (IDataReader dr = GetReader(sqlCommand)) { if (dr != null) { dr.Read(); retVal = Convert.ToDecimal(dr["AvailableBalance"]); } } } } return retVal; } } [TestFixture] public class IMTTests : TransactionStore { IDataReader idr = null; public override IDataReader GetReader(SqlCommand cmd) { Expect.AtLeastOnce.On(idr).Method("Read").Will(Return.Value(true)); Expect.AtLeastOnce.On(idr).Method("Dispose"); return idr; } [Test] public void TestAvailableBalance() { Expect.AtLeastOnce.On(idr).Get["AvailableBalance"].Will(Return.Value(42.00M)); Decimal amount = this.GetAvailableBalance(12345); Assert.AreEqual(42.00M, amount); } }