Skip to content

Unit testing code using LazyCache

Alastair Crabtree edited this page Jul 4, 2017 · 3 revisions

To make testing easier and to follow SOLID principles your code should not depend on an instance of CachingService. Instead you should depend upon the interface IAppCache and use a dependency injection container to pass you an instance of CachingService at runtime.

In your unit tests you can then choose - either mock the interface yourself, pass an instance of MemoryCache and include it in your test coverage, or use the built in mock - see LazyCache/Mocks/MockCachingService.cs