Advertisement
andruhovski

querySelectorTest

Sep 18th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.53 KB | None | 0 0
  1. using System.Linq;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Aspose.Html;
  4.  
  5. namespace querySelectorTest
  6. {
  7.     [TestClass]
  8.     public class UnitTest1
  9.     {
  10.         private readonly HTMLDocument _document =
  11.             new HTMLDocument("http://asposedemo20170904120448.azurewebsites.net/home/CssSelectorTest");
  12.  
  13.         [TestMethod]
  14.         public void TestMethod01()
  15.         {
  16.             //Class
  17.             var element = _document.QuerySelector(".intro");
  18.             Assert.AreEqual(element.TagName, "DIV");
  19.         }
  20.  
  21.         [TestMethod]
  22.         public void TestMethod02()
  23.         {
  24.             //Id
  25.             var element = _document.QuerySelector("#Lastname");
  26.             Assert.AreEqual(element.TagName, "SPAN");
  27.         }
  28.  
  29.         [TestMethod]
  30.         public void TestMethod03()
  31.         {
  32.             //class and id
  33.             var collection = _document.QuerySelectorAll(".intro, #Lastname");
  34.             Assert.IsNotNull(collection);
  35.             Assert.AreEqual(2, collection.Length);
  36.             Assert.AreEqual("DIV", collection[0].TagName);
  37.             Assert.AreEqual("SPAN", collection[1].TagName);
  38.            
  39.         }
  40.  
  41.         [TestMethod]
  42.         public void TestMethod04()
  43.         {
  44.             //tag
  45.             var collection = _document.QuerySelectorAll("h1");
  46.             Assert.AreEqual(1,collection.Length);
  47.             Assert.AreEqual("H1",collection[0].TagName);            
  48.         }
  49.  
  50.         [TestMethod]
  51.         public void TestMethod05()
  52.         {            
  53.             var collection = _document.QuerySelectorAll("h1, p");
  54.             Assert.AreEqual(8, collection.Length);
  55.             Assert.AreEqual("H1",collection[0].TagName);
  56.             for (var i = 1; i < 8; i++)
  57.             {
  58.                 Assert.AreEqual("P", collection[i].TagName);
  59.             }            
  60.         }
  61.  
  62.         [TestMethod]
  63.         public void TestMethod06()
  64.         {        
  65.             var collection = _document.QuerySelectorAll("div p");
  66.             Assert.AreEqual(4, collection.Length);            
  67.             Assert.IsTrue(collection.All(el=>el.TagName.Equals("P")));
  68.         }
  69.  
  70.         [TestMethod]
  71.         public void TestMethod07()
  72.         {            
  73.             var collection = _document.QuerySelectorAll("div > p");
  74.             Assert.AreEqual(3, collection.Length);
  75.             Assert.IsTrue(collection.All(el => el.TagName.Equals("P")));
  76.             foreach (var element in collection)
  77.             {
  78.                 Assert.AreEqual(element.TagName, "P");
  79.             }
  80.  
  81.         }
  82.         [TestMethod]
  83.         public void TestMethod08()
  84.         {            
  85.             var collection = _document.QuerySelectorAll("ul + h3");            
  86.             Assert.AreEqual(1,collection.Length);
  87.             Assert.AreEqual("H3",collection[0].TagName);
  88.         }
  89.         [TestMethod]
  90.         public void TestMethod09()
  91.         {                
  92.             var collection = _document.QuerySelectorAll("ul ~ table");
  93.             Assert.AreEqual(1, collection.Length);
  94.             Assert.IsTrue(collection.All(el=>el.TagName.Equals("TABLE")));                        
  95.         }
  96.         [TestMethod]
  97.         public void TestMethod10()
  98.         {              
  99.             var collection = _document.QuerySelectorAll("*");
  100.             Assert.AreEqual(71,collection.Length);
  101.         }
  102.         [TestMethod]
  103.         public void TestMethod11()
  104.         {            
  105.             var collection = _document.QuerySelectorAll("[id]");
  106.             Assert.AreEqual(9,collection.Length);
  107.         }
  108.         [TestMethod]
  109.         public void TestMethod12()
  110.         {            
  111.             var collection = _document.QuerySelectorAll("[id=my-Address]");
  112.             Assert.AreEqual(1, collection.Length);
  113.             Assert.AreEqual("P",collection[0].TagName);            
  114.         }
  115.         [TestMethod]
  116.         public void TestMethod13()
  117.         {            
  118.             var collection = _document.QuerySelectorAll("p[title*=beautiful]");
  119.             Assert.AreEqual("P", collection[0].TagName);
  120.             Assert.AreEqual(collection.Length, 1);
  121.         }
  122.         [TestMethod]
  123.         public void TestMethod14()
  124.         {            
  125.             var collection = _document.QuerySelectorAll("[id$=ess]");
  126.             Assert.AreEqual("P",collection[0].TagName);
  127.             Assert.AreEqual(1,collection.Length);
  128.         }
  129.         [TestMethod]
  130.         public void TestMethod15()
  131.         {            
  132.             var collection = _document.QuerySelectorAll("[id|=my]");
  133.             Assert.AreEqual("P",collection[0].TagName, "P");
  134.             Assert.AreEqual(1, collection.Length);
  135.         }
  136.  
  137.         [TestMethod]
  138.         public void TestMethod16()
  139.         {            
  140.             var collection = _document.QuerySelectorAll("[id^=L]");
  141.             Assert.AreEqual(2, collection.Length);
  142.             Assert.AreEqual(collection[0].TagName, "SPAN");
  143.             Assert.AreEqual(collection[1].TagName, "UL");            
  144.         }
  145.  
  146.         [TestMethod]
  147.         public void TestMethod17()
  148.         {            
  149.             //TODO: Improve this test
  150.             var collection = _document.QuerySelectorAll("[title~=beautiful]");            
  151.             Assert.AreEqual(1, collection.Length);
  152.             Assert.AreEqual("P", collection[0].TagName);
  153.         }
  154.         [TestMethod]
  155.         public void TestMethod17A()
  156.         {
  157.             //TODO: Improve this test
  158.             var otherDocument = new HTMLDocument(@"http://asposedemo20170904120448.azurewebsites.net/home/jobposting");                        
  159.             var collection = otherDocument.QuerySelectorAll("[itemtype~=JobPosting]");
  160.             Assert.AreEqual(1, collection.Length);
  161.             Assert.AreEqual("DIV", collection[0].TagName);
  162.         }
  163.  
  164.         [TestMethod]
  165.         public void TestMethod18()
  166.         {            
  167.             var collection = _document.QuerySelectorAll("[id*=s]");
  168.             Assert.AreEqual(3, collection.Length, 3);
  169.             Assert.AreEqual("SPAN",collection[0].TagName, "SPAN");
  170.             Assert.AreEqual("P",collection[1].TagName) ;
  171.             Assert.AreEqual("UL",collection[2].TagName);            
  172.         }
  173.  
  174.         [TestMethod]
  175.         public void TestMethod19()
  176.         {              
  177.             var collection = _document.QuerySelectorAll(":checked");
  178.             Assert.AreEqual(2, collection.Length);
  179.             Assert.AreEqual("INPUT",collection[0].TagName);
  180.             Assert.AreEqual("INPUT",collection[1].TagName);            
  181.         }
  182.  
  183.         [TestMethod]
  184.         public void TestMethod20()
  185.         {
  186.             var collection = _document.QuerySelectorAll(":disabled");
  187.             Assert.AreEqual(1, collection.Length, 1);
  188.             Assert.AreEqual("INPUT", collection[0].TagName);            
  189.         }
  190.  
  191.         [TestMethod]
  192.         public void TestMethod21()
  193.         {        
  194.             var collection = _document.QuerySelectorAll(":enabled");            
  195.             Assert.IsTrue(collection.All(el=>el.TagName.Equals("INPUT")));
  196.             Assert.AreEqual(8, collection.Length);
  197.         }
  198.  
  199.         [TestMethod]
  200.         public void TestMethod22()
  201.         {
  202.             var collection = _document.QuerySelectorAll(":empty");
  203.             Assert.AreEqual(12,collection.Length, 12);
  204.         }
  205.  
  206.         //[TestMethod]
  207.         //public void TestMethod23()
  208.         //{
  209.            
  210.         //    //TODO: IMPROVE THIS TEST
  211.         //    var collection = _document.QuerySelectorAll(":focus");
  212.         //    Assert.AreEqual(0,collection.Length);
  213.         //}
  214.         //[TestMethod]
  215.         //public void TestMethod24()
  216.         //{
  217.         //    //TODO: IMPROVE THIS TEST    
  218.         //    var collection = _document.QuerySelectorAll("p:first-child");
  219.         //    Assert.AreEqual(1, collection.Length);
  220.         //    Assert.AreEqual("P", collection[0].TagName);            
  221.         //}
  222.  
  223.         //[TestMethod]
  224.         //public void TestMethod25()
  225.         //{
  226.         //    //TODO: IMPROVE THIS TEST
  227.         //    var collection = _document.QuerySelectorAll("p:first-letter");
  228.         //    Assert.AreEqual(collection.Length, 0);
  229.         //    Assert.AreEqual("P", collection[0].TagName);            
  230.         //}
  231.  
  232.         //[TestMethod]
  233.         //public void TestMethod26()
  234.         //{
  235.         //    //TODO: IMPROVE THIS TEST      
  236.         //    var collection= _document.QuerySelectorAll("p:first-line");
  237.         //    Assert.AreEqual("P", collection[0].TagName);
  238.         //    Assert.AreEqual(collection.Length, 0);
  239.         //}
  240.     }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement