Ejemplo n.º 1
0
        public ObservableCollection <Action> CreateActions(string[] commands, ConstructingContext context)
        {
            ObservableCollection <Action> actions = new ObservableCollection <Action>();
            Version version = context.DefaultFrontendVersion;

            foreach (var command in commands)
            {
                if (IsFrontEndSwitch(command))
                {
                    var versionCodeStr = command.Trim().Replace(Constants.Configs.FrontEndSwitchPrefix, "").Replace(":", "").Trim();
                    version = Version.FromString(versionCodeStr);
                    continue;
                }
                else if (IsFunctionCall(command))
                {
                    //FunctionFactory和ActionFactory存在循环依赖的可能。这取决于用户定义函数的时候,不能递归调用自身
                    actions.Add(FunctionFactory.Instance.CreateFunction(command, context));
                }
                else if (IsAssert(command))
                {
                    actions.Add(AssertActionFactory.Instance.CreateAction(command.Trim(), version, context));
                    //testCase.AssertActions.Add(AssertActionFactory.Instance.CreateAction(command.Trim(), version,context));
                }
                else if (IsUserFunc(command))
                {
                    actions.Add(FuncActionFactory.Instance.CreateAction(command.Trim(), version, context));
                }
                else
                {
                    actions.Add(PerformActionFactory.Instance.CreateAction(command.Trim(), version, context));
                    //testCase.OrdinaryActions.Add(PerformActionFactory.Instance.CreateAction(command.Trim(),version,context));
                }
            }
            return(actions);
        }
Ejemplo n.º 2
0
        public TestCase CreateTestCase(string[] userCommands, string caseName, ConstructingContext context)
        {
            var testCase = new TestCase();

            testCase.Name = caseName;
            Version version = context.DefaultFrontendVersion;

            testCase.Actions = ActionsFactory.Instance.CreateActions(userCommands, context);
            return(testCase);
        }
Ejemplo n.º 3
0
        public TestSuite CreateTestSuiteFrom(string[] userTestLines, string suiteName)
        {
            TestSuite           suite            = new TestSuite(suiteName);
            var                 result           = TextPreProcesser.Preprocess(userTestLines.ToList());
            var                 defaultVersion   = ExtractFrontEndVersion(result.Item1);
            ConstructingContext context          = new ConstructingContext(result.Item2, defaultVersion.Item2); //保存构建上下文
            var                 splitedCaseLines = SplitTestCases(defaultVersion.Item1);

            foreach (var caseTerm in splitedCaseLines)
            {
                if (caseTerm.Count == 0)
                {
                    continue;
                }
                var title = GetCaseTitle(caseTerm[0]);
                caseTerm.RemoveAt(0);
                suite.TestCases.Add(TestCaseFactory.Instance.CreateTestCase(caseTerm.ToArray(), title, context));
            }
            return(suite);
        }
Ejemplo n.º 4
0
        public FunctionAction CreateFunction(string command, ConstructingContext context)
        {
            //解析Command,获得函数名、实参列表
            var functionInfo = GetFunctionActualInfo(command);

            //如果之前解析的上下文中,没有该函数定义,则异常
            if (!context.UserFunctions.ContainsKey(functionInfo.Item1))
            {
                throw new FunctionNotFoundException(functionInfo.Item1);
            }
            //找到函数定义,并根据实参列表,进行形参->实参转换
            var functionActual = context.UserFunctions[functionInfo.Item1].ToRuntime(functionInfo.Item2); //获得实参下的函数

            FunctionAction funcAction = new FunctionAction()
            {
                FunctionActual = functionActual, CommandText = command
            };

            funcAction.BodyActions = ActionsFactory.Instance.CreateActions(functionActual.ActualBody.ToArray(), context);
            return(funcAction);
        }