Exemple #1
0
        /// <summary>
        /// Create new test suites. Bind each suite with corresponding build and assembly. Save suite in DB
        /// </summary>
        /// <param name="importedConfig"></param>
        /// <param name="assemblies"></param>
        /// <returns>Return updated test assemblies (bounded with suites)</returns>
        private List <TestAssembly> BindTestSuitesWithAssemblies(ImportConfigModel importedConfig,
                                                                 List <TestAssembly> assemblies)
        {
            foreach (var projectConfig in importedConfig.Projects)
            {
                foreach (var branchConfig in projectConfig.Branches)
                {
                    foreach (var testConfigAssembly in branchConfig.TestAssemblies)
                    {
                        var mappedSuites    = mapper.GetSuites(testConfigAssembly.TestSuites).ToList();
                        var currentAssembly = assemblies.Find(item => item.Name == testConfigAssembly.Name);

                        for (int index = 0; index < mappedSuites.Count(); index++)
                        {
                            var suite = mappedSuites[index];

                            suite.BuildId     = currentAssembly.BuildId;
                            suite.ParentObjId = currentAssembly.Id;
                            suite.Status      = ObjectStatus.InQueue;

                            suite.Id = TestSuiteRepository.Instance.Insert(suite).Value;
                        }

                        currentAssembly.TestSuites = mappedSuites.ToDictionary(item => item.Id, item => item);
                    }
                }
            }

            return(assemblies);
        }
Exemple #2
0
        /// <summary>
        /// Create new test assemblies. Bind each assembly with corresponding build and branch. Save assembly in DB
        /// </summary>
        /// <param name="importedConfig"></param>
        /// <param name="branches"></param>
        /// <returns>List of new bounded assemblies</returns>
        private List <TestAssembly> BindTestAssembliesWithBuilds(ImportConfigModel importedConfig,
                                                                 IEnumerable <Branch> branches)
        {
            var assemblies = new List <TestAssembly>();

            foreach (var project in importedConfig.Projects)
            {
                foreach (var branchConfig in project.Branches)
                {
                    var mappedAssemblies = mapper.GetAssemblies(branchConfig.TestAssemblies).ToList();
                    var assemblyBranch   = branches.FirstOrDefault(proj => proj.Name == branchConfig.Name);

                    for (int index = 0; index < mappedAssemblies.Count(); index++)
                    {
                        var mappedAssembly = mappedAssemblies[0];

                        mappedAssembly.ParentObjId = assemblyBranch.LatestBuildId;
                        mappedAssembly.BuildId     = assemblyBranch.LatestBuildId;
                        mappedAssembly.Status      = ObjectStatus.InQueue;

                        mappedAssembly.Id = TestAssemblyRepository.Instance.Insert(mappedAssembly).Value;
                    }

                    assemblies.AddRange(mappedAssemblies);
                }
            }

            return(assemblies);
        }
Exemple #3
0
        private List <Branch> BindBranchesWithProjects(ImportConfigModel importedConfig, List <Project> mappedProjects)
        {
            var branches = new List <Branch>();

            foreach (var mappedProject in mappedProjects)
            {
                if (!mappedProject.MainBranchId.HasValue)
                {
                    throw new Exception(new ErrorMessage()
                    {
                        Code             = ErrorMessage.ErorCode.ProjectDontHaveMainBranch,
                        ExceptionMessage =
                            $"Project '{mappedProject.Name}' don't have main branch. Please, manually specify for project which branch should be considered as main."
                    }.ToString());
                }


                var storedBranches   = BranchRepository.Instance.Find(new { ProjectId = mappedProject.Id });
                var importedBranches = mapper.GetBranches(importedConfig.Projects
                                                          .First(project => project.Name == mappedProject.Name).Branches).ToList();

                var mainBranch = BranchRepository.Instance.Get(mappedProject.MainBranchId.Value);
                var mainBranchBaselineScreenShots =
                    ScreenShotRepository.Instance.GetBaselineScreenShots(mainBranch.BaseLineId.Value);

                for (int index = 0; index < importedBranches.Count; index++)
                {
                    var importedBranch = importedBranches[index];
                    var storedBranchEqualWithImporedBranch =
                        storedBranches.FirstOrDefault(branch => branch.Name == importedBranch.Name);

                    if (storedBranchEqualWithImporedBranch != null)
                    {
                        importedBranch = storedBranchEqualWithImporedBranch;
                    }
                    else // if branch don't exist in DB, copy a baseline from main branch and screenshots from baseline
                    {
                        importedBranch.ProjectId = mappedProject.Id;
                        importedBranch.Id        = BranchRepository.Instance.Insert(importedBranch).Value;

                        var baseline = new BaseLine()
                        {
                            BranchId = importedBranch.Id
                        };
                        baseline.Id = BaseLineRepository.Instance.Insert(baseline).Value;

                        importedBranch.BaseLineId = baseline.Id;
                        BranchRepository.Instance.Update(importedBranch);

                        CopyScreenShotsFromMainBranchBaselineToNewBaseline(baseline, mainBranchBaselineScreenShots);
                    }

                    branches.Add(importedBranch);
                }
            }

            return(branches);
        }
Exemple #4
0
        /// <summary>
        /// Create new screenshots. Bind each screenshot with corresponding build, suite. Save test case in DB
        /// </summary>
        /// <param name="importedConfig"></param>
        /// <param name="branches"></param>
        /// <param name="assemblies"></param>
        private void BindScreenshotsWithTestCases(ImportConfigModel importedConfig, List <Branch> branches,
                                                  List <TestAssembly> assemblies)
        {
            foreach (var projectConfig in importedConfig.Projects)
            {
                foreach (var branchConfig in projectConfig.Branches)
                {
                    var currentBranch = branches.Find(item => item.Name == branchConfig.Name);

                    foreach (var testConfigAssembly in branchConfig.TestAssemblies)
                    {
                        var currentAssembly = assemblies.Find(item => item.Name == testConfigAssembly.Name);
                        foreach (var testSuiteConfig in testConfigAssembly.TestSuites)
                        {
                            var currentSuite =
                                currentAssembly.TestSuites.ToList()
                                .Find(item => item.Value.Name == testSuiteConfig.Name);
                            foreach (var testCaseConfig in testSuiteConfig.TestCases)
                            {
                                var currentCase =
                                    currentSuite.Value.TestCases.ToList()
                                    .Find(item => item.Value.Name == testCaseConfig.Name);

                                // Create all directories for the diff and preview screenshots
                                var pathToSaveScreenShotsDiffs =
                                    CreateDirectoryTree(Path.Combine(projectConfig.Name, currentBranch.Name,
                                                                     currentCase.Value.BuildId.ToString(), currentAssembly.Name,
                                                                     currentSuite.Value.Name, currentCase.Value.Name));

                                var screenShots = testCaseConfig.ScreenShots;

                                for (int index = 0; index < screenShots.Count; index++)
                                {
                                    var screenShot = screenShots[index];

                                    screenShot.BuildId     = currentCase.Value.BuildId;
                                    screenShot.ParentObjId = currentCase.Key;
                                    screenShot.BaseLineId  = currentBranch.BaseLineId.Value;
                                    screenShot.Status      = ObjectStatus.InQueue;

                                    screenShot.DiffImagePath   = pathToSaveScreenShotsDiffs.Item1;
                                    screenShot.DiffPreviewPath = pathToSaveScreenShotsDiffs.Item2;

                                    screenShot.Id = ScreenShotRepository.Instance.Insert(screenShot).Value;
                                }

                                currentCase.Value.ScreenShots = screenShots.ToDictionary(item => item.Id, item => item);
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Create new test cases. Bind each test case with corresponding build, suite. Save test case in DB
        /// </summary>
        /// <param name="importedConfig"></param>
        /// <param name="assemblies"></param>
        /// <returns></returns>
        private void BindTestCasesWithSuites(ImportConfigModel importedConfig, List <TestAssembly> assemblies)
        {
            // map cases
            // bind cases with suites
            // save cases in db

            foreach (var projectConfig in importedConfig.Projects)
            {
                foreach (var branchConfig in projectConfig.Branches)
                {
                    foreach (var testConfigAssembly in branchConfig.TestAssemblies)
                    {
                        var currentAssembly = assemblies.Find(item => item.Name == testConfigAssembly.Name);
                        foreach (var testSuiteConfig in testConfigAssembly.TestSuites)
                        {
                            var currentSuite =
                                currentAssembly.TestSuites.ToList()
                                .Find(item => item.Value.Name == testSuiteConfig.Name);
                            var mappedCases = mapper.GetCases(testSuiteConfig.TestCases).ToList();

                            for (int index = 0; index < mappedCases.Count; index++)
                            {
                                var testCase = mappedCases[index];
                                testCase.Status      = ObjectStatus.InQueue;
                                testCase.BuildId     = currentAssembly.BuildId;
                                testCase.ParentObjId = currentSuite.Key;

                                testCase.Id = TestCaseRepository.Instance.Insert(testCase).Value;
                            }

                            currentSuite.Value.TestCases = mappedCases.ToDictionary(item => item.Id, item => item);
                        }
                    }
                }
            }
        }
Exemple #6
0
        private string ValidateImportedConfigObjects(ImportConfigModel importedConfig)
        {
            var mapper         = new ConfigMapper();
            var mappedProjects = mapper.GetProjects(importedConfig.Projects).ToList();

            // validate projects
            var validationMessage = ConfigValidator.ValidateProjects(mappedProjects);

            if (validationMessage != "")
            {
                return(validationMessage);
            }

            // validate test assemblies
            foreach (var project in importedConfig.Projects)
            {
                foreach (var branchConfig in project.Branches)
                {
                    var assemblies = mapper.GetAssemblies(branchConfig.TestAssemblies);
                    validationMessage = ConfigValidator.ValidateTestAssemblies(assemblies.ToList());

                    if (validationMessage != "")
                    {
                        return(validationMessage);
                    }
                }
            }


            foreach (var project in importedConfig.Projects)
            {
                foreach (var branchConfig in project.Branches)
                {
                    //validate suites
                    foreach (var testAssemblyConfig in branchConfig.TestAssemblies)
                    {
                        var items = mapper.GetSuites(testAssemblyConfig.TestSuites);
                        validationMessage = ConfigValidator.ValidateTestSuites(items.ToList());

                        if (validationMessage != "")
                        {
                            return(validationMessage);
                        }


                        //validate cases
                        foreach (var testSuite in testAssemblyConfig.TestSuites)
                        {
                            var cases = mapper.GetCases(testSuite.TestCases);
                            validationMessage = ConfigValidator.ValidateTestCases(cases.ToList());

                            if (validationMessage != "")
                            {
                                return(validationMessage);
                            }


                            //validate screenshots
                            foreach (var testCase in testSuite.TestCases)
                            {
                                validationMessage = ConfigValidator.ValidateScreenshots(testCase.ScreenShots);

                                if (validationMessage != "")
                                {
                                    return(validationMessage);
                                }
                            }
                        }
                    }
                }
            }

            return("");
        }