public async Task LocalSetup() { var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider(); var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger <UserManager <ApplicationUser> >(); UserStore <ApplicationUser> store = new UserStore <ApplicationUser>(_dbContext); _userManager = new UserManager <ApplicationUser>(store, null, new PasswordHasher <ApplicationUser>(), null, null, null, null, null, logger); _securityService = new SecurityService(_dbContext, _userManager, _roleManager); _securityController = new SecurityController(_securityService); SetUser(_securityController, _createdUser2.Entity.Id); _crew = _dbContext.Crews.Find(1); CrewService crewService = new CrewService(_dbContext, _mainEventProvider); CrewController crewController = new CrewController(crewService); await crewController.AddCrewLeaderAsync(_crew.Id, _createdUser2.Entity.Id); await _securityController.SetPoliciesAsync( new List <CrewPermissionsVm> { new CrewPermissionsVm { Name = "CheckInAdmin", Value = 0, CrewHasPermission = true }, new CrewPermissionsVm { Name = "CrewAdmin", Value = 1, CrewHasPermission = true } }, _crew.Id ); }
public async Task ShouldAddCrewLeader() { await CreateCrew(_crewName2); Crew crew2 = _dbContext.Crews.Find(2); CrewService crewService = new CrewService(_dbContext, _mainEventProvider); CrewController crewController = new CrewController(crewService); ActionResult <List <CrewMembersListVm> > result = await crewController.GetCrewLeadersAsync(crew2.Id); List <CrewMembersListVm> returnedCrewLeaders = (List <CrewMembersListVm>)((OkObjectResult)result.Result).Value; Assert.AreEqual(0, returnedCrewLeaders.Count); await crewController.AddCrewLeaderAsync(crew2.Id, _createdUser2.Entity.Id); result = await crewController.GetCrewLeadersAsync(crew2.Id); returnedCrewLeaders = (List <CrewMembersListVm>)((OkObjectResult)result.Result).Value; Assert.AreEqual(1, returnedCrewLeaders.Count); Assert.AreEqual(_createdUser2.Entity.Id, returnedCrewLeaders[0].Id); }