Beispiel #1
0
    public async Task<TestRun> Run(TestContext context)
    {
      var start = DateTime.Now;
      var st = Stopwatch.StartNew();
      int i = 0;
      try
      {
        TestRun result = null;

        for (i = 0; i < _commands.Count; i++)
        {
          try
          {
            await _commands[i].Run(context);
          }
          catch (AssertionFailedException ex)
          {
            if (result == null)
              result = new TestRun()
              {
                Name = this.Name,
                Result = TestResult.Fail,
                Start = start,
                ErrorLine = i + 1,
                Message = ex.Message
              };
          }
        }

        if (result == null)
          return new TestRun()
          {
            Name = this.Name,
            Result = TestResult.Pass,
            ElapsedMilliseconds = st.ElapsedMilliseconds,
            Start = start
          };

        result.ElapsedMilliseconds = st.ElapsedMilliseconds;
        return result;
      }
      catch (Exception ex)
      {
        return new TestRun()
        {
          Name = this.Name,
          Result = TestResult.Fail,
          ElapsedMilliseconds = st.ElapsedMilliseconds,
          Start = start,
          ErrorLine = i + 1,
          Message = ex.Message
        };
      }
      finally
      {
        context.LastResult = null;
      }
    }
Beispiel #2
0
        public async Task <TestRun> Run(TestContext context)
        {
            var start = DateTime.Now;
            var st    = Stopwatch.StartNew();
            int i     = 0;

            try
            {
                TestRun result = null;

                using (context.StartSubProgress())
                {
                    for (i = 0; i < _commands.Count; i++)
                    {
                        context.ReportProgress(i, _commands.Count, "Running test '" + this.Name + "'...");
                        try
                        {
                            await _commands[i].Run(context);
                        }
                        catch (AssertionFailedException ex)
                        {
                            if (result == null)
                            {
                                result = new TestRun()
                                {
                                    Name      = this.Name,
                                    Result    = TestResult.Fail,
                                    Start     = start,
                                    ErrorLine = i + 1,
                                    Message   = ex.Message
                                }
                            }
                            ;
                        }
                    }
                }

                if (result == null)
                {
                    return new TestRun()
                           {
                               Name   = this.Name,
                               Result = TestResult.Pass,
                               ElapsedMilliseconds = st.ElapsedMilliseconds,
                               Start = start
                           }
                }
                ;

                result.ElapsedMilliseconds = st.ElapsedMilliseconds;
                return(result);
            }
            catch (Exception ex)
            {
                return(new TestRun()
                {
                    Name = this.Name,
                    Result = TestResult.Fail,
                    ElapsedMilliseconds = st.ElapsedMilliseconds,
                    Start = start,
                    ErrorLine = i + 1,
                    Message = ex.Message
                });
            }
            finally
            {
                context.LastResult = null;
            }
        }