There is some talk about how testing using EPiServer is a hassle. And it is for many reasons. There are exceptions though, and Dynamic Data Store is one of them. In contrast to EPiServer.DataFactory for example, which is a sealed class, both DynamicDataStoreFactory and DynamicDataStore are abstract classes. This is good news from a testing perspective since we can override their behavior. Good work team!
The example I´m gonna show is from the EPiSocial plugin I´ve been working on, which uses DDS. This is from the CommentRepository.
First some setup changes. Instead of using DynamicDataStoreFactory.Instance to get the store:
To test that method we have to setup a fake data store to test against. I did this using Moq. Let´s say that we want to test that the method returns only pages in the language that we provide. It could look something like this: