Based on the materials of YouTube video by Nick Chapsas
(@Elfocrash)
This attribute indicates to the source code generator the type and its method in which certain methods specified in the Intercepted<TInterception, TReturn>
arguments should be intercepted
The source code generator can get the following data from this data:
- Line numbers and the path to the file containing this type;
- Return value of the method;
- Synchronous or asynchronous method.
This attribute specifies the following data to the source code generator:
- Intercepted type -
TInterception
; - Return value type -
TReturn
; - The name of the intercepted method -
interceptionMethodName
; - The required return value -
returnValue
. This value must be nullable.
Also, the constructor of this attribute must have 2 overloads: with and without the return value.
In the second case, the source code generator should automatically return void
or non-generic classes Task
or ValueTask
when the call in the method under test is not essential for the test itself.
- How will the compiler understand which generated method to use? For example, if you run both tests from option 1, how should the compiler understand that some methods are needed in the first test, and others in the second, if both intercept the same lines of code?
- Would it be right to move away from the usual practice of writing unit tests, where one service class (for example) tests one test class and all its methods? Or would a separation similar to the REPR pattern be appropriate in this case when one test class is responsible for only one test method of the service?