3

设想:

我有一个基本控制器,它在 OnActionExecuting 覆盖中禁用缓存。

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
    filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
    filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); //IE
    filterContext.HttpContext.Response.Cache.SetNoStore(); //FireFox 
}

如何创建单元测试来测试这种行为?

4

1 回答 1

0

Trying to do the same. The best I have so far is this...

    [TestCase]
    public void ResponseNotFromCache()
    {

            System.Net.WebRequest rq = System.Net.WebRequest.Create("testmethod");
            System.Net.HttpWebResponse rs = rq.GetResponse() as System.Net.HttpWebResponse;

            Assert.IsFalse(rs.IsFromCache);
    }

There must be a better way!

Update: How can I test an event of a MVC controller

于 2010-02-28T02:42:34.433 回答