Ejemplo n.º 1
0
        /// <summary>

        /// Reports a log row to the report

        /// </summary>

        /// <param name="status"></param>

        /// <param name="details"></param>

        /// <param name="addScreenshot"></param>

        private static void SubStep(Status status, string details, bool breakIfFail = false, bool addScreenshot = true)

        {
            if (!addScreenshot || DriverManager.Driver == null)

            {
                SubTest.Log(status, details);
            }

            else

            {
                SubTest.Log(status, details + "</td><td width='12%'><a href=\"" + Capture() + "\" target=_blank> screenshot </a></td> ");
            }

            if (breakIfFail && (status == Status.Fail || status == Status.Error))

            {
                //Debugger.Break();

                throw new Exception("Step fail");
            }



            Extent.Flush();
        }
Ejemplo n.º 2
0
 public int SaveSubTest(SubTest subTest)
 {
     using (var context = new EnglishQuestionContext())
     {
         context.Entry(subTest).State = EntityState.Modified;
         return(context.SaveChanges());
     }
 }
Ejemplo n.º 3
0
 public static int RunTests()
 {
     AddTest.RunTests();
     SubTest.RunTests();
     MulTest.RunTests();
     DivTest.RunTests();
     return(0);
 }
Ejemplo n.º 4
0
    public void RemoveSubTest(SubTest SubTest)
    {
        if (_subTests == null)
        {
            return;
        }

        _subTests.Remove(SubTest);
    }
