Example #1
0
        public static void Main(string[] args)
        {
            // set up log4net
            XmlConfigurator.Configure(new FileInfo("log4net.config"));

            Console.Write("User: "******"Password: "******"Server: ");
            var server = Console.ReadLine();

            var rs = new RQMSession(server, user, password);

            if (!rs.LogIn())
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Unable to log in to RQM at {0} as \"{1}\".", server, user);
                Console.ReadKey();
                Console.ResetColor();
                return;
            }

            var rqmIdentity = rs.Identity();

            var fc = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Logged in as \"{0}\".", rqmIdentity.UserID);
            Console.WriteLine("Roles:");
            rqmIdentity.Roles.ToList().ForEach(a => Console.WriteLine("\t{0}", a));

            // show the user a project list too
            Console.ForegroundColor = fc;

            Console.WriteLine();
            var projects = rs.GetProjects().Select(a => a.Content).ToList();

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Available Projects");
            for (var i = 0; i < projects.Count; i++)
            {
                var p = projects[i];
                Console.WriteLine("{0}: {1}", i, p.Title);
                Console.WriteLine("(API Name: {0})", p.Aliases[0].Value);
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine("Done");
            Console.ReadKey();
        }
Example #2
0
        public static void Main(string[] args)
        {
            // set up log4net
            XmlConfigurator.Configure(new FileInfo("log4net.config"));

            Console.Write("User: "******"Password: "******"Server: ");
            var server = Console.ReadLine();

            var rs = new RQMSession(server, user, password);

            if (!rs.LogIn())
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Unable to log in to RQM at {0} as \"{1}\".", server, user);
                Console.ReadKey();
                Console.ResetColor();
                return;
            }

            var initial = DateTime.Now;

            var projects = rs.GetProjects().Select(a => a.Content).ToList();
            Parallel.ForEach(projects, p =>
            {
                using (var cache = new RQMCache())
                {
                    LocalProject lp;
                    if (!cache.LocalProjects.Any(a => a.ServerID == p.Identifier))
                    {
                        lp = cache.LocalProjects.Add(new LocalProject {
                            ServerID = p.Identifier,
                            APIName = p.Aliases[0].Value,
                            Name = p.Title,
                            ServerURL = server
                        });
                    }
                    else
                    {
                        lp = cache.LocalProjects.First(a => a.ServerID == p.Identifier);
                    }

                    cache.SaveChanges();

                    var apiName = lp.APIName;
                    var projectID = lp.ID;

                    #region Testcase Feed

                    var testcases = rs.GetArtifacts<TestCase>(apiName);
                    foreach (var tc in testcases.Where(a => a.Content != null).Select(a => a.Content).OrderBy(b => b.WebId).ToList())
                    {
                        Log.DebugFormat("==========================================================================");
                        Log.DebugFormat("Encountered Testcase ID {0} on {1}.", tc.WebId, server);
                        Log.DebugFormat("Name: {0}", tc.Title);
                        Log.DebugFormat("Description: {0}", tc.Description);

                        LocalTestcase ltc;
                        if (!cache.LocalTestcases.Any(a => a.ProjectID == projectID && a.WebID == tc.WebId))
                        {
                            Log.DebugFormat("We've never seen this test case before.");
                            ltc = cache.LocalTestcases.Add(new LocalTestcase {
                                Name = tc.Title,
                                Description = tc.Description,
                                WebID = tc.WebId,
                                URL = tc.Identifier,
                                ProjectID = projectID,
                            });
                            cache.SaveChanges();
                        }
                        else
                        {
                            ltc = cache.LocalTestcases.First(a => a.ProjectID == projectID && a.WebID == tc.WebId);
                        }

                        foreach (var tsReference in tc.TestScripts)
                        {
                            Log.DebugFormat("Attempting to download a test script from {0}.", tsReference.HREF);
                            var ts = rs.GetURLAs<TestScript>(tsReference.HREF);
                            if (ts == null)
                            {
                                Log.ErrorFormat("The URL {0} returned an object that could not be parsed as a test script.", tsReference.HREF);
                                continue;
                            }
                            Log.DebugFormat("Successfully downloaded test script ID {0} from {1}.", ts.WebId, tsReference.HREF);
                            Log.DebugFormat("Name: {0}", ts.Title);

                            LocalTestscript lts;
                            if (!cache.LocalTestscripts.Any(a => a.ProjectID == projectID && a.WebID == ts.WebId))
                            {
                                Log.DebugFormat("Testscript ID {0} was already in the system, but since it showed up here it's linked to at least one testcase.", ts.WebId);
                                lts = cache.LocalTestscripts.Add(new LocalTestscript { Name = ts.Title, ProjectID = projectID, WebID = ts.WebId, URL = tsReference.HREF });
                            }
                            else
                            {
                                lts = cache.LocalTestscripts.First(a => a.ProjectID == projectID && a.WebID == ts.WebId);
                            }
                            ltc.Testscripts.Add(lts);
                            cache.SaveChanges();
                        }

                    }
                    #endregion

                    #region Testscript Feed
                    var testscripts = rs.GetArtifacts<TestScript>(apiName).Where(a => a.Content != null).Select(a => a.Content).OrderBy(b => b.WebId).ToList();
                    foreach (var ts in testscripts)
                    {
                        if (ts == null)
                        {
                            Log.ErrorFormat("Null test script encountered.");
                            continue;
                        }
                        Log.DebugFormat("==========================================================================");
                        Log.DebugFormat("Encountered Testscript ID {0} on {1}.", ts.WebId, server);
                        Log.DebugFormat("Name: {0}", ts.Title);

                        if (!cache.LocalTestscripts.Any(a => a.WebID == ts.WebId && a.ProjectID == projectID))
                        {
                            Log.DebugFormat("Testscript ID {0} was not already in the system. This means it was not associated with any test cases.", ts.WebId);
                            cache.LocalTestscripts.Add(new LocalTestscript { Name = ts.Title, ProjectID = projectID, WebID = ts.WebId, URL = ts.Identifier });
                        }
                        cache.SaveChanges();
                    }
                    #endregion
                }
            });
            Console.WriteLine("Took {0} seconds.", DateTime.Now.Subtract(initial).TotalSeconds);
            Console.WriteLine("Done");
            Console.ReadKey();
        }
