Monday, October 1, 2012

Web Service Unit Testing

 My Web Service return a JSON .Than i decide to unit test The Json



My controller Action return the Json


 public ActionResult GetShipingPrice(string Category = "india")
        {
            var Shipprice = (from Shipingprice in db.Tbl_ShippingPrice
                             where (Shipingprice.Sp_Location.Equals(Category) && Shipingprice.Sp_IsActivated == 1)
                             select new
                             {
                                DeliveryTime = Shipingprice.Sp_DeliveryTime,
                                 Price = Shipingprice.Sp_Price
                             }).SingleOrDefault();
         
         
            return this.Json(Shipprice, JsonRequestBehavior.AllowGet);
           //basically it return the
                    var a="{ DeliveryTime = 2, Price = 88 }";

        }



Then  i write a Test Class for unit testing


  [TestFixture]
    public class Ecommerce
    {

 [Test]
         public void GetShipingPrice(){
              StoreController SC = new StoreController();
              JsonResult actual = SC.GetShipingPrice("india") as JsonResult;
              var a="{ DeliveryTime = 2, Price = 88 }";
              Assert.AreEqual(a, actual.Data.ToString());
         }

}




No comments:

Post a Comment