public void ManualCreatedSUTWithMockedCollaborator() { //how we usually do it var fixture = new Fixture(); var gateway = new Mock<EmailGateway>(); var sut = new EmailBuffer(gateway.Object); sut.Add(fixture.Create<EmailMessage>()); sut.Send(); gateway.Verify(g=>g.Send(It.IsAny<EmailMessage>())); }
public void AutoMockWithoutAnySetupByUsingACustomAttribute( [Frozen] Mock<EmailGateway> gateway, //Frozen attribute freezes a type //Note that the ORDER OF ARGUMENTS MATTERS HERE. if not frozen before a buffer object is created, gateway is not frozen yet!!! EmailBuffer buffer, EmailMessage message ) { buffer.Add(message); buffer.Send(); gateway.Verify(g=>g.Send(It.IsAny<EmailMessage>())); }