Within Startup I have defined a factory, something similar to How to register multiple implementations of the same interface in Asp.Net Core?
Interface has 1 method Process as below.
//saves to db.
public interface Iprocessor
{
void Process(List<items>);
}
Code to register factory within the Startup.cs
Func<string, IProcessor> accessor = key =>
{
switch(key){
case "new":
return factory.GetService<NewProcessor>();
case "old":
return factory.GetService<OldProcessor>();
}
}
My Service class uses this factory and I need help to mock the same.
private readonly Func<string,Iprocessor> _processor;
_processor is assigned using DI.
public void ProcessRecords(List<items> items){
List<string> types = new List<string> () { "new", "old"};
foreach(var type in types)
{
var processor = _processor(type);
if(processor != null)
{
_processor.Process(items);
}
}
}
How do I Mock the Process method calls?