async Task RemoveAdminTest() { //arrange var activeSub = new List <SnooNotes.Models.Subreddit>() { new SnooNotes.Models.Subreddit { Active = true, BotSettings = null, Settings = new SnooNotes.Models.SubredditSettings { AccessMask = 64 + (int)RedditSharp.ModeratorPermission.Wiki, NoteTypes = null }, SubName = "NotTheBestTest", SubredditID = 1 } }; var um = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); await serviceProvider.GetRequiredService <RoleManager <IdentityRole> >().CreateAsync(new IdentityRole("notthebesttest")); await um.CreateAsync(testUser); await um.AddToRoleAsync(testUser, "notthebesttest"); await um.AddClaimAsync(testUser, new Claim( "uri:snoonotes:admin", "notthebesttest" )); var subDAL = new Mock <SnooNotes.DAL.ISubredditDAL>(); subDAL.Setup(s => s.GetActiveSubs()).Returns(Task.FromResult(activeSub)); var util = new SnooNotes.Utilities.BaseAuthUtils(Configuration, um, null, null, subDAL.Object, agentPool, new RedditSharp.WebAgentPool <string, RedditSharp.BotWebAgent>()); //act await util.UpdateModeratedSubredditsAsync(testUser); //assert var endUser = await um.FindByNameAsync(testUser.UserName); var endUserRoles = await um.GetRolesAsync(endUser); var endUserClaims = await um.GetClaimsAsync(endUser); Assert.Single(endUserRoles); Assert.StrictEqual("notthebesttest", endUserRoles.SingleOrDefault()); Assert.Single(endUserClaims); Assert.True(endUserClaims.Single().Type == "uri:snoonotes:cabal" && endUserClaims.Single().Value == "true"); }
async Task NewUserTest() { //arrange var activeSub = new List <SnooNotes.Models.Subreddit>() { new SnooNotes.Models.Subreddit { Active = true, BotSettings = null, Settings = new SnooNotes.Models.SubredditSettings { AccessMask = 64, NoteTypes = null }, SubName = "GooAway", SubredditID = 1 } }; var um = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); await serviceProvider.GetRequiredService <RoleManager <IdentityRole> >().CreateAsync(new IdentityRole("gooaway")); await um.CreateAsync(testUser); var subDAL = new Mock <SnooNotes.DAL.ISubredditDAL>(); subDAL.Setup(s => s.GetActiveSubs()).Returns(Task.FromResult(activeSub)); var util = new SnooNotes.Utilities.BaseAuthUtils(Configuration, um, null, null, subDAL.Object, agentPool, new RedditSharp.WebAgentPool <string, RedditSharp.BotWebAgent>()); //act await util.UpdateModeratedSubredditsAsync(testUser); //assert var endUser = await um.FindByNameAsync(testUser.UserName); var endUserRoles = await um.GetRolesAsync(endUser); var endUserClaims = await um.GetClaimsAsync(endUser); Assert.Single(endUserRoles); Assert.StrictEqual("gooaway", endUserRoles.SingleOrDefault()); Assert.Single(endUserClaims, euc => euc.Type == "uri:snoonotes:admin" && euc.Value == "gooaway"); Assert.Single(endUserClaims, euc => euc.Type == "uri:snoonotes:cabal" && euc.Value == "true"); Assert.Equal(2, endUserClaims.Count); }