public void Setup() { var claim = new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", _userId.ToString()); Thread.CurrentPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim> { claim })); var connectionString = ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString; _context = new DataContext(connectionString); _facade = new LocationTypeFacade(_context, new LocationTypeValidator()); ODataHelper oDataHelper = new ODataHelper(); _controller = new LocationTypesController(oDataHelper, _facade); _controller.Request = new HttpRequestMessage(); _controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); // Setting the URI of the request here is needed for the API POST method to work _controller.Request.RequestUri = new Uri("http://tempuri.com"); /* * TODO: akrone - Taking on some Techincal Debt doing this, but pulling the Seeder into it's own project would need to * be merged into other development work going on for sprint 60 */ Seeder.SeedWithTestData(_context); }
public void Setup() { var userName = "******"; var controllerContext = new Mock <ControllerContext>(); controllerContext.SetupGet(cc => cc.HttpContext.User.Identity.Name).Returns(userName); controller = new LocationTypesController(new UserService(new FakeRepositories.TestUserRepository()), new LocationService(new FakeRepositories.FakeLocationRepository())); controller.ControllerContext = controllerContext.Object; }