Monday, February 6, 2017

Unit Tests Moq: Verify Number Times Called

The format for the number of times a moq method is called:

// Arrange
someSystem.Setup(x => x.MyMethod(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask);              

//Act             
IList newAlerts = em.ReplaceAlerts(alerts, mockedSystem.Object);              

// Assert
someSystem.Verify(x => x.MyMethod(It.IsAny(), It.IsAny()), Times.Once);