/// <summary> /// Tests calling <c>MakeOpenGraph</c> method /// </summary> public void MakeOpenGraph_Test() { var title = "some title"; var type = "website"; var image = "http://www.go.com/someimg.jpg"; var url = "http://www.go.com/"; var description = "some description"; var siteName = "my site"; var graph = OpenGraph.MakeGraph(title, type, image, url, description, siteName); Assert.AreEqual(title, graph.Title); Assert.AreEqual(type, graph.Type); Assert.AreEqual(image, graph.Image.ToString()); Assert.AreEqual(url, graph.Url.ToString()); Assert.AreEqual(description, graph["description"]); Assert.AreEqual(siteName, graph["site_name"]); var expected = "<meta property=\"og:title\" content=\"some title\">" + "<meta property=\"og:type\" content=\"website\">" + "<meta property=\"og:image\" content=\"http://www.go.com/someimg.jpg\">" + "<meta property=\"og:url\" content=\"http://www.go.com/\">" + "<meta property=\"og:description\" content=\"some description\">" + "<meta property=\"og:site_name\" content=\"my site\">"; Assert.AreEqual(expected, graph.ToString()); }
public void TestMakingOpenGraphMetaTags() { var title = "some title"; var type = "website"; var image = "http://www.go.com/img1.png"; var image2 = "http://www.go.com/img2.png"; var url = "http://www.go.com/"; var description = "some description"; var siteName = "my site"; var width1 = "30"; var width2 = "60"; var graph = OpenGraph.MakeGraph(title, type, image, url, description, siteName); graph.AddMetadata("og", "image", image2); var imageMetadata = graph.Metadata["og:image"]; imageMetadata[0].AddProperty("width", width1); imageMetadata[1].AddProperty("width", width2); Assert.Equal("og", graph.Namespaces.First().Value.Prefix); Assert.Equal("http://ogp.me/ns#", graph.Namespaces.First().Value.SchemaUri.ToString()); Assert.Equal(graph.Namespaces.First().Value, graph.Metadata["og:title"].Namespace()); Assert.Equal(graph.Metadata["og:image"][0].Name, graph.Metadata["og:image"].Name()); Assert.Equal(graph.Namespaces.First().Value, graph.Metadata["og:image"].First().Properties["width"].Namespace()); Assert.Equal(graph.Metadata["og:image"].First().Properties["width"].First().Name, graph.Metadata["og:image"].First().Properties["width"].Name()); Assert.Equal(title, graph.Title); Assert.Equal(type, graph.Type); Assert.Equal(image, graph.Image.ToString()); Assert.Equal(width1, graph.Metadata["og:image"].First().Properties["width"].Value()); Assert.Equal(image2, graph.Metadata["og:image"][1].Value); Assert.Equal(width2, graph.Metadata["og:image"][1].Properties["width"].Value()); Assert.Equal(url, graph.Url.ToString()); Assert.Equal(description, graph.Metadata["og:description"].Value()); Assert.Equal(description, graph["description"].Value); Assert.Equal(siteName, graph.Metadata["og:site_name"].Value()); Assert.Equal(siteName, graph["site_name"]); Assert.Equal(0, graph.Metadata["og:donotexist"].Count); var expected = $"<meta property=\"og:title\" content=\"{title}\">" + "<meta property=\"og:type\" content=\"website\">" + $"<meta property=\"og:image\" content=\"{image}\">" + $"<meta property=\"og:image:width\" content=\"{width1}\">" + $"<meta property=\"og:image\" content=\"{image2}\">" + $"<meta property=\"og:image:width\" content=\"{width2}\">" + $"<meta property=\"og:url\" content=\"{url}\">" + $"<meta property=\"og:description\" content=\"{description}\">" + $"<meta property=\"og:site_name\" content=\"{siteName}\">"; Assert.Equal(expected, graph.ToString()); }