Ejemplo n.º 1
0
        private static void GetTestPlans(ITestManagementTeamProject testproject, int TeamId)
        {
            ITestPlanCollection plans = testproject.TestPlans.Query("Select * From TestPlan");

            List <TestPlan> testPlans = new List <TestPlan>();

            foreach (ITestPlan plan in plans)
            {
                TestPlan testPlan = new TestPlan();
                testPlan.TeamId        = TeamId;
                testPlan.TestPlanName  = plan.Name;
                testPlan.PlanId        = plan.Id;
                testPlan.TestCaseCount = 0;

                if (plan.RootSuite != null && plan.RootSuite.Entries.Count > 0)
                {
                    var Suites = GetPlanSuites(plan.RootSuite.Entries);
                    foreach (var suite in Suites)
                    {
                        suite.TestPlan = testPlan;
                        testPlan.TestSuites.Add(suite);
                    }
                }
                testPlans.Add(testPlan);
            }

            foreach (var item in testPlans)
            {
                item.TestCaseCount = item.TestSuites.Where(s => s.ParentSuite == -1).Sum(col => col.TotalTests);
            }

            DeleteTestSuitesFromDB(TeamId);

            foreach (var testPlan in testPlans)
            {
                db.TestPlans.Add(testPlan);
                db.Entry(testPlan).State = System.Data.Entity.EntityState.Added;
            }
            db.SaveChanges();
        }
        public static void UpdateWeeklyAutomationStatus(string FileName, int TeamId)
        {
            //Retrieve data from the excel file and store it in a dictionary
            Helpers.PopulateInCollectionFromExcel(FileName, TeamId);

            var db = new AutomationDashboardEntities();
            Dictionary <string, spGetCurrentStatusOfAutomationForATeam_Result> CurrentStatus = db.spGetCurrentStatusOfAutomationForATeam(TeamId).ToDictionary(e => e.ProductArea);
            List <AutomateData>   RowsToBeInserted           = new List <AutomateData>();
            List <WeeklyTriaging> WeeklyTriagingToBeInserted = new List <WeeklyTriaging>();
            var CurrentFriday = Helpers.GetPreviousFriday(DateTime.Now).AddDays(7);

            //Filter out the rows to be inserted
            foreach (var record in Helpers.automateData)
            {
                if (!CurrentStatus.ContainsKey(record.Key))
                {
                    //Insert this data in the database as this is a new entry which does not exist in the database
                    RowsToBeInserted.Add(record.Value);
                }
                else
                {
                    //check if there is progress in the field and insert only those fields in the database

                    spGetCurrentStatusOfAutomationForATeam_Result StatusFromDatabase = CurrentStatus[record.Key];
                    AutomateData StatusFromUser = record.Value;

                    if (StatusFromUser.NoOfAutomatedTestcases > StatusFromDatabase.NoOfAutomatedTestcases ||
                        StatusFromUser.NoOfTFSTestcase > StatusFromDatabase.NoOfTFSTestcase)
                    {
                        //only then select the record for insert
                        RowsToBeInserted.Add(StatusFromUser);
                    }
                }

                //check if any modifications is done to the triaging data in the excel
                var entry = db.WeeklyTriagings.FirstOrDefault(row => row.TeamId == TeamId && row.ProductArea == record.Key && row.Date == CurrentFriday.Date);

                if ((record.Value.NoOfTestCasesDebugged > 0 && entry == null) || (entry != null && entry.NoOfTestCasesDebugged < record.Value.NoOfTestCasesDebugged))
                {
                    WeeklyTriaging triaging = new WeeklyTriaging(TeamId, record.Key, CurrentFriday, record.Value.NoOfTestCasesDebugged);
                    WeeklyTriagingToBeInserted.Add(triaging);
                }
            }

            foreach (var record in RowsToBeInserted)
            {
                //if the record exists in the database then only update the existing one
                var entry = db.AutomateDatas.FirstOrDefault(row => row.TeamId == TeamId && row.ProductArea == record.ProductArea && row.date == record.date.Date);
                if (entry == null)
                {
                    db.AutomateDatas.Add(record);
                }
                else
                {
                    entry.NoOfAutomatedTestcases = record.NoOfAutomatedTestcases;
                    entry.NoOfTFSTestcase        = record.NoOfTFSTestcase;
                    db.Entry(entry).State        = EntityState.Modified;
                }

                db.SaveChanges();
            }

            foreach (var record in WeeklyTriagingToBeInserted)
            {
                var entry = db.WeeklyTriagings.FirstOrDefault(row => row.TeamId == TeamId && row.ProductArea == record.ProductArea && row.Date == CurrentFriday.Date);
                if (entry == null)
                {
                    db.WeeklyTriagings.Add(record);
                }
                else
                {
                    entry.NoOfTestCasesDebugged = record.NoOfTestCasesDebugged;
                    db.Entry(entry).State       = EntityState.Modified;
                }
                db.SaveChanges();
            }
        }