How to drown out an abstract collection using Moq?

Say I have this class:

public abstract class CustomerCollectionBase : Collection<Customer>{}

One of my tested classes accepts an instance of CustomerCollectionBase (this will be some subclass). In the test method, this collection is transferred through a cycle, and the results are analyzed and processed. eg:

for (int i=0;i<_customers.Count; i++){
 //process customer
}

Is it possible to stub this collection with Moq so that I can pass the stub depending on my constructor under the class?

Thanks.

+3
source share
1 answer

Technically, this would be possible, but difficult, since only protected members are protected Collection<T>.

, - .

, Moq, :

using Moq.Protected;

Protected() CustomerCollectionBase.

. , Mock Moq.

+3

Source: https://habr.com/ru/post/1726055/


All Articles