'Verify a method call within the tested class

Suppose I have the below interface. And also assume MethodA calls MethodB like in the class below:

public interface IFoo
{
   public void MethodA();
   public void MethodB();
}

public class Foo : IFoo
{
   public void MethodA()
   {
      //some business logic

      //then call to MethodB
      if (somConditionMet)
      {  
         MethodB();
      }
   }

   public void MethodB()
   {
      //some other business logic
   }
}

And I'm writing a unit test to test MethodA.

[Test]
public MethodA_VerifyCallToMethodB()
{
   //Arrange

   //Act
   _sut.MethodA();
   
   //Assert
   // here I have to verify that MethodB is called in MethodA, how can I do it?
}

Is there a way to verify the call to MethodB? Because it's in the instantiated _sut object and not mocked, I can't use the Verify method.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source