I have the following code in my class under testing:
devices = ContainerLocator.Container.Resolve<IDevicesList>(); [1]
In test method I'm trying to write:
var fakeDeviceList = Substitute.For<IDevicesList>();
Substitute.For<IContainerProvider>().Resolve<IDevicesList>().Returns(fakeDeviceList);
but I got a null reference exception for ContainerLocator.Container in line [1].
I tried to use
var provider = Substitute.For<IContainerProvider>();
ContainerLocator.Container.Returns(provider);
provider.Resolve<IDevicesList>().Returns(fakeDeviceList);
but got an exception during test run:
Message:
NSubstitute.Exceptions.CouldNotSetReturnDueToNoLastCallException : Could not find a call to return from.
So my question is how could I make a substitution for ContainerLocator.Container? Thank you in advance.