public async Task InitializeAsync(bool startWorker = true) { // The initialization requires administrative credentials (default) await new SqlOrchestrationService(this.OrchestrationServiceOptions).CreateIfNotExistsAsync(); // Enable multitenancy to isolate each test using low-privilege credentials await SharedTestHelpers.EnableMultitenancyAsync(); // The runtime will use low-privilege credentials this.testCredential = await SharedTestHelpers.CreateTaskHubLoginAsync(this.testName); this.OrchestrationServiceOptions = new SqlOrchestrationServiceSettings(this.testCredential.ConnectionString) { LoggerFactory = this.loggerFactory, }; // A mock orchestration service allows us to stub out specific methods for testing. this.OrchestrationServiceMock = new Mock <SqlOrchestrationService>(this.OrchestrationServiceOptions) { CallBase = true }; this.worker = new TaskHubWorker(this.OrchestrationServiceMock.Object, this.loggerFactory); if (startWorker) { await this.worker.StartAsync(); } this.client = new TaskHubClient(this.OrchestrationServiceMock.Object, loggerFactory: this.loggerFactory); }
public static async Task DropTaskHubLoginAsync(TestCredential credential) { // Drop the generated user information string userId = credential.UserId; await ExecuteSqlAsync($"ALTER ROLE dt_runtime DROP MEMBER [testuser_{userId}]"); await ExecuteSqlAsync($"DROP USER IF EXISTS [testuser_{userId}]"); // drop all the connections; otherwise, the DROP LOGIN statement will fail await ExecuteSqlAsync($"DECLARE @kill varchar(max) = ''; SELECT @kill = @kill + 'KILL ' + CAST(session_id AS varchar(5)) + ';' FROM sys.dm_exec_sessions WHERE original_login_name = 'testlogin_{userId}'; EXEC(@kill);"); await ExecuteSqlAsync($"DROP LOGIN [testlogin_{userId}]"); }