|
1 | 1 | Unity Coroutines for NSubstitute |
2 | 2 | ======== |
3 | 3 | [](https://github.com/AAulicino/Unity-Coroutines-for-NSubstitute/actions/workflows/main.yml) |
| 4 | + |
| 5 | +- [Unity Coroutines for NSubstitute](#unity-coroutines-for-nsubstitute) |
| 6 | + * [What is it?](#what-is-it) |
| 7 | + * [Installation](#installation) |
| 8 | + * [Basic use](#basic-use) |
| 9 | + + [Creating the mock](#creating-the-mock) |
| 10 | + + [Using the mock](#using-the-mock) |
| 11 | + + [Custom Assertions](#custom-assertions) |
| 12 | + |
4 | 13 | ## What is it? |
5 | 14 |
|
6 | 15 | Testing and mocking Unity Coroutines can be tricky. This is an extension for |
@@ -73,7 +82,7 @@ Let's use this simple counter class for testing: |
73 | 82 | while (true) |
74 | 83 | { |
75 | 84 | Current++; |
76 | | - yield return null; |
| 85 | + yield return new WaitForSeconds(1); |
77 | 86 | } |
78 | 87 | } |
79 | 88 | } |
@@ -116,4 +125,28 @@ public class GameSetup : MonoBehaviour, ICoroutineRunner |
116 | 125 | } |
117 | 126 | ``` |
118 | 127 |
|
| 128 | +### Custom Assertions |
| 129 | + |
| 130 | +You can also assert the yielded values from the coroutine: |
| 131 | + |
| 132 | +```csharp |
| 133 | +ICoroutineRunner runner = CoroutineSubstitute.Create(); |
| 134 | +Counter counter = new Counter(Runner); |
| 135 | + |
| 136 | +Runner.MoveNextAndExpect<WaitForSeconds>(); |
| 137 | +``` |
| 138 | + |
| 139 | +To assert the amount of seconds configured in the `WaitForSeconds` object: |
| 140 | +```csharp |
| 141 | +ICoroutineRunner runner = CoroutineSubstitute.Create(); |
| 142 | +Counter counter = new Counter(Runner); |
| 143 | + |
| 144 | +Runner.MoveNextAndExpect(new WaitForSeconds(1)); |
| 145 | +``` |
| 146 | + |
| 147 | + |
119 | 148 | Other samples can be found in the [Samples](https://github.com/AAulicino/Unity-Coroutines-for-NSubstitute/tree/main/Tests/Editor/Samples) folder. |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +You can also have a look at the [SystemTests](https://github.com/AAulicino/Unity-Coroutines-for-NSubstitute/tree/main/Tests/Editor/SystemTests) folder as the tests found in there represent some real uses cases. |
0 commit comments