Foq icon indicating copy to clipboard operation
Foq copied to clipboard

Is it possible to first get the abstract and then setup its behaviour?

Open voroninp opened this issue 5 years ago • 0 comments

Description

When using Moq framework I usually create mocks and pass mocked objects to constructor of the object under test. Doing this I avoid repeating part of initialising logic:

public sealed class FooTests
{
    private readonly IMock<IBar1> bar1Mock = new Mock<IBar1>();
    private readonly IMock<IBar2> bar2Mock = new Mock<IBar2>();

    private readonly Foo sut;

    public FooTests()
    {
         sut = new Foo(bar1Mock.Object, bar2Mock.Object);
    }

    [Fact]
    public void Fact1()
    {
         // setup mocks here
    }
}

Is same achievable with Foq?

voroninp avatar Mar 13 '20 20:03 voroninp