TUnit.Mocks - Feedback · thomhurst/TUnit · Discussion #4981 (original) (raw)

As a user of Moq, I always disliked, having to specify those It.IsAny<TheExactType>() for all method parameters. Since TUnit.Mocks is source generated, I think it should be possible to come up with a more convenient API.

For example instead of this...

var equalityComparer = Mock.Of<IEqualityComparer>(); var equals = equalityComparer.Equals_(Arg.Any(), Arg.Is(b => b > 0)).Returns((a, b) => a == b); // ... some testing code ... await Assert.That(equals).WasCalled(Times.Once);

... this might be an alternative:

var equalityComparer = Mock.Of<IEqualityComparer>(); var equals = equalityComparer.SetupEquals((a, b) => a == b, if: (_, b) => b > 0); // ... some testing code ... await Assert.That(equals).WasCalled(Times.Once);

It is not necessary the best way to do it and it will need some refinement, but I think it is already better than the classical syntax.
A few points to think about: