jeudi 23 juin 2016

Unit Testing an MVC Cache using Rhino Mocks, do I need to use HttpContext?

I am trying to create a Unit Test for an MVC Cache. Currently, I created a new MockRepository (CacheManager is the wrapper class), and I am trying to figure out why the Get function returns null. My manager mentioned that he believes it has something to do with creating a mock HTTP context.

  1. Do I need to use a mock HTTP Context to do a unit test with a cache using Rhino?
  2. Is my current code correct, assuming that Get and Set actually do work as they are supposed to?
  3. Can anyone explain to me how a cache works in this MVC context, so I can get a better understanding of coding?

       // ARRANGE
        MockRepository mocks = new MockRepository();
        CacheManager cache = mocks.Stub<CacheManager>();
        cache.initialize();
    
        String str = "world";
    
        // ACT
        cache.Add<String>("hello", str);
        String hi = cache.Get<String>("hello");
    
        // ASSERT
        Assert.AreEqual(str, hi);
    
    

Aucun commentaire:

Enregistrer un commentaire