public void MakeEqualityChecksVeryReadable() { var actual = new EmailMessage { Subject = "Subject" }; var identicalButNotSame = new EmailMessage { Subject = "Subject" }; var likenessThatActuallyIsEqualWithoutExtraWork = identicalButNotSame .AsSource() //using Ploeh.SemanticComparison Nuget package! .OfLikeness<EmailMessage>() .CreateProxy(); Assert.False(identicalButNotSame.Equals(actual)); Assert.True(likenessThatActuallyIsEqualWithoutExtraWork.Equals(actual)); //look ma, no work/custom equality! //works because the likeness has a generated custom equality comparator. Other way around does not work: Assert.False(actual.Equals(likenessThatActuallyIsEqualWithoutExtraWork)); //Too bad XUnits Assert.Equal uses default comparator :( Assert.NotEqual(likenessThatActuallyIsEqualWithoutExtraWork, actual); }
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>())); }
public void Add(EmailMessage message) { _bufferedMessages.Add(message); }