Commit ce576e1
authored
refactor: improve concurrent test cases for mock setup (#607)
This pull request updates unit tests and test helpers to improve test reliability and correctness, especially around method and indexer setup matching. The most significant changes include fixing the logic for determining the latest matching setup in tests and introducing a new `FakeMethodMatch` helper class.
**Test logic improvements:**
* Updated `GetLatestOrDefault_ShouldReturnLatestMatching` in `MockSetupsTests.MethodSetupsTests.cs` to check that the latest added matching setup is returned, aligning with expected behavior.
* Refactored `ThreadSafety_ConcurrentAddsAndQueries_ShouldReturnConsistentMatches` in `MockSetupsTests.IndexerSetupsTests.cs` to more accurately track and assert the latest matching setup under concurrent conditions, removing unnecessary helper methods and using `Interlocked.Exchange` for thread safety.
**Test helper enhancements:**
* Added a new `FakeMethodMatch` class to `TestHelpers/FakeMethodSetup.cs` to allow configurable matching logic for method setups in tests.
* Updated `FakeMethodSetup` to use `FakeMethodMatch` for more flexible and accurate test setup.
**Other:**
* Added missing `System.Threading` using directive to `MockSetupsTests.IndexerSetupsTests.cs` to support thread-safe operations.1 parent 33ee188 commit ce576e1
3 files changed
Lines changed: 16 additions & 20 deletions
File tree
- Tests/Mockolate.Internal.Tests
- TestHelpers
Lines changed: 6 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
| 42 | + | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
53 | 54 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | 55 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 56 | + | |
65 | 57 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 58 | + | |
70 | 59 | | |
71 | 60 | | |
72 | 61 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
6 | 13 | | |
7 | 14 | | |
8 | | - | |
| 15 | + | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
| |||
0 commit comments