public void LoginTestInitialize() { TestDbPopulator.PopulateUsers(2); TestDbPopulator.PopulateStandartAccounts(2); var config = new HttpConfiguration(); _controller = new LoginController(TestContext) { Request = new HttpRequestMessage() }; _controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; }
public void UserController_ShouldReturnCurrentUser() { TestDbPopulator.PopulateUsers(2); TestDbPopulator.PopulateStandartAccounts(2); _user = TestDbPopulator.GetUser(1); var req = new StandartAuthRequest { Email = _user.Email, Password = "******" }; string token = BaseAuth.CreateToken("u1"); var config = new HttpConfiguration(); var request = new HttpRequestMessage { RequestUri = new Uri("http://localhost:50268/api/User") }; request.Headers.Add("x-zumo-auth", token); request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; var username = "******"; var identity = new GenericIdentity(username, ""); var nameIdentifierClaim = new Claim(ClaimTypes.NameIdentifier, username); identity.AddClaim(nameIdentifierClaim); var principal = new GenericPrincipal(identity, new string[] {}); var user = new ClaimsPrincipal(principal); _controller = new UserApiController(TestContext) { Request = request, User = user }; var response = _controller.GetCurrentUser(); var result = TestHelper.ParseUserResponse(response); Assert.AreEqual("OK", result.StatusCode); }