Beispiel #1
0
        public static List <TestSuiteMethod> GetTestRunOptions(ApplicationEnvironment applicationEnvironment)
        {
            List <TestSuiteMethod> testRunOptions   = new List <TestSuiteMethod>();
            List <string>          testSuiteClasses = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
                                                      .Where(x => typeof(ITestSuite).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract)
                                                      .Select(x => x.FullName).ToList();
            int methodOrder = 1;

            foreach (string testSuiteClassName in testSuiteClasses)
            {
                Type              testSuiteType    = Type.GetType(testSuiteClassName);
                ConstructorInfo   constructor      = testSuiteType.GetConstructor(Type.EmptyTypes);
                object            magicClassObject = constructor.Invoke(new object[] { });
                List <MethodInfo> methodInfos      = testSuiteType.GetMethods(BindingFlags.Public | BindingFlags.Instance)
                                                     .Where(m => m.DeclaringType != typeof(object)).ToList();
                foreach (MethodInfo methodInfo in methodInfos)
                {
                    TestSuiteMethod testSuiteMethod = new TestSuiteMethod();
                    testSuiteMethod.Title     = $"{testSuiteType.Name} => {methodInfo.Name}";
                    testSuiteMethod.Order     = methodOrder;
                    testSuiteMethod.TaskToRun = delegate
                    {
                        object[] parameters = { applicationEnvironment };
                        methodInfo.Invoke(magicClassObject, parameters);
                    };
                    testRunOptions.Add(testSuiteMethod);
                    methodOrder++;
                }
            }
            return(testRunOptions);
        }
Beispiel #2
0
        // ReSharper disable once FunctionRecursiveOnAllPaths
        public static void Main(string[] args)
        {
            Guid guid = Guid.NewGuid();

            Console.WriteLine(@"Choose an option below:");
            Console.WriteLine();
            Console.WriteLine($"SessionId: {guid}");
            Console.WriteLine($"Application Environment: {applicationEnvironment}");
            Console.WriteLine();
            // list options
            List <TestSuiteMethod> testRunOptions = TestRunManager.GetTestRunOptions(applicationEnvironment);

            foreach (TestSuiteMethod testRunOption in testRunOptions)
            {
                Console.WriteLine($"{testRunOption.Order}- {testRunOption.Title} ({testRunOption.Order})");
            }
            // pick an option
            string option = Console.ReadLine();
            int    optionInt;

            int.TryParse(option, out optionInt);
            TestSuiteMethod actionToRun = testRunOptions.FirstOrDefault(q => q.Order.Equals(optionInt));

            if (actionToRun == null)
            {
                Console.WriteLine();
                Console.WriteLine($"Invalid option: {option}");
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine($"===================================================");
                Console.WriteLine($"Executing: {actionToRun.Order}- {actionToRun.Title}");
                Console.WriteLine($"SessionId: {guid}");
                Console.WriteLine($"===================================================");
                Console.WriteLine();
                try
                {
                    actionToRun.TaskToRun.Invoke();
                    Console.WriteLine();
                    Console.WriteLine($"===================================================");
                    Console.WriteLine($"Executed: {actionToRun.Order}- {actionToRun.Title}");
                    Console.WriteLine($"SessionId: {guid}");
                    Console.WriteLine($"===================================================");
                    Console.WriteLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            Console.WriteLine();
            Console.WriteLine();
            Main(null);
            Console.ReadLine();
        }