Beispiel #1
0
        public async Task <(TestRunResponse, bool isNew, ServiceError)> ReplaceTestRun(
            int sessionId, int testRunId, TestRunRequest testRunRequest)
        {
            var testRun = await _dbService.Query <TestRun>(testRunId).Include(r => r.ExtraData).FirstOrDefaultAsync();

            bool isNew;

            if (testRun == null)
            {
                isNew   = true;
                testRun = testRunRequest.ToDataModel(sessionId);
                _dbService.Add(testRun);
            }
            else
            {
                isNew = false;
                if (testRun.TestRunSessionId != sessionId)
                {
                    return(null, false, ServiceError.NotFound($"TestRun with Id of {testRunId} does not belong to session {sessionId}."));
                }
                testRunRequest.Update(testRun);
            }
            await _dbService.SaveChangesAsync();

            return(testRun.ToResponse(), isNew, null);
        }
Beispiel #2
0
        public async Task <(TestRunResponse, ServiceError)> DeleteTestRunAsync(int sessionId, int testRunId)
        {
            var testRun = await _dbService.Query <TestRun>(testRunId).FirstOrDefaultAsync();

            if (testRun == null)
            {
                return(null, ServiceError.NotFound(null));
            }
            if (testRun.TestRunSessionId != sessionId)
            {
                return(null, ServiceError.NotFound($"TestRun with Id of {testRunId} does not belong to session {sessionId}."));
            }
            await _dbService.DeleteAsync(testRun);

            return(testRun.ToResponse(), ServiceError.NoError);
        }
Beispiel #3
0
        public async Task <(TestRunSessionResponse, ServiceError)> UpdateSessionAsync(int sessionId, Action <TestRunSessionRequest> sessionUpdater)
        {
            var session = await _dbService.Query <TestRunSession>(sessionId).Include(s => s.ExtraData).FirstOrDefaultAsync();

            if (session == null)
            {
                return(null, ServiceError.NotFound($"No TestRunSession with Id of {sessionId} found."));
            }
            var sessionRequest = session.ToRequest();

            sessionUpdater(sessionRequest);
            sessionRequest.Update(session);
            await _dbService.SaveChangesAsync();

            return(session.ToResponse(), null);
        }
Beispiel #4
0
        public async Task <(TestRunResponse, ServiceError)> UpdateTestRunAsync(
            int sessionId, int testRunId, Action <TestRunRequest> testRunUpdater)
        {
            var testRun = await _dbService.Query <TestRun>(testRunId).Include(r => r.ExtraData).FirstOrDefaultAsync();

            if (testRun == null)
            {
                return(null, ServiceError.NotFound($"No TestRun with Id of {testRunId} found."));
            }
            if (testRun.TestRunSessionId != sessionId)
            {
                return(null, ServiceError.NotFound($"TestRun with Id of {testRunId} does not belong to session {sessionId}."));
            }
            var testRunRequest = testRun.ToRequest();

            testRunUpdater(testRunRequest);
            testRunRequest.Update(testRun);
            await _dbService.SaveChangesAsync();

            return(testRun.ToResponse(), null);
        }