才开始学C#单元测试 请问各位能帮我看看这个方法怎么写么    public ActionResult AttachDelete(string dir, string file)
        {
            try
            {
                System.IO.File.Delete(HttpRuntime.AppDomainAppPath + "Upload\\" + dir + "\\" + file);
            }
            catch (Exception e)
            {
                return RedirectToAction("Error");
            }
            return RedirectToAction("AttachIndex");
        }
帮帮忙 谢谢!

解决方案 »

  1.   

    尝试下使用Nunit,使用起来不错
      

  2.   

    看代码应该是基于.net mvc架构的吧
    可以考虑以下代码[TestMethod]
    public void AttachDeleteTestNormal()
    {
        if(!File.Exists("D:\1.txt")){
            File.Create("D:\1.txt");
        }
        ControllerName controller=new ControllerName();
        controller.AttachDelete("d:\","1.txt");
        Assert.IsTrue(!File.Exists("D:\1.txt"));
    }public void AttachDeleteTestErrorFileName()
    {
        Assert.IsTrue(!File.Exists("D:\1.txt"));
        ControllerName controller=new ControllerName();
        ActionResult action=controller.AttachDelete("d:\","1.txt");
        Assert.IsTrue(ActionResult.Url.Indexof("Error")>=0);
    }