Reset mock verification in Moq?

前端 未结 8 1666
执笔经年
执笔经年 2021-02-11 12:01

Setup as so:

public interface IFoo
{
    void Fizz();
}

[Test]
public void A()
{
    var foo = new Mock(MockBehavior.Loose);

    foo.Object.Fizz();         


        
8条回答
  •  滥情空心
    2021-02-11 12:36

    Next approach works fine for me (using Moq.Sequence)

        public void Justification()
        {
            var foo = new Mock(MockBehavior.Loose);
            foo.Setup(x => x.Fizz());
    
            var objectUnderTest = new ObjectUnderTest(foo.Object);
    
            objectUnderTest.DoStuffToPushIntoState1(); // this is various lines of code and setup
    
            foo.Verify(x => x.Fizz());
    
            // Some cool stuff
    
            using (Sequence.Create())
            {
                foo.Setup(x => x.Fizz()).InSequence(Times.Never())
                objectUnderTest.DoStuffToPushIntoState2(); // more lines of code
            }
        }
    

    Let me know if it worked out for you

提交回复
热议问题