public void RequestUrlTest() { // C:\Users\Grant\Downloads\imsmanifest.xml // init and check valid Uri // alive page - 200 ParseLinks parser = new ParseLinks("http://www.cs.odu.edu/~gatkins"); bool isAlive = parser.RequestUrl(); Assert.AreEqual("http://www.cs.odu.edu/~gatkins/", parser.FinalUri); Assert.AreEqual(true, isAlive); // check 404 page - 404 parser = new ParseLinks("http://www.cs.odu.edu/~gatkins/blahblah404definitely"); isAlive = parser.RequestUrl(); Assert.AreEqual("", parser.FinalUri); Assert.AreEqual(false, isAlive); // check redirect to an alive page - 200 parser = new ParseLinks("http://www.cs.odu.edu/~gatkins/cs532/redirect.php"); isAlive = parser.RequestUrl(); Assert.AreEqual("http://www.cs.odu.edu/~mln/teaching/cs532-s17/test/pdfs.html", parser.FinalUri); Assert.AreEqual(true, isAlive); // check infinite redirect error - 404 parser = new ParseLinks("http://www.cs.odu.edu/~gatkins/cs532/redirect2.php"); isAlive = parser.RequestUrl(); Assert.AreEqual("", parser.FinalUri); Assert.AreEqual(false, isAlive); }
public void ParseLinksTest() { ParseLinks parser = new ParseLinks("http://www.cs.odu.edu/~gatkins"); Assert.AreEqual(parser.Uri, "http://www.cs.odu.edu/~gatkins"); Assert.AreEqual(parser.FinalUri, ""); }
public void AbsolutePathTest() { ParseLinks parser = new ParseLinks("./test.html"); bool relativePath = parser.IsAbsoluteUri(); Assert.AreEqual(relativePath, false); parser.Uri = "http://www.cs.odu.edu"; bool absolutePath = parser.IsAbsoluteUri(); Assert.AreEqual(absolutePath, true); parser.Uri = ""; bool errorTest = parser.IsAbsoluteUri(); Assert.AreEqual(errorTest, false); }
public TextResource(string PathToResourceFile) { string xml = File.ReadAllText(PathToResourceFile); XElement xele = XElement.Parse(xml); List <XElement> urls = xele.Descendants("URL").ToList(); if (xele.Descendants("TEXT").Any()) { List <XElement> texts = xele.Descendants("TEXT").ToList(); Text = texts[0].Value; } else { Text = ""; } if (xele.Descendants("FILE").Any()) { IEnumerable <XElement> files = xele.Descendants("FILE"); if (files.Elements("NAME").Any()) { this.FileName = files.Elements("NAME").First(f => !string.IsNullOrEmpty(f.Value)).Value; } } RefId = Path.GetFileNameWithoutExtension(PathToResourceFile); this.PathToResourceFile = PathToResourceFile; if (urls.Any()) { string val = urls[0].Attribute("value").Value; if (val.Length > 0) { Url = urls[0].Attribute("value").Value; } } // arg flag if (linkArgs.checkLinks) { if (xele.Descendants("URL").Any()) { for (int i = 0; i < urls.Count; i++) { string val = urls[i].Attribute("value").Value; if (val.Length != 0) { // static dictionary var dict = UriDictionary.UriDict; ParseLinks parser = new ParseLinks(val); if (parser.IsAbsoluteUri() && !dict.ContainsKey(val)) { if (!dict.ContainsKey(val)) { dict.Add(val, new URLObj()); } dict[val].isAlive = true; Console.WriteLine("Length:{val.Length} Ref {this.RefId} CONTAINS URL: '{val}'"); var isAlive = parser.RequestUrl(); Console.WriteLine(PathToResourceFile, "is alive:", isAlive); if (!isAlive) { Console.WriteLine(val, "For resource", RefId, "is not alive."); dict[val].isAlive = false; // Remove element if considered dead } } else if (parser.IsAbsoluteUri() && dict.ContainsKey(val)) { if (!dict[val].filesFound.Contains(PathToResourceFile)) { dict[val].filesFound.Add(PathToResourceFile); } } } } } } }