Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 82 additions & 41 deletions Source/Mockolate.SourceGenerators/Sources/Sources.IndexerSetups.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private static void AppendVoidMethodSetup(StringBuilder sb, int numberOfParamete
sb.Append("{").AppendLine();
sb.Append("\t\t/// <summary>").AppendLine();
sb.Append(
"\t\t/// Limits the callback to only execute for the given number of <paramref name=\"times\" />.")
"\t\t/// Repeats the callback for the given number of <paramref name=\"times\" />.")
.AppendLine();
sb.Append("\t\t/// </summary>").AppendLine();
sb.Append("\t\t/// <remarks>").AppendLine();
Expand Down Expand Up @@ -331,7 +331,7 @@ private static void AppendVoidMethodSetup(StringBuilder sb, int numberOfParamete
sb.Append("{").AppendLine();
sb.Append("\t\t/// <summary>").AppendLine();
sb.Append(
"\t\t/// Limits the throw to only execute for the given number of <paramref name=\"times\" />.")
"\t\t/// Repeats the throw for the given number of <paramref name=\"times\" />.")
.AppendLine();
sb.Append("\t\t/// </summary>").AppendLine();
sb.Append("\t\t/// <remarks>").AppendLine();
Expand Down Expand Up @@ -599,7 +599,7 @@ private static void AppendVoidMethodSetup(StringBuilder sb, int numberOfParamete
.Append(typeParams)
.Append(">.For(int times)").AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\t_currentCallback?.For(x => x < times);").AppendLine();
sb.Append("\t\t\t_currentCallback?.For(times);").AppendLine();
sb.Append("\t\t\treturn this;").AppendLine();
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
Expand Down Expand Up @@ -633,7 +633,7 @@ private static void AppendVoidMethodSetup(StringBuilder sb, int numberOfParamete
.Append(typeParams)
.Append(">.For(int times)").AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\t_currentReturnCallback?.For(x => x < times);").AppendLine();
sb.Append("\t\t\t_currentReturnCallback?.For(times);").AppendLine();
sb.Append("\t\t\treturn this;").AppendLine();
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
Expand Down Expand Up @@ -967,7 +967,7 @@ private static void AppendReturnMethodSetup(StringBuilder sb, int numberOfParame
sb.Append("{").AppendLine();
sb.Append("\t\t/// <summary>").AppendLine();
sb.Append(
"\t\t/// Limits the callback to only execute for the given number of <paramref name=\"times\" />.")
"\t\t/// Repeats the callback for the given number of <paramref name=\"times\" />.")
.AppendLine();
sb.Append("\t\t/// </summary>").AppendLine();
sb.Append("\t\t/// <remarks>").AppendLine();
Expand Down Expand Up @@ -1039,7 +1039,7 @@ private static void AppendReturnMethodSetup(StringBuilder sb, int numberOfParame
sb.Append("{").AppendLine();
sb.Append("\t\t/// <summary>").AppendLine();
sb.Append(
"\t\t/// Limits the callback to only execute for the given number of <paramref name=\"times\" />.")
"\t\t/// Repeats the callback for the given number of <paramref name=\"times\" />.")
.AppendLine();
sb.Append("\t\t/// </summary>").AppendLine();
sb.Append("\t\t/// <remarks>").AppendLine();
Expand Down Expand Up @@ -1345,7 +1345,7 @@ private static void AppendReturnMethodSetup(StringBuilder sb, int numberOfParame
.Append("> IReturnMethodSetupCallbackWhenBuilder<TReturn, ").Append(typeParams)
.Append(">.For(int times)").AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\t_currentCallback?.For(x => x < times);").AppendLine();
sb.Append("\t\t\t_currentCallback?.For(times);").AppendLine();
sb.Append("\t\t\treturn this;").AppendLine();
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
Expand Down Expand Up @@ -1378,7 +1378,7 @@ private static void AppendReturnMethodSetup(StringBuilder sb, int numberOfParame
.Append("> IReturnMethodSetupReturnWhenBuilder<TReturn, ").Append(typeParams)
.Append(">.For(int times)").AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\t_currentReturnCallback?.For(x => x < times);").AppendLine();
sb.Append("\t\t\t_currentReturnCallback?.For(times);").AppendLine();
sb.Append("\t\t\treturn this;").AppendLine();
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
Expand Down
18 changes: 9 additions & 9 deletions Source/Mockolate/Setup/Callback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Mockolate.Setup;
/// </summary>
public class Callback
{
private int? _forTimes;
private Func<int, bool>? _invocationPredicate;
private Func<int, bool>? _matchingPredicate;
private int _onlyTimes;

/// <summary>
Expand All @@ -20,7 +20,7 @@ public class Callback
/// <summary>
/// Check if a <see cref="For" />-predicate was specified.
/// </summary>
protected bool HasForSpecified => _matchingPredicate != null;
protected bool HasForSpecified => _forTimes != null;

/// <summary>
/// Flag indicating whether the callback is active.
Expand All @@ -45,15 +45,15 @@ public void When(Func<int, bool> predicate)
=> _invocationPredicate = predicate;

/// <summary>
/// Limits the callback to only execute for matching property accesses where the predicate returns
/// Repeats the callback for the given number of <paramref name="times" />.
/// <see langword="true" />.
/// </summary>
/// <remarks>
/// The number of times is only counted for actual executions (<see cref="When" /> evaluates to <see langword="true" />
/// ).
/// The number of times is only counted for actual executions (<see cref="When" /> evaluates
/// to <see langword="true" />).
/// </remarks>
public void For(Func<int, bool> predicate)
=> _matchingPredicate = predicate;
public void For(int times)
=> _forTimes = times;

/// <summary>
/// Deactivates the callback after it was invoked the given number of <paramref name="times" />.
Expand Down Expand Up @@ -82,10 +82,10 @@ protected bool CheckInvocations(int invocationCount)
=> _invocationPredicate?.Invoke(invocationCount) ?? true;

/// <summary>
/// Check if the invocation count satisfies the <see cref="For" />-predicate.
/// Check if the callback should be repeated (at least) once more.
/// </summary>
protected bool CheckMatching(int matchingCount)
=> _matchingPredicate?.Invoke(matchingCount) ?? true;
=> _forTimes is null || matchingCount < _forTimes;
}

/// <summary>
Expand Down
16 changes: 8 additions & 8 deletions Source/Mockolate/Setup/IndexerSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ IIndexerSetupCallbackBuilder<TValue, T1> IIndexerSetupCallbackBuilder<TValue, T1
/// <inheritdoc cref="IIndexerSetupCallbackWhenBuilder{TValue,T1}.For(int)" />
IIndexerSetupCallbackWhenBuilder<TValue, T1> IIndexerSetupCallbackWhenBuilder<TValue, T1>.For(int times)
{
_currentCallback?.For(x => x < times);
_currentCallback?.For(times);
return this;
}

Expand All @@ -376,7 +376,7 @@ IIndexerSetupReturnWhenBuilder<TValue, T1> IIndexerSetupReturnBuilder<TValue, T1
/// <inheritdoc cref="IIndexerSetupReturnWhenBuilder{TValue,T1}.For(int)" />
IIndexerSetupReturnWhenBuilder<TValue, T1> IIndexerSetupReturnWhenBuilder<TValue, T1>.For(int times)
{
_currentReturnCallback?.For(x => x < times);
_currentReturnCallback?.For(times);
return this;
}

Expand Down Expand Up @@ -711,7 +711,7 @@ IIndexerSetupCallbackBuilder<TValue, T1, T2> IIndexerSetupCallbackBuilder<TValue
/// <inheritdoc cref="IIndexerSetupCallbackWhenBuilder{TValue,T1, T2}.For(int)" />
IIndexerSetupCallbackWhenBuilder<TValue, T1, T2> IIndexerSetupCallbackWhenBuilder<TValue, T1, T2>.For(int times)
{
_currentCallback?.For(x => x < times);
_currentCallback?.For(times);
return this;
}

Expand All @@ -733,7 +733,7 @@ IIndexerSetupReturnWhenBuilder<TValue, T1, T2> IIndexerSetupReturnBuilder<TValue
/// <inheritdoc cref="IIndexerSetupReturnWhenBuilder{TValue,T1, T2}.For(int)" />
IIndexerSetupReturnWhenBuilder<TValue, T1, T2> IIndexerSetupReturnWhenBuilder<TValue, T1, T2>.For(int times)
{
_currentReturnCallback?.For(x => x < times);
_currentReturnCallback?.For(times);
return this;
}

Expand Down Expand Up @@ -1083,7 +1083,7 @@ IIndexerSetupCallbackBuilder<TValue, T1, T2, T3> IIndexerSetupCallbackBuilder<TV
IIndexerSetupCallbackWhenBuilder<TValue, T1, T2, T3> IIndexerSetupCallbackWhenBuilder<TValue, T1, T2, T3>.
For(int times)
{
_currentCallback?.For(x => x < times);
_currentCallback?.For(times);
return this;
}

Expand All @@ -1105,7 +1105,7 @@ IIndexerSetupReturnWhenBuilder<TValue, T1, T2, T3> IIndexerSetupReturnBuilder<TV
/// <inheritdoc cref="IIndexerSetupReturnWhenBuilder{TValue,T1, T2, T3}.For(int)" />
IIndexerSetupReturnWhenBuilder<TValue, T1, T2, T3> IIndexerSetupReturnWhenBuilder<TValue, T1, T2, T3>.For(int times)
{
_currentReturnCallback?.For(x => x < times);
_currentReturnCallback?.For(times);
return this;
}

Expand Down Expand Up @@ -1469,7 +1469,7 @@ IIndexerSetupCallbackBuilder<TValue, T1, T2, T3, T4> IIndexerSetupCallbackBuilde
IIndexerSetupCallbackWhenBuilder<TValue, T1, T2, T3, T4> IIndexerSetupCallbackWhenBuilder<TValue, T1, T2, T3, T4>.
For(int times)
{
_currentCallback?.For(x => x < times);
_currentCallback?.For(times);
return this;
}

Expand All @@ -1492,7 +1492,7 @@ IIndexerSetupReturnWhenBuilder<TValue, T1, T2, T3, T4> IIndexerSetupReturnBuilde
IIndexerSetupReturnWhenBuilder<TValue, T1, T2, T3, T4> IIndexerSetupReturnWhenBuilder<TValue, T1, T2, T3, T4>.
For(int times)
{
_currentReturnCallback?.For(x => x < times);
_currentReturnCallback?.For(times);
return this;
}

Expand Down
Loading
Loading