Ejemplo n.º 5
0
    public virtual void AddSubTest(SubTest SubTest)
    {
        if (_subTests == null)
        {
            _subTests = new List <SubTest>();
        }

        _subTests.Add(SubTest);

        return(this);
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a SubTest entry with the values currently loaded in the SubTaskItem instance
        /// </summary>
        /// <returns>The new SubTest entity</returns>
        public SubTest GetSubTest()
        {
            SubTest tempSubTest = new SubTest()
            {
                Name            = Name,
                RequiredValue   = RequiredValue,
                SubRequiremntID = SubRequirementID,
                SubMethodID     = SubMethodID,
                UM = UM
            };

            return(tempSubTest);
        }
Ejemplo n.º 7
0
        public static string BuildTestHeader(TestLevel level, string type, SubTest subTest, Test test)
        {
            switch (level)
            {
            case TestLevel.GLevelA:
            case TestLevel.GcLevelA:
                return((type == SubTestType.Writing.ToString())
                        ? string.Format(AppCommonResource.LevelAWritingHeader, subTest.Name, test.CreatedDate, test.TotalTime)
                        : string.Format(AppCommonResource.LevelAListeningHeader, test.CreatedDate));

            case TestLevel.GLevelB:
            case TestLevel.GcLevelB:
                return(string.Format(AppCommonResource.LevelBWritingHeader, test.TotalTime, subTest.Name));

            case TestLevel.GLevelC:
            case TestLevel.GcLevelC:
                return(string.Format(AppCommonResource.LevelCHeader, test.CreatedDate, test.TotalTime));

            default:
                return(string.Empty);
            }
        }
Ejemplo n.º 8
0
        public ICollection <Test> GenerateTestList(IEnumerable <Requirement> reqList)
        {
            List <Test> output = new List <Test>();

            foreach (Requirement req in reqList)
            {
                req.Load();

                Test tempTest = new Test()
                {
                    Deprecated2     = req.Deprecated2,
                    MethodVariantID = req.MethodVariantID
                };

                tempTest.Duration      = req.MethodVariant.Method.Duration;
                tempTest.RequirementID = req.ID;
                tempTest.Notes         = req.Description;

                foreach (SubRequirement subReq in req.SubRequirements)
                {
                    SubTest tempSubTest = new SubTest()
                    {
                        SubRequiremntID = subReq.ID,
                        Name            = subReq.SubMethod.Name,
                        Position        = subReq.SubMethod.Position,
                        RequiredValue   = subReq.RequiredValue,
                        SubMethodID     = subReq.SubMethodID,
                        UM = subReq.SubMethod.UM,
                    };
                    tempTest.SubTests.Add(tempSubTest);
                }
                output.Add(tempTest);
            }

            return(output);
        }
    public static void Main(string[] args)
    {
        SubTest t = new SubTest();

        Console.WriteLine(t.pos.x);
    }
Ejemplo n.º 10
0
        public static Test GenerateTest(GenerateBaseVM model)
        {
            // 1. Get Ids NumOfTest * NumOfQuestion from DB
            // 2. Loop NumOfTest
            // 3. Each NumOfTest, generate all test, random ids, remove from list if can
            // 4. Use something.OrderBy(x => Guid.NewGuid()) to select random row
            if (model.GenerateConfig.NumOfSubTests == 0)
            {
                throw new Exception(AppCommonResource.NumOfSubTestGreaterThan0);
            }

            var subTestMetaList = new List <SubTestMeta>();

            for (int i = 0; i < model.GenerateConfig.NumOfSubTests; i++)
            {
                subTestMetaList.Add(new SubTestMeta());
            }

            foreach (var config in model.ConfigLevels)
            {
                //config.Templatekey: template key
                if (config.IsManual)
                {
                    for (int i = 0; i < model.GenerateConfig.NumOfSubTests; i++)
                    {
                        if (config.IsLitening)
                        {
                            config.ParagraphMeta.IsListening = true;
                            subTestMetaList[i].ListeningParagraphMetas.Add(config.Section, config.ParagraphMeta);
                        }
                        else
                        {
                            subTestMetaList[i].WritingParagraphMetas.Add(config.Section, config.ParagraphMeta);
                        }
                    }
                    continue;
                }

                if (config.IsParagraph)
                {
                    var paragraphMetaList = DbHelper.Instance.GetParagraphMetaOfSection(
                        model.GenerateConfig.TestLevel.GetSubTypeFromTestLevel(),
                        config.QuestionLevel,
                        model.GenerateConfig.Purpose,
                        config.Section);
                    if (paragraphMetaList.Count == 0 || paragraphMetaList.Count < config.NumOfQuestion)
                    {
                        throw new Exception(AppCommonResource.NotEnoughQuestion);
                    }

                    bool isRemove = paragraphMetaList.Count > config.NumOfQuestion * model.GenerateConfig.NumOfSubTests;
                    for (int i = 0; i < model.GenerateConfig.NumOfSubTests; i++)
                    {
                        if (config.IsLitening)
                        {
                            var listeningParagraph = paragraphMetaList.OrderBy(x => Guid.NewGuid()).First();
                            listeningParagraph.IsListening = true;
                            subTestMetaList[i].ListeningParagraphMetas.Add(config.Section, listeningParagraph);
                        }
                        else
                        {
                            subTestMetaList[i].WritingParagraphMetas.Add(config.Section,
                                                                         paragraphMetaList.OrderBy(x => Guid.NewGuid()).First());
                        }
                        if (isRemove)
                        {
                            paragraphMetaList.Remove(config.IsLitening
                                ? subTestMetaList[i].ListeningParagraphMetas[config.Section]
                                : subTestMetaList[i].WritingParagraphMetas[config.Section]);
                        }
                    }
                }
                else
                {
                    var paragraphMeta = DbHelper.Instance.GetQuestionMetaOfSection(
                        model.GenerateConfig.TestLevel.GetSubTypeFromTestLevel(),
                        config.QuestionLevel,
                        model.GenerateConfig.Purpose,
                        config.Section);
                    if (paragraphMeta.QuestionMeta.Count == 0 || paragraphMeta.QuestionMeta.Count < config.NumOfQuestion)
                    {
                        throw new Exception(AppCommonResource.NotEnoughQuestion);
                    }
                    bool isRemove = paragraphMeta.QuestionMeta.Count > config.NumOfQuestion * model.GenerateConfig.NumOfSubTests;
                    for (int i = 0; i < model.GenerateConfig.NumOfSubTests; i++)
                    {
                        if (config.IsLitening)
                        {
                            subTestMetaList[i].ListeningParagraphMetas.Add(config.Section, new ParagraphMeta()
                            {
                                Id           = 1,
                                QuestionMeta = paragraphMeta.QuestionMeta.OrderBy(x => Guid.NewGuid()).Take(config.NumOfQuestion).ToList()
                            });
                            subTestMetaList[i].ListeningParagraphMetas[config.Section].TimeDone =
                                subTestMetaList[i].ListeningParagraphMetas[config.Section].QuestionMeta.Sum(x => x.TimeDone);

                            if (isRemove)
                            {
                                foreach (var qMeta in subTestMetaList[i].ListeningParagraphMetas[config.Section].QuestionMeta)
                                {
                                    var removeItem = paragraphMeta.QuestionMeta.First(x => x.Id == qMeta.Id);
                                    paragraphMeta.QuestionMeta.Remove(removeItem);
                                }
                            }
                        }
                        else
                        {
                            subTestMetaList[i].WritingParagraphMetas.Add(config.Section, new ParagraphMeta()
                            {
                                Id           = 1,
                                QuestionMeta = paragraphMeta.QuestionMeta.OrderBy(x => Guid.NewGuid()).Take(config.NumOfQuestion).ToList()
                            });
                            subTestMetaList[i].WritingParagraphMetas[config.Section].TimeDone =
                                subTestMetaList[i].WritingParagraphMetas[config.Section].QuestionMeta.Sum(x => x.TimeDone);

                            if (isRemove)
                            {
                                foreach (var qMeta in subTestMetaList[i].WritingParagraphMetas[config.Section].QuestionMeta)
                                {
                                    var removeItem = paragraphMeta.QuestionMeta.First(x => x.Id == qMeta.Id);
                                    paragraphMeta.QuestionMeta.Remove(removeItem);
                                }
                            }
                        }
                    }
                }
            }

            var test = new Test()
            {
                Name            = model.GenerateConfig.TestName,
                ClassNo         = model.GenerateConfig.ClassNo,
                Level           = model.GenerateConfig.TestLevel.GetSubTypeFromTestLevel(),
                TotalTime       = model.GenerateConfig.TotalTime,
                TotalQuestion   = subTestMetaList[0].WritingParagraphMetas.Sum(x => x.Value.QuestionMeta.Count),
                NumOfSubTest    = model.GenerateConfig.NumOfSubTests,
                Purpose         = model.GenerateConfig.Purpose,
                ConfigStructure = XmlHelper.BuildConfigStructure(model).ToString(),
                SubTests        = new ObservableCollection <SubTest>(),
                RealTestTime    = subTestMetaList[0].WritingParagraphMetas.Sum(x => x.Value.TimeDone),
                TestDate        = model.GenerateConfig.TestDate,
                IsChoice        = model.IsChoice,
                No = model.GenerateConfig.TestDate.ToString("yyyyMMddHHmmss")
            };
            int subTestCount = 0;

            foreach (var subTestMeta in subTestMetaList)
            {
                var subTest = new SubTest()
                {
                    Name = $"{AppCommonResource.SubTest} {++subTestCount}",
                    XmlWritingStructure   = XmlHelper.BuildStructureSubTest(subTestMeta.WritingParagraphMetas, test).ToString(),
                    XmlListeningStructure = XmlHelper.BuildStructureSubTest(subTestMeta.ListeningParagraphMetas, test).ToString()
                };

                TestLevel level;
                TestLevel.TryParse(model.GenerateConfig.TestLevel, out level);

                var builder = new StringBuilder();
                builder.AppendLine(XmlHelper.BuildTestHeader(level, SubTestType.Writing.ToString(), subTest, test));
                builder.AppendLine(XmlHelper.BuildTestFromXml(subTest.XmlWritingStructure));
                subTest.WritingTestContent = builder.ToString();

                builder = new StringBuilder();
                builder.AppendLine(XmlHelper.BuildTestHeader(level, SubTestType.Listening.ToString(), subTest, test));
                builder.AppendLine(XmlHelper.BuildTestFromXml(subTest.XmlListeningStructure));
                subTest.ListeningTestContent = builder.ToString();

                test.SubTests.Add(subTest);
            }

            return(test);
        }