Example #3
0
        public static void Main(string[] args)
        {
            // set up log4net
            XmlConfigurator.Configure(new FileInfo("log4net.config"));

            Console.Write("User: "******"Password: "******"Server: ");
            var server = Console.ReadLine();

            var rqmSession = new RQMSession(server, user, password);

            if (!rqmSession.LogIn())
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Unable to log in to RQM at {0} as \"{1}\".", server, user);
                Console.ReadKey();
                Console.ResetColor();
                return;
            }
            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.BackgroundColor = ConsoleColor.Yellow;
            Console.WriteLine("The log4net logging output is sent to a file in this example.");

            Console.ResetColor();

            // 1. show the user a project list so they can pick a project for use with the later parts of this example.
            Console.WriteLine("Available Projects");
            var projects = rqmSession.GetProjects().Select(a => a.Content).ToList();
            for (var i = 0; i < projects.Count; i++)
            {
                var p = projects[i];
                Console.WriteLine("{0}: {1}", i, p.Title);
                Console.WriteLine("(API Name: {0})", p.Aliases[0].Value);
                Console.WriteLine();
            }

            Console.Write("Please enter the index of the project you want to work with (0-{0}):", projects.Count-1);
            var projectChoice = Convert.ToInt32(Console.ReadLine());
            var project = projects[projectChoice];
            var projectAPIName = project.Aliases[0].Value;
            var projectUIName = project.Title;
            Console.WriteLine("Chosen Project: #{0}: {1} (API Name: {2})", projectChoice, projectUIName, projectAPIName);

            var testPlans = rqmSession.GetArtifacts<TestPlan>(projectAPIName).Select(a => a.ID).ToList();
            Console.WriteLine("Test Plans:");
            for (var i = 0; i < Math.Min(testPlans.Count, 3); i++)
            {
                var testPlan = rqmSession.GetURLAs<TestPlan>(testPlans[i]);
                Console.WriteLine("{0}: {1}", i, testPlan.Title);
                Console.WriteLine("Test Phases:");
                var phases = rqmSession.GetPhasesForPlan(projectAPIName, testPlan.WebId);
                foreach (var phase in phases)
                {
                    Console.WriteLine("\t{0}", phase.Title);
                }
                Console.WriteLine();
            }

            var testcases = rqmSession.GetArtifacts<TestCase>(projectAPIName).Select(a => a.ID).ToList();
            Console.WriteLine("{0} testcases in the project.", testcases.Count);
            for (var i = 0; i < Math.Min(testcases.Count, 3); i++)
            {
                var testcase = rqmSession.GetURLAs<TestCase>(testcases[i]);

                Console.WriteLine("{0}: {1}", i, testcase.Title);
                Console.WriteLine("Test Scripts under this Test Case:");
                var scripts = rqmSession.GetScriptsForTestCase(projectAPIName, testcase.WebId);
                foreach (var script in scripts)
                {
                    Console.WriteLine("\t{0}", script.Title);
                }
                Console.WriteLine();
            }

            Console.Write("Please enter the UI ID of a testcase to download:");
            var tcID = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Attempting to download Testcase #{0}", tcID);
            var tc1 = rqmSession.GetArtifactByWebID<TestCase>(projectAPIName, tcID);
            Console.WriteLine("Testcase #{0} Name: \"{1}\"", tc1.WebId, tc1.Title);
            Console.WriteLine("Testcase #{0} ID: \"{1}\"", tc1.WebId, tc1.Identifier);

            Console.WriteLine();
            Console.WriteLine("Done");
            Console.ReadKey();
        }
