HtmlHelperTest.cs 1.3 KB

12345678910111213141516171819202122232425
  1. using Masuit.Tools.Html;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. namespace Masuit.Tools.UnitTest
  4. {
  5. [TestClass]
  6. public class HtmlHelperTest
  7. {
  8. [TestMethod]
  9. public void MatchRandomImgSrc_NormalHtml_ReturnAImgUrl()
  10. {
  11. string html = "<p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxefem7juyj30ld037q35\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxeffei83dj30l90nbgr8\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxeffz9u1kj30lc0n90y1\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxefgh6xxoj30lc09aq4q\"/></p>";
  12. string src = html.MatchRandomImgSrc();
  13. Assert.IsTrue(src.StartsWith("http"));
  14. }
  15. [TestMethod]
  16. public void MatchRandomImgSrc_NoImgHtml_ReturnNull()
  17. {
  18. string html = "<p>如果你是通过某宝、或是其他论坛等渠道,通过任何付费的方式获取到本资源,请直接退款并在相应的平台举报,如果是论坛的,请将本页链接分享到你购买源的评论区,告诫他人谨防上当,或者直接将本页链接转发分享给有需要的人,感谢您的支持和监督。</p>";
  19. string src = html.MatchRandomImgSrc();
  20. Assert.IsTrue(string.IsNullOrEmpty(src));
  21. }
  22. }
  23. }