I have a method that takes an object and stores it in a database. But, before I save the object, I do the following ...
(psuedo code)
if (IsAuthenticated)
{
foo.UserId = AuthenticatedUser.Id;
}
else
{
foo.AnonEmail = "Jon@World-Domination";
foo.AnonName = "Jon Skeet";
}
try
{
_fooService.Save(foo);
}
catch
{
return View(...); ViewData.ModelState.
}
return RedirectToAction(...);
This code works fine, but I'm not sure how to write two unit tests for success. a) The user is authenticated with reliable data b) The user is not authenticated with reliable data.
The reason I'm not sure what to do is because both scripts return the same RedirectToAction (..) view object. Therefore, I can successfully test this. But it doesn’t tell me if the object contains the stored user ID or anonymous information. I like the first unit test to say
- authenticate user
- call method
- test, RedirectToActionView
- , foo, , moq'd.
?
Update
, fooService. Dependency Injection Moq, - , Moq? , DI , ???