private async Task <(Sensor, Sensor)> SeedDefaultCaseAsync() { var roleManager = IdentityHelpers.BuildRoleManager(ApplicationDbContextHelper.BuildTestDbContext()); await roleManager.CreateAsync(new IdentityRole <long>("Admin")); foreach (var userName in new[] { "normal-user-1", "normal-user-2", "normal-user-3", "admin-user" }) { await _userManager.CreateAsync(new User { UserName = userName, NormalizedUserName = userName.ToUpperInvariant(), SecurityStamp = Guid.NewGuid().ToString() }, "normal-password"); } var admin = await _userManager.FindByNameAsync("admin-user"); await _userManager.AddToRoleAsync(admin, "Admin"); var deviceName = "device"; var device = new Device { Name = deviceName, NormalizedName = deviceName.ToUpperInvariant(), AuthenticationType = DeviceAuthenticationType.PreSharedKey, PreSharedKey = "key" }; _dbContext.Devices.Add(device); var name1 = "sensor-1"; var sensor1 = new Sensor { Name = name1, NormalizedName = name1.ToUpperInvariant(), Device = device }; _dbContext.Sensors.Add(sensor1); var name2 = "sensor-2"; var sensor2 = new Sensor { Name = name2, NormalizedName = name2.ToUpperInvariant(), Device = device }; _dbContext.Sensors.Add(sensor2); var user1 = await _userManager.FindByNameAsync("normal-user-1"); var user2 = await _userManager.FindByNameAsync("normal-user-2"); _dbContext.UserSensors.Add(new UserSensor { UserId = user1.Id, Sensor = sensor1 }); _dbContext.UserSensors.Add(new UserSensor { UserId = user1.Id, Sensor = sensor2 }); _dbContext.UserSensors.Add(new UserSensor { UserId = user2.Id, Sensor = sensor1 }); await _dbContext.SaveChangesAsync(); return(sensor1, sensor2); }
public DashboardServiceTest() { _initial = SystemClock.Instance.GetCurrentInstant(); _dbContext = ApplicationDbContextHelper.BuildTestDbContext(); _userManager = IdentityHelpers.BuildUserManager(ApplicationDbContextHelper.BuildTestDbContext()); _roleManager = IdentityHelpers.BuildRoleManager(ApplicationDbContextHelper.BuildTestDbContext()); _service = new DashboardService(_dbContext, _userManager); }
public UserManagementServiceTest() { _clock = new FakeClock(SystemClock.Instance.GetCurrentInstant()); _dbContext = ApplicationDbContextHelper.BuildTestDbContext(_clock); _userManager = IdentityHelpers.BuildUserManager(ApplicationDbContextHelper.BuildTestDbContext(_clock)); _roleManager = IdentityHelpers.BuildRoleManager(ApplicationDbContextHelper.BuildTestDbContext(_clock)); _service = new UserManagementService(_dbContext, _userManager, _roleManager, new NullLogger <UserManagementService>(), _clock); }