Ejemplo n.º 1
0
        private void UpdateDatabase()
        {
            SetLoading(true);
            var testCasesCount = 0;

            testCasesCountLbl.Invoke((MethodInvoker) delegate
            {
                testCasesCountLbl.Text = "updating...";
            });
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Parallel.ForEach(SelectedSuites, new ParallelOptions {
                MaxDegreeOfParallelism = Threads
            }, suite =>
            {
                var testCases  = _trr.GetTestCases(ProjectId, Int32.Parse(suite));
                var exceptions = new ConcurrentQueue <Exception>();
                Parallel.ForEach(testCases, new ParallelOptions {
                    MaxDegreeOfParallelism = Threads
                }, testCase =>
                {
                    try
                    {
                        var id = (int)testCase["id"];
                        var customOriginalId       = "";
                        var jTokenCustomOriginalId = testCase["custom_custom_original_id"];
                        if (jTokenCustomOriginalId != null)
                        {
                            if (jTokenCustomOriginalId.Type != JTokenType.Null)
                            {
                                customOriginalId = jTokenCustomOriginalId.ToString();
                            }
                        }
                        var title             = testCase["title"].ToString();
                        var sectionId         = (int)testCase["section_id"];
                        var sectionName       = GetSectionName(sectionId);
                        int milestoneId       = -1;
                        var jTokenMilestoneId = testCase["milestone_id"];
                        if (jTokenMilestoneId != null)
                        {
                            if (jTokenMilestoneId.Type != JTokenType.Null)
                            {
                                milestoneId = (int)jTokenMilestoneId;
                            }
                        }
                        var suiteId                    = (int)testCase["suite_id"];
                        var suiteName                  = GetSuiteName(suiteId);
                        var customCustomStatusId       = -1;
                        var jTokenCustomCustomStatusId = testCase["custom_custom_status"];
                        if (jTokenCustomCustomStatusId != null)
                        {
                            if (jTokenCustomCustomStatusId.Type != JTokenType.Null)
                            {
                                customCustomStatusId = (int)jTokenCustomCustomStatusId;
                            }
                        }
                        var customCustomStatusName              = GetStatusName(customCustomStatusId);
                        List <int> customCustomTestTypeIds      = new List <int>();
                        var jTokenCustomCustomCustomTestTypeIds = testCase["custom_custom_test_type"];
                        if (jTokenCustomCustomCustomTestTypeIds != null)
                        {
                            if (jTokenCustomCustomCustomTestTypeIds.Type != JTokenType.Null)
                            {
                                customCustomTestTypeIds = jTokenCustomCustomCustomTestTypeIds.ToObject <List <int> >();
                            }
                        }
                        var customCustomTestTypeName   = GetTestTypeName(customCustomTestTypeIds);
                        List <int> customCustomTagsIds = new List <int>();
                        var jTokenCustomCustomTagsIds  = testCase["custom_custom_tags"];
                        if (jTokenCustomCustomTagsIds != null)
                        {
                            if (jTokenCustomCustomTagsIds.Type != JTokenType.Null)
                            {
                                customCustomTagsIds = jTokenCustomCustomTagsIds.ToObject <List <int> >();
                            }
                        }
                        var customCustomTagsName = GetTagName(customCustomTagsIds);
                        var customAssigneeId     = -1;
                        var jTokenAssigneeId     = testCase["custom_assignee"];
                        if (jTokenAssigneeId != null)
                        {
                            if (jTokenAssigneeId.Type != JTokenType.Null)
                            {
                                customAssigneeId = (int)jTokenAssigneeId;
                            }
                        }
                        var customAssigneeName = GetAssigneeName(customAssigneeId);
                        var notes       = "";
                        var jTokenNotes = testCase["custom_notes"];
                        if (jTokenNotes != null)
                        {
                            if (jTokenNotes.Type != JTokenType.Null)
                            {
                                notes = jTokenNotes.ToString().ToLower();
                            }
                        }
                        var preconds       = "";
                        var jTokenPreconds = testCase["custom_preconds"];
                        if (jTokenPreconds != null)
                        {
                            if (jTokenPreconds.Type != JTokenType.Null)
                            {
                                preconds = jTokenPreconds.ToString().ToLower();
                            }
                        }
                        var customComments = "";
                        var jTokenComments = testCase["custom_custom_comments"];
                        if (jTokenComments != null)
                        {
                            if (jTokenComments.Type != JTokenType.Null)
                            {
                                customComments = jTokenComments.ToString().ToLower();
                            }
                        }
                        List <string> steps     = new List <string>();
                        List <string> expecteds = new List <string>();
                        var stepsInString       = "";
                        var expectedsInString   = "";
                        var jTokenCustomSteps   = testCase["custom_steps_separated"];
                        if (jTokenCustomSteps != null)
                        {
                            if (jTokenCustomSteps.Type != JTokenType.Null)
                            {
                                foreach (var step in jTokenCustomSteps)
                                {
                                    steps.Add((string)step["content"]);
                                    expecteds.Add((string)step["expected"]);
                                }
                                stepsInString     = String.Join(", ", steps.ToArray()).ToLower();
                                expectedsInString = String.Join(", ", expecteds.ToArray()).ToLower();
                            }
                        }

                        var dbs = new DatabaseServer(DatabaseFilePath, TestCasesCollectionName);

                        // Create your new Test Case instance
                        var testCaseDocument = new TestCase();
                        testCaseDocument.SetProperties(
                            id,
                            customOriginalId,
                            title,
                            sectionId,
                            sectionName,
                            milestoneId,
                            suiteId,
                            suiteName,
                            customCustomStatusId,
                            customCustomStatusName,
                            customCustomTestTypeIds,
                            customCustomTestTypeName,
                            customCustomTagsIds,
                            customCustomTagsName,
                            customAssigneeId,
                            customAssigneeName,
                            notes,
                            preconds,
                            stepsInString,
                            expectedsInString,
                            customComments,
                            (int)testCase["updated_on"]
                            );

                        if (dbs.DocumentExists(TestCasesCollectionName, testCaseDocument.Id))
                        {
                            if (dbs.IsTestCaseUpdatable(testCaseDocument.Id, testCaseDocument.UpdatedOn))
                            {
                                dbs.UpdateDocument(testCaseDocument);
                            }
                        }
                        else
                        {
                            dbs.InsertDocument(testCaseDocument);
                        }

                        testCasesCountLbl.Invoke((MethodInvoker) delegate
                        {
                            testCasesCountLbl.Text = (++testCasesCount).ToString();
                        });
                    }
                    catch (Exception ex)
                    {
                        exceptions.Enqueue(ex);
                    }
                });

                if (exceptions.Count > 0)
                {
                    try
                    {
                        throw new AggregateException(exceptions);
                    }
                    catch (AggregateException exs)
                    {
                        foreach (var ex in exs.InnerExceptions)
                        {
                            Program.LogException(ex);
                        }
                        MessageBox.Show(@"Cannot update DB properly, see log file.");
                    }
                }
            });

            sw.Stop();
            Console.WriteLine(@"Update took: " + sw.Elapsed.ToString("ss") + @"s");

            SetLoading(false);

            try
            {
                Thread threadInput = new Thread(CountTestCases);
                threadInput.Start();
            }
            catch (Exception ex)
            {
                Program.LogException(ex);
            }
        }
