When Stub return actions or stubs should depend on the arguments, you can use the Do handler few examples in github
Regarding your example.
My assumptions:
There are several CarMake and interface IMetadataLogic , as shown below:
class CarMake { public string Id { get; set; } } interface IMetadataLogic { CarMake GetMake(string id); }
And metadataLogic is
var metadataLogic = MockRepository.GenerateStub<IMetadataLogic>();
If you just need to install Stub, which returns an instance of CarMake with the specified Id , then you can do something like this:
metadataLogic .Stub(x => x.GetMake(Arg<string>.Is.Anything)) .Do((Func<string, CarMake>)(id => new CarMake { Id = id }));
Unfortunately, an explicit lambda expression for the delegate is necessary.
Note that the stub in my example works for any argument, but the stub in your example only works for args.Vehicle1.Make and for args.Vehicle2.Make .
PS
If you just need to install Stub, you do not need to use the Expect() method. You can use Stub() instead.
source share