// ------------------------ Utility --------------------------- private (WebmailContext, GroupApiController) CreateTestTools(string name) { var context = CreateTestContext(name); var controller = new GroupApiController( new SqlGroupService(context), new SqlUserService(context, new SqlMessageService(context)) ) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal() } } }; return(context, controller); }
/// <summary> /// Setup the test /// </summary> public GroupApiUnitTest() { DbContextOptions <DbAppContext> options = new DbContextOptions <DbAppContext>(); Mock <DbAppContext> dbAppContext = new Mock <DbAppContext>(options); /* * * Here you will need to mock up the context. * * ItemType fakeItem = new ItemType(...); * * Mock<DbSet<ItemType>> mockList = MockDbSet.Create(fakeItem); * * dbAppContext.Setup(x => x.ModelEndpoint).Returns(mockItem.Object); * */ GroupApiService _service = new GroupApiService(dbAppContext.Object); _GroupApi = new GroupApiController(_service); }