public void BuildLinkTest() { Uri url =new Uri("http://www.erewr.com/discounttickets/default.aspx?area=hangzhou&topic=t_shanshui&level=4a"); string type = "area"; string value = "ningbo"; UrlParamHelper helper = new UrlParamHelper(url.AbsoluteUri); Assert.AreEqual("/ningbo/4a/t_shanshui",helper.BuildLink2(type,value)); value = ""; Assert.AreEqual("/4a/t_shanshui", helper.BuildLink2(type, value)); }
public void TestBuildLink2() { string level="3a"; string area="hangzhou"; string url = string.Format("www.tourol.com/default.aspx?area={0}&level={1}", area, level); CommonLibrary.UrlParamHelper helper = new UrlParamHelper(url); Assert.AreEqual("/hangzhou/4a", helper.BuildLink2("level", "4a")); level = ""; area = ""; url = string.Format("www.tourol.com/default.aspx"); helper = new UrlParamHelper(url); Assert.AreEqual("/4a", helper.BuildLink2("level", "4a")); level = ""; area = ""; url = string.Format("www.tourol.com/default.aspx?pgotindex=2"); helper = new UrlParamHelper(url); Assert.AreEqual("/4a", helper.BuildLink2("level", "4a")); level = ""; area = "ningbo"; url = string.Format("www.tourol.com/default.aspx?area={0}&pgotindex=2",area); helper = new UrlParamHelper(url); Assert.AreEqual("/ningbo", helper.BuildLink2("area", area)); level = "4a"; url ="www.tourol.com/default.aspx?area=hangzhou"; helper = new UrlParamHelper(url); Assert.AreEqual("/hangzhou/4a", helper.BuildLink2("level", level)); }