Ejemplo n.º 2
0
        private void TestRailSearcher_Load(object sender, EventArgs e)
        {
            LoginForm loginForm = new LoginForm();

            if (loginForm.ShowDialog() != DialogResult.OK)
            {
                this.Close();
            }

            // Set window location
            if (Settings.Default.WindowLocation != null)
            {
                this.Location = Settings.Default.WindowLocation;
            }

            // Set window size
            if (Settings.Default.WindowSize != null)
            {
                this.Size = Settings.Default.WindowSize;
            }

            this._server   = loginForm.serverTxt.Text;
            this._user     = loginForm.loginTxt.Text;
            this._password = loginForm.passwordTxt.Text;

            loginLabel.Text = this._user;
            searchTxt.Text  = "";
            SetLoading(false);

            _trr        = new TestRailReader(this._server, this._user, this._password);
            _caseFields = _trr.GetCaseFields();
            GetAssignees();

            var projects = _trr.GetProjects();

            foreach (var project in projects)
            {
                ComboboxItem item = new ComboboxItem();
                item.Text  = (string)project["name"];
                item.Value = project["id"];
                projectsCmb.Items.Add(item);
            }

            var dbs   = new DatabaseServer(DatabaseFilePath, AdminCollectionName);
            var admin = dbs.GetAdmin();
            var index = 0;

            foreach (var projectsCmbItem in projectsCmb.Items)
            {
                if (((ComboboxItem)projectsCmbItem).Value.ToString().Equals(admin.ProjectId.ToString()))
                {
                    projectsCmb.SelectedIndex = index;
                    SetLoading(true);
                    FillSuites();
                    GetSections();
                    GetStatusesAndTestTypesAndTags();
                    SetLoading(false);
                    break;
                }
                index++;
            }

            testCasesDataGridView.Columns.Add("Suite", "Suite");
            testCasesDataGridView.Columns.Add("ID", "ID");
            testCasesDataGridView.Columns.Add("Category", "Category");
            testCasesDataGridView.Columns.Add("Title", "Title");
            testCasesDataGridView.Columns.Add("Original ID", "Original ID");
            testCasesDataGridView.Columns.Add("Test Type", "Test Type");
            testCasesDataGridView.Columns.Add("Tags", "Tags");
            testCasesDataGridView.Columns.Add("Status", "Status");
            testCasesDataGridView.Columns.Add("Assignee", "Assignee");

            this.Text = Program.VersionLabel;
            loginForm.Close();
        }