public override void Verify(AstoriaResponse response) { base.Verify(response); string payload = response.Payload; XmlNode xmlData = FormatVerifyUtils.FindFirstChild(payload); if (xmlData.Name == "feed") { this.VerifyEntry(xmlData); } }
public virtual void Verify(AstoriaResponse response) { string payload = response.Payload; XmlNode xmlData = FormatVerifyUtils.FindFirstChild(payload); if (xmlData.Name == "feed") { XmlNodeList entries = xmlData.SelectNodes("atom:entry", _formatVerifier.XmlNamespaceManager); foreach (XmlNode node in entries) { VerifyEntry(node); } } else if (xmlData.Name == "entry") { VerifyEntry(xmlData); } }
public static FormatVerifier CreateFormatVerifier(FormatVerifierSerializationKind kind, bool isBatch) { FormatVerifier formatVerifier = new FormatVerifier(); if (isBatch) { // do something interesting } else { switch (kind) { case FormatVerifierSerializationKind.JSON: formatVerifier.AddRule(new JsonFormatVerifier()); break; case FormatVerifierSerializationKind.Atom: formatVerifier.XmlNamespaceManager = FormatVerifyUtils.CreateNamespaceManager(); formatVerifier.AddRule(new AtomFeedVerifier(formatVerifier)); formatVerifier.AddRule(new AtomEntryVerifier(formatVerifier)); formatVerifier.AddRule(new AtomCategoryVerifier(formatVerifier)); formatVerifier.AddRule(new AtomAuthorVerifier(formatVerifier)); formatVerifier.AddRule(new AtomContentVerifier(formatVerifier)); formatVerifier.AddRule(new AtomContributorVerifier(formatVerifier)); formatVerifier.AddRule(new AtomLinkVerifier(formatVerifier)); formatVerifier.AddRule(new AtomTitleVerifier(formatVerifier)); formatVerifier.AddRule(new AtomUpdatedVerifier(formatVerifier)); break; default: break; } } return(formatVerifier); }
public void Verify(AstoriaResponse response) { string payload = response.Payload; XmlNodeList childNodes = null; XmlNode xmlData = FormatVerifyUtils.FindFirstChild(payload); if (xmlData.Name == "feed") { /* atom:feed elements MUST contain one or more atom:author elements, * unless all of the atom:feed element's child atom:entry elements * contain at least one atom:author element. */ childNodes = xmlData.SelectNodes("atom:author", _formatVerifier.XmlNamespaceManager); XmlNodeList entries = xmlData.SelectNodes("atom:entry", _formatVerifier.XmlNamespaceManager); if (childNodes.Count == 0) { if (entries.Count > 0) { foreach (XmlNode node in entries) { XmlNode authorNode = node.SelectSingleNode("atom:author[1]", _formatVerifier.XmlNamespaceManager); if (authorNode == null) { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: No author node in entry of feed without author node.")); } } } else { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: No author node in feed with no entries.")); } } // atom:feed elements MUST NOT contain more than one atom:generator element. childNodes = xmlData.SelectNodes("atom:generator", _formatVerifier.XmlNamespaceManager); if (childNodes.Count > 1) { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 generator node found for feed.")); } // atom:feed elements MUST NOT contain more than one atom:icon element. childNodes = xmlData.SelectNodes("atom:icon", _formatVerifier.XmlNamespaceManager); if (childNodes.Count > 1) { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 icon node found for feed.")); } // atom:feed elements MUST NOT contain more than one atom:logo element. childNodes = xmlData.SelectNodes("atom:logo", _formatVerifier.XmlNamespaceManager); if (childNodes.Count > 1) { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 logo node found for feed.")); } // atom:feed elements MUST contain exactly one atom:id element childNodes = xmlData.SelectNodes("atom:id", _formatVerifier.XmlNamespaceManager); if (childNodes.Count != 1) { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: Not exactly 1 id node found for feed.")); } /* atom:feed elements SHOULD contain one atom:link element with a rel * attribute value of "self". This is the preferred URI for * retrieving Atom Feed Documents representing this Atom feed. * * atom:feed elements MUST NOT contain more than one atom:link * element with a rel attribute value of "alternate" that has the * same combination of type and hreflang attribute values. */ int selfLinkCount = 0, altLinkCount = 0; childNodes = xmlData.SelectNodes("atom:link", _formatVerifier.XmlNamespaceManager); foreach (XmlNode node in childNodes) { if (node.Attributes["rel"] != null && node.Attributes["rel"].Value == "self") { selfLinkCount++; } else if (node.Attributes["rel"] != null && node.Attributes["rel"].Value == "alternate") { altLinkCount++; } } AstoriaTestLog.AreEqual(1, selfLinkCount, "4.1.1 Feed element: Not exactly 1 self link node found for feed"); AstoriaTestLog.AreEqual(false, altLinkCount > 1, "4.1.1 Feed element: More than 1 alternate link node found for feed"); // atom:feed elements MUST NOT contain more than one atom:rights element. childNodes = xmlData.SelectNodes("atom:rights", _formatVerifier.XmlNamespaceManager); if (childNodes.Count > 1) { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 rights node found for feed.")); } // atom:feed elements MUST NOT contain more than one atom:subtitle element. childNodes = xmlData.SelectNodes("atom:subtitle", _formatVerifier.XmlNamespaceManager); if (childNodes.Count > 1) { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 subtitle node found for feed.")); } // atom:feed elements MUST contain exactly one atom:title element. childNodes = xmlData.SelectNodes("atom:title", _formatVerifier.XmlNamespaceManager); if (childNodes.Count != 1) { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: Not exactly 1 title node found for feed.")); } // atom:feed elements MUST contain exactly one atom:updated element. childNodes = xmlData.SelectNodes("atom:updated", _formatVerifier.XmlNamespaceManager); if (childNodes.Count != 1) { AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: Not exactly 1 updated node found for feed.")); } } }