I edited and simplified this question a lot.
If I have this method on my HomeController:
public ActionResult Strangeness( int id )
{
StrangenessClass strangeness = null;
if( id == 1 )
{
strangeness = new StrangenessClass() { Name="Strangeness", Desc="Really weird behavior" };
}
return View( strangeness );
}
And this class:
public class StrangenessClass
{
public string Name { get; set; }
public string Desc { get; set; }
}
Why does this unit test not work?
[TestMethod]
public void Strangeness()
{
HomeController controller = new HomeController();
ViewResult result = controller.Strangeness( 1 ) as ViewResult;
var model = result.ViewData.Model;
result = controller.Strangeness( 2 ) as ViewResult;
model = result.ViewData.Model;
Assert.IsNull( model );
}
I understand that, as a rule, I will have one test to check the zero condition, and the other to check the good condition, but I ran into this problem when testing my deletion controller. In a delete test, I usually take a record, delete the record, and then try to extract it again. It should be zero the second time I get it, but it is not. So, I boiled the problem as described above.
If this is not the right way to test deletions, how would you do it? You do not need to make sure that the record is really deleted?