public void ItDoesIncludeBaseUrlWhenCreatingRelativeLinks() { // Act WebLink l = new WebLink(new Uri("http://dr.dk"), "/xxx/yyy?z=1", "abc", "app/x", "hello"); // Assert Assert.AreEqual("http://dr.dk/xxx/yyy?z=1", l.Parameters["href"]); Assert.AreEqual("http://dr.dk/xxx/yyy?z=1", l.HRef.AbsoluteUri); }
public void CanUseLinksForRelValues() { // Act WebLink l1 = new WebLink(new Uri("http://dr.dk"), "http://elfisk.dk next http://example.com prev", "app/x", "hello"); // Assert Assert.AreEqual("http://dr.dk/", l1.HRef.AbsoluteUri); Assert.AreEqual("http://elfisk.dk next http://example.com prev", l1.RelationType); Assert.AreEqual(4, l1.RelationTypes.Count()); Assert.Contains("http://elfisk.dk", l1.RelationTypes.ToList()); Assert.Contains("next", l1.RelationTypes.ToList()); Assert.Contains("prev", l1.RelationTypes.ToList()); Assert.Contains("http://example.com", l1.RelationTypes.ToList()); }
public void CanConstructWithParameters() { // Act WebLink l1 = new WebLink(new Uri("http://dr.dk"), "http://dr.dk", "abc", "app/x", "hello"); // Assert Assert.AreEqual("http://dr.dk/", l1.Parameters["href"]); Assert.AreEqual("http://dr.dk/", l1.HRef.AbsoluteUri); Assert.AreEqual("abc", l1.Parameters["rel"]); Assert.AreEqual("abc", l1.RelationType); Assert.AreEqual("app/x", l1.Parameters["type"]); Assert.AreEqual("app/x", (string)l1.MediaType); Assert.AreEqual("hello", l1.Parameters["title"]); Assert.AreEqual("hello", l1.Title); }
public void CanAssignParameters() { // Arrange WebLink l1 = new WebLink(); // Act l1.Parameters["href"] = "http://svt.se/"; l1.Parameters["rel"] = "xyz"; l1.Parameters["type"] = "app/y"; l1.Parameters["title"] = "bonsoir"; // Assert Assert.AreEqual("http://svt.se/", l1.Parameters["href"]); Assert.AreEqual("http://svt.se/", l1.HRef.AbsoluteUri); Assert.AreEqual("xyz", l1.Parameters["rel"]); Assert.AreEqual("xyz", l1.RelationType); Assert.AreEqual("app/y", l1.Parameters["type"]); Assert.AreEqual("app/y", (string)l1.MediaType); Assert.AreEqual("bonsoir", l1.Parameters["title"]); Assert.AreEqual("bonsoir", l1.Title); }
protected WebLink ParseLink() { Condition.Requires(NextToken.Type, "CurrentToken.Type").IsEqualTo(TokenType.Url); string url = NextToken.Value; string rel = null; string title = null; string title_s = null; string type = null; GetNextToken(); while (NextToken.Type == TokenType.Semicolon) { try { GetNextToken(); bool isExtended; KeyValuePair<string, string> p = ParseParameter(out isExtended); if (p.Key == "rel" && rel == null) rel = p.Value; else if (p.Key == "title" && title == null && !isExtended) title = p.Value; else if (p.Key == "title" && title_s == null && isExtended) title_s = p.Value; else if (p.Key == "type" && type == null) type = p.Value; } catch (FormatException) { while (NextToken.Type != TokenType.Semicolon && NextToken.Type != TokenType.Comma && NextToken.Type != TokenType.EOF) { try { GetNextToken(); } catch (FormatException) { } } } } WebLink link = new WebLink(BaseUrl, url, rel, type, title_s ?? title); return link; }
public void WhenConstructingWebLinkItInitializesParameters() { // Act WebLink l = new WebLink(); // Assert Assert.IsNotNull(l.Parameters); }
public void WhenBaseUrlIsNullItHandlesAbsoluteLinks() { // Act WebLink l = new WebLink(null, "http://dr.dk", "abc", "app/x", "hello"); // Assert Assert.AreEqual("http://dr.dk/", l.Parameters["href"]); Assert.AreEqual("http://dr.dk/", l.HRef.AbsoluteUri); }