using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using TCMSDAL.DTO; using TCMSDAL.Interfaces; using TCMSDAL.QueryBuilders; namespace TCMSDAL.Implementations; public class TCMSTestRunDAL : ITCMSTestRunDAL { private readonly IQueryExecutor _QueryExecutor; public TCMSTestRunDAL(IQueryExecutor queryExecutor) { _QueryExecutor = queryExecutor; } public async Task GetTestRunAsync( int testRunId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QuerySingleAsync( login, TCMSTestRunQB.GET_TESTRUN, new { TestRunId = testRunId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); public async Task> GetTestRunListAsync( int? projectId, int? moduleId, string? runType, string? status, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryAsync( login, TCMSTestRunQB.GET_TESTRUN_LIST, new { TenantId = login.ClientId, ProjectId = projectId, ModuleId = moduleId, RunType = runType, Status = status }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); public async Task> GetRunResultsAsync( int testRunId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryAsync( login, TCMSTestRunQB.GET_RUN_RESULTS, new { TestRunId = testRunId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); public async Task> GetDashboardAsync( int? projectId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryAsync( login, TCMSTestRunQB.GET_DASHBOARD, new { TenantId = login.ClientId, ProjectId = projectId }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); public async Task SaveTestRunAsync( TCMSTestRunDTO dto, LoginDTO login, CancellationToken ct) => await _QueryExecutor.ExecuteIdentityAsync( login, TCMSTestRunQB.SAVE_TESTRUN, new { dto.RunCode, dto.RunName, dto.ProjectId, dto.ModuleId, dto.RunType, dto.SuiteType, dto.Status, dto.LeadExecutor, dto.ScheduledStart, dto.ScheduledEnd, TenantId = login.ClientId, CreatedBy = login.UserId }).ConfigureAwait(false); public async Task UpdateTestRunStatusAsync( int testRunId, string status, int modifiedBy, LoginDTO login, CancellationToken ct) => await _QueryExecutor.ExecuteAsync( login, TCMSTestRunQB.UPDATE_TESTRUN_STATUS, new { TestRunId = testRunId, Status = status, ModifiedBy = modifiedBy, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); public async Task UpsertRunResultAsync( TCMSRunResultDTO dto, LoginDTO login, CancellationToken ct) => await _QueryExecutor.ExecuteAsync( login, TCMSTestRunQB.UPSERT_RUN_RESULT, new { dto.TestRunId, dto.TestCaseId, dto.Result, dto.FailureReason, dto.Screenshot, dto.Notes, dto.ExecutionMs, dto.ExecutedBy, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); public async Task GetNextRunSequenceAsync( LoginDTO login, CancellationToken ct) => await _QueryExecutor.ExecuteScalarAsync( login, TCMSTestRunQB.GET_NEXT_RUN_SEQUENCE, new { TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); }