public void AddSizeCallback_Mutliple() { MockRepository mockRepository; Mock <IMultiInstancePerformanceCounterCategory> multiInstancePerformanceCounterCategoryMock; Mock <NumberOfItems64PerformanceCounter> numberOfItems64PerformanceCounterMock; const string cacheName1 = "test"; const string cacheName2 = "test2"; mockRepository = new MockRepository(MockBehavior.Strict); numberOfItems64PerformanceCounterMock = mockRepository.Create <NumberOfItems64PerformanceCounter>(); numberOfItems64PerformanceCounterMock.Setup(pc => pc.SetValue(0)); numberOfItems64PerformanceCounterMock.Setup(pc => pc.Dispose()); multiInstancePerformanceCounterCategoryMock = mockRepository.Create <IMultiInstancePerformanceCounterCategory>(); multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.SizeCounterName, cacheName1)) .Returns(numberOfItems64PerformanceCounterMock.Object); multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.SizeCounterName, cacheName2)) .Returns(numberOfItems64PerformanceCounterMock.Object); using (PerformanceCounterLoggingCacheMetricReporter metricReporter = new Mock <PerformanceCounterLoggingCacheMetricReporter>(multiInstancePerformanceCounterCategoryMock.Object).Object) { metricReporter.AddSizeCallback(cacheName1, () => 1); metricReporter.AddSizeCallback(cacheName2, () => 2); Assert.That(metricReporter, Has.Property("SizeCallbacks").Property("Keys").EquivalentTo(new [] { cacheName1, cacheName2 })); Assert.That(metricReporter, Has.Property("HitsAndMissesCallbacks").Empty); } }
public void AddSizeCallBack_NullFunc() { IMultiInstancePerformanceCounterCategory multiInstancePerformanceCounterCategory; multiInstancePerformanceCounterCategory = new Mock <IMultiInstancePerformanceCounterCategory>().Object; using (PerformanceCounterLoggingCacheMetricReporter metricReporter = new Mock <PerformanceCounterLoggingCacheMetricReporter>(multiInstancePerformanceCounterCategory).Object) { Assert.That( () => metricReporter.AddSizeCallback("test", null), Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("getSize")); } }
public void AddSizeCallback_InvalidName(string name) { IMultiInstancePerformanceCounterCategory multiInstancePerformanceCounterCategory; multiInstancePerformanceCounterCategory = new Mock <IMultiInstancePerformanceCounterCategory>().Object; using (PerformanceCounterLoggingCacheMetricReporter metricReporter = new Mock <PerformanceCounterLoggingCacheMetricReporter>(multiInstancePerformanceCounterCategory).Object) { Assert.That( () => metricReporter.AddSizeCallback(name, () => 1), Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("name")); } }