Template Question
Answered
Hi,
I often find myself doing something like this
[TestFixture]public class XyzTests
{
ISomeService _alpha;
IOtherService _bravo;
Xyz _underTest;
[SetUp]
public void Setup()
{
_alpha= Substitute.For<ISomeService>(); // <=== HERE
_bravo= Substitute.For<IOtherService>(); // <=== and HERE
_underTest= new Xyz(_alpha, _bravo);
}
}
Note the two marked lines. I'm looking for a way to write a template so that I would just type the name of the field - for example _alpha - and the rest of the line is generated.
So I looked into live templates and macros. But I can't figure out how to get to the type of the field (eg, _alpha) so I could fill it in as type parameter to the .For<> clause.
Any idea how to do this would be very much appreciated. This is such a frequent activity for me that anything shaving off a few seconds of it will make my life happier :-)
Thank you & cheers,
Mark
Please sign in to leave a comment.
We discussed the problem and came to the conclusion that in order to achieve this behavior, the following pattern should be used:
$name$ = Substitute.For<$type$>();
with "Guess type expected at this point" macro selected for $type$.