Example #4
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            if (session != null)
            {
                btnLogIn.Text = "Log In";
                session = null;
                cbxRQMArtifacts.Enabled = false;
                txtRQMWebID.Enabled = false;
                btnDownload.Enabled = false;
                return;
            }

            lblLoading.Show();
            loadingSpinner.Show();
            btnLogIn.Enabled = false;

            if (string.IsNullOrWhiteSpace(txtRQMUser.Text))
            {
                MessageBox.Show("Please supply a user name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrWhiteSpace(txtRQMPassword.Text))
            {
                MessageBox.Show("Please supply a password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrWhiteSpace(txtRQMServer.Text))
            {
                MessageBox.Show("Please supply a server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var server = txtRQMServer.Text;
            var user = txtRQMUser.Text;
            var password = txtRQMPassword.Text;

            ThreadPool.QueueUserWorkItem(q => {
                session = new RQMSession(server, user, password);

                if (!session.LogIn())
                {
                    MessageBox.Show("Unable to log in to RQM.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                projects = session.GetProjects().Select(a => a.Content).ToList();

                cbxRQMProjects.Invoke(new MethodInvoker(() => {
                    cbxRQMProjects.Enabled = true;
                    cbxRQMProjects.DataSource = new BindingSource(projects.ToDictionary(a => a.Title, a => a.Aliases[0].Value), null);
                    cbxRQMProjects.DisplayMember = "Key";
                    cbxRQMProjects.ValueMember = "Value";
                }));

                cbxRQMArtifacts.Invoke(new MethodInvoker(() => cbxRQMArtifacts.Enabled = true));
                txtRQMWebID.Invoke(new MethodInvoker(() => txtRQMWebID.Enabled = true));
                btnDownload.Invoke(new MethodInvoker(() => btnDownload.Enabled = true));

                btnLogIn.Invoke(new MethodInvoker(() => {
                    btnLogIn.Enabled = true;
                    btnLogIn.Text = "Log Out";
                }));

                lblLoading.Invoke(new MethodInvoker(() => lblLoading.Hide()));
                loadingSpinner.Invoke(new MethodInvoker(() => loadingSpinner.Hide()));
            });
        }
Example #5
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            if (session != null)
            {
                btnLogIn.Text = "Log In";
                session = null;

                cbxProject.Enabled = false;
                cbxTestPlan.Enabled = false;
                cbxTestPhase.Enabled = false;

                numericTestcaseWebID.Enabled = false;

                txtAttachmentPath.Enabled = false;
                txtAttachmentPath.Text = "";

                txtComment.Enabled = false;
                txtComment.Text = "";

                btnBrowseAttachment.Enabled = false;
                btnUpload.Enabled = false;
                return;
            }

            lblLoading.Show();
            btnLogIn.Enabled = false;

            if (string.IsNullOrWhiteSpace(txtUsername.Text))
            {
                MessageBox.Show("Please supply a user name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                MessageBox.Show("Please supply a password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrWhiteSpace(txtServer.Text))
            {
                MessageBox.Show("Please supply a server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            session = new RQMSession(txtServer.Text, txtUsername.Text, txtPassword.Text);

            if (!session.LogIn())
            {
                MessageBox.Show("Unable to log in to RQM.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ThreadPool.QueueUserWorkItem(q => {
                projects = session.GetProjects().Select(a => a.Content).ToList();

                cbxProject.Invoke(new MethodInvoker(() => {
                    cbxProject.Enabled = true;
                    cbxProject.DataSource = new BindingSource(projects.ToDictionary(a => a.Title, a => a.Aliases[0].Value), null);
                    cbxProject.DisplayMember = "Key";
                    cbxProject.ValueMember = "Value";
                }));

                btnLogIn.Invoke(new MethodInvoker(() => {
                    btnLogIn.Enabled = true;
                    btnLogIn.Text = "Log Out";
                }));

                lblLoading.Invoke(new MethodInvoker(() => lblLoading.Hide()));
            });
        }