【发布时间】:2012-07-15 22:36:07
【问题描述】:
如何对日记帐分录是否正确创建(使用正确值添加到数据库)进行单元测试?
[HttpPost]
public ActionResult Create(
int journalId,
string text)
{
JournalEntry journalentry = new JournalEntry();
journalentry.Text = text;
if (ModelState.IsValid)
{
var journal = db.Journals.Find(journalId);
journalentry.Journal = journal;
db.JournalEntries.Add(journalentry);
db.SaveChanges();
}
return View(journalentry);
}
【问题讨论】:
-
如果您的日记条目实体成功保存到数据库中,它应该有一个行标识符。您甚至可以在返回视图之前进行检查。
-
可以,但是如何进行单元测试呢?
标签: c# asp.net-mvc asp.net-mvc-3 ef-code-first mstest