interface IA {
B Foo();
}
interface IB {
// more code
}
var a = Substitute.For<IA>();
var b = Substitute.For<IB>();
a.Foo().Returns(b);
Is that possible?
interface IA {
B Foo();
}
interface IB {
// more code
}
var a = Substitute.For<IA>();
var b = Substitute.For<IB>();
a.Foo().Returns(b);
Is that possible?
Assuming that your interface IA
is meant to have IB Foo();
and not B Foo();
, yes, it's possible. See the following example, which uses NUnit.
namespace NSubstituteTests
{
using NSubstitute;
using NUnit.Framework;
/// <summary>
/// Corresponds to your type IA
/// </summary>
public interface IMyInterface
{
IMyOtherInterface Foo();
}
/// <summary>
/// Corresponds to your type IB
/// </summary>
public interface IMyOtherInterface
{
string Message { get; }
}
[TestFixture]
public class NSubstituteTest
{
[TestCase]
public void TestSomething()
{
// var a = Substitute.For<IA>();
var myConcreteClass = Substitute.For<IMyInterface>();
// var b = Substitute.For<IB>();
var myOtherConcreteClass = Substitute.For<IMyOtherInterface>();
// a.Foo().Returns(b);
myConcreteClass.Foo().Returns(myOtherConcreteClass);
myOtherConcreteClass.Message.Returns("Thanks for testing!");
var testResult = myConcreteClass.Foo().Message;
Assert.AreEqual("Thanks for testing!", testResult);
}
}
}