Test code on ASP.NET

Simon Leung
Simon Leung used Ask the Experts™
on
Any idea what's the mock code in attached file mean ? What does x in #2 perform ?

Thx
TestCode01.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
On the Moq, ".Verify" checks that a method has been called on the Mock object
Commented:
Unit tests are generally arranged into three distinct sections: Arrange, Act and Assert.  Here is your test separated into those sections:
public void GetAll_NoCondition_ReturnsAllAudioBooks()
{
    // Arrange
    var audioServiceMock = new Mock<IAudioBookService>();
    var apiController = new AudioBookApiController(audioServiceMock.Object);

    // Act
    apiController.Get(); // Call the apiController Get method passing no parameters

    // Assert
    audioServiceMock.Verify(x => x.GetAll()); // Verify that the GetAll method on the mocked IAudioBookService was called
}

Open in new window

-saige-

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial