/// <summary> /// Adds the standard dummy users to the DB, uses NPOCO to save /// </summary> private void CreateDummyUsers() { var user = new IdentityUser(TestUserName) { NormalizedUserName = TestUserName, Email = TestUserEmail, NormalizedEmail = TestUserEmail, PasswordHash = TestUserPassword }; var user2 = new IdentityUser("Dont Use Me") { NormalizedUserName = "******", Email = "*****@*****.**", NormalizedEmail = "*****@*****.**", PasswordHash = "goaway" }; var dummyLogin = new UserLogin() { ProviderKey = "Dummy", LoginProvider = "LoginProvider", ProviderDisplayName = "DummyDontUse", UserId = user2.Id }; var role = new IdentityRole(TestRoleName) { NormalizedName = TestRoleName }; var testClaim = new UserClaim { ClaimType = TestClaimType, ClaimValue = TestClaimValue, UserId = user.Id }; using (var db = new Database(ConnectionString, ProviderName)) { db.Insert(user); db.Insert(user2); db.Insert(dummyLogin); db.Insert(role); db.Insert(testClaim); } _testUserId = user.Id; _testRoleId = role.Id; }
/// <summary> /// Get a specific UserLogin directly fromn the DB using ADO.NET rather than NPOCO. /// </summary> /// <param name="loginProvider">Login provider</param> /// <param name="providerKey">Provider key</param> /// <param name="userId">User ID</param> /// <returns>UserLogin or NULL</returns> public UserLogin GetUserLogin(string loginProvider, string providerKey, string userId) { UserLogin userLogin = null; using (var conn = new SqlConnection(ConnectionString)) using (var cmd = new SqlCommand("SELECT * FROM AspNetUserLogins WHERE LoginProvider = @provider AND ProviderKey = @providerKey AND UserId = @userId", conn)) { cmd.Parameters.AddWithValue("@provider", loginProvider); cmd.Parameters.AddWithValue("@providerKey", providerKey); cmd.Parameters.AddWithValue("@userId", userId); conn.Open(); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { int col = 0; userLogin = new UserLogin(); // Read in UserLogin data userLogin.LoginProvider = reader.GetString(col++); userLogin.ProviderKey = reader.GetString(col++); userLogin.ProviderDisplayName = reader.GetStringSafe(col++); userLogin.UserId = reader.GetStringSafe(col++); } } conn.Close(); } return userLogin; }