Skip to content

New Main Content Token #24

@jchesshir

Description

@jchesshir

Installed Product Versions

  • Visual Studio: 2019 Professional
  • This extension: 2.6.1

Description

The following token would be another nice addition to your main content section.

The particular use case I'm working with involves mimicking existing SUT functionality in an API level Constructor for our Business Level Tests. The constructor calls a function in the Business Level Base class. This Business Level function, if called, changes the default behavior of several of our MUTs (Methods Under Test). But we have to remember to call it EVERY time we generate a new Test class.

The complexity comes in the fact that this function automatically calls another function in the Database Level Base Interface, which is the base interface of every single Database interface that we have to mock. We are also using Strict detection, so the Database function will have to have to have an arrangement set up for it before the SUT's method is called. We know that each interface will be the first one that the UTBG picks up, but it will be one that is only known at generation time. We cannot merely name the base Interface and arrange it. We have to know the name of the mock object at code generation time.

This single new token would give us the flexibility we need to set up the template to automatically set up this call as part of the SUT initialization:

Scope Token Description Example
Main Content $MockField[&lt;n&gt;]$ The name of a generated mock field token where <n> is the field index of the token.
Also usable in the Test Method Invoke/Empty templates.
$MockField[0]$.baseClassFunction(); ->
mockChildInterface.baseClassFunction();
Main Content $MockField
<InterfaceOrClassName>$
The name of a generated mock field token where InterfaceOrClassName is the Class Name, a Base Class it inherits, or an Interface/Base Interface it implements.
Also usable in the Test Method Invoke/Empty templates.
$MockField&lt;BaseInterface&gt;$
.baseFunction(); ->
mockChildInterface.baseFunction();
Mock Field Formats $MockField$ The generated name for the mock object.
Specified by "Mock object reference format" field.
$MockField$.Object ->
mockChildInterface.Object

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions