Skip to content

Commit

Permalink
fix(S4487): remove unused private field.
Browse files Browse the repository at this point in the history
  • Loading branch information
skwasjer committed Sep 29, 2024
1 parent a451c71 commit 4ee064b
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions src/MockHttp/IsSent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ namespace MockHttp;
public sealed class IsSent
{
private readonly Func<int, bool> _evaluator;
private readonly int _min;
private readonly int _max;
private readonly string _name;
private readonly string _message;

private IsSent(Func<int, bool> evaluator, int min, int max, string name, string message)
private IsSent(Func<int, bool> evaluator, string name, string message)
{
_evaluator = evaluator ?? throw new ArgumentNullException(nameof(evaluator));
_min = min;
_max = max;
_name = name;
_message = message;
}
Expand All @@ -32,15 +28,23 @@ public static IsSent AtLeast(int callCount)
throw new ArgumentOutOfRangeException(nameof(callCount));
}

return new IsSent(i => i >= callCount, callCount, int.MaxValue, $"{nameof(AtLeast)}({callCount})", $"Expected request to have been sent at least {callCount} time(s){{0}}, but was sent only {{1}} time(s).");
return new IsSent(
i => i >= callCount,
$"{nameof(AtLeast)}({callCount})",
$"Expected request to have been sent at least {callCount} time(s){{0}}, but was sent only {{1}} time(s)."
);
}

/// <summary>
/// Specifies that the mocked request should be sent one time at minimum.
/// </summary>
public static IsSent AtLeastOnce()
{
return new IsSent(i => i >= 1, 1, int.MaxValue, nameof(AtLeastOnce), "Expected request to have been sent at least once{0}, but it was not.");
return new IsSent(
i => i >= 1,
nameof(AtLeastOnce),
"Expected request to have been sent at least once{0}, but it was not."
);
}

/// <summary>
Expand All @@ -53,15 +57,23 @@ public static IsSent AtMost(int callCount)
throw new ArgumentOutOfRangeException(nameof(callCount));
}

return new IsSent(i => i <= callCount, 0, callCount, $"{nameof(AtMost)}({callCount})", $"Expected request to have been sent at most {callCount} time(s){{0}}, but was actually sent {{1}} time(s).");
return new IsSent(
i => i <= callCount,
$"{nameof(AtMost)}({callCount})",
$"Expected request to have been sent at most {callCount} time(s){{0}}, but was actually sent {{1}} time(s)."
);
}

/// <summary>
/// Specifies that the mocked request should be sent one time at maximum.
/// </summary>
public static IsSent AtMostOnce()
{
return new IsSent(i => i <= 1, 0, 1, nameof(AtMostOnce), "Expected request to have been sent at most once{0}, but was actually sent {1} time(s).");
return new IsSent(
i => i <= 1,
nameof(AtMostOnce),
"Expected request to have been sent at most once{0}, but was actually sent {1} time(s)."
);
}

/// <summary>
Expand All @@ -74,23 +86,35 @@ public static IsSent Exactly(int callCount)
throw new ArgumentOutOfRangeException(nameof(callCount));
}

return new IsSent(i => i == callCount, callCount, callCount, $"{nameof(Exactly)}({callCount})", $"Expected request to have been sent exactly {callCount} time(s){{0}}, but was actually sent {{1}} time(s).");
return new IsSent(
i => i == callCount,
$"{nameof(Exactly)}({callCount})",
$"Expected request to have been sent exactly {callCount} time(s){{0}}, but was actually sent {{1}} time(s)."
);
}

/// <summary>
/// Specifies that the mocked request should not be sent.
/// </summary>
public static IsSent Never()
{
return new IsSent(i => i == 0, 0, 0, nameof(Never), "Expected request to have never been sent{0}, but was actually sent {1} time(s).");
return new IsSent(
i => i == 0,
nameof(Never),
"Expected request to have never been sent{0}, but was actually sent {1} time(s)."
);
}

/// <summary>
/// Specifies that the mocked request should be sent exactly one time.
/// </summary>
public static IsSent Once()
{
return new IsSent(i => i == 1, 1, 1, nameof(Once), "Expected request to have been sent exactly once{0}, but was actually sent {1} time(s).");
return new IsSent(
i => i == 1,
nameof(Once),
"Expected request to have been sent exactly once{0}, but was actually sent {1} time(s)."
);
}

internal bool Verify(int callCount)
Expand All @@ -100,7 +124,12 @@ internal bool Verify(int callCount)

internal string GetErrorMessage(int actualCount, string becauseMessage)
{
return string.Format(CultureInfo.CurrentCulture, _message, becauseMessage, actualCount);
return string.Format(
CultureInfo.CurrentCulture,
_message,
becauseMessage,
actualCount
);
}

/// <inheritdoc />
Expand Down

0 comments on commit 4ee064b

Please sign in to comment.