The params keyword is syntactic sugar for passing an array of arguments.
The following method:
public void MyMethod(params object[] args)
{
}
Can be invoked in both of the following ways with the same results:
MyMethod(new object(), new object());
MyMethod(new []{ new object(), new object());
When Unity looks for constructors, it sees a constructor with one parameter of type object[]. So the value provided by Unity must be an array.
The InjectionConstructor also utilises the params keyword, where each parameter is a value to forward to your own constructor. If you instantiate the InjectionConstructor with an array, it will try and use each element of the array and forward them to your class constructor.
To stop this, we require two levels of wrapping, one for unity to provide an array to your class, and one so that the InjectionConstructor uses the first array as the first and only parameter.
So you should use the following:
container.RegisterType<IProviderContext, MockOrderServiceProviderContext>(
new InjectionConstructor(new []
{
new []
{
new Pharmacy { SiteId = 2, DistrictCode = "2" }
}
}));
If you want additional items to be passed, merely add them to the inner array:
container.RegisterType<IProviderContext, MockOrderServiceProviderContext>(
new InjectionConstructor(new []
{
new []
{
new Pharmacy { SiteId = 2, DistrictCode = "2" },
new Hospital { SiteId = 5, DistrictCode="2" }
}
}));