public void TestInitialize() { // Create mock repository - will be empty unless setup in test methods below _mockRepository = new Mock <ICoopRepository>(); // Create a moq unit of work var mockUoW = new Mock <IUnitOfWork>(); // because we are unit testing the controller, we don't want to couple to the real UnitOfWork which uses EntityFramework to talk to the db mockUoW.SetupGet(u => u.Coops).Returns(_mockRepository.Object); // * --> when we access the Coops property of UoW, we get the mock repository * // Create the controller (*references the Api controller) _controller = new CoopsController(mockUoW.Object); // the Object property is the actual mock implementation of IUnitOfWork // Set controller user w/ the generic principal object by calling extension method, passing in the userid/username we want to use _userId = "1"; _controller.MockCurrentUser(_userId, "*****@*****.**"); }
public void SetUp() { // Instantiate controller w/ a real unit of work that talks to the database (which requires a real ApplicationDbContext) _context = new ApplicationDbContext(); _controller = new CoopsController(new UnitOfWork(_context)); }