public List <Suite> GetSuites()
        {
            if (_client == null)
            {
                return(new List <Suite>());
            }

            return(_client.GetSuites(_testRailProjectId));
        }
Пример #2
0
        static void Main(string[] args)
        {
            //PrintCasesDependency();
            //return;
            var url    = System.Configuration.ConfigurationManager.AppSettings["testRailUrl"];
            var user   = System.Configuration.ConfigurationManager.AppSettings["testRailUser"];
            var apikey = System.Configuration.ConfigurationManager.AppSettings["testRailApiKey"];

            client = new TestRailClient(url, user, apikey);

            var ezbobProject = client.Projects.FirstOrDefault(x => x.Name == "EZbob");

            if (ezbobProject == null)
            {
                Console.WriteLine("Project EZbob was not found");
                Console.WriteLine("Project are:");
                foreach (var project in client.Projects)
                {
                    Console.WriteLine("Project {0}, id {1}", project.Name, project.ID);
                }

                return;
            }

            Console.WriteLine("Project found: {0}, id: {1}", ezbobProject.Name, ezbobProject.ID);
            Console.WriteLine();

            var configurationGroups      = client.GetConfigurationGroups(ezbobProject.ID);
            List <Configuration> configs = new List <Configuration>();

            foreach (var confGroup in configurationGroups)
            {
                Console.WriteLine("Configuration group: {0}, id {1}", confGroup.Name, confGroup.ID);
                foreach (var conf in confGroup.Configurations)
                {
                    Console.WriteLine("\tConfiguration: {0} id {1}", conf.Name, conf.ID);
                }
                Console.WriteLine("select {0} configuration id:", confGroup.Name);
                input = Console.ReadLine();
                ulong confID = 0;
                if (!ulong.TryParse(input, out confID))
                {
                    Console.WriteLine("wrong input");
                    return;
                }
                var selectedConf = confGroup.Configurations.FirstOrDefault(x => x.ID == confID);
                if (selectedConf != null)
                {
                    configs.Add(selectedConf);
                }
            }

            var suites = client.GetSuites(ezbobProject.ID);

            foreach (var s in suites)
            {
                Console.WriteLine("suit: {0}, id: {1}", s.Name, s.ID);
            }

            Console.Write("Select suit id:");
            input = Console.ReadLine();

            ulong suitId = 0;

            if (!ulong.TryParse(input, out suitId))
            {
                Console.WriteLine("wrong input");
                return;
            }

            var suit = suites.FirstOrDefault(x => x.ID == suitId);

            if (suit == null || !suit.ID.HasValue)
            {
                Console.WriteLine("suit {0} not found", suitId);
                return;
            }

            var cases = client.GetCases(ezbobProject.ID, suit.ID.Value);

            foreach (var c in cases)
            {
                string labels = c.Labels.Any() ? c.Labels.Select(x => x.ToString()).Aggregate((a, b) => a + ", " + b) : "";
                Console.WriteLine("case: {0}, id: {1} \n {2}", c.Title, c.ID, labels);
            }

            var milestones = client.GetMilestones(ezbobProject.ID);

            foreach (var m in milestones)
            {
                Console.WriteLine("milestone {0}, id {1}", m.Name, m.ID);
            }

            Console.Write("select milestone id:");
            input = Console.ReadLine();
            ulong milestoneId = 0;

            if (!ulong.TryParse(input, out milestoneId))
            {
                Console.WriteLine("wrong input");
                return;
            }

            var milestone = milestones.FirstOrDefault(x => x.ID == milestoneId);

            if (milestone == null)
            {
                Console.WriteLine("milestone {0} not found", milestoneId);
                return;
            }

            Console.Write("run all cases (Y/N):");
            input = Console.ReadLine();
            if (input != "Y" && input != "N")
            {
                Console.WriteLine("wrong input");
                return;
            }

            if (input == "Y")
            {
                RunAllCases(ezbobProject, suit, milestone);
            }
            else
            {
                List <Label> labels = cases.SelectMany(x => x.Labels).Distinct().ToList();
                foreach (var label in labels)
                {
                    Console.WriteLine("label {0}, id {1}", label.ToString(), (int)label);
                }
                Console.WriteLine("select label id:");
                input = Console.ReadLine();
                int labelID = 0;
                if (!int.TryParse(input, out labelID))
                {
                    Console.WriteLine("wrong input");
                    return;
                }
                Label selectedLabel = (Label)labelID;

                HashSet <ulong> selectedCases = cases.Where(x => x.Labels.Contains(selectedLabel) && x.ID.HasValue).Select(x => x.ID.Value).ToHashSet();
                if (selectedCases.Any())
                {
                    RunSelectedCases(ezbobProject, suit, milestone, selectedCases, selectedLabel, configs, configurationGroups);
                }
                else
                {
                    Console.WriteLine("No cases match your filter");
                    return;
                }
            }
        }