public void WHEN_Passing_Any_TemplateName_Resulting_View_SHOULD_Be_Cached_ByTemplateName() { //Arrange var controllerContext = new Mock <ControllerContext>(MockBehavior.Strict); var cachedView = new HandlebarsView((w, o) => { }, GetRandom.String(32), new Dictionary <string, HandlebarsView>()); var monitor = new CacheProviderFactory.CacheHistMonitor(); var cacheProvider = CacheProviderFactory.CreateForHandlebarsWithMonitor(monitor, cachedView, cachedView); var viewEngine = new UnitTestableHandlebarsViewEngine(cacheProvider.Object); string templateNameA = "SubLevel2"; string templateNameB = "OtherLeaf"; //Act monitor.Reset(); monitor.CacheMissCount.ShouldBeEquivalentTo(0, "Otherwise this test is irrelevent"); monitor.CacheHitCount.ShouldBeEquivalentTo(0, "Otherwise this test is irrelevent"); var result1A = viewEngine.FindPartialView(controllerContext.Object, templateNameA, false); monitor.CacheMissCount.ShouldBeEquivalentTo(1, "First attempt to load the TemplateA should cache miss"); var result2A = viewEngine.FindPartialView(controllerContext.Object, templateNameA, false); monitor.CacheHitCount.ShouldBeEquivalentTo(1, "Second attempt to load the TemplateA should cache hit"); monitor.Reset(); for (int i = 0; i < 10; i++) { var result3A = viewEngine.FindPartialView(controllerContext.Object, templateNameA, false); } monitor.CacheMissCount.ShouldBeEquivalentTo(0, "Subsequent attempt to load the TemplateA should not cache miss"); monitor.CacheHitCount.Should().BeGreaterOrEqualTo(10, "Subsequent attempt to load the TemplateA should cache hit"); //-- monitor.Reset(); var result1B = viewEngine.FindPartialView(controllerContext.Object, templateNameB, false); monitor.CacheMissCount.ShouldBeEquivalentTo(1, "First attempt to load the CultureB should cache miss, key is culture dependant"); monitor.CacheHitCount.ShouldBeEquivalentTo(0, "First attempt to load the CultureB should not cache hit, key is culture dependant"); }