IConfiguration.Itemwhen I call
Hi. I'm attempting to use
It.Is<> outside of
Setup but it seems to be returning null - I assume due to relying on knowing the current method. I was trying to add some code to remove boilerplate where the only thing changing is an argument (and condition expression) to a method call. Something like:
var mockCommandBus = new Mock<ICommandBus>(); mockCommandBus .Setup(_ => _.PublishAsync( testCommand, It.IsAny<CancellationToken>())) .ReturnsAsync(result); return (mockCommandBus.Object, mockCommandBus);
CommandBusBuilder.BuildMockCommandCall( It.Is<RegisterNewApplication>(_ => _.Name == name && _.Description == description), Result.Ok(new ApplicationId(id)));
Setup. Anyone got any thoughts on this? Alternatives? I'm trying to avoid constantly writing the first block.
It.Isand other matchers only work when used inside LINQ expression tree. What's important is their identity, so to speak, and that is only preserved in a LINQ expression tree. Once evaluated, that is gone and all ypu're left with is their retuen value, which is in fact completely irrelevant & ignored by Moq.
Expression.*factory methods which is going to be a pain in the b*tt compared to the C# compiler doing that for you automagically.
Span<T>and other by-ref-like types due to limitations in .NET Reflection and LINQ expression trees. No way around it unfortunately.