Inheritance: Ramone.HyperMedia.SelectableBase, IParameters, ILink
Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        public void WhenConstructingWebLinkItInitializesParameters()
        {
            // Act
              WebLink l = new WebLink();

              // Assert
              Assert.IsNotNull(l.Parameters);
        }
Ejemplo n.º 7
0
        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);
        }