Пример #1
0
        protected IStalkNode CreateNode(string type, string stalkTarget)
        {
            IStalkNode newNode;

            var escapedTarget = Regex.Escape(stalkTarget);

            switch (type)
            {
            case "user":
                var usn = new UserStalkNode();
                usn.SetMatchExpression(escapedTarget);
                newNode = usn;
                break;

            case "page":
                var psn = new PageStalkNode();
                psn.SetMatchExpression(escapedTarget);
                newNode = psn;
                break;

            case "summary":
                var ssn = new SummaryStalkNode();
                ssn.SetMatchExpression(escapedTarget);
                newNode = ssn;
                break;

            case "xml":
                try
                {
                    var xml = this.xmlCacheService.RetrieveXml(this.User);
                    if (xml == null)
                    {
                        throw new CommandErrorException("No cached XML. Please use the xml command first.");
                    }

                    newNode = this.stalkNodeFactory.NewFromXmlFragment(xml);
                }
                catch (XmlException ex)
                {
                    throw new CommandErrorException(ex.Message, ex);
                }

                break;

            default:
                throw new CommandErrorException("Unknown stalk type!");
            }

            return(newNode);
        }
        public void ShouldSerialiseSummaryCorrectly()
        {
            // arrange
            var node = new SummaryStalkNode();

            node.SetMatchExpression("abc");

            var doc = new XmlDocument();

            var snf = new StalkNodeFactory(this.phabExternalMock.Object);

            // act
            var result = snf.ToXml(doc, node);

            // assert
            Assert.AreEqual("<summary value=\"abc\" />", result.OuterXml);
        }