-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Mock DbContext Async methods and SqlLite methods (#29)
* Add Async handling * Fix interface for original functionality while maintaining new functionality. * Fix GetDbContext with SqlLite db
- Loading branch information
Showing
11 changed files
with
454 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace FastMoq.Extensions | ||
{ | ||
/// <summary> | ||
/// Class ObjectExtensions. | ||
/// </summary> | ||
public static class ObjectExtensions | ||
{ | ||
/// <summary> | ||
/// Raises if predicate is true. | ||
/// </summary> | ||
/// <param name="predicate">The predicate.</param> | ||
/// <param name="name">The name.</param> | ||
/// <param name="path">The path.</param> | ||
/// <param name="line">The line.</param> | ||
/// <param name="exp">The exp.</param> | ||
/// <returns><c>true</c> if expression is true, <c>false</c> otherwise.</returns> | ||
/// <exception cref="System.InvalidOperationException"></exception> | ||
public static bool RaiseIf(Func<bool> predicate, string name, string path, int line, string exp) => | ||
predicate() ? throw new InvalidOperationException($"{exp} in {name} is invalid on line {line} of {path}") : true; | ||
|
||
/// <summary> | ||
/// Raises if null. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="thing">The thing.</param> | ||
/// <param name="name">The name.</param> | ||
/// <param name="path">The path.</param> | ||
/// <param name="line">The line.</param> | ||
/// <param name="exp">The exp.</param> | ||
/// <exception cref="System.InvalidOperationException"></exception> | ||
public static void RaiseIfNull<T>([NotNull] this T? thing, [CallerMemberName] string? name = null, [CallerFilePath] string? path = null, | ||
[CallerLineNumber] int? line = null, [CallerArgumentExpression(nameof(thing))] string? exp = null) | ||
where T : class | ||
=> RaiseIf(() => thing is null, name ?? string.Empty, path ?? string.Empty, line ?? 0, exp ?? string.Empty); | ||
|
||
/// <summary> | ||
/// Raises if null. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="thing">The thing.</param> | ||
/// <param name="name">The name.</param> | ||
/// <param name="path">The path.</param> | ||
/// <param name="line">The line.</param> | ||
/// <param name="exp">The exp.</param> | ||
/// <exception cref="System.InvalidOperationException"></exception> | ||
public static void RaiseIfNull<T>([NotNull] this T? thing, [CallerMemberName] string? name = null, [CallerFilePath] string? path = null, | ||
[CallerLineNumber] int? line = null, [CallerArgumentExpression(nameof(thing))] string? exp = null) | ||
where T : struct | ||
=> RaiseIf(() => thing is null, name ?? string.Empty, path ?? string.Empty, line ?? 0, exp ?? string.Empty); | ||
|
||
/// <summary> | ||
/// Raises if null or empty. | ||
/// </summary> | ||
/// <param name="thing">The thing.</param> | ||
/// <param name="name">The name.</param> | ||
/// <param name="path">The path.</param> | ||
/// <param name="line">The line.</param> | ||
/// <param name="exp">The exp.</param> | ||
public static void RaiseIfNullOrEmpty([NotNull] this string? thing, [CallerMemberName] string? name = null, | ||
[CallerFilePath] string? path = null, [CallerLineNumber] int? line = null, [CallerArgumentExpression(nameof(thing))] string? exp = null) | ||
=> RaiseIf(() => string.IsNullOrEmpty(thing), name ?? string.Empty, path ?? string.Empty, line ?? 0, exp ?? string.Empty); | ||
|
||
/// <summary> | ||
/// Raises if null or whitespace. | ||
/// </summary> | ||
/// <param name="thing">The thing.</param> | ||
/// <param name="name">The name.</param> | ||
/// <param name="path">The path.</param> | ||
/// <param name="line">The line.</param> | ||
/// <param name="exp">The exp.</param> | ||
public static void RaiseIfNullOrWhitespace([NotNull] this string? thing, [CallerMemberName] string? name = null, | ||
[CallerFilePath] string? path = null, [CallerLineNumber] int? line = null, [CallerArgumentExpression(nameof(thing))] string? exp = null) | ||
=> RaiseIf(() => string.IsNullOrWhiteSpace(thing), name ?? string.Empty, path ?? string.Empty, line ?? 0, exp ?? string.Empty); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.