Reputation: 5157
I'm trying to write unit tests for the default MVC application. Since this application uses the EntityFramework, I suspect that I will need to modify the application to use a mock repository (Is this what people mean by "injecting"?)
So based off of the generated MVC app code, do I need to create a mock repository for both UserManager and UserStore?
[Authorize]
public class AccountController : Controller
{
public AccountController()
: this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
{
}
public AccountController(UserManager<ApplicationUser> userManager)
{
UserManager = userManager;
}
public UserManager<ApplicationUser> UserManager { get; private set; }
//
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null)
Upvotes: 0
Views: 160
Reputation: 6992
"Injecting" is completely different to mocking. And even mocking may not be the right choice of word here. Especially the context you are testing. It's a stub you dealing with if you are providing fake/canned answers to the SUT (system under test). Injection comes into play in different ways. Yes you would "inject" a stub or mock on unit testing context. But with DI (dependency injection) you would also inject real instances during execution using your DI framework if any.
If you are testing the Login method, yes you need to create stub or mock for user manager and or user store based on what you testing 'inject' those to you SUT.
Upvotes: 1