Пример #1
0
        public List <Mock> Get()
        {
            var words    = _sourceText.Split(_splitters, StringSplitOptions.RemoveEmptyEntries);
            var result   = new List <Mock>();
            var wordBank = new List <string>();
            int temp     = 0;

            for (int i = 0; i < words.Length; i++)
            {
                if (TextMatcher.MatchVerb(words[i]))
                {
                    if (temp != i)
                    {
                        var mock = new Mock(wordBank.ToArray());
                        result.Add(mock);
                        temp = i;
                        wordBank.Clear();
                    }
                }
                wordBank.Add(words[i]);
            }
            result.Add(new Mock(wordBank.ToArray()));
            return(result);
        }
Пример #2
0
        public IMockGetter BuildGetter()
        {
            MockGetter getter = new MockGetter();

            for (int i = 0; i < _wordBank.Length; i++)
            {
                if (TextMatcher.MatchIdentifier(_wordBank[i]))
                {
                    getter.Id = "element" + "." + _wordBank[i + 1];
                }
                else if (TextMatcher.MatchVerb(_wordBank[i]))
                {
                    getter.Action = MockModel.MapToActionType(_wordBank[i]);
                    if (getter.Action == ActionType.Clear)
                    {
                        return(getter);
                    }
                }
                else if (TextMatcher.MatchMockType(_wordBank[i]))
                {
                    getter.PropertyValues["type"] = FirstCharToUpper(_wordBank[i]);
                }
                else if (TextMatcher.MatchPropertyType(_wordBank[i]))
                {
                    getter.PropertyValues[_wordBank[i]] = _wordBank[i + 1];
                    i++;
                }
                object obj;
                IDictionary <string, object> expobj = null;
                if (!getter.PropertyValues.TryGetValue("style", out obj))
                {
                    expobj = new ExpandoObject();
                }
                expobj = expobj ?? (IDictionary <string, object>)obj;
                if (TextMatcher.MatchBackgroundColor(_wordBank[i]))
                {
                    if (!TextMatcher.MatchColor(_wordBank[i + 1]))
                    {
                        i++;
                    }
                    else
                    {
                        i = i + 2;
                    }
                    expobj.Add("background-color", _wordBank[i]);
                }
                else if (TextMatcher.MatchColor(_wordBank[i]))
                {
                    expobj.Add("color", _wordBank[i + 1]);
                    i++;
                }
                getter.PropertyValues["style"] = expobj;
            }
            object type;

            if (getter.PropertyValues.TryGetValue("type", out type) || getter.Id != null)
            {
                return(getter);
            }
            return(new MockGetter());
        }