You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interface
public interface ICustomInterface { ... }
Class
public class CustomObject
{
public CustomObject(Func< ICustomInterface > factoryFunc) { ... }
}
Test
[SetUp]
public void TestInitialize()
{
Mock<Func< ICustomInterface >> factoryFuncMock =
MoqMockingKernel.GetMock<Func< ICustomInterface >>(); <-- ArgumentException
factoryFuncMock.Setup(...).Returns(...);
}
As I understand, the exception is thrown because Mock.Get< T >(T) waits for Func< ICustomInterface >, but MoqMockingKernel.Get<Func< ICustomInterface >> returns a FunctionFactory<> type instead of Func<>
This case is helpful when we try to inject Func< ... > with several generic types and then we want to check that Func was called with correct arguments
Example:
Mock<Func<bool, ICustomInterface>> factoryFuncMock = MoqMockingKernel.GetMock<Func<bool, ICustomInterface>>();
factoryFuncMock.Setup(factoryFunc => factoryFunc(true)).Returns(...);
The text was updated successfully, but these errors were encountered:
There is the following example:
Interface
public interface ICustomInterface { ... }
Class
public class CustomObject
{
public CustomObject(Func< ICustomInterface > factoryFunc) { ... }
}
Test
[SetUp]
public void TestInitialize()
{
Mock<Func< ICustomInterface >> factoryFuncMock =
MoqMockingKernel.GetMock<Func< ICustomInterface >>(); <-- ArgumentException
factoryFuncMock.Setup(...).Returns(...);
}
As I understand, the exception is thrown because Mock.Get< T >(T) waits for Func< ICustomInterface >, but MoqMockingKernel.Get<Func< ICustomInterface >> returns a FunctionFactory<> type instead of Func<>
This case is helpful when we try to inject Func< ... > with several generic types and then we want to check that Func was called with correct arguments
Example:
Mock<Func<bool, ICustomInterface>> factoryFuncMock = MoqMockingKernel.GetMock<Func<bool, ICustomInterface>>();
factoryFuncMock.Setup(factoryFunc => factoryFunc(true)).Returns(...);
The text was updated successfully, but these errors were encountered: