A mocking structure such as Moq is not fully replaces the Assert testing platform. sometimes it happens, sometimes it is not.
Let mocks and stubs be distinguished first. Billets are used solely for isolation and for introducing any controlled behavior into the system under test (SUT).
Mocks is a superset of stubs, and they can check if something was called on a fake call. In Moq, calling Verify() makes a joke a mock regarding this method. Calling VerifyAll() makes all the methods that mocks configured.
The recommended approach is that you should have no more than one layout in your test. In this sense, it is similar to Assert - that you should not test multiple tests in a test.
Returning to the original question. If you perform state testing, you will use zero or more stubs, and one will state. If you conduct interaction testing, you will use zero or more butts and one layout. The following is an example where it might be appropriate to use both layouts and statements to test the same service.
public interface IAccountRepository { decimal GetBalance(int accountId); void SetBalance(int accountId, decimal funds); } public class DepositTransaction { IAccountRepository m_repo; public DepositTransaction(IAccountRepository repo) { m_repo = repo; } public decimal DepositedFunds {get; private set;}; void Deposit(int accountId, decimal funds) { decimal balance = m_repo.GetBalance(accountId); balance += funds; m_repo.SetBalance(balance); DepositedFunds += funds; } } public class DepositTest { [TestMethod] void DepositShouldSetBalance() { var accountMock = new Mock<IAccountRepository>(); accountMock.Setup(a=>a.GetBalance(1)).Returns(100);
source share