Ok, here is an example.
Suppose you have an order processor that calls an external service for credit card verification. (This is a super naive approach, but it proves the point).
This code will verify that the processing pipeline performs the call to the credit card verification service when processing the order.
using Moq;
public interface ICreditCardService { //<= The dependency.
bool IsValidCreditCard(int cardNumer);
}
public class OrderProcessor {
readonly ICreditCardService _creditCardService;
public OrderProcessor(ICreditCardService creditCardService) { // <= Injection happens here.
_creditCardService = creditCardService;
}
public void ProcessOrder(int cardNumber, object order) {
// Uncomment this line, and the assertion will fail.
// return;
if (_creditCardService.IsValidCreditCard(cardNumber)) {
//TODO: Do the actual processing.
}
//TODO: Reject the order.