diff --git a/Source/Mockolate.SourceGenerators/Sources/Sources.IndexerSetups.cs b/Source/Mockolate.SourceGenerators/Sources/Sources.IndexerSetups.cs
index d82ab7a6..defc523d 100644
--- a/Source/Mockolate.SourceGenerators/Sources/Sources.IndexerSetups.cs
+++ b/Source/Mockolate.SourceGenerators/Sources/Sources.IndexerSetups.cs
@@ -93,7 +93,7 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
string discards = string.Join(", ", Enumerable.Range(1, numberOfParameters).Select(_ => "_"));
sb.Append("\t/// ").AppendLine();
- sb.Append("\t/// Sets up a indexer for ");
+ sb.Append("\t/// Sets up a indexer getter for ");
for (int i = 1; i < numberOfParameters - 1; i++)
{
sb.Append(", ");
@@ -102,41 +102,14 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append(" and .").AppendLine();
sb.Append("\t/// ").AppendLine();
- sb.Append("\tinternal interface IIndexerSetup").AppendLine();
+ sb.Append("\tinternal interface IIndexerGetterSetup").AppendLine();
sb.Append("\t{").AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append(
- "\t\t/// Flag indicating if the base class implementation should be called, and its return values used as default values.")
- .AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\t/// If not specified, use .").AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetup CallingBaseClass(bool callBaseClass = true);").AppendLine();
- sb.AppendLine();
-
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\t/// Initializes the indexer with the given .").AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetup InitializeWith(TValue value);")
- .AppendLine();
- sb.AppendLine();
-
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\t/// Initializes the according to the given .")
- .AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetup InitializeWith(Func<")
- .Append(typeParams).Append(", TValue> valueGenerator);").AppendLine();
- sb.AppendLine();
-
sb.Append("\t\t/// ").AppendLine();
sb.Append(
"\t\t/// Registers a to be invoked whenever the indexer's getter is accessed.")
.AppendLine();
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetupCallbackBuilder OnGet(Action callback);")
+ sb.Append("\t\tIIndexerSetupCallbackBuilder Do(Action callback);")
.AppendLine();
sb.AppendLine();
@@ -148,7 +121,7 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t/// ").AppendLine();
sb.Append("\t\t/// The callback receives the parameters of the indexer.").AppendLine();
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetupCallbackBuilder OnGet(Action<")
+ sb.Append("\t\tIIndexerSetupCallbackBuilder Do(Action<")
.Append(typeParams)
.Append("> callback);").AppendLine();
sb.AppendLine();
@@ -161,7 +134,7 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t/// ").AppendLine();
sb.Append("\t\t/// The callback receives the parameters of the indexer and the value of the indexer as last parameter.").AppendLine();
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetupCallbackBuilder OnGet(Action<")
+ sb.Append("\t\tIIndexerSetupCallbackBuilder Do(Action<")
.Append(typeParams)
.Append(", TValue> callback);").AppendLine();
sb.AppendLine();
@@ -174,17 +147,30 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t/// ").AppendLine();
sb.Append("\t\t/// The callback receives an incrementing access counter as first parameter, the parameters of the indexer and the value of the indexer as last parameter.").AppendLine();
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetupCallbackBuilder OnGet(Action Do(Action callback);").AppendLine();
+ sb.Append("\t}").AppendLine();
sb.AppendLine();
+ sb.Append("\t/// ").AppendLine();
+ sb.Append("\t/// Sets up a indexer setter for ");
+ for (int i = 1; i < numberOfParameters - 1; i++)
+ {
+ sb.Append(", ");
+ }
+
+ sb.Append(" and .").AppendLine();
+ sb.Append("\t/// ").AppendLine();
+ sb.Append("\tinternal interface IIndexerSetterSetup").AppendLine();
+ sb.Append("\t{").AppendLine();
sb.Append("\t\t/// ").AppendLine();
sb.Append(
"\t\t/// Registers a to be invoked whenever the indexer's setter is accessed.")
.AppendLine();
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetupCallbackBuilder OnSet(Action callback);")
+ sb.Append("\t\tIIndexerSetupCallbackBuilder Do(Action callback);")
.AppendLine();
sb.AppendLine();
@@ -197,7 +183,7 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t/// The callback receives the value the indexer is set to as single parameter.").AppendLine();
sb.Append("\t\t/// ").AppendLine();
sb.Append("\t\tIIndexerSetupCallbackBuilder OnSet(Action callback);").AppendLine();
+ .Append("> Do(Action callback);").AppendLine();
sb.AppendLine();
sb.Append("\t\t/// ").AppendLine();
@@ -208,7 +194,7 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t/// ").AppendLine();
sb.Append("\t\t/// The callback receives the parameters of the indexer and the value the indexer is set to as last parameter.").AppendLine();
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetupCallbackBuilder OnSet(Action<")
+ sb.Append("\t\tIIndexerSetupCallbackBuilder Do(Action<")
.Append(typeParams).Append(", TValue> callback);").AppendLine();
sb.AppendLine();
@@ -220,8 +206,62 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t/// ").AppendLine();
sb.Append("\t\t/// The callback receives an incrementing access counter as first parameter, the parameters of the indexer and the value the indexer is set to as last parameter.").AppendLine();
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tIIndexerSetupCallbackBuilder OnSet(Action Do(Action callback);").AppendLine();
+ sb.Append("\t}").AppendLine();
+ sb.AppendLine();
+
+ sb.Append("\t/// ").AppendLine();
+ sb.Append("\t/// Sets up a indexer for ");
+ for (int i = 1; i < numberOfParameters - 1; i++)
+ {
+ sb.Append(", ");
+ }
+
+ sb.Append(" and .").AppendLine();
+ sb.Append("\t/// ").AppendLine();
+ sb.Append("\tinternal interface IIndexerSetup").AppendLine();
+ sb.Append("\t{").AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\t/// Sets up callbacks on the getter.").AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerGetterSetup OnGet { get; }").AppendLine();
+ sb.AppendLine();
+
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\t/// Sets up callbacks on the setter.").AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetterSetup OnSet { get; }").AppendLine();
+ sb.AppendLine();
+
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append(
+ "\t\t/// Flag indicating if the base class implementation should be called, and its return values used as default values.")
+ .AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\t/// If not specified, use .").AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetup CallingBaseClass(bool callBaseClass = true);").AppendLine();
+ sb.AppendLine();
+
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\t/// Initializes the indexer with the given .").AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetup InitializeWith(TValue value);")
+ .AppendLine();
+ sb.AppendLine();
+
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\t/// Initializes the according to the given .")
+ .AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetup InitializeWith(Func<")
+ .Append(typeParams).Append(", TValue> valueGenerator);").AppendLine();
sb.AppendLine();
sb.Append("\t\t/// ").AppendLine();
@@ -481,7 +521,9 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
.Append(") : IndexerSetup,")
.AppendLine();
sb.Append("\t\tIIndexerSetupCallbackBuilder,").AppendLine();
- sb.Append("\t\tIIndexerSetupReturnBuilder").AppendLine();
+ sb.Append("\t\tIIndexerSetupReturnBuilder,").AppendLine();
+ sb.Append("\t\tIIndexerGetterSetup,").AppendLine();
+ sb.Append("\t\tIIndexerSetterSetup").AppendLine();
sb.Append("\t{").AppendLine();
sb.Append("\t\tprivate readonly List>> _getterCallbacks = [];")
@@ -543,9 +585,16 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tpublic IIndexerSetupCallbackBuilder OnGet(Action callback)").AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tpublic IIndexerGetterSetup OnGet").AppendLine();
+ sb.Append("\t\t\t=> this;").AppendLine();
+ sb.AppendLine();
+
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action callback)").AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\tCallback>? currentCallback = new((_, ")
.Append(discards).Append(", _) => callback());").AppendLine();
@@ -555,8 +604,9 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tpublic IIndexerSetupCallbackBuilder OnGet(Action<")
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action<")
.Append(typeParams)
.Append("> callback)").AppendLine();
sb.Append("\t\t{").AppendLine();
@@ -568,8 +618,9 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tpublic IIndexerSetupCallbackBuilder OnGet(Action<")
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action<")
.Append(typeParams)
.Append(", TValue> callback)").AppendLine();
sb.Append("\t\t{").AppendLine();
@@ -581,8 +632,9 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tpublic IIndexerSetupCallbackBuilder OnGet(Action").AppendLine();
+ sb.Append("\t\tIIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action callback)").AppendLine();
sb.Append("\t\t{").AppendLine();
@@ -594,9 +646,16 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tpublic IIndexerSetupCallbackBuilder OnSet(Action callback)").AppendLine();
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tpublic IIndexerSetterSetup OnSet").AppendLine();
+ sb.Append("\t\t\t=> this;").AppendLine();
+ sb.AppendLine();
+
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)").AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\tCallback>? currentCallback = new((_, _, ")
.Append(discards).Append(") => callback());").AppendLine();
@@ -606,9 +665,10 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tpublic IIndexerSetupCallbackBuilder OnSet(Action callback)")
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)")
.AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\tCallback>? currentCallback = new((_, ")
@@ -619,9 +679,10 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tpublic IIndexerSetupCallbackBuilder OnSet(Action<")
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tIIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action<")
.Append(typeParams).Append(", TValue> callback)").AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\tCallback>? currentCallback = new((_, ")
@@ -632,9 +693,10 @@ private static void AppendIndexerSetup(StringBuilder sb, int numberOfParameters)
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
- sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tpublic IIndexerSetupCallbackBuilder OnSet(Action").AppendLine();
+ sb.Append("\t\tIIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)").AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\tCallback(MockBehavior behavior, Func def
///
/// Sets up a indexer for .
///
-public class IndexerSetup(IParameter match1)
- : IndexerSetup, IIndexerSetupCallbackBuilder, IIndexerSetupReturnBuilder
+public class IndexerSetup(IParameter match1) : IndexerSetup,
+ IIndexerSetupCallbackBuilder, IIndexerSetupReturnBuilder,
+ IIndexerGetterSetup, IIndexerSetterSetup
{
private readonly List>> _getterCallbacks = [];
private readonly List>> _returnCallbacks = [];
@@ -143,39 +144,8 @@ public class IndexerSetup(IParameter match1)
private int _currentSetterCallbacksIndex;
private Func? _initialization;
- ///
- public IIndexerSetup CallingBaseClass(bool callBaseClass = true)
- {
- _callBaseClass = callBaseClass;
- return this;
- }
-
- ///
- public IIndexerSetup InitializeWith(TValue value)
- {
- if (_initialization is not null)
- {
- throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
- }
-
- _initialization = _ => value;
- return this;
- }
-
- ///
- public IIndexerSetup InitializeWith(Func valueGenerator)
- {
- if (_initialization is not null)
- {
- throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
- }
-
- _initialization = valueGenerator;
- return this;
- }
-
- ///
- public IIndexerSetupCallbackBuilder OnGet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, _, _) => callback());
_currentCallback = currentCallback;
@@ -183,8 +153,8 @@ public IIndexerSetupCallbackBuilder OnGet(Action callback)
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnGet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, p1, _) => callback(p1));
_currentCallback = currentCallback;
@@ -192,8 +162,8 @@ public IIndexerSetupCallbackBuilder OnGet(Action callback)
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnGet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, p1, v) => callback(p1, v));
_currentCallback = currentCallback;
@@ -201,8 +171,8 @@ public IIndexerSetupCallbackBuilder OnGet(Action callbac
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnGet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action callback)
{
Callback> currentCallback = new(callback);
_currentCallback = currentCallback;
@@ -210,8 +180,8 @@ public IIndexerSetupCallbackBuilder OnGet(Action ca
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnSet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, _, _) => callback());
_currentCallback = currentCallback;
@@ -219,8 +189,8 @@ public IIndexerSetupCallbackBuilder OnSet(Action callback)
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnSet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, _, v) => callback(v));
_currentCallback = currentCallback;
@@ -228,8 +198,8 @@ public IIndexerSetupCallbackBuilder OnSet(Action callback)
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnSet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, p1, v) => callback(p1, v));
_currentCallback = currentCallback;
@@ -237,8 +207,8 @@ public IIndexerSetupCallbackBuilder OnSet(Action callbac
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnSet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)
{
Callback> currentCallback = new(callback);
_currentCallback = currentCallback;
@@ -246,6 +216,45 @@ public IIndexerSetupCallbackBuilder OnSet(Action ca
return this;
}
+ ///
+ public IIndexerSetup CallingBaseClass(bool callBaseClass = true)
+ {
+ _callBaseClass = callBaseClass;
+ return this;
+ }
+
+ ///
+ public IIndexerSetup InitializeWith(TValue value)
+ {
+ if (_initialization is not null)
+ {
+ throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
+ }
+
+ _initialization = _ => value;
+ return this;
+ }
+
+ ///
+ public IIndexerSetup InitializeWith(Func valueGenerator)
+ {
+ if (_initialization is not null)
+ {
+ throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
+ }
+
+ _initialization = valueGenerator;
+ return this;
+ }
+
+ ///
+ public IIndexerGetterSetup OnGet
+ => this;
+
+ ///
+ public IIndexerSetterSetup OnSet
+ => this;
+
///
public IIndexerSetupReturnBuilder Returns(TValue returnValue)
{
@@ -472,8 +481,9 @@ protected override bool TryGetInitialValue(MockBehavior behavior, Func def
///
/// Sets up a indexer for and .
///
-public class IndexerSetup(IParameter match1, IParameter match2)
- : IndexerSetup, IIndexerSetupCallbackBuilder, IIndexerSetupReturnBuilder
+public class IndexerSetup(IParameter match1, IParameter match2) : IndexerSetup
+ , IIndexerSetupCallbackBuilder, IIndexerSetupReturnBuilder,
+ IIndexerGetterSetup, IIndexerSetterSetup
{
private readonly List>> _getterCallbacks = [];
private readonly List>> _returnCallbacks = [];
@@ -486,39 +496,8 @@ public class IndexerSetup(IParameter match1, IParameter match2)
private int _currentSetterCallbacksIndex;
private Func? _initialization;
- ///
- public IIndexerSetup CallingBaseClass(bool callBaseClass = true)
- {
- _callBaseClass = callBaseClass;
- return this;
- }
-
- ///
- public IIndexerSetup InitializeWith(TValue value)
- {
- if (_initialization is not null)
- {
- throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
- }
-
- _initialization = (_, _) => value;
- return this;
- }
-
- ///
- public IIndexerSetup InitializeWith(Func valueGenerator)
- {
- if (_initialization is not null)
- {
- throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
- }
-
- _initialization = valueGenerator;
- return this;
- }
-
- ///
- public IIndexerSetupCallbackBuilder OnGet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, _, _, _) => callback());
_currentCallback = currentCallback;
@@ -526,8 +505,8 @@ public IIndexerSetupCallbackBuilder OnGet(Action callback)
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnGet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, p1, p2, _) => callback(p1, p2));
_currentCallback = currentCallback;
@@ -535,8 +514,8 @@ public IIndexerSetupCallbackBuilder OnGet(Action callbac
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnGet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, p1, p2, v) => callback(p1, p2, v));
_currentCallback = currentCallback;
@@ -544,8 +523,9 @@ public IIndexerSetupCallbackBuilder OnGet(Action
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnGet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerGetterSetup.Do(
+ Action callback)
{
Callback> currentCallback = new(callback);
_currentCallback = currentCallback;
@@ -553,8 +533,8 @@ public IIndexerSetupCallbackBuilder OnGet(Action
- public IIndexerSetupCallbackBuilder OnSet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, _, _, _) => callback());
_currentCallback = currentCallback;
@@ -562,8 +542,8 @@ public IIndexerSetupCallbackBuilder OnSet(Action callback)
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnSet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, _, _, v) => callback(v));
_currentCallback = currentCallback;
@@ -571,8 +551,8 @@ public IIndexerSetupCallbackBuilder OnSet(Action callbac
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnSet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(Action callback)
{
Callback> currentCallback = new((_, p1, p2, v) => callback(p1, p2, v));
_currentCallback = currentCallback;
@@ -580,8 +560,9 @@ public IIndexerSetupCallbackBuilder OnSet(Action
return this;
}
- ///
- public IIndexerSetupCallbackBuilder OnSet(Action callback)
+ ///
+ IIndexerSetupCallbackBuilder IIndexerSetterSetup.Do(
+ Action callback)
{
Callback> currentCallback = new(callback);
_currentCallback = currentCallback;
@@ -589,6 +570,45 @@ public IIndexerSetupCallbackBuilder OnSet(Action
+ public IIndexerSetup CallingBaseClass(bool callBaseClass = true)
+ {
+ _callBaseClass = callBaseClass;
+ return this;
+ }
+
+ ///
+ public IIndexerSetup InitializeWith(TValue value)
+ {
+ if (_initialization is not null)
+ {
+ throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
+ }
+
+ _initialization = (_, _) => value;
+ return this;
+ }
+
+ ///
+ public IIndexerSetup InitializeWith(Func valueGenerator)
+ {
+ if (_initialization is not null)
+ {
+ throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
+ }
+
+ _initialization = valueGenerator;
+ return this;
+ }
+
+ ///
+ public IIndexerGetterSetup OnGet
+ => this;
+
+ ///
+ public IIndexerSetterSetup OnSet
+ => this;
+
///
public IIndexerSetupReturnBuilder Returns(TValue returnValue)
{
@@ -825,8 +845,9 @@ protected override bool TryGetInitialValue(MockBehavior behavior, Func def
public class IndexerSetup(
IParameter match1,
IParameter match2,
- IParameter match3)
- : IndexerSetup, IIndexerSetupCallbackBuilder, IIndexerSetupReturnBuilder
+ IParameter match3) : IndexerSetup,
+ IIndexerSetupCallbackBuilder, IIndexerSetupReturnBuilder,
+ IIndexerGetterSetup, IIndexerSetterSetup
{
private readonly List>> _getterCallbacks = [];
private readonly List>> _returnCallbacks = [];
@@ -839,39 +860,8 @@ public class IndexerSetup(
private int _currentSetterCallbacksIndex;
private Func? _initialization;
- ///
- public IIndexerSetup CallingBaseClass(bool callBaseClass = true)
- {
- _callBaseClass = callBaseClass;
- return this;
- }
-
- ///
- public IIndexerSetup InitializeWith(TValue value)
- {
- if (_initialization is not null)
- {
- throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
- }
-
- _initialization = (_, _, _) => value;
- return this;
- }
-
- ///
- public IIndexerSetup InitializeWith(Func valueGenerator)
- {
- if (_initialization is not null)
- {
- throw new MockException("The indexer is already initialized. You cannot initialize it twice.");
- }
-
- _initialization = valueGenerator;
- return this;
- }
-
- ///