Equals()
is called on the parameter actually passed in rather than the mock setup parameter. So instead of only needing to pass that derived class in Setup()
, I would need to modify my actual code to use a HttpMessageHandler
that uses the derived class behind the scenes. Anyway thanks for the help, for this particular use case I am actually pursuing using mockhttp
instead, it's a little more forgiving here in that I can define a custom Func<bool>
to match a request
IFluentInterface
, as it is not in the project. Now it is complaining Process finished with exception The target "Restore" does not exist in the project. /repo/Directory.Build.props
. What shall I do?
Heya @kzu, I've been meaning to ask you for a while whether you'd be OK with changing Moq 4's copyright notice so it includes contributors (such as myself :wink:).
That's what we have right now:
Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD.
If it's OK with you, I'd like to change it to this:
Copyright (c) 2007, Clarius Consulting, Manas Technology Solutions, InSTEDD, and Contributors.
Microsoft.Extensions.Configuration.IConfiguration
)IConfiguration.Item
when I call configurationMock.VerifyNoOtherCalls()
.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);
Called:
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.Is
and 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.