How do I unit test that the journal entry was created correctly (added to the db with the correct values)?
[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);
}
You should not unit test against a real DbContext instance.
Your unit tests should instead mockup interfaces and inject them into the controller.
For example:
Your interface would look something like this:
You could unit test this like so (using Moq):