public void Test1() { var context = new ControllerContext( HttpContext.Request.RequestContext, new TestController() ); var result = ViewEngines.Engines.FindView( context, "~/ActionUrlTest/Test1.html", null ); Assert.NotNull( result.View, "找不到视图" ); IHtmlDocument document; using ( var writer = new StringWriter() ) { result.View.Render( new ViewContext( context, result.View, new ViewDataDictionary(), new TempDataDictionary(), writer ), writer ); document = new JumonyParser().Parse( writer.ToString() ); } var link = document.FindFirst( "a" ); Assert.NotNull( link ); Assert.AreEqual( link.Attribute( "href" ).Value(), "/TestController/TestAction?arg=args" ); }
public void AttributeTest1() { var document = new JumonyParser().LoadDocument( Path.Combine( Environment.CurrentDirectory, "Test1.html" ) ); var dataValues = new Dictionary<string, object>() { { "StyleClass", "Test" }, { "ThisTime", new DateTime( 2000,1,2 ) }, { "ScriptValue1", null } }; HtmlBinding.Create( document, dataValues ).DataBind(); Assert.AreEqual( document.FindFirst( "body" ).Attribute( "class" ).Value(), "Test", "针对属性的表达式绑定不成功" ); Assert.AreEqual( document.FindFirst( "body" ).Attribute( "test" ).Value(), "this time is 2000-01-02 #", "格式表达式测试失败" ); }
public void Test1() { var document = new JumonyParser().LoadDocument( Path.Combine( Environment.CurrentDirectory, "Test1.html" ) ); HtmlBinding.Create( document, null ).DataBind(); Assert.AreEqual( document.FindFirst( "title" ).InnerHtml(), "Test Title abc text", "对 title 元素内容的文本替换测试失败" ); }
public Blog LoadStar(string blogUrl,string imgPath) { Blog blog = new Blog(); GC.Collect(); ServicePointManager.DefaultConnectionLimit = 200; HttpWebRequest request = HttpWebRequestFactory.CreateSimpleRequest(blogUrl); WebProxy proxy = new WebProxy("127.0.0.1", 1080); request.Proxy = proxy; try { WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); string result = ""; using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("utf-8"))) { result = reader.ReadToEnd(); } var document = new JumonyParser().Parse(result); blog.Name = document.FindFirst(".ProfileHeaderCard-nameLink").InnerHtml(); blog.Description = document.FindFirst(".ProfileHeaderCard-bio").InnerHtml(); string imgUrl = document.FindFirst(".ProfileAvatar-image").Attribute("src").Value(); request = HttpWebRequestFactory.CreateSimpleRequest(imgUrl); HttpWebResponse imageResponse = (HttpWebResponse)request.GetResponse(); //反馈请求 Stream srr = imageResponse.GetResponseStream(); string path = imgPath + blog.Name.ToString() + ".jpg"; FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write); //造一个字节类型的数组来存放图片 byte[] buff = new byte[512]; int c = 0; while ((c = srr.Read(buff, 0, buff.Length)) > 0) { fs.Write(buff, 0, c); } srr.Close(); } catch (Exception e) { throw e; } return blog; }
public void Test1() { var document = new JumonyParser().LoadDocument( Path.Combine( Environment.CurrentDirectory, "Test1.html" ) ); var data = new Dictionary<string, object>(); data.Add( "StyleClass", null ); data.Add( "ThisTime", null ); data.Add( "ScriptValue1", "TestValue" ); HtmlBinding.Create( document, data ).DataBind(); StringAssert.Contains( document.FindFirst( "script" ).InnerHtml(), "var value1 =\"TestValue\";" ); }
public void SpecificationTest9() { var document = new JumonyParser().LoadDocument( Path.Combine( Environment.CurrentDirectory, "SpecificationTest9.html" ) ); Assert.AreEqual( document.FindFirst( "body" ).InnerText(), " <-anc> <_test> <中文> <1a> <:abc> ", "特殊字符解析错误" ); }
public void StyleParseTest() { var document = new JumonyParser().LoadDocument( Path.Combine( Environment.CurrentDirectory, "CssStyleSettingTest1.html" ) ); Assert.AreEqual( document.FindFirst( "div" ).Style().GetValue( "display" ), "none", "无法正确解析丢失分号的属性值" ); Assert.AreEqual( document.FindFirst( "a" ).Style().GetValue( "display" ), null, "无法正确解析没有style属性的元素" ); Assert.AreEqual( document.FindFirst( "p" ).Style().GetValue( "width" ), "12px", "无法正确解析空白样式设置值后随的正确表达式" ); Assert.AreEqual( document.FindFirst( "p" ).Style().GetValue( "display" ), null, "无法正确解析空白样式设置值" ); var element = document.FindFirst( "div#test1" ); Assert.AreEqual( element.Style().GetValue( "display" ), "none", "CSS 属性设置不应区分大小写" ); }