public void ShouldCreateBasicXmlElement() { // arrange var doc = new XmlDocument(); var ns = string.Empty; var snf = new Mock <IStalkNodeFactory>(); var irc = new Mock <IIrcClient>(); snf.Setup(x => x.ToXml(doc, It.IsAny <IStalkNode>())).Returns(doc.CreateElement("false", ns)); var node = new Mock <IStalkNode>(); var stalk = new Mock <IStalk>(); stalk.Setup(x => x.Subscribers).Returns(new List <StalkUser>()); stalk.Setup(x => x.SearchTree).Returns(node.Object); stalk.Setup(x => x.Identifier).Returns("testflag"); stalk.Setup(x => x.IsEnabled).Returns(true); stalk.Setup(x => x.TriggerCount).Returns(4); stalk.Setup(x => x.WatchChannel).Returns("#en.wikipedia"); var sf = new StalkFactory(this.LoggerMock.Object, snf.Object, irc.Object, this.AppConfigMock.Object); // act var xmlElement = sf.ToXmlElement(stalk.Object, doc); // assert Assert.AreEqual("<complexstalk flag=\"testflag\" enabled=\"true\" watchchannel=\"#en.wikipedia\" triggercount=\"4\"><searchtree><false /></searchtree><subscribers /></complexstalk>", xmlElement.OuterXml); }
public void ShouldCreateCompleteXmlElement() { // arrange var doc = new XmlDocument(); var snf = new Mock <IStalkNodeFactory>(); var irc = new Mock <IIrcClient>(); var node = new Mock <IStalkNode>(); snf.Setup(x => x.ToXml(doc, It.IsAny <IStalkNode>())).Returns(doc.CreateElement("false")); var stalk = new Mock <IStalk>(); stalk.Setup(x => x.Subscribers).Returns(new List <StalkUser>()); stalk.Setup(x => x.SearchTree).Returns(node.Object); stalk.Setup(x => x.Identifier).Returns("testflag"); stalk.Setup(x => x.Description).Returns("my description here"); stalk.Setup(x => x.IsEnabled).Returns(true); stalk.Setup(x => x.LastUpdateTime).Returns(new DateTime(2018, 3, 14, 1, 2, 3)); stalk.Setup(x => x.LastTriggerTime).Returns(DateTime.MinValue); stalk.Setup(x => x.ExpiryTime).Returns(DateTime.MaxValue); stalk.Setup(x => x.TriggerCount).Returns(3334); stalk.Setup(x => x.LastMessageId).Returns("foobar"); stalk.Setup(x => x.WatchChannel).Returns("#metawiki"); stalk.Setup(x => x.DynamicExpiry).Returns(new TimeSpan(90, 0, 0, 0)); stalk.Setup(x => x.CreationDate).Returns(new DateTime(2019, 03, 28, 1, 2, 3)); var sf = new StalkFactory(this.LoggerMock.Object, snf.Object, irc.Object, this.AppConfigMock.Object); // act var xmlElement = sf.ToXmlElement(stalk.Object, doc); // assert Assert.AreEqual("<complexstalk flag=\"testflag\" lastupdate=\"2018-03-14T01:02:03Z\" lasttrigger=\"0001-01-01T00:00:00Z\" creation=\"2019-03-28T01:02:03Z\" description=\"my description here\" lastmessageid=\"foobar\" enabled=\"true\" watchchannel=\"#metawiki\" expiry=\"9999-12-31T23:59:59.9999999Z\" dynamicexpiry=\"P90D\" triggercount=\"3334\"><searchtree><false /></searchtree><subscribers /></complexstalk>", xmlElement.OuterXml); }