|
| 1 | +# Decision on Supporting Methods |
| 2 | + |
| 3 | +## Context |
| 4 | + |
| 5 | +In the MiniMock framework, there is a need to determine the scope of support for mocking methods. Supporting all standard ways of creating methods is essential to ensure the framework's |
| 6 | +flexibility and usability. |
| 7 | + |
| 8 | +The following type of methods must be supported |
| 9 | +- __Asynchronous__ with Task<>, Task, CancellationToken |
| 10 | +- __Overloaded__ methods in a way that keeps the required effort to setup the mock to a minimum. |
| 11 | +- __Generic__ Including the 'where' __constraints__. |
| 12 | +- __Out__ and __ref__ attributes on the method parameters. |
| 13 | + |
| 14 | +## Decision |
| 15 | + |
| 16 | +The MiniMock framework will support all standard ways of creating methods. This includes instance methods, static methods, virtual methods, and abstract methods. However, support for methods returning `ref` values will require additional work and will be addressed in future updates. See [issue #5](https://github.com/oswaldsql/MiniMock/issues/5) |
| 17 | + |
| 18 | +Methods must be mockable using the following parameters |
| 19 | + |
| 20 | +- Call : A Delegate matching the method signature with functionality to be executed. |
| 21 | +- Throw : An exception to be thrown when the method is called. |
| 22 | +- Return : A value to be returned when the method is called. |
| 23 | +- ReturnValues : A sequence of values to be returned when the method is called multiple times. |
| 24 | +- () : Methods returning `void` can be mocked using an empty delegate. |
| 25 | + |
| 26 | +if none of the above parameters are provided, calling the method must throw a InvalidOperationException with a message in the form "The method '__[method name]__' in '__[mocked class]__' is not explicitly mocked.". |
| 27 | + |
| 28 | +__Asynchronous__ methods are supported. Helper methods are provided to simplify the testing of asynchronous methods. Overloads of the following helper methods are added |
| 29 | + |
| 30 | +- Return : Allows for returning either a Task object or the object to be wrapped in the task object. |
| 31 | +- ReturnValues : Allows for returning either a sequence of Task objects or a sequence of objects to be wrapped in task objects. |
| 32 | +- () : Methods returning Task can also use the empty delegate. |
| 33 | + |
| 34 | +__Overloaded__ methods can either be mocked explicitly by using `Call` or collectively using the following |
| 35 | + |
| 36 | +- Throw : An exception to be thrown when calling any of the overwritten methods. |
| 37 | +- Return : A value to be returned when a method with that return type is called. |
| 38 | +- ReturnValues : A sequence of values to be returned when a method with those return types is called multiple times. |
| 39 | +- () : Methods returning `void` or `Task` can be mocked using an empty delegate. |
| 40 | + |
| 41 | +Generic methods are supported. The generic type is passed as a type parameter to the 'call' labmda method. |
| 42 | + |
| 43 | +## Consequences |
| 44 | + |
| 45 | +### Positive: |
| 46 | + |
| 47 | +- **Comprehensive**: Ensures that the framework can handle a wide variety of method types. |
| 48 | +- **Flexibility**: Provides developers with the ability to mock different kinds of methods, enhancing the framework's usability. |
| 49 | + |
| 50 | +### Negative: |
| 51 | + |
| 52 | +- **Complexity**: Supporting all standard methods adds complexity to the framework. |
| 53 | +- **Ref Values**: Current issues with methods returning `ref` values need to be resolved, which may require significant effort. |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +More ADRs can be found in the [docs/ADR](../README.md) directory. |
0 commit comments