public void ShouldCreateObjectFromXmlWithTriggerCount()
        {
            string xml =
                "<complexstalk flag=\"testytest\" lastupdate=\"2018-03-25T16:42:30.984000Z\" lasttrigger=\"2018-03-25T16:42:21.878000Z\" immediatemail=\"true\" enabled=\"false\" triggercount=\"533\"><searchtree><true /></searchtree></complexstalk>";
            var doc = new XmlDocument();

            doc.LoadXml(xml);
            var snf = new Mock <IStalkNodeFactory>();
            var irc = new Mock <IIrcClient>();

            snf.Setup(x => x.NewFromXmlFragment(It.IsAny <XmlElement>())).Returns(new TrueNode());

            // act
            var fact  = new StalkFactory(this.LoggerMock.Object, snf.Object, irc.Object, this.AppConfigMock.Object);
            var stalk = fact.NewFromXmlElement(doc.DocumentElement);

            // assert
            Assert.IsNull(stalk.Description);
            Assert.IsNull(stalk.ExpiryTime);
            Assert.AreEqual("testytest", stalk.Identifier);
            Assert.IsFalse(stalk.IsEnabled);
            Assert.AreEqual(new DateTime(2018, 03, 25, 16, 42, 21, 878), stalk.LastTriggerTime);
            Assert.AreEqual(new DateTime(2018, 03, 25, 16, 42, 30, 984), stalk.LastUpdateTime);
            Assert.AreEqual(533, stalk.TriggerCount);

            Assert.IsNotNull(stalk.SearchTree);
            Assert.IsInstanceOf <IStalkNode>(stalk.SearchTree);

            snf.Verify(x => x.NewFromXmlFragment(It.IsAny <XmlElement>()), Times.Once);
        }
        public void ShouldCreateObjectFromXmlWithExpiry()
        {
            string xml =
                "<complexstalk flag=\"testytest\" expiry=\"2018-03-25T16:42:30.984000Z\" dynamicexpiry=\"P3M\"><searchtree><true /></searchtree></complexstalk>";
            var doc = new XmlDocument();

            doc.LoadXml(xml);
            var snf = new Mock <IStalkNodeFactory>();
            var irc = new Mock <IIrcClient>();

            snf.Setup(x => x.NewFromXmlFragment(It.IsAny <XmlElement>())).Returns(new TrueNode());

            // act
            var fact  = new StalkFactory(this.LoggerMock.Object, snf.Object, irc.Object, this.AppConfigMock.Object);
            var stalk = fact.NewFromXmlElement(doc.DocumentElement);

            // assert
            Assert.AreEqual("testytest", stalk.Identifier);
            Assert.AreEqual(new DateTime(2018, 03, 25, 16, 42, 30, 984), stalk.ExpiryTime);
            Assert.AreEqual(new TimeSpan(90, 0, 0, 0), stalk.DynamicExpiry);

            Assert.IsNotNull(stalk.SearchTree);
            Assert.IsInstanceOf <IStalkNode>(stalk.SearchTree);

            snf.Verify(x => x.NewFromXmlFragment(It.IsAny <XmlElement>()), Times.Once);
        }
        public void ShouldCreateObjectFromXmlWithComments()
        {
            string xml =
                "<complexstalk flag=\"testytest\" enabled=\"false\"><!-- comment 1 --><searchtree><!--comment 2--><and><!-- comment 3 --><true /><!-- comment 4 --><false /><!-- comment 5 --></and><!-- comment 6 --></searchtree><!-- lastcomment --></complexstalk>";
            var doc = new XmlDocument();

            doc.LoadXml(xml);
            var snf = new Mock <IStalkNodeFactory>();
            var irc = new Mock <IIrcClient>();

            snf.Setup(x => x.NewFromXmlFragment(It.IsAny <XmlElement>())).Returns(new TrueNode());

            // act
            var fact  = new StalkFactory(this.LoggerMock.Object, snf.Object, irc.Object, this.AppConfigMock.Object);
            var stalk = fact.NewFromXmlElement(doc.DocumentElement);

            // assert
            Assert.AreEqual("testytest", stalk.Identifier);
            Assert.IsFalse(stalk.IsEnabled);

            Assert.IsNotNull(stalk.SearchTree);
            Assert.IsInstanceOf <AndNode>(stalk.SearchTree);

            var andnode = (AndNode)stalk.SearchTree;

            Assert.AreEqual(2, andnode.ChildNodes.Count);
            Assert.IsNotNull(andnode.ChildNodes[0]);
            Assert.IsNotNull(andnode.ChildNodes[1]);
            Assert.IsInstanceOf <TrueNode>(andnode.ChildNodes[0]);
            Assert.IsInstanceOf <FalseNode>(andnode.ChildNodes[1]);

            snf.Verify(x => x.NewFromXmlFragment(It.IsAny <XmlElement>()), Times.AtLeastOnce);
        }