public async Task <TestCaseResponce> SaveAsync(TestCaseFile testCase)
        {
            if ((int)testCase.Type == 0)
            {
                return(new TestCaseResponce("Invalid input Test case file type, should be 1 - 5"));
            }
            try
            {
                await _testCaseRepository.AddAsync(testCase);

                await _unitOfWork.CompleteAsync();

                return(new TestCaseResponce(testCase));
            }
            catch (Exception ex)
            {
                _logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(SaveAsync), ex);
                // Do some logging stuff
                return(new TestCaseResponce($"An error occurred when saving the testcase: {ex.Message}"));
            }
        }
예제 #2
0
        /// <summary>
        /// Runs a test on the program.
        /// </summary>
        /// <param name="testCase">Test case to use</param>
        /// <returns>Success of the test</returns>
        public TestResult RunTest(TestCaseFile testCase)
        {
            testCase.LoadFiles(TemporaryDirectory + InputFileName);

            using (var app = new Process())
            {
                app.StartInfo.FileName         = base.ExecPath;
                app.StartInfo.WorkingDirectory = TemporaryDirectory;

                app.StartInfo.UseShellExecute = false;
                app.Start();

                var processExited = app.WaitForExit(5000);

                if (processExited == false)
                {
                    testCase.Results = TestResult.TimedOut;
                    return(testCase.Results);
                }
                else if (app.ExitCode != 0)
                {
                    testCase.Results = TestResult.BadExitCode;
                    return(testCase.Results);
                }

                string appOutput = File.ReadAllText(TemporaryDirectory + OutputFileName);

                bool correct = testCase.Answer(appOutput);
                if (correct)
                {
                    testCase.Results = TestResult.Correct;
                }
                else
                {
                    testCase.Results = TestResult.Incorrect;
                }

                return(testCase.Results);
            }
        }
예제 #3
0
 /// <summary>
 /// Adds a Test Case to the program.
 /// </summary>
 /// <param name="testCase">TestCase to add to the list.</param>
 /// <remarks>No need to preload test files, this will be done later by RunTest method.</remarks>
 public void AddTest(TestCaseFile testCase)
 {
     TestCases.Add(testCase);
 }
 /// <summary>
 /// Creates a success response.
 /// </summary>
 /// <param name="category">Saved category.</param>
 /// <returns>Response.</returns>
 public TestCaseResponce(TestCaseFile testCase) : this(true, string.Empty, testCase)
 {
 }
 private TestCaseResponce(bool success, string message, TestCaseFile testCase) : base(success, message)
 {
     Folder = testCase;
 }
예제 #6
0
 public void Remove(TestCaseFile testCase)
 {
     _context.TestCases.Remove(testCase);
 }
예제 #7
0
 public async Task AddAsync(TestCaseFile testCase)
 {
     await _context.TestCases.AddAsync(testCase);
 }