-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathUnitTestExExpectations.cs
More file actions
40 lines (37 loc) · 1.96 KB
/
Copy pathUnitTestExExpectations.cs
File metadata and controls
40 lines (37 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma warning disable IDE0130 // Namespace does not match folder structure; by design.
namespace UnitTestEx.Expectations;
#pragma warning restore IDE0130 // Namespace does not match folder structure
/// <summary>
/// Provides <see cref="CoreEx"/>-specific extension methods to <see cref="UnitTestEx"/>.
/// </summary>
public static partial class UnitTestExExpectations
{
/// <summary>
/// Sets the configured expectation logic.
/// </summary>
private static TSelf SetValueExpectationExtension<TValue, TSelf>(this IValueExpectations<TValue, TSelf> tester, Func<AssertArgs, Task<bool>> extension) where TSelf : IValueExpectations<TValue, TSelf>
{
tester.ExpectationsArranger.GetOrAdd(() => new ValueExpectations<TSelf>(tester.ExpectationsArranger.Owner, (TSelf)tester)).AddExtension(extension);
return (TSelf)tester;
}
/// <summary>
/// Verifies that the <typeparamref name="TValue"/> implements <typeparamref name="TInterface"/>.
/// </summary>
private static void VerifyImplements<TValue, TInterface>()
{
if (typeof(TValue).GetInterface(typeof(TInterface).FullName ?? typeof(TInterface).Name) == null)
throw new InvalidOperationException($"{typeof(TValue).Name} must implement the interface {typeof(TInterface).Name}.");
}
/// <summary>
/// Adds <paramref name="paths"/> to ignore from the JSON value comparison.
/// </summary>
/// <typeparam name="TSelf">The expectations <see cref="Type"/>.</typeparam>
/// <param name="tester">The <see cref="IExpectations{TSelf}"/> tester.</param>
/// <param name="paths">The JSON paths to ignore.</param>
/// <returns>The <typeparamref name="TSelf"/> instance to support fluent-style method-chaining.</returns>
public static TSelf IgnorePaths<TSelf>(IExpectations<TSelf> tester, params string[] paths) where TSelf : IExpectations<TSelf>
{
tester.ExpectationsArranger.PathsToIgnore.AddRange(paths);
return (TSelf)tester;
}
}