microsoft / UnitTestBoilerplateGenerator

An extension for Visual Studio that generates a unit test boilerplate from a given class, setting up mocks for all dependencies. Supports NUnit, Visual Studio Test, Moq and SimpleStubs.
MIT License
158 stars 51 forks source link

$ClassName.CamelCase$ not working in Mock field initialization format field #23

Closed cesarfp closed 6 years ago

cesarfp commented 6 years ago

In "Mock field initialization format" field I have this:

$InterfaceMockName.CamelCase$ = $ClassName.CamelCase$.Get<$InterfaceType$>();

And the result is this:

countryRepository = $ClassName$.Get();

RandomEngy commented 6 years ago

$ClassName$ refers to the name of the class being tested, and is not valid in the mock field initialization format string. See https://github.com/Microsoft/UnitTestBoilerplateGenerator/wiki/Custom-Format-Tokens

It sounds like you'd like the ClassName token to be available here as well. Would you be able to work around it by naming the field _testedClass or something static?

cesarfp commented 6 years ago

Hi! Thanks for your reply. Yes, that's what I was trying to do. I need the ClassName token because this is the way that I initialize the mock fields. Something static doesn't help me because I was trying to create the template for be able to generate the unit tests of my other classes, but it looks like this is not possible then :/

RandomEngy commented 6 years ago

I can't say I fully understand what you're going for, but it might be pretty easy to allow the "global" tokens at this scope as well.

cesarfp commented 6 years ago

How can I do that? Inside the code?

RandomEngy commented 6 years ago

Oh sorry, I'm just talking about how hard it would be for me to do. The change is on my backlog, I'll work on it when I find some time.

cesarfp commented 6 years ago

What a pity. I think that would be a good feature because it is less restricted and more customizable. Thanks for your help!

RandomEngy commented 6 years ago

You misunderstand. I said I'd implement it. :P

cesarfp commented 6 years ago

I just said that because I wanted to use the extension in my current project. But It's great to hear you have the change on your backlog. Thanks.

RandomEngy commented 6 years ago

If it's any consolation it's the only item on the backlog. :)

cesarfp commented 6 years ago

Haha, thanks man, I'll be happy to wait for the update!

RandomEngy commented 6 years ago

Just released 1.6.9. It will replace globally-scoped tokens in the interface templates.