You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Ensures that the immutable array contains the specified item, or otherwise throws your custom exception.
228
+
/// </summary>
229
+
/// <param name="parameter">The immutable array to be checked.</param>
230
+
/// <param name="item">The item that must be part of the immutable array.</param>
231
+
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" /> and <paramref name="item" /> are passed to this delegate.</param>
232
+
/// <exception cref="Exception">Your custom exception thrown when <paramref name="parameter" /> does not contain <paramref name="item" />.</exception>
The .NET library Light.GuardClauses already has several assertions for collections. They often rely on `IEnumerable<T>` or `IEnumerable`. However, these assertions would result in `ImmutableArray<T>` being boxed - we want to avoid that by providing dedicated assertions for this type which avoids boxing. For this issue, we implement the `MustContain` assertion for `ImmutableArray<T>`.
6
+
7
+
## Tasks for this issue
8
+
9
+
-[ ] The production code should be placed in the Light.GuardClauses project. Extend the existing `Check.MustContain.cs` in the root folder of the project.
10
+
-[ ] In this file, add several extension method overloads called `MustContain` for `ImmutableArray<T>`. They should be placed in the existing class `Check` which is marked as `partial`.
11
+
-[ ] Each assertion in Light.GuardClauses has two overloads - the first one takes the optional `parameterName` and `message` arguments and throws the default exception (in this case the existing `MissingItemException`). The actual exception is thrown in the `Throw` class, you need to call the existing method for it in this class.
12
+
-[ ] The other overload takes a delegate which allows the caller to provide their own custom exceptions. Use the existing `Throw.CustomException` method and pass the delegate, the erroneous `ImmutableArray<T>` instance and the missing item.
13
+
-[ ] Create unit tests for both overloads. The corresponding tests should be placed in Light.GuardClauses.Tests project, in the existing file 'CollectionAssertions/MustContainTests.cs'. Please follow conventions of the existing tests (e.g. use FluentAssertions' `Should()` for assertions).
14
+
15
+
## Notes
16
+
17
+
- There are already plenty of other assertions and tests in this library. All overloads are placed in the same file in the production code project. The test projects has top-level folders for different groups of assertions, like `CollectionAssertions`, `StringAssertions`, `DateTimeAssertions` and so on. Please take a look at them to follow a similar structure and code style.
18
+
- This assertion specifically targets `ImmutableArray<T>` to avoid boxing that would occur with generic `IEnumerable<T>` extensions.
19
+
- The assertion should verify that the `ImmutableArray<T>` contains the specified item.
20
+
- If you have any questions or suggestions, please ask me about them.
0 commit comments