public IHttpActionResult Add([FromBody] TblTestQueueDto testQueueDto)
        {
            var result = new ResultMessage <TblTestQueueDto>();

            if (ModelState.IsValid)
            {
                return(this.AddUpdate(testQueueDto));
            }

            result.Messages.AddRange(this.ModelStateToMessage());

            return(this.CreateCustomResponse(result));
        }
Example #2
0
        /// <summary>
        /// Adds the update.
        /// </summary>
        /// <param name="testQueueDto">The testQueue dto.</param>
        /// <returns>
        /// Newly added object
        /// </returns>
        private IHttpActionResult AddUpdate(TblTestQueueDto testQueueDto)
        {
            var result = new ResultMessage <TblTestQueueDto>();

            try
            {
                if (testQueueDto.GroupName.IsBlank())
                {
                    testQueueDto.GroupName = DateTime.Now.ToGroupName();
                }

                result = this.testQueueService.SaveOrUpdate(testQueueDto, this.UserId);
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException(ex);
                result.Messages.Add(new Message(null, ex.Message));
            }

            return(this.CreateCustomResponse(result));
        }
        /// <summary>
        /// Adds the update.
        /// </summary>
        /// <param name="testQueueDto">The testQueue dto.</param>
        /// <returns>
        /// Newly added object
        /// </returns>
        private IHttpActionResult AddUpdate(TblTestQueueDto testQueueDto)
        {
            var result = new ResultMessage <TblTestQueueDto>();

            try
            {
                int repeatTimes = 1;

                if (testQueueDto.Settings != null && testQueueDto.Settings.RepeatTimes.HasValue)
                {
                    repeatTimes = testQueueDto.Settings.RepeatTimes.Value;

                    if (repeatTimes > 100)
                    {
                        repeatTimes = 100;
                    }
                }

                if (testQueueDto.GroupName.IsBlank())
                {
                    testQueueDto.GroupName = DateTime.Now.ToGroupName();
                }

                for (int i = 0; i < repeatTimes; i++)
                {
                    result = this.testQueueService.SaveOrUpdate(testQueueDto, this.UserId);
                }
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException(ex);
                result.Messages.Add(new Message(null, ex.Message));
            }

            return(this.CreateCustomResponse(result));
        }
        /// <summary>
        /// process test data to generate testplan
        /// </summary>
        /// <param name="testDataDto">the test data object</param>
        /// <param name="testQueue">the test queue object</param>
        /// <param name="deepIndex">Index of the deep.</param>
        public void ProcessTestQueueExecutableData(IEnumerable <TblTestDataDto> testDataDto, TblTestQueueDto testQueue, int deepIndex = 0)
        {
            if (testDataDto != null && testDataDto.Any())
            {
                bool breakParentLoop = false;

                foreach (var item in testDataDto)
                {
                    if (item.ActionId == ActionConstants.Instance.IgnoreLoadNeUrlActionId && this.testPlan.Any() && this.testPlan.Last().ActionId.Value == ActionConstants.Instance.LoadNewUrlActionId)
                    {
                        this.testPlan.Remove(this.testPlan.Last());
                        this.ExecutionSequence--;
                        continue;
                    }

                    switch (item.LinkTestType)
                    {
                    case (int)LinkTestType.TestStep:
                    {
                        if (item.ActionId.Value != ActionConstants.Instance.TerminateTestActionId)
                        {
                            item.ExecutionSequence = this.ExecutionSequence++;
                            this.testPlan.Add(item);
                        }
                        else
                        {
                            breakParentLoop = true;
                        }

                        break;
                    }

                    case (int)LinkTestType.ApiTestStep:
                    {
                        long environMentId;
                        if (testQueue.SchedulerId.HasValue)
                        {
                            ResultMessage <TblSchedulerDto> schedulerDto = this.schedulerService.GetById(testQueue.SchedulerId.Value);
                            environMentId = schedulerDto.Item.UrlId;
                            if (environMentId == 0)
                            {
                                environMentId = this.environmentService.GetDefaultEnvironment().Item.Id;
                            }
                        }
                        else
                        {
                            environMentId = testQueue.Settings.UrlId;
                            if (environMentId == 0)
                            {
                                environMentId = this.environmentService.GetDefaultEnvironment().Item.Id;
                            }
                        }

                        ResultMessage <TblApiConnectionDto> apiConnectionDto = this.apiConncetionService.GetByEnvironmentAndCategoryId(environMentId, item.ApiTestData.ApiCategoryId.Value);
                        item.ApiUrl = (item.ApiTestData.ApiUrl.IsBlank() ? apiConnectionDto.Item.BaseUrl : item.ApiTestData.ApiUrl).Trim();

                        if (item.ApiTestData.EndPoint.IsNotBlank())
                        {
                            item.ApiUrl += ((item.ApiUrl.EndsWith("\\") || item.ApiUrl.EndsWith("/")) ? string.Empty : "/") + item.ApiTestData.EndPoint;
                        }

                        item.Headers = item.ApiTestData.Headers ?? new List <NameValuePair>();

                        if (apiConnectionDto.Item.Headers != null)
                        {
                            foreach (var header in apiConnectionDto.Item.Headers)
                            {
                                if (!item.Headers.Any(x => x.Name.EqualsIgnoreCase(header.Name)))
                                {
                                    item.Headers.Add(header);
                                }
                            }
                        }

                        item.IgnoreHeaders     = item.ApiTestData.IgnoreHeaders;
                        item.RequestType       = item.ApiTestData.RequestName;
                        item.RequestBody       = item.ApiTestData.RequestBody;
                        item.ExecutionSequence = this.ExecutionSequence++;
                        this.testPlan.Add(item);
                        break;
                    }

                    case (int)LinkTestType.SqlTestStep:
                    {
                        item.ExecutionSequence = this.ExecutionSequence++;
                        this.testPlan.Add(item);
                        break;
                    }

                    case (int)LinkTestType.SharedTest:
                    {
                        var sharedSteps = item.SharedTest.SharedTestDataList.Where(x => !x.IsDeleted).OrderBy(x => x.ExecutionSequence).ToList();
                        foreach (var sharedStep in sharedSteps)
                        {
                            var lnkSharedTestStep = item.SharedTestSteps.FirstOrDefault(x => x.SharedTestDataId == sharedStep.Id && x.IsDeleted != true);
                            if (lnkSharedTestStep != null)
                            {
                                if (lnkSharedTestStep.NewOrder > 0)
                                {
                                    sharedSteps.Where(x => x.ExecutionSequence > lnkSharedTestStep.NewOrder).ToList().ForEach(x => x.ExecutionSequence++);
                                    sharedStep.ExecutionSequence = lnkSharedTestStep.NewOrder + 1;
                                }

                                if (!string.IsNullOrEmpty(lnkSharedTestStep.NewValue))
                                {
                                    sharedStep.Value = lnkSharedTestStep.NewValue;
                                }

                                if (!string.IsNullOrEmpty(lnkSharedTestStep.NewVariable))
                                {
                                    sharedStep.VariableName = lnkSharedTestStep.NewVariable;
                                }

                                sharedStep.IsIgnored = lnkSharedTestStep.IsIgnored ?? false;
                            }

                            if (sharedStep.ActionId == ActionConstants.Instance.TerminateTestActionId && !sharedStep.IsIgnored)
                            {
                                breakParentLoop = true;
                                break;
                            }
                        }

                        sharedSteps.RemoveAll(m => m.IsIgnored);
                        int indx = sharedSteps.IndexOf(sharedSteps.FirstOrDefault(m => m.ActionId == ActionConstants.Instance.TerminateTestActionId));

                        if (indx >= 0)
                        {
                            sharedSteps.RemoveRange(indx, sharedSteps.Count - indx);
                        }

                        var mapper = this.mapperFactory.GetMapper <TblSharedTestDataDto, TblTestDataDto>();
                        var sharedStepMappedWithTestData = sharedSteps.Select(mapper.Map).OrderBy(x => x.ExecutionSequence).ToList();

                        long es = this.ExecutionSequence;
                        sharedStepMappedWithTestData.ForEach(x => { x.ExecutionSequence = es++; x.IsStepBelongsToSharedComponent = true; x.Id = item.Id; });
                        this.ExecutionSequence = es;
                        this.testPlan.AddRange(sharedStepMappedWithTestData);
                        break;
                    }

                    case (int)LinkTestType.SharedWebsiteTest:
                    {
                        var testData = this.table.Find(x => x.TestId == item.SharedStepWebsiteTestId && !x.IsDeleted).OrderBy(x => x.ExecutionSequence).ToList();
                        var mapper   = this.mapperFactory.GetMapper <TblTestData, TblTestDataDto>();
                        var testDataDtoForSharedWebsiteTest = testData.Select(mapper.Map).OrderBy(x => x.ExecutionSequence).ToList();
                        var website = this.mapperFactory.GetMapper <TblWebsite, TblWebsiteDto>().Map(testData[0].Test.Website);

                        WebsiteUrl urlData;
                        if (testQueue.SuiteId.HasValue)
                        {
                            var schedular = this.schedulerService.GetById(testQueue.SchedulerId.Value);
                            urlData = website.WebsiteUrlList.FirstOrDefault(m => m.Id == schedular.Item.UrlId) ?? new WebsiteUrl();
                        }
                        else
                        {
                            urlData = website.WebsiteUrlList.FirstOrDefault(m => m.Id == testQueue.Settings.UrlId) ?? new WebsiteUrl();
                        }

                        if (!this.testPlan.Any() || (this.testPlan.Last().ActionId.Value != ActionConstants.Instance.IgnoreLoadNeUrlActionId))
                        {
                            TblTestDataDto dummyStep = new TblTestDataDto
                            {
                                ActionValue  = this.actionService.GetById(ActionConstants.Instance.LoadNewUrlActionId).Item.Value,
                                ActionId     = ActionConstants.Instance.LoadNewUrlActionId,
                                Value        = urlData.Url,
                                LinkTestType = (int)LinkTestType.TestStep
                            };
                            testDataDtoForSharedWebsiteTest.Insert(0, dummyStep);
                        }

                        if (testDataDtoForSharedWebsiteTest.Any())
                        {
                            testDataDtoForSharedWebsiteTest.Add(new TblTestDataDto
                                {
                                    ActionValue = this.actionService.GetById(ActionConstants.Instance.LoadNewUrlActionId).Item.Value,
                                    ActionId    = ActionConstants.Instance.LoadNewUrlActionId,
                                    Value       = "ind#" + deepIndex
                                });
                        }

                        this.ProcessTestQueueExecutableData(testDataDtoForSharedWebsiteTest, testQueue, deepIndex + 1);
                        break;
                    }
                    }

                    if (breakParentLoop)
                    {
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// process test data to generate testplan
        /// </summary>
        /// <param name="testDataDto"> the test data object</param>
        /// <param name="testQueue"> the test queue object</param>
        public void ProcessTestQueueExecutableData(IEnumerable <TblTestDataDto> testDataDto, TblTestQueueDto testQueue)
        {
            if (testDataDto != null && testDataDto.Any())
            {
                foreach (var item in testDataDto)
                {
                    switch (item.LinkTestType)
                    {
                    case (int)LinkTestType.TestStep:
                    {
                        item.ExecutionSequence = this.ExecutionSequence++;
                        this.testPlan.Add(item);
                        break;
                    }

                    case (int)LinkTestType.SqlTestStep:
                    {
                        item.ExecutionSequence = this.ExecutionSequence++;
                        this.testPlan.Add(item);
                        break;
                    }

                    case (int)LinkTestType.SharedTest:
                    {
                        var sharedSteps = item.SharedTest.SharedTestDataList.Where(x => !x.IsDeleted).OrderBy(x => x.ExecutionSequence).ToList();
                        foreach (var sharedStep in sharedSteps)
                        {
                            var lnkSharedTestStep = item.SharedTestSteps.FirstOrDefault(x => x.SharedTestDataId == sharedStep.Id && x.IsDeleted != true);
                            if (lnkSharedTestStep != null)
                            {
                                if (lnkSharedTestStep.NewOrder > 0)
                                {
                                    sharedStep.ExecutionSequence = lnkSharedTestStep.NewOrder;
                                }

                                if (!string.IsNullOrEmpty(lnkSharedTestStep.NewValue))
                                {
                                    sharedStep.Value = lnkSharedTestStep.NewValue;
                                }

                                sharedStep.IsIgnored = lnkSharedTestStep.IsIgnored ?? false;
                            }
                        }

                        sharedSteps.RemoveAll(m => m.IsIgnored);
                        var  mapper = this.mapperFactory.GetMapper <TblSharedTestDataDto, TblTestDataDto>();
                        var  sharedStepMappedWithTestData = sharedSteps.Select(mapper.Map).OrderBy(x => x.ExecutionSequence).ToList();
                        long es = this.ExecutionSequence;
                        sharedStepMappedWithTestData.ForEach(x => { x.ExecutionSequence = es++; x.IsStepBelongsToSharedComponent = true; });
                        this.ExecutionSequence = es;
                        this.testPlan.AddRange(sharedStepMappedWithTestData);
                        break;
                    }

                    case (int)LinkTestType.SharedWebsiteTest:
                    {
                        var        testData = this.table.Find(x => x.TestId == item.SharedStepWebsiteTestId && !x.IsDeleted).OrderBy(x => x.ExecutionSequence).ToList();
                        var        mapper   = this.mapperFactory.GetMapper <TblTestData, TblTestDataDto>();
                        var        testDataDtoForSharedWebsiteTest = testData.Select(mapper.Map).OrderBy(x => x.ExecutionSequence).ToList();
                        var        website = this.mapperFactory.GetMapper <TblWebsite, TblWebsiteDto>().Map(testData[0].Test.Website);
                        WebsiteUrl urlData = new WebsiteUrl();
                        if (testQueue.SuiteId.HasValue)
                        {
                            var schedular = this.schedulerService.GetById(testQueue.SchedulerId.Value);
                            urlData = website.WebsiteUrlList.FirstOrDefault(m => m.Id == schedular.Item.UrlId);
                        }
                        else
                        {
                            urlData = website.WebsiteUrlList.FirstOrDefault(m => m.Id == testQueue.Settings.UrlId);
                        }

                        TblTestDataDto dummyStep = new TblTestDataDto {
                            ActionValue = this.actionService.GetById(long.Parse(ConfigurationManager.AppSettings["LoadNewUrlActionId"].ToString())).Item.Value, ActionId = long.Parse(ConfigurationManager.AppSettings["LoadNewUrlActionId"].ToString()), Value = urlData.Url, LinkTestType = (int)LinkTestType.TestStep
                        };
                        testDataDtoForSharedWebsiteTest.Insert(0, dummyStep);
                        this.ProcessTestQueueExecutableData(testDataDtoForSharedWebsiteTest, testQueue);
                        break;
                    }
                    }
                }
            }
        }
 public IHttpActionResult Update([FromBody] TblTestQueueDto testQueueDto, long testQueueId)
 {
     testQueueDto.Id = testQueueId;
     return(this.AddUpdate(testQueueDto));
 }