Esempio n. 1
0
    public void Run()
    {
      var toolNames = Program.ToolNames;
      string ltArg = Program.Args.Where(a => a.StartsWith(LtArgMarker)).SingleOrDefault();
      if (ltArg!=null) {
        ltArg = ltArg.Remove(0, LtArgMarker.Length);
        toolNames = ltArg.RevertibleSplit('/', ',').Distinct().ToList();;
      }

      string lucArg = Program.Args.Where(a => a==LucArgMarker).SingleOrDefault();
      if (lucArg!=null)
        updateComments = true;


      scorecard = new LinqScorecard();
      var tests = new List<LinqTestBase> {
        new BLToolkitTest(),
        new Linq2DbTest(),
        new EF6Test(), 
        //new DOTest(),
        //new LightSpeedTest(),
        //new LinqConnectTest(),
        new Linq2SqlTest(),
        new NHibernateTest(),
        //new OpenAccessTest(),
      };
      if (toolNames!=null)
        tests = (
          from test in tests
          let shortToolName = test.ShortToolName.ToLower()
          let toolIndex = toolNames.IndexOf(shortToolName) 
          where toolIndex>=0
          orderby toolIndex
          select test).ToList();
      if (tests.Count==0)
        return;
      tests.Add(new MaximumTest());
      foreach (var test in tests)
        scorecard.Tools.Add(test.ShortToolName);
      scorecard.Tools.Add(ToolTestBase.Unit);

      string sequenceName = "LINQ tests";
      Console.WriteLine("{0}:", sequenceName);

      bool firstTest = true;
      foreach (var test in tests) {
        test.Scorecard = scorecard;
        var total = 0;
        var failed = 0;
        var asserted = 0;
        var type = test.GetType();
        try {
          if (!(test is MaximumTest)) {
            var setupMethod = type.GetMethod("BaseSetup");
            setupMethod.Invoke(test, ArrayUtils<object>.EmptyArray);
          }
          foreach (var method in type.GetMethods().Where(mi => mi.IsDefined(typeof (TestAttribute), false))) {
            try {
              total++;
              if ((test is MaximumTest)) {
                LogResult(test, method, new Exception(), false);
                failed++;
                asserted++;
              }
              else {
                method.Invoke(test, ArrayUtils<object>.EmptyArray);
                LogResult(test, method, null, false);
              }
            }
            catch (Exception error) {
              failed++;
              error = EnumerableUtils.Unfold(error, e => e.InnerException).Last();
              bool isAssertion = error is AssertionException;
              asserted += isAssertion ? 1 : 0;
              LogResult(test, method, error, isAssertion);
            }
          }
        }
        catch (Exception e) {
          Console.WriteLine("  Failed: {0}", e);
          continue;
        }
        finally {
          if (firstTest) {
            firstTest = false;
            scorecard.Tests.Sort();
            scorecard.Tests.Insert(0, "LINQ Implementation:");
          }
          LogOverallResult(test, total, failed, asserted);
          var tearDownMethod = type.GetMethod("BaseTearDown");
          try {
            tearDownMethod.Invoke(test, ArrayUtils<object>.EmptyArray);
          }
          catch (Exception e) {
            Console.WriteLine("  BaseTearDown failed: {0}", e);
          }
        }
      }

      
      Console.WriteLine();
      Console.WriteLine("{0} scorecard:", sequenceName);
      
      Console.Write(scorecard);
      JsonWriter.Write(scorecard.ToJson(sequenceName, tests.ToArray<ToolTestBase>()));

      Console.WriteLine();
      Console.WriteLine("Units:");
      Console.WriteLine("  f/a: total count of failed tests [ / count of tests failed with assertion ],");
      Console.WriteLine("       less is better (0 is ideal);");
      Console.WriteLine("  #:   count;");
      Console.WriteLine("  %:   percentage (% of passed tests), more is better.");
      Console.WriteLine();
      Console.WriteLine();
    }
Esempio n. 2
0
        public void Run()
        {
            var    toolNames = Program.ToolNames;
            string ltArg     = Program.Args.Where(a => a.StartsWith(LtArgMarker)).SingleOrDefault();

            if (ltArg != null)
            {
                ltArg     = ltArg.Remove(0, LtArgMarker.Length);
                toolNames = ltArg.RevertibleSplit('/', ',').Distinct().ToList();;
            }

            string lucArg = Program.Args.Where(a => a == LucArgMarker).SingleOrDefault();

            if (lucArg != null)
            {
                updateComments = true;
            }


            scorecard = new LinqScorecard();
            var tests = new List <LinqTestBase> {
                new BLToolkitTest(),
                new Linq2DbTest(),
                new EFCoreTest(),
                new EF6Test(),
                //new DOTest(),
                //new LightSpeedTest(),
                //new LinqConnectTest(),
                new Linq2SqlTest(),
                new NHibernateTest(),
                //new OpenAccessTest(),
            };

            if (toolNames != null)
            {
                tests = (
                    from test in tests
                    let shortToolName = test.ShortToolName.ToLower()
                                        let toolIndex = toolNames.IndexOf(shortToolName)
                                                        where toolIndex >= 0
                                                        orderby toolIndex
                                                        select test).ToList();
            }
            if (tests.Count == 0)
            {
                return;
            }
            tests.Add(new MaximumTest());
            foreach (var test in tests)
            {
                scorecard.Tools.Add(test.ShortToolName);
            }
            scorecard.Tools.Add(ToolTestBase.Unit);

            string sequenceName = "LINQ tests";

            Console.WriteLine("{0}:", sequenceName);

            bool firstTest = true;

            foreach (var test in tests)
            {
                test.Scorecard = scorecard;
                var total    = 0;
                var failed   = 0;
                var asserted = 0;
                var type     = test.GetType();
                try {
                    if (!(test is MaximumTest))
                    {
                        var setupMethod = type.GetMethod("BaseSetup");
                        setupMethod.Invoke(test, ArrayUtils <object> .EmptyArray);
                    }
                    foreach (var method in type.GetMethods().Where(mi => mi.IsDefined(typeof(TestAttribute), false)))
                    {
                        try {
                            total++;
                            if ((test is MaximumTest))
                            {
                                LogResult(test, method, new Exception(), false);
                                failed++;
                                asserted++;
                            }
                            else
                            {
                                method.Invoke(test, ArrayUtils <object> .EmptyArray);
                                LogResult(test, method, null, false);
                            }
                        }
                        catch (Exception error) {
                            failed++;
                            error = EnumerableUtils.Unfold(error, e => e.InnerException).Last();
                            bool isAssertion = error is AssertionException;
                            asserted += isAssertion ? 1 : 0;
                            LogResult(test, method, error, isAssertion);
                        }
                    }
                }
                catch (Exception e) {
                    Console.WriteLine("  Failed: {0}", e);
                    continue;
                }
                finally {
                    if (firstTest)
                    {
                        firstTest = false;
                        scorecard.Tests.Sort();
                        scorecard.Tests.Insert(0, "LINQ Implementation:");
                    }
                    LogOverallResult(test, total, failed, asserted);
                    var tearDownMethod = type.GetMethod("BaseTearDown");
                    try {
                        tearDownMethod.Invoke(test, ArrayUtils <object> .EmptyArray);
                    }
                    catch (Exception e) {
                        Console.WriteLine("  BaseTearDown failed: {0}", e);
                    }
                }
            }


            Console.WriteLine();
            Console.WriteLine("{0} scorecard:", sequenceName);

            Console.Write(scorecard);
            JsonWriter.Write(scorecard.ToJson(sequenceName, tests.ToArray <ToolTestBase>()));

            Console.WriteLine();
            Console.WriteLine("Units:");
            Console.WriteLine("  f/a: total count of failed tests [ / count of tests failed with assertion ],");
            Console.WriteLine("       less is better (0 is ideal);");
            Console.WriteLine("  #:   count;");
            Console.WriteLine("  %:   percentage (% of passed tests), more is better.");
            Console.WriteLine();
            Console.WriteLine();
        }