3

We would like to mock inner method of the sut object. For example, we want to mock CustomerHasLimitObligation when we are testing CheckCustomerAssessmentType. How we can mock this method with AutoFixture?

public class OfferAssessmentBusiness: IOfferAssessmentBusiness
{
                               
        public bool CheckCustomerAssessmentType(int offerId)
        {
            return this.CustomerHasLimitObligation(offerI);
        }
                               
                               
        public bool CustomerHasLimitObligation(int offerId)
        {
            //....
            //....

        }
}

[TestMethod]
public void CheckCustomerAssessmentType_CheckIndividualLimit_Success()
{
    //Arrange
    var sut = Fixture.Freeze<OfferAssessmentBusiness>();

    //Act
    var result = sut.CheckCustomerAssessmentType(It.IsAny<int>());

    //Assert
    Assert.IsTrue(result);
}
Fikret Asma
  • 121
  • 2
  • 6
  • Please check this [SO topic](https://stackoverflow.com/a/18172472/13268855) to get insight how `Register` or `Inject` should be used to create the desired mock. – Peter Csala Jun 29 '20 at 08:43
  • 1
    Hi, not sure if i can help. First, found a nice [cheat sheet](https://www.jankowskimichal.pl/wp-content/uploads/downloads/2016/01/Cheatsheet_Moq_xUnit_AutoFixture.pdf). Second: with Moq you can use `Setup`, i.e.: `sut.Setup(s => s.CustomerHasLimitObligation()).Returns(true)`. – nilsK Jun 29 '20 at 09:05

0 Answers0