单元测试工具

[TestMethod()]
      public void SearchForWatiNOnGoogle()
      {
          // 打开IE浏览器,并来到Google站点  
          using (var browser = new IE("http://www.google.com.hk/%22))
          {               
             
              // 定位到搜索框,并输入WatiN  
              browser.TextField(Find.ByName("q")).TypeText("WatiN");
              // 点击“搜索”按钮  
              browser.Button(Find.ByName("btnG")).Click();
              // 验证搜索结果中是否包含关键字“WatiN”  
              Assert.IsTrue(browser.ContainsText("google"));
          }
      } 

from WatiN.dll

 

[TestMethod]
       public void Test_FindByName_GetCalled()
       {
           // create some mock data
           IList<Product> products = new List<Product>{
           new Product { ProductId = 1, Name = "C# Unleashed",Description = "Short description here", Price = 49.99 },
           new Product { ProductId = 2, Name = "ASP.Net Unleashed",Description = "Short description here", Price = 59.99 },
           new Product { ProductId = 3, Name = "Silverlight Unleashed",Description = "Short description here", Price = 29.99 }};

           Mock<IProductRepository> mock = new Mock<IProductRepository>();
           mock
           .Setup(sender => sender.FindById(It.IsAny<int>()))
           .Returns((int s) =>
               products.Where(x => x.ProductId == s).Single());

           var Product = new Product { ProductId = 1, Name = "C# Unleashed", Description = "Short description here", Price = 49.99 };

           Assert.AreEqual(Product.ProductId, mock.Object.FindById(1).ProductId);

           //mock.Object.FindById(1);
           //mock
           //.Verify(x => x.FindById(1), Times.Once());
       }

moq.dll

 

/Files/zbw911/ss.zip 

 

TestRunner

posted @ 2012-03-09 10:39  张保维  阅读(152)  评论(0编辑  收藏  举报