id = "AROUT";
comName = "Around the Horn";
found = customerDAO.FindCustomerByID(id);
Assert.That(found, Is.Not.Null);
Assert.That(found.CustomerID, Is.EqualTo(id));
Assert.That(found.CompanyName, Is.EqualTo(comName));
}
}
這段代碼不能編譯,因為并沒有CustomerDAO這個類,所以得新增該類以及FindCustomerByID方法,而且上面的測試中已經包括了兩個測試場景,現在可以直接寫實現:
public class CustomerDAO
{
public Customer FindCustomerByID(string id)
{
using (NorthwindDataContext ctx = new NorthwindDataContext())
{
IQueryable
if (customers.Count() > 0)
return customers.Single();
else
return null;
}
}
}
文章來源于領測軟件測試網 http://www.kjueaiud.com/