diff --git a/Source/Mockolate.SourceGenerators/Sources/Sources.MockClass.cs b/Source/Mockolate.SourceGenerators/Sources/Sources.MockClass.cs
index 1f60c87d..1181fbca 100644
--- a/Source/Mockolate.SourceGenerators/Sources/Sources.MockClass.cs
+++ b/Source/Mockolate.SourceGenerators/Sources/Sources.MockClass.cs
@@ -69,25 +69,32 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
};
if (hasEvents)
{
- mockPropertyRemarks.Add(" Raise - trigger events declared on the mocked type.");
+ mockPropertyRemarks.Add(
+ " Raise - trigger events declared on the mocked type.");
}
if (hasProtectedMembers || hasProtectedEvents)
{
- mockPropertyRemarks.Add(" SetupProtected / VerifyProtected / RaiseProtected - target members on class mocks.");
+ mockPropertyRemarks.Add(
+ " SetupProtected / VerifyProtected / RaiseProtected - target members on class mocks.");
}
if (hasStaticMembers || hasStaticEvents)
{
- mockPropertyRemarks.Add(" SetupStatic / VerifyStatic / RaiseStatic - target members on interface mocks.");
+ mockPropertyRemarks.Add(
+ " SetupStatic / VerifyStatic / RaiseStatic - target members on interface mocks.");
}
- mockPropertyRemarks.Add(" InScenario / TransitionTo - scope setups and behavior to a named scenario and switch between scenarios.");
- mockPropertyRemarks.Add(" Monitor, ClearAllInteractions, VerifyThatAllInteractionsAreVerified, VerifyThatAllSetupsAreUsed - manage recorded interactions.");
- mockPropertyRemarks.Add(" VerifySetup - verify how often a specific setup matched.");
+ mockPropertyRemarks.Add(
+ " InScenario / TransitionTo - scope setups and behavior to a named scenario and switch between scenarios.");
+ mockPropertyRemarks.Add(
+ " Monitor, ClearAllInteractions, VerifyThatAllInteractionsAreVerified, VerifyThatAllSetupsAreUsed - manage recorded interactions.");
+ mockPropertyRemarks.Add(
+ " VerifySetup - verify how often a specific setup matched.");
mockPropertyRemarks.Add("");
- sb.AppendXmlSummary($"Gets the mock accessor for - the entry point for configuring setups, verifying interactions and raising events.");
+ sb.AppendXmlSummary(
+ $"Gets the mock accessor for - the entry point for configuring setups, verifying interactions and raising events.");
sb.AppendXmlRemarks(mockPropertyRemarks.ToArray());
sb.AppendXmlException("global::Mockolate.Exceptions.MockException",
$"The instance is not a Mockolate-generated mock of .");
@@ -123,12 +130,15 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
};
if (hasEvents)
{
- createMockRemarks.Add(" .Mock.Raise triggers events declared on the mocked type.");
+ createMockRemarks.Add(
+ " .Mock.Raise triggers events declared on the mocked type.");
}
createMockRemarks.Add("");
- createMockRemarks.Add("With the default behavior, un-configured members return default values (empty collections / strings, completed tasks, otherwise) and base-class implementations are invoked for class mocks. Use one of the overloads that accepts a to customize this (for example to make un-configured calls throw or to skip the base class).");
- createMockRemarks.Add("Overloads allow you to additionally pass constructor parameters (for class mocks), apply an initial setup callback before the instance is returned, or combine both.");
+ createMockRemarks.Add(
+ "With the default behavior, un-configured members return default values (empty collections / strings, completed tasks, otherwise) and base-class implementations are invoked for class mocks. Use one of the overloads that accepts a to customize this (for example to make un-configured calls throw or to skip the base class).");
+ createMockRemarks.Add(
+ "Overloads allow you to additionally pass constructor parameters (for class mocks), apply an initial setup callback before the instance is returned, or combine both.");
sb.AppendXmlSummary(
$"Creates a new mock of with the default .");
@@ -140,8 +150,10 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
sb.AppendXmlSummary(
$"Creates a new mock of with the default , applying the given immediately.");
- sb.AppendXmlRemarks("The provided is immediately applied to the mock. Use this overload when you want setups to cover virtual interactions triggered inside the constructor.");
- sb.AppendXmlParam("setup", "Callback that receives the mock's setup surface and registers initial setups before the mock is returned.");
+ sb.AppendXmlRemarks(
+ "The provided is immediately applied to the mock. Use this overload when you want setups to cover virtual interactions triggered inside the constructor.");
+ sb.AppendXmlParam("setup",
+ "Callback that receives the mock's setup surface and registers initial setups before the mock is returned.");
sb.AppendXmlReturns(createMockReturns);
sb.Append("\t\tpublic static ").Append(@class.ClassFullName).Append(" CreateMock(global::System.Action<")
.Append(setupType).Append("> setup)").AppendLine();
@@ -150,7 +162,8 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
sb.AppendXmlSummary(
$"Creates a new mock of with the given .");
- sb.AppendXmlParam("mockBehavior", "Controls how the mock responds when members are invoked without a matching setup; see .");
+ sb.AppendXmlParam("mockBehavior",
+ "Controls how the mock responds when members are invoked without a matching setup; see .");
sb.AppendXmlReturns(createMockReturns);
sb.Append("\t\tpublic static ").Append(@class.ClassFullName)
.Append(" CreateMock(global::Mockolate.MockBehavior mockBehavior)").AppendLine();
@@ -159,9 +172,12 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
sb.AppendXmlSummary(
$"Creates a new mock of with the given , applying the given immediately.");
- sb.AppendXmlRemarks("The provided is immediately applied to the mock. Use this overload when you want setups to cover virtual interactions triggered inside the constructor.");
- sb.AppendXmlParam("mockBehavior", "Controls how the mock responds when members are invoked without a matching setup; see .");
- sb.AppendXmlParam("setup", "Callback that receives the mock's setup surface and registers initial setups before the mock is returned.");
+ sb.AppendXmlRemarks(
+ "The provided is immediately applied to the mock. Use this overload when you want setups to cover virtual interactions triggered inside the constructor.");
+ sb.AppendXmlParam("mockBehavior",
+ "Controls how the mock responds when members are invoked without a matching setup; see .");
+ sb.AppendXmlParam("setup",
+ "Callback that receives the mock's setup surface and registers initial setups before the mock is returned.");
sb.AppendXmlReturns(createMockReturns);
sb.Append("\t\tpublic static ").Append(@class.ClassFullName)
.Append(" CreateMock(global::Mockolate.MockBehavior mockBehavior, global::System.Action<").Append(setupType)
@@ -173,7 +189,8 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
{
sb.AppendXmlSummary(
$"Creates a new mock of using the given to invoke the base-class constructor.");
- sb.AppendXmlParam("constructorParameters", "Values forwarded to a matching base-class constructor. Required when no parameterless constructor exists.");
+ sb.AppendXmlParam("constructorParameters",
+ "Values forwarded to a matching base-class constructor. Required when no parameterless constructor exists.");
sb.AppendXmlReturns(createMockReturns);
sb.Append("\t\tpublic static ").Append(@class.ClassFullName)
.Append(" CreateMock(object?[] constructorParameters)").AppendLine();
@@ -182,8 +199,10 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
sb.AppendXmlSummary(
$"Creates a new mock of using the given and .");
- sb.AppendXmlParam("mockBehavior", "Controls how the mock responds when members are invoked without a matching setup; see .");
- sb.AppendXmlParam("constructorParameters", "Values forwarded to a matching base-class constructor. Required when no parameterless constructor exists.");
+ sb.AppendXmlParam("mockBehavior",
+ "Controls how the mock responds when members are invoked without a matching setup; see .");
+ sb.AppendXmlParam("constructorParameters",
+ "Values forwarded to a matching base-class constructor. Required when no parameterless constructor exists.");
sb.AppendXmlReturns(createMockReturns);
sb.Append("\t\tpublic static ").Append(@class.ClassFullName)
.Append(" CreateMock(global::Mockolate.MockBehavior mockBehavior, object?[] constructorParameters)")
@@ -193,9 +212,12 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
sb.AppendXmlSummary(
$"Creates a new mock of applying the given immediately, using the given .");
- sb.AppendXmlRemarks("The provided is immediately applied to the mock. Use this overload when you want setups to cover virtual interactions triggered inside the constructor.");
- sb.AppendXmlParam("setup", "Callback that receives the mock's setup surface and registers initial setups before the mock is returned.");
- sb.AppendXmlParam("constructorParameters", "Values forwarded to a matching base-class constructor. Required when no parameterless constructor exists.");
+ sb.AppendXmlRemarks(
+ "The provided is immediately applied to the mock. Use this overload when you want setups to cover virtual interactions triggered inside the constructor.");
+ sb.AppendXmlParam("setup",
+ "Callback that receives the mock's setup surface and registers initial setups before the mock is returned.");
+ sb.AppendXmlParam("constructorParameters",
+ "Values forwarded to a matching base-class constructor. Required when no parameterless constructor exists.");
sb.AppendXmlReturns(createMockReturns);
sb.Append("\t\tpublic static ").Append(@class.ClassFullName)
.Append(" CreateMock(global::System.Action<").Append(setupType)
@@ -208,10 +230,14 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
sb.AppendXmlSummary(
$"Creates a new mock of using the given , applying the given immediately, using the given .");
- sb.AppendXmlRemarks("The provided is immediately applied to the mock. Use this overload when you want setups to cover virtual interactions triggered inside the constructor.");
- sb.AppendXmlParam("mockBehavior", "Controls how the mock responds when members are invoked without a matching setup, or for MockBehavior.Default.");
- sb.AppendXmlParam("setup", "Callback that receives the mock's setup surface and registers initial setups before the mock is returned, or to skip.");
- sb.AppendXmlParam("constructorParameters", "Values forwarded to a matching base-class constructor, or to use the parameterless constructor.");
+ sb.AppendXmlRemarks(
+ "The provided is immediately applied to the mock. Use this overload when you want setups to cover virtual interactions triggered inside the constructor.");
+ sb.AppendXmlParam("mockBehavior",
+ "Controls how the mock responds when members are invoked without a matching setup, or for MockBehavior.Default.");
+ sb.AppendXmlParam("setup",
+ "Callback that receives the mock's setup surface and registers initial setups before the mock is returned, or to skip.");
+ sb.AppendXmlParam("constructorParameters",
+ "Values forwarded to a matching base-class constructor, or to use the parameterless constructor.");
sb.AppendXmlReturns(createMockReturns);
sb.Append("\t\t").Append(hasParameterizedConstructor ? "public" : "private").Append(" static ")
.Append(@class.ClassFullName)
@@ -250,7 +276,8 @@ public static string MockClass(string name, Class @class, bool hasOverloadResolu
if (@class is { ClassFullName: "global::System.Net.Http.HttpClient", })
{
- sb.Append("\t\t\tglobal::Mockolate.MockBehavior effectiveBehavior = mockBehavior ?? global::Mockolate.MockBehavior.Default;")
+ sb.Append(
+ "\t\t\tglobal::Mockolate.MockBehavior effectiveBehavior = mockBehavior ?? global::Mockolate.MockBehavior.Default;")
.AppendLine();
sb.Append(
"\t\t\tglobal::Mockolate.MockRegistry mockRegistry = new global::Mockolate.MockRegistry(effectiveBehavior, global::Mockolate.Mock.")
@@ -443,9 +470,12 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
#endregion CreateMock
sb.AppendXmlSummary("Creates a mock that wraps the given .");
- sb.AppendXmlRemarks("Public members on the mock forward to unless overridden by a setup; protected members still go through the base-class implementation. All forwarded interactions are recorded and can be verified the same as on a plain mock.");
- sb.AppendXmlParam("instance", "The real object whose calls should be forwarded. Must not be .");
- sb.AppendXmlReturns($"A new mock of that delegates to .");
+ sb.AppendXmlRemarks(
+ "Public members on the mock forward to unless overridden by a setup; protected members still go through the base-class implementation. All forwarded interactions are recorded and can be verified the same as on a plain mock.");
+ sb.AppendXmlParam("instance",
+ "The real object whose calls should be forwarded. Must not be .");
+ sb.AppendXmlReturns(
+ $"A new mock of that delegates to .");
sb.Append("\t\tpublic ").Append(@class.ClassFullName).Append(" Wrapping(").Append(@class.ClassFullName)
.Append(" instance)").AppendLine();
sb.Append("\t\t{").AppendLine();
@@ -483,9 +513,11 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
"Initializes mocks of type with the given .");
sb.AppendXmlRemarks(
"The is applied to the mock before the constructor is executed. Calling Initialize again overlays additional setups on top of any previously registered ones.");
- sb.AppendXmlTypeParam("T", $"The mockable type derived from that this setup should apply to.");
+ sb.AppendXmlTypeParam("T",
+ $"The mockable type derived from that this setup should apply to.");
sb.AppendXmlParam("setup", "Callback invoked when a new mock of is created.");
- sb.AppendXmlReturns("A new with the registered initializer. The original instance is unchanged.");
+ sb.AppendXmlReturns(
+ "A new with the registered initializer. The original instance is unchanged.");
sb.Append("\t\tpublic global::Mockolate.MockBehavior Initialize(global::System.Action<").Append(setupType)
.Append("> setup)").AppendLine();
sb.Append("\t\t\twhere T : ").Append(@class.ClassFullName).AppendLine();
@@ -633,6 +665,10 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
AppendCreateFastInteractions(sb, "\t\t", @class, memberIds, memberIdPrefix);
sb.AppendLine();
+ bool hasMockRegistryProvider = constructors?.Count > 0 || (@class.IsInterface && hasStaticMembers);
+ AppendCreateRegistryFromBehavior(sb, "\t\t", hasMockRegistryProvider);
+ sb.AppendLine();
+
sb.Append("\t\t/// ").AppendLine();
sb.Append(
"\t\t[global::System.Diagnostics.DebuggerBrowsable(global::System.Diagnostics.DebuggerBrowsableState.Never)]")
@@ -690,6 +726,7 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
+ AppendMockSubject_BehaviorConstructor(sb, name);
}
else if (constructors is not null)
{
@@ -697,6 +734,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
{
AppendMockSubject_BaseClassConstructor(sb, mockRegistryName, name, constructor,
@class.HasRequiredMembers);
+ AppendMockSubject_BehaviorBaseClassConstructor(sb, name, constructor,
+ @class.HasRequiredMembers);
}
}
else
@@ -707,6 +746,7 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
sb.Append("\t\t\tthis.").Append(mockRegistryName).Append(" = mockRegistry;").AppendLine();
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
+ AppendMockSubject_BehaviorConstructor(sb, name);
}
AppendMockSubject_ImplementClass(sb, @class, mockRegistryName, null, memberIds, memberIdPrefix);
@@ -848,7 +888,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
sb.AppendLine();
sb.Append("\t{").AppendLine();
- sb.Append("\t\tprivate global::Mockolate.MockRegistry ").Append(mockRegistryName).Append(" { get; }").AppendLine();
+ sb.Append("\t\tprivate global::Mockolate.MockRegistry ").Append(mockRegistryName).Append(" { get; }")
+ .AppendLine();
sb.Append("\t\tprivate string _scenarioName;").AppendLine();
sb.AppendLine();
sb.Append("\t\tpublic MockInScenarioFor").Append(name)
@@ -867,7 +908,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
{
sb.Append("\t\t/// ").AppendLine();
sb.Append("\t\tglobal::Mockolate.Mock.IMockProtectedSetupFor").Append(name)
- .Append(" global::Mockolate.Mock.IMockInScenarioFor").Append(name).Append(".SetupProtected").AppendLine();
+ .Append(" global::Mockolate.Mock.IMockInScenarioFor").Append(name).Append(".SetupProtected")
+ .AppendLine();
sb.Append("\t\t\t=> this;").AppendLine();
sb.AppendLine();
}
@@ -895,13 +937,16 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
#region IMockForXXX
- sb.AppendXmlSummary($"The Mockolate accessor for a mock of , reached through .Mock on the mocked instance.", "\t");
+ sb.AppendXmlSummary(
+ $"The Mockolate accessor for a mock of , reached through .Mock on the mocked instance.",
+ "\t");
sb.AppendXmlRemarks([
"Groups every operation that acts on the mock rather than on the mocked subject: setups, verifications, event raising, scenarios and monitoring.",
], "\t");
sb.Append("\tinternal interface IMockFor").Append(name).AppendLine();
sb.Append("\t{").AppendLine();
- sb.AppendXmlSummary($"Configures how members of the mock of respond when invoked.");
+ sb.AppendXmlSummary(
+ $"Configures how members of the mock of respond when invoked.");
sb.AppendXmlRemarks([
"Each mocked member is available as a strongly-typed entry on this surface. Chain Returns, ReturnsAsync, Throws, ThrowsAsync or Do to control the response; chain InitializeWith/Register to initialize properties and indexers; chain multiple returns/throws to define a sequence; use .For(n), .Only(n), .Forever(), .When(predicate) to control when a callback runs.",
"When two setups overlap, the most recently defined one wins.",
@@ -910,7 +955,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
sb.AppendLine();
if (hasProtectedMembers)
{
- sb.AppendXmlSummary($"Configures how virtual members of the mock of respond when invoked.");
+ sb.AppendXmlSummary(
+ $"Configures how virtual members of the mock of respond when invoked.");
sb.AppendXmlRemarks([
"Only members declared as (or ) on the mocked class appear here. All setup chain operators (Returns, Throws, Do, sequences, .For/.Only/.Forever, ...) work identically to .",
]);
@@ -920,7 +966,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
if (hasStaticMembers)
{
- sb.AppendXmlSummary($"Configures how members declared on respond when invoked.");
+ sb.AppendXmlSummary(
+ $"Configures how members declared on respond when invoked.");
sb.AppendXmlRemarks([
"Static members are scoped per async/execution flow while the mock is alive; invocations from other flows are not intercepted.",
]);
@@ -928,27 +975,34 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
sb.AppendLine();
}
- sb.AppendXmlSummary($"Opens a named scenario scope on the mock of so that additional setups can be registered for that scenario.");
+ sb.AppendXmlSummary(
+ $"Opens a named scenario scope on the mock of so that additional setups can be registered for that scenario.");
sb.AppendXmlRemarks([
"Scenarios let you define per-state behavior. Setups registered inside the returned IMockInScenarioFor... scope only apply while the mock's current scenario matches ; switch scenarios with .",
]);
- sb.AppendXmlParam("scenario", "Name of the scenario to enter. Any non-null string acts as a key; the mock starts in an unnamed default scenario.");
- sb.AppendXmlReturns("A scoped accessor whose Setup (and SetupProtected, where applicable) register scenario-specific setups.");
+ sb.AppendXmlParam("scenario",
+ "Name of the scenario to enter. Any non-null string acts as a key; the mock starts in an unnamed default scenario.");
+ sb.AppendXmlReturns(
+ "A scoped accessor whose Setup (and SetupProtected, where applicable) register scenario-specific setups.");
sb.Append("\t\tIMockInScenarioFor").Append(name).Append(" InScenario(string scenario);").AppendLine();
sb.AppendLine();
- sb.AppendXmlSummary($"Opens a named scenario scope on the mock of and immediately invokes to register scenario-specific setups.");
+ sb.AppendXmlSummary(
+ $"Opens a named scenario scope on the mock of and immediately invokes to register scenario-specific setups.");
sb.AppendXmlRemarks([
"Equivalent to InScenario(scenario) followed by the setup callback, but returns the original IMockFor... accessor so it chains nicely at mock-creation time.",
]);
sb.AppendXmlParam("scenario", "Name of the scenario to enter.");
- sb.AppendXmlParam("setup", "Callback that receives the scenario-scoped setup surface and registers scenario-specific setups.");
+ sb.AppendXmlParam("setup",
+ "Callback that receives the scenario-scoped setup surface and registers scenario-specific setups.");
sb.AppendXmlReturns("This accessor, to allow chaining.");
- sb.Append("\t\tIMockFor").Append(name).Append(" InScenario(string scenario, global::System.Action setup);").AppendLine();
sb.AppendLine();
- sb.AppendXmlSummary($"Switches the active scenario of the mock of to .");
+ sb.AppendXmlSummary(
+ $"Switches the active scenario of the mock of to .");
sb.AppendXmlRemarks([
"After the transition, setups registered via under that scenario take effect. Scenarios that have no matching setup for a given member fall back to the default (un-scoped) setups.",
]);
@@ -959,7 +1013,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
if (hasEvents)
{
- sb.AppendXmlSummary($"Triggers events declared on so that currently subscribed handlers are invoked.");
+ sb.AppendXmlSummary(
+ $"Triggers events declared on so that currently subscribed handlers are invoked.");
sb.AppendXmlRemarks([
"One entry per event is generated; the signature matches the event's delegate. Only handlers that are subscribed at the moment of the Raise call are invoked - handlers subscribed later (or already removed) are skipped.",
]);
@@ -969,7 +1024,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
if (hasProtectedEvents)
{
- sb.AppendXmlSummary($"Triggers events declared on so that currently subscribed handlers are invoked.");
+ sb.AppendXmlSummary(
+ $"Triggers events declared on so that currently subscribed handlers are invoked.");
sb.AppendXmlRemarks([
"Same semantics as but for events whose accessibility prevents external subscription from outside the class. Useful when testing code that subclasses the mocked type.",
]);
@@ -979,7 +1035,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
if (hasStaticEvents)
{
- sb.AppendXmlSummary($"Triggers events declared on so that currently subscribed handlers are invoked.");
+ sb.AppendXmlSummary(
+ $"Triggers events declared on so that currently subscribed handlers are invoked.");
sb.AppendXmlRemarks([
"Static events are scoped per async/execution flow while the mock is alive.",
]);
@@ -987,7 +1044,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
sb.AppendLine();
}
- sb.AppendXmlSummary($"Asserts how often, and in which order, members of the mock of were invoked.");
+ sb.AppendXmlSummary(
+ $"Asserts how often, and in which order, members of the mock of were invoked.");
sb.AppendXmlRemarks([
"Each call to a member here returns a VerificationResult that you terminate with a count assertion: Never(), Once(), Twice(), Exactly(n), AtLeast(n)/AtLeastOnce()/AtLeastTwice(), AtMost(n)/AtMostOnce()/AtMostTwice(), Between(min, max) or Times(predicate).",
"Use Within(TimeSpan) / WithCancellation(CancellationToken) before the terminator to wait for expected interactions that happen on background threads.",
@@ -997,7 +1055,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
sb.AppendLine();
if (hasProtectedMembers || hasProtectedEvents)
{
- sb.AppendXmlSummary($"Asserts how often, and in which order, members of the mock of were invoked.");
+ sb.AppendXmlSummary(
+ $"Asserts how often, and in which order, members of the mock of were invoked.");
sb.AppendXmlRemarks([
"Same terminators and modifiers as (Once(), Exactly(n), Within(...), Then(...), ...); applies to members and events instead of public ones.",
]);
@@ -1007,7 +1066,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
if (hasStaticMembers || hasStaticEvents)
{
- sb.AppendXmlSummary($"Asserts how often, and in which order, members declared on were invoked.");
+ sb.AppendXmlSummary(
+ $"Asserts how often, and in which order, members declared on were invoked.");
sb.AppendXmlRemarks([
"Same terminators and modifiers as ; scoped per async/execution flow in the same way as .",
]);
@@ -1019,26 +1079,32 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
sb.AppendXmlRemarks([
"Useful when you want to verify "this particular setup was hit N times" without re-stating the matchers. Chain the usual count terminators (Once(), AtLeastOnce(), Exactly(n), ...) on the returned result.",
]);
- sb.AppendXmlParam("setup", "The setup previously registered through (typically returned from a Returns(...)/Throws(...) call).");
+ sb.AppendXmlParam("setup",
+ "The setup previously registered through (typically returned from a Returns(...)/Throws(...) call).");
sb.AppendXmlReturns("A VerificationResult that counts invocations matching the given setup.");
sb.Append("\t\tglobal::Mockolate.Verify.VerificationResult VerifySetup(global::Mockolate.Setup.IMethodSetup setup);").AppendLine();
sb.AppendLine();
- sb.AppendXmlSummary("Checks whether every recorded interaction on this mock has been observed by at least one Verify call.");
+ sb.AppendXmlSummary(
+ "Checks whether every recorded interaction on this mock has been observed by at least one Verify call.");
sb.AppendXmlRemarks([
"Useful in test teardown to catch unexpected interactions ("strict verification"): if any recorded call has never been matched by a verification, the method returns .",
]);
- sb.AppendXmlReturns(" if every recorded interaction was verified at least once; otherwise .");
+ sb.AppendXmlReturns(
+ " if every recorded interaction was verified at least once; otherwise .");
sb.Append("\t\tbool VerifyThatAllInteractionsAreVerified();").AppendLine();
sb.AppendLine();
- sb.AppendXmlSummary("Checks whether every registered setup on this mock was matched by at least one actual invocation.");
+ sb.AppendXmlSummary(
+ "Checks whether every registered setup on this mock was matched by at least one actual invocation.");
sb.AppendXmlRemarks([
"Useful to catch unused setups that silently rot as the test subject evolves.",
]);
- sb.AppendXmlReturns(" if every registered setup was used at least once; otherwise .");
+ sb.AppendXmlReturns(
+ " if every registered setup was used at least once; otherwise .");
sb.Append("\t\tbool VerifyThatAllSetupsAreUsed();").AppendLine();
sb.AppendLine();
- sb.AppendXmlSummary("Removes every recorded interaction from this mock while keeping all registered setups intact.");
+ sb.AppendXmlSummary(
+ "Removes every recorded interaction from this mock while keeping all registered setups intact.");
sb.AppendXmlRemarks([
"Handy when a single test exercises multiple logical phases and you only want to verify the interactions of the latest phase.",
]);
@@ -1049,7 +1115,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
sb.AppendXmlRemarks([
"The underlying mock keeps recording all interactions as usual - only the monitor's Verify view is scoped. Useful to verify only the interactions produced by a specific block of test code without resetting the mock.",
]);
- sb.AppendXmlReturns("A that exposes Verify over the monitored interactions and a Run() method that opens the recording scope.");
+ sb.AppendXmlReturns(
+ "A that exposes Verify over the monitored interactions and a Run() method that opens the recording scope.");
sb.Append("\t\tglobal::Mockolate.Monitor.MockMonitor Monitor();")
.AppendLine();
sb.Append("\t}").AppendLine();
@@ -1060,7 +1127,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
#region IMockInScenarioForXXX
- sb.AppendXmlSummary($"Scoped access to setups for a scenario on the mock of .", "\t");
+ sb.AppendXmlSummary(
+ $"Scoped access to setups for a scenario on the mock of .", "\t");
sb.Append("\tinternal interface IMockInScenarioFor").Append(name).AppendLine();
sb.Append("\t{").AppendLine();
sb.AppendXmlSummary($"Set up the mock of within the scenario scope.");
@@ -1068,7 +1136,8 @@ static bool TryCastWithDefaultValue(object?[] values, int index, TValue
if (hasProtectedMembers)
{
sb.AppendLine();
- sb.AppendXmlSummary($"Set up protected members of the mock of within the scenario scope.");
+ sb.AppendXmlSummary(
+ $"Set up protected members of the mock of within the scenario scope.");
sb.Append("\t\tIMockProtectedSetupFor").Append(name).Append(" SetupProtected { get; }").AppendLine();
}
@@ -1213,14 +1282,18 @@ private static void AppendCreateFastInteractions(StringBuilder sb, string indent
MemberIdTable memberIds, string memberIdPrefix)
{
sb.Append(indent).Append("/// ").AppendLine();
- sb.Append(indent).Append("/// Creates a sized to ")
+ sb.Append(indent)
+ .Append("/// Creates a sized to ")
.Append(" for use as the mock's interaction store.").AppendLine();
sb.Append(indent).Append("/// ").AppendLine();
sb.Append(indent)
- .Append("internal static global::Mockolate.Interactions.FastMockInteractions CreateFastInteractions(global::Mockolate.MockBehavior behavior)")
+ .Append(
+ "internal static global::Mockolate.Interactions.FastMockInteractions CreateFastInteractions(global::Mockolate.MockBehavior behavior)")
.AppendLine();
sb.Append(indent).Append("{").AppendLine();
- sb.Append(indent).Append("\tglobal::Mockolate.Interactions.FastMockInteractions fast = new global::Mockolate.Interactions.FastMockInteractions(MemberCount, behavior.SkipInteractionRecording);")
+ sb.Append(indent)
+ .Append(
+ "\tglobal::Mockolate.Interactions.FastMockInteractions fast = new global::Mockolate.Interactions.FastMockInteractions(MemberCount, behavior.SkipInteractionRecording);")
.AppendLine();
foreach (Method method in @class.AllMethods())
@@ -1258,12 +1331,14 @@ private static void AppendCreateFastInteractions(StringBuilder sb, string indent
}
string getMemberIdRef = memberIdPrefix + memberIds.GetPropertyGetIdentifier(property);
- sb.Append(indent).Append("\tglobal::Mockolate.Interactions.FastPropertyBufferFactory.InstallPropertyGetter(fast, ")
+ sb.Append(indent)
+ .Append("\tglobal::Mockolate.Interactions.FastPropertyBufferFactory.InstallPropertyGetter(fast, ")
.Append(getMemberIdRef).Append(");").AppendLine();
string setMemberIdRef = memberIdPrefix + memberIds.GetPropertySetIdentifier(property);
string propertyType = property.Type.ToTypeOrWrapper();
- sb.Append(indent).Append("\tglobal::Mockolate.Interactions.FastPropertyBufferFactory.InstallPropertySetter<")
+ sb.Append(indent)
+ .Append("\tglobal::Mockolate.Interactions.FastPropertyBufferFactory.InstallPropertySetter<")
.Append(propertyType).Append(">(fast, ").Append(setMemberIdRef).Append(");").AppendLine();
}
@@ -1276,7 +1351,8 @@ private static void AppendCreateFastInteractions(StringBuilder sb, string indent
string getMemberIdRef = memberIdPrefix + memberIds.GetIndexerGetIdentifier(indexer);
string setMemberIdRef = memberIdPrefix + memberIds.GetIndexerSetIdentifier(indexer);
- string indexerKeyTypeArgs = string.Join(", ", indexer.IndexerParameters!.Value.Select(p => p.ToTypeOrWrapper()));
+ string indexerKeyTypeArgs =
+ string.Join(", ", indexer.IndexerParameters!.Value.Select(p => p.ToTypeOrWrapper()));
string indexerValueType = indexer.Type.ToTypeOrWrapper();
sb.Append(indent).Append("\tglobal::Mockolate.Interactions.FastIndexerBufferFactory.InstallIndexerGetter<")
@@ -1295,9 +1371,11 @@ private static void AppendCreateFastInteractions(StringBuilder sb, string indent
string subMemberIdRef = memberIdPrefix + memberIds.GetEventSubscribeIdentifier(@event);
string unsubMemberIdRef = memberIdPrefix + memberIds.GetEventUnsubscribeIdentifier(@event);
- sb.Append(indent).Append("\tglobal::Mockolate.Interactions.FastEventBufferFactory.InstallEventSubscribe(fast, ")
+ sb.Append(indent)
+ .Append("\tglobal::Mockolate.Interactions.FastEventBufferFactory.InstallEventSubscribe(fast, ")
.Append(subMemberIdRef).Append(");").AppendLine();
- sb.Append(indent).Append("\tglobal::Mockolate.Interactions.FastEventBufferFactory.InstallEventUnsubscribe(fast, ")
+ sb.Append(indent)
+ .Append("\tglobal::Mockolate.Interactions.FastEventBufferFactory.InstallEventUnsubscribe(fast, ")
.Append(unsubMemberIdRef).Append(");").AppendLine();
}
@@ -1765,7 +1843,9 @@ private static void AppendMockSubject_BaseClassConstructor(StringBuilder sb, str
string mockRegistry = CreateUniqueParameterName(constructor.Parameters, "mockRegistry");
sb.Append("\t\t/// ").AppendLine();
sb.Append(constructor.Attributes, "\t\t");
- if (hasRequiredMembers && constructor.Attributes?.Any(a => a.Name == "global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers") != true)
+ if (hasRequiredMembers &&
+ constructor.Attributes?.Any(a => a.Name == "global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers") !=
+ true)
{
sb.Append("\t\t[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]").AppendLine();
}
@@ -1806,6 +1886,105 @@ private static void AppendMockSubject_BaseClassConstructor(StringBuilder sb, str
sb.AppendLine();
}
+ ///
+ /// Emits a static helper that creates a typed-buffer-sized MockRegistry from a
+ /// MockBehavior. Used by the generator-emitted (MockBehavior) constructors so
+ /// subclasses of the generated mock can construct from a behavior without bypassing the FastMockInteractions
+ /// sizing. When is true, the helper also primes the
+ /// MockRegistryProvider AsyncLocal so virtual calls during base-class construction can resolve
+ /// the registry before the chained constructor body has run.
+ ///
+ private static void AppendCreateRegistryFromBehavior(StringBuilder sb, string indent,
+ bool setsMockRegistryProvider)
+ {
+ sb.Append(indent).Append("/// ").AppendLine();
+ sb.Append(indent)
+ .Append("/// Builds a backed by a typed-buffer-sized ")
+ .Append(
+ " from .")
+ .AppendLine();
+ sb.Append(indent).Append("/// ").AppendLine();
+ sb.Append(indent)
+ .Append(
+ "private static global::Mockolate.MockRegistry MockolateCreateRegistryFromBehavior(global::Mockolate.MockBehavior behavior)")
+ .AppendLine();
+ sb.Append(indent).Append("{").AppendLine();
+ sb.Append(indent)
+ .Append(
+ "\tglobal::Mockolate.MockRegistry registry = new global::Mockolate.MockRegistry(behavior, CreateFastInteractions(behavior));")
+ .AppendLine();
+ if (setsMockRegistryProvider)
+ {
+ sb.Append(indent).Append("\tMockRegistryProvider.Value = registry;").AppendLine();
+ }
+
+ sb.Append(indent).Append("\treturn registry;").AppendLine();
+ sb.Append(indent).Append("}").AppendLine();
+ }
+
+ ///
+ /// Emits a public (MockBehavior) constructor on the generated mock for interface targets and class
+ /// targets without detected base-class constructors. Chains via : this(...) to the existing
+ /// (MockRegistry) constructor with a properly-sized registry.
+ ///
+ private static void AppendMockSubject_BehaviorConstructor(StringBuilder sb, string name)
+ {
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append("\t\tpublic ").Append(name).Append("(global::Mockolate.MockBehavior behavior)").AppendLine();
+ sb.Append("\t\t\t: this(MockolateCreateRegistryFromBehavior(behavior))").AppendLine();
+ sb.Append("\t\t{").AppendLine();
+ sb.Append("\t\t}").AppendLine();
+ sb.AppendLine();
+ }
+
+ ///
+ /// Emits a public (MockBehavior, ...baseCtorParams) constructor sibling for each detected base-class
+ /// constructor. The chained (MockRegistry, ...baseCtorParams) constructor handles base invocation;
+ /// MockolateCreateRegistryFromBehavior primes the MockRegistryProvider AsyncLocal before that
+ /// chain so virtual calls during base construction resolve the registry.
+ ///
+ private static void AppendMockSubject_BehaviorBaseClassConstructor(StringBuilder sb, string name,
+ Method constructor, bool hasRequiredMembers)
+ {
+ string behavior = CreateUniqueParameterName(constructor.Parameters, "behavior");
+ sb.Append("\t\t/// ").AppendLine();
+ sb.Append(constructor.Attributes, "\t\t");
+ if (hasRequiredMembers &&
+ constructor.Attributes?.Any(a => a.Name == "global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers") !=
+ true)
+ {
+ sb.Append("\t\t[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]").AppendLine();
+ }
+
+ sb.Append("\t\tpublic ").Append(name).Append("(global::Mockolate.MockBehavior ").Append(behavior);
+ foreach (MethodParameter parameter in constructor.Parameters)
+ {
+ sb.Append(", ");
+ if (parameter.IsParams)
+ {
+ sb.Append("params ");
+ }
+
+ sb.Append(parameter.Type.Fullname).Append(' ').Append(parameter.Name);
+ if (parameter.HasExplicitDefaultValue)
+ {
+ sb.Append(" = ").Append(parameter.ExplicitDefaultValue);
+ }
+ }
+
+ sb.Append(")").AppendLine();
+ sb.Append("\t\t\t: this(MockolateCreateRegistryFromBehavior(").Append(behavior).Append(")");
+ foreach (MethodParameter parameter in constructor.Parameters)
+ {
+ sb.Append(", ").Append(parameter.Name);
+ }
+
+ sb.Append(")").AppendLine();
+ sb.Append("\t\t{").AppendLine();
+ sb.Append("\t\t}").AppendLine();
+ sb.AppendLine();
+ }
+
#pragma warning disable S107 // Methods should not have too many parameters
private static void AppendMockSubject_ImplementClass(StringBuilder sb, Class @class, string mockRegistryName,
MockClass? mockClass, MemberIdTable memberIds, string memberIdPrefix,
@@ -1844,7 +2023,8 @@ private static void AppendMockSubject_ImplementClass(StringBuilder sb, Class @cl
(property.ExplicitImplementation ?? "") + "::" +
property.Type.Fullname + "->|" +
string.Join("|",
- property.IndexerParameters.Value.Select(p => p.RefKind + " " + p.Type.Fullname));
+ property.IndexerParameters.Value.Select(p
+ => p.RefKind + " " + p.Type.Fullname));
if (!signatureIndices.TryGetValue(signatureKey, out signatureIndex))
{
signatureIndex = nextSignatureIndex[0]++;
@@ -2604,7 +2784,8 @@ private static void AppendMockSubject_ImplementClass_AddMethod(StringBuilder sb,
if (method.GenericParameters is not null && method.GenericParameters.Value.Count > 0)
{
bool isOverride = !isClassInterface && method.UseOverride;
- bool isExplicitImplementation = explicitInterfaceImplementation || method.ExplicitImplementation is not null;
+ bool isExplicitImplementation =
+ explicitInterfaceImplementation || method.ExplicitImplementation is not null;
bool inheritsConstraints = isExplicitImplementation || isOverride || method.IsEquals() ||
method.IsGetHashCode() || method.IsToString();
foreach (GenericParameter gp in method.GenericParameters.Value)
@@ -2630,9 +2811,11 @@ private static void AppendMockSubject_ImplementClass_AddMethod(StringBuilder sb,
string methodSetupType = (method.ReturnType == Type.Void, method.Parameters.Count) switch
{
(true, 0) => "global::Mockolate.Setup.VoidMethodSetup",
- (true, _) => $"global::Mockolate.Setup.VoidMethodSetup<{string.Join(", ", method.Parameters.Select(p => p.ToTypeOrWrapper()))}>",
+ (true, _) =>
+ $"global::Mockolate.Setup.VoidMethodSetup<{string.Join(", ", method.Parameters.Select(p => p.ToTypeOrWrapper()))}>",
(_, 0) => $"global::Mockolate.Setup.ReturnMethodSetup<{method.ReturnType.ToTypeOrWrapper()}>",
- (_, _) => $"global::Mockolate.Setup.ReturnMethodSetup<{method.ReturnType.ToTypeOrWrapper()}, {string.Join(", ", method.Parameters.Select(p => p.ToTypeOrWrapper()))}>",
+ (_, _) =>
+ $"global::Mockolate.Setup.ReturnMethodSetup<{method.ReturnType.ToTypeOrWrapper()}, {string.Join(", ", method.Parameters.Select(p => p.ToTypeOrWrapper()))}>",
};
bool hasOutParams = method.Parameters.Any(p => p.RefKind is RefKind.Out);
bool hasRefParams = method.Parameters.Any(p => p.RefKind is RefKind.Ref);
@@ -2699,7 +2882,8 @@ private static void AppendMockSubject_ImplementClass_AddMethod(StringBuilder sb,
}
}
- sb.Append("\t\t\tif (").Append(mockRegistry).Append(".Behavior.SkipInteractionRecording == false)").AppendLine();
+ sb.Append("\t\t\tif (").Append(mockRegistry).Append(".Behavior.SkipInteractionRecording == false)")
+ .AppendLine();
sb.Append("\t\t\t{").AppendLine();
if (useFastBuffers && IsFastBufferEligibleMethod(method))
{
@@ -2725,7 +2909,8 @@ private static void AppendMockSubject_ImplementClass_AddMethod(StringBuilder sb,
.Append(".RegisterInteraction(new global::Mockolate.Interactions.MethodInvocation");
if (method.Parameters.Count > 0)
{
- sb.Append('<').Append(string.Join(", ", method.Parameters.Select(p => p.ToTypeOrWrapper()))).Append('>');
+ sb.Append('<').Append(string.Join(", ", method.Parameters.Select(p => p.ToTypeOrWrapper())))
+ .Append('>');
}
sb.Append("(").Append(method.GetUniqueNameString());
@@ -2816,7 +3001,8 @@ private static void AppendMockSubject_ImplementClass_AddMethod(StringBuilder sb,
{
string outParamBase = Helpers.GetUniqueIndexedLocalVariableBase("outParam", method.Parameters);
string refParamBase = Helpers.GetUniqueIndexedLocalVariableBase("refParam", method.Parameters);
- sb.Append("\t\t\t\tif (!").Append(hasWrappedResult).Append(" || ").Append(methodSetup).Append(" is ").Append(methodSetupType)
+ sb.Append("\t\t\t\tif (!").Append(hasWrappedResult).Append(" || ").Append(methodSetup).Append(" is ")
+ .Append(methodSetupType)
.Append(".WithParameterCollection)")
.AppendLine();
sb.Append("\t\t\t\t{").AppendLine();
@@ -2831,7 +3017,8 @@ private static void AppendMockSubject_ImplementClass_AddMethod(StringBuilder sb,
{
sb.Append("\t\t\t\t\t\tif (").Append(wpc).Append(".Parameter").Append(parameterIndex)
.Append(" is not global::Mockolate.Parameters.IOutParameter<")
- .Append(parameter.Type.ToTypeOrWrapper()).Append("> ").Append(outParamBase).Append(parameterIndex)
+ .Append(parameter.Type.ToTypeOrWrapper()).Append("> ").Append(outParamBase)
+ .Append(parameterIndex)
.Append(" || !").Append(outParamBase).Append(parameterIndex).Append(".TryGetValue(out ")
.Append(parameter.Name).Append("))").AppendLine();
sb.Append("\t\t\t\t\t\t{").AppendLine();
@@ -2844,10 +3031,12 @@ private static void AppendMockSubject_ImplementClass_AddMethod(StringBuilder sb,
{
sb.Append("\t\t\t\t\t\tif (").Append(wpc).Append(".Parameter").Append(parameterIndex)
.Append(" is global::Mockolate.Parameters.IRefParameter<")
- .Append(parameter.Type.ToTypeOrWrapper()).Append("> ").Append(refParamBase).Append(parameterIndex)
+ .Append(parameter.Type.ToTypeOrWrapper()).Append("> ").Append(refParamBase)
+ .Append(parameterIndex)
.Append(")").AppendLine();
sb.Append("\t\t\t\t\t\t{").AppendLine();
- sb.Append("\t\t\t\t\t\t\t").Append(parameter.Name).Append(" = ").Append(refParamBase).Append(parameterIndex)
+ sb.Append("\t\t\t\t\t\t\t").Append(parameter.Name).Append(" = ").Append(refParamBase)
+ .Append(parameterIndex)
.Append(".GetValue(").Append(parameter.Name).Append(");").AppendLine();
sb.Append("\t\t\t\t\t\t}").AppendLine();
}
@@ -2873,16 +3062,20 @@ private static void AppendMockSubject_ImplementClass_AddMethod(StringBuilder sb,
AppendTriggerCallbacks(sb, "\t\t\t\t", methodSetup, method.Parameters);
sb.Append("\t\t\t}").AppendLine();
- string displayMethodName = $"{method.ContainingType}.{method.Name}({string.Join(", ", method.Parameters.Select(p => p.Type.DisplayName))})";
- sb.Append("\t\t\tif (").Append(methodSetup).Append(" is null && !").Append(hasWrappedResult).Append(" && ").Append(mockRegistry).Append(".Behavior.ThrowWhenNotSetup)").AppendLine();
+ string displayMethodName =
+ $"{method.ContainingType}.{method.Name}({string.Join(", ", method.Parameters.Select(p => p.Type.DisplayName))})";
+ sb.Append("\t\t\tif (").Append(methodSetup).Append(" is null && !").Append(hasWrappedResult).Append(" && ")
+ .Append(mockRegistry).Append(".Behavior.ThrowWhenNotSetup)").AppendLine();
sb.Append("\t\t\t{").AppendLine();
- sb.Append("\t\t\t\tthrow new global::Mockolate.Exceptions.MockNotSetupException(\"The method '").Append(displayMethodName).Append("' was invoked without prior setup.\");").AppendLine();
+ sb.Append("\t\t\t\tthrow new global::Mockolate.Exceptions.MockNotSetupException(\"The method '")
+ .Append(displayMethodName).Append("' was invoked without prior setup.\");").AppendLine();
sb.Append("\t\t\t}").AppendLine();
if (method.ReturnType != Type.Void)
{
string returnValue = Helpers.GetUniqueLocalVariableName("returnValue", method.Parameters);
- sb.Append("\t\t\tif (").Append(methodSetup).Append("?.HasReturnCallbacks != true && ").Append(hasWrappedResult).Append(")").AppendLine();
+ sb.Append("\t\t\tif (").Append(methodSetup).Append("?.HasReturnCallbacks != true && ")
+ .Append(hasWrappedResult).Append(")").AppendLine();
sb.Append("\t\t\t{").AppendLine();
sb.Append("\t\t\t\treturn ").Append(wrappedResult).Append(";").AppendLine();
sb.Append("\t\t\t}").AppendLine();
@@ -2895,7 +3088,8 @@ private static void AppendMockSubject_ImplementClass_AddMethod(StringBuilder sb,
}
sb.Append("out var ").Append(returnValue).Append(") == true ? ").Append(returnValue).Append(" : ")
- .AppendDefaultValueGeneratorFor(method.ReturnType, $"{mockRegistry}.Behavior.DefaultValue", defaultValueGeneratorSuffix)
+ .AppendDefaultValueGeneratorFor(method.ReturnType, $"{mockRegistry}.Behavior.DefaultValue",
+ defaultValueGeneratorSuffix)
.Append(';').AppendLine();
}
@@ -3026,7 +3220,8 @@ method.ReturnType.SpecialGenericType is not
string displayMethodName =
$"{method.ContainingType}.{method.Name}({string.Join(", ", method.Parameters.Select(p => p.Type.DisplayName))})";
- sb.Append("\t\t\tif (!").Append(matchedVar).Append(" && ").Append(mockRegistry).Append(".Behavior.ThrowWhenNotSetup)")
+ sb.Append("\t\t\tif (!").Append(matchedVar).Append(" && ").Append(mockRegistry)
+ .Append(".Behavior.ThrowWhenNotSetup)")
.AppendLine();
sb.Append("\t\t\t{").AppendLine();
sb.Append("\t\t\t\tthrow new global::Mockolate.Exceptions.MockNotSetupException(\"The method '")
@@ -3092,7 +3287,8 @@ private static void AppendRefStructIndexerGetterBody(StringBuilder sb, Property
// Iterate setups in latest-registered-first order; stop on the first matching setup.
string paramNames = string.Join(", ", property.IndexerParameters.Value.Select(p => p.Name));
string setupVar = Helpers.GetUniqueLocalVariableName("setup", property.IndexerParameters.Value);
- sb.Append("\t\t\t\tforeach (").Append(setupType).Append(' ').Append(setupVar).Append(" in ").Append(mockRegistry)
+ sb.Append("\t\t\t\tforeach (").Append(setupType).Append(' ').Append(setupVar).Append(" in ")
+ .Append(mockRegistry)
.Append(".GetMethodSetups<").Append(setupType).Append(">(").Append(indexerName).Append("))")
.AppendLine();
sb.Append("\t\t\t\t{").AppendLine();
@@ -3188,7 +3384,8 @@ private static void AppendRefStructIndexerSetterBody(StringBuilder sb, Property
: string.Empty;
string setupVar = Helpers.GetUniqueLocalVariableName("setup", property.IndexerParameters.Value);
- sb.Append("\t\t\t\tforeach (").Append(setupType).Append(' ').Append(setupVar).Append(" in ").Append(mockRegistry)
+ sb.Append("\t\t\t\tforeach (").Append(setupType).Append(' ').Append(setupVar).Append(" in ")
+ .Append(mockRegistry)
.Append(".GetMethodSetups<").Append(setupType).Append(">(").Append(indexerName).Append("))")
.AppendLine();
sb.Append("\t\t\t\t{").AppendLine();
@@ -3197,7 +3394,8 @@ private static void AppendRefStructIndexerSetterBody(StringBuilder sb, Property
sb.Append("\t\t\t\t\t\tcontinue;").AppendLine();
sb.Append("\t\t\t\t\t}").AppendLine();
sb.AppendLine();
- sb.Append("\t\t\t\t\t").Append(setupVar).Append(".Invoke(").Append(keyNames).Append(", value").Append(rawKeysArgs).Append(");").AppendLine();
+ sb.Append("\t\t\t\t\t").Append(setupVar).Append(".Invoke(").Append(keyNames).Append(", value")
+ .Append(rawKeysArgs).Append(");").AppendLine();
sb.Append("\t\t\t\t\treturn;").AppendLine();
sb.Append("\t\t\t\t}").AppendLine();
@@ -3222,13 +3420,17 @@ private static void AppendNestedCovariantParameterAdapter(StringBuilder sb)
{
sb.AppendLine();
sb.Append("\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]").AppendLine();
- sb.Append("\tprivate sealed class CovariantParameterAdapter(global::Mockolate.Parameters.IParameter inner) : global::Mockolate.Parameters.IParameterMatch").AppendLine();
+ sb.Append(
+ "\tprivate sealed class CovariantParameterAdapter(global::Mockolate.Parameters.IParameter inner) : global::Mockolate.Parameters.IParameterMatch")
+ .AppendLine();
sb.Append("\t{").AppendLine();
sb.Append("\t\tpublic bool Matches(T value) => inner.Matches(value);").AppendLine();
sb.Append("\t\tpublic void InvokeCallbacks(T value) => inner.InvokeCallbacks(value);").AppendLine();
sb.Append("\t\tpublic override string? ToString() => inner.ToString();").AppendLine();
sb.AppendLine();
- sb.Append("\t\tpublic static global::Mockolate.Parameters.IParameterMatch Wrap(global::Mockolate.Parameters.IParameter parameter)").AppendLine();
+ sb.Append(
+ "\t\tpublic static global::Mockolate.Parameters.IParameterMatch Wrap(global::Mockolate.Parameters.IParameter parameter)")
+ .AppendLine();
sb.Append("\t\t\t=> parameter is global::Mockolate.Parameters.IParameterMatch direct").AppendLine();
sb.Append("\t\t\t\t? direct").AppendLine();
sb.Append("\t\t\t\t: new CovariantParameterAdapter(parameter);").AppendLine();
@@ -3421,7 +3623,8 @@ private static void AppendOverloadDifferentiatorRemark(StringBuilder sb,
}
else if (valueFlags is null)
{
- text = "This overload takes argument matchers (e.g. It.IsAny<T>(), It.Is<T>(value)) for every parameter.";
+ text =
+ "This overload takes argument matchers (e.g. It.IsAny<T>(), It.Is<T>(value)) for every parameter.";
}
else if (valueFlags.All(x => x))
{
@@ -3506,7 +3709,8 @@ private static void AppendMethodSetupDefinition(StringBuilder sb, Class @class,
sb.Append(".").AppendLine();
sb.Append("\t\t/// ").AppendLine();
- AppendOverloadDifferentiatorRemark(sb, method.Parameters.Select(p => p.Name).ToArray(), useParameters, valueFlags);
+ AppendOverloadDifferentiatorRemark(sb, method.Parameters.Select(p => p.Name).ToArray(), useParameters,
+ valueFlags);
if (method.ReturnType != Type.Void)
{
if (valueFlags?.All(x => x) == true)
@@ -4719,7 +4923,8 @@ private static void AppendIndexerVerifyImplementation(StringBuilder sb, Property
AppendIndexerVerifyParameterMatches(sb, indexer.IndexerParameters.Value, valueFlags, "g");
sb.Append(",").AppendLine();
- sb.Append("\t\t\t\t\t(interaction, value) => interaction is global::Mockolate.Interactions.IndexerSetterAccess<");
+ sb.Append(
+ "\t\t\t\t\t(interaction, value) => interaction is global::Mockolate.Interactions.IndexerSetterAccess<");
ti = 0;
foreach (MethodParameter parameter in indexer.IndexerParameters.Value)
{
@@ -5058,7 +5263,8 @@ private static void AppendMethodVerifyDefinition(StringBuilder sb, Method method
sb.Append(".").AppendLine();
sb.Append("\t\t/// ").AppendLine();
- AppendOverloadDifferentiatorRemark(sb, method.Parameters.Select(p => p.Name).ToArray(), useParameters, valueFlags, true);
+ AppendOverloadDifferentiatorRemark(sb, method.Parameters.Select(p => p.Name).ToArray(), useParameters,
+ valueFlags, true);
if (valueFlags?.All(x => x) == true || (method.Parameters.Count == 0 && !useParameters))
{
sb.Append("\t\tglobal::Mockolate.Verify.VerificationResult<").Append(verifyName)
@@ -5369,7 +5575,9 @@ private static void AppendMethodVerifyImplementation(StringBuilder sb, Method me
&& method.Parameters.Count <= 4
&& (method.GenericParameters is null || method.GenericParameters.Value.Count == 0)
&& (valueFlags is null || !valueFlags.Any(x => x))
- && !method.Parameters.Any(p => p.RefKind == RefKind.Out || p.RefKind == RefKind.Ref || p.RefKind == RefKind.RefReadOnlyParameter);
+ && !method.Parameters.Any(p
+ => p.RefKind == RefKind.Out || p.RefKind == RefKind.Ref ||
+ p.RefKind == RefKind.RefReadOnlyParameter);
if (canUseTypedVerify)
{
@@ -5384,11 +5592,14 @@ private static void AppendMethodVerifyImplementation(StringBuilder sb, Method me
{
string paramType = parameter.ToTypeOrWrapper();
sb.Append(", ").Append(parameter.Name).Append(" is null ? ")
- .Append("(global::Mockolate.Parameters.IParameterMatch<").Append(paramType).Append(">)global::Mockolate.It.Is<").Append(paramType).Append(">(default!) : ")
- .Append("CovariantParameterAdapter<").Append(paramType).Append(">.Wrap(").Append(parameter.Name).Append(")");
+ .Append("(global::Mockolate.Parameters.IParameterMatch<").Append(paramType)
+ .Append(">)global::Mockolate.It.Is<").Append(paramType).Append(">(default!) : ")
+ .Append("CovariantParameterAdapter<").Append(paramType).Append(">.Wrap(").Append(parameter.Name)
+ .Append(")");
}
- sb.Append(", () => $\"").Append(method.Name).Append("(").Append(string.Join(", ", method.Parameters.Select(p => $"{{{p.Name}}}"))).Append(")\");").AppendLine();
+ sb.Append(", () => $\"").Append(method.Name).Append("(")
+ .Append(string.Join(", ", method.Parameters.Select(p => $"{{{p.Name}}}"))).Append(")\");").AppendLine();
return;
}
@@ -5404,8 +5615,12 @@ private static void AppendMethodVerifyImplementation(StringBuilder sb, Method me
{
sb.Append(", i => parameters switch").AppendLine();
sb.Append("\t\t\t\t{").AppendLine();
- sb.Append("\t\t\t\t\tglobal::Mockolate.Parameters.IParametersMatch m => m.Matches([").Append(string.Join(", ", Enumerable.Range(1, method.Parameters.Count).Select(i => $"i.Parameter{i}"))).Append("]),").AppendLine();
- sb.Append("\t\t\t\t\tglobal::Mockolate.Parameters.INamedParametersMatch m => m.Matches([").Append(string.Join(", ", method.Parameters.Select((p, i) => $"(\"{p.Name}\", i.Parameter{i + 1})"))).Append("]),").AppendLine();
+ sb.Append("\t\t\t\t\tglobal::Mockolate.Parameters.IParametersMatch m => m.Matches([")
+ .Append(string.Join(", ", Enumerable.Range(1, method.Parameters.Count).Select(i => $"i.Parameter{i}")))
+ .Append("]),").AppendLine();
+ sb.Append("\t\t\t\t\tglobal::Mockolate.Parameters.INamedParametersMatch m => m.Matches([")
+ .Append(string.Join(", ", method.Parameters.Select((p, i) => $"(\"{p.Name}\", i.Parameter{i + 1})")))
+ .Append("]),").AppendLine();
sb.Append("\t\t\t\t\t_ => true").AppendLine();
sb.Append("\t\t\t\t}");
}
@@ -5430,24 +5645,30 @@ private static void AppendMethodVerifyImplementation(StringBuilder sb, Method me
bool isValueParam = valueFlags?[i] == true;
if (isValueParam)
{
- sb.Append($"(global::System.Collections.Generic.EqualityComparer<{parameter.ToTypeOrWrapper()}>.Default.Equals({parameter.Name}, i.Parameter{i + 1}))");
+ sb.Append(
+ $"(global::System.Collections.Generic.EqualityComparer<{parameter.ToTypeOrWrapper()}>.Default.Equals({parameter.Name}, i.Parameter{i + 1}))");
}
- else if (parameter.RefKind == RefKind.Out || parameter.RefKind == RefKind.Ref || parameter.RefKind == RefKind.RefReadOnlyParameter)
+ else if (parameter.RefKind == RefKind.Out || parameter.RefKind == RefKind.Ref ||
+ parameter.RefKind == RefKind.RefReadOnlyParameter)
{
// out/ref verify parameters use IVerifyOutParameter / IVerifyRefParameter, which don't inherit
// from IParameter — covariance isn't applicable, so keep the direct IParameterMatch check.
- sb.Append($"({parameter.Name} is global::Mockolate.Parameters.IParameterMatch<{parameter.ToTypeOrWrapper()}> {parameter.Name}Match ? {parameter.Name}Match.Matches(i.Parameter{i + 1}) : global::System.Collections.Generic.EqualityComparer<{parameter.ToTypeOrWrapper()}>.Default.Equals(i.Parameter{i + 1}, default({parameter.ToTypeOrWrapper()})))");
+ sb.Append(
+ $"({parameter.Name} is global::Mockolate.Parameters.IParameterMatch<{parameter.ToTypeOrWrapper()}> {parameter.Name}Match ? {parameter.Name}Match.Matches(i.Parameter{i + 1}) : global::System.Collections.Generic.EqualityComparer<{parameter.ToTypeOrWrapper()}>.Default.Equals(i.Parameter{i + 1}, default({parameter.ToTypeOrWrapper()})))");
}
else
{
- sb.Append($"({parameter.Name} is not null ? CovariantParameterAdapter<{parameter.ToTypeOrWrapper()}>.Wrap({parameter.Name}).Matches(i.Parameter{i + 1}) : global::System.Collections.Generic.EqualityComparer<{parameter.ToTypeOrWrapper()}>.Default.Equals(i.Parameter{i + 1}, default({parameter.ToTypeOrWrapper()})))");
+ sb.Append(
+ $"({parameter.Name} is not null ? CovariantParameterAdapter<{parameter.ToTypeOrWrapper()}>.Wrap({parameter.Name}).Matches(i.Parameter{i + 1}) : global::System.Collections.Generic.EqualityComparer<{parameter.ToTypeOrWrapper()}>.Default.Equals(i.Parameter{i + 1}, default({parameter.ToTypeOrWrapper()})))");
}
i++;
}
}
- sb.Append(", () => $\"").Append(method.Name).Append("(").Append(useParameters ? "{parameters}" : string.Join(", ", method.Parameters.Select(p => $"{{{p.Name}}}"))).Append(")\");").AppendLine();
+ sb.Append(", () => $\"").Append(method.Name).Append("(")
+ .Append(useParameters ? "{parameters}" : string.Join(", ", method.Parameters.Select(p => $"{{{p.Name}}}")))
+ .Append(")\");").AppendLine();
}
#endregion Verify Helpers
diff --git a/Source/Mockolate.SourceGenerators/Sources/Sources.MockDelegate.cs b/Source/Mockolate.SourceGenerators/Sources/Sources.MockDelegate.cs
index 414695b1..c91a7822 100644
--- a/Source/Mockolate.SourceGenerators/Sources/Sources.MockDelegate.cs
+++ b/Source/Mockolate.SourceGenerators/Sources/Sources.MockDelegate.cs
@@ -40,11 +40,13 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\tget").AppendLine();
sb.Append("\t\t\t{").AppendLine();
- sb.Append("\t\t\t\tif (mock.Target is global::Mockolate.Mock.IMockFor").Append(name).Append(" mockInterface)").AppendLine();
+ sb.Append("\t\t\t\tif (mock.Target is global::Mockolate.Mock.IMockFor").Append(name).Append(" mockInterface)")
+ .AppendLine();
sb.Append("\t\t\t\t{").AppendLine();
sb.Append("\t\t\t\t\treturn mockInterface;").AppendLine();
sb.Append("\t\t\t\t}").AppendLine();
- sb.Append("\t\t\t\tthrow new global::Mockolate.Exceptions.MockException(\"The subject is no mock.\");").AppendLine();
+ sb.Append("\t\t\t\tthrow new global::Mockolate.Exceptions.MockException(\"The subject is no mock.\");")
+ .AppendLine();
sb.Append("\t\t\t}").AppendLine();
sb.Append("\t\t}").AppendLine();
sb.AppendLine();
@@ -53,14 +55,18 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
#region CreateMock
- sb.AppendXmlSummary($"Create a new mock of with the default .");
+ sb.AppendXmlSummary(
+ $"Create a new mock of with the default .");
sb.Append("\t\tpublic static ").Append(@class.ClassFullName).Append(" CreateMock()").AppendLine();
sb.Append("\t\t\t=> CreateMock(null, []);").AppendLine();
sb.AppendLine();
- sb.AppendXmlSummary($"Create a new mock of with the default .");
+ sb.AppendXmlSummary(
+ $"Create a new mock of with the default .");
sb.AppendXmlRemarks("All provided are immediately applied to the mock.");
- sb.Append("\t\tpublic static ").Append(@class.ClassFullName).Append(" CreateMock(params global::System.Action[] setups)").AppendLine();
+ sb.Append("\t\tpublic static ").Append(@class.ClassFullName)
+ .Append(" CreateMock(params global::System.Action[] setups)").AppendLine();
sb.Append("\t\t\t=> CreateMock(null, setups);").AppendLine();
sb.AppendLine();
@@ -73,7 +79,9 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
.Append(name).Append(">[] setups)").AppendLine();
sb.Append("\t\t{").AppendLine();
sb.Append("\t\t\tmockBehavior ??= global::Mockolate.MockBehavior.Default;").AppendLine();
- sb.Append("\t\t\tvar mockRegistry = new global::Mockolate.MockRegistry(mockBehavior);").AppendLine();
+ sb.Append(
+ "\t\t\tvar mockRegistry = new global::Mockolate.MockRegistry(mockBehavior, new global::Mockolate.Interactions.FastMockInteractions(0, mockBehavior.SkipInteractionRecording));")
+ .AppendLine();
sb.Append("\t\t\tglobal::Mockolate.Mock.").Append(name).Append(" mockTarget = new global::Mockolate.Mock.")
.Append(name).Append("(mockRegistry);")
.AppendLine();
@@ -100,9 +108,12 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
sb.Append("internal static partial class Mock").AppendLine();
sb.Append("{").AppendLine();
sb.Append("\t/// ").AppendLine();
- sb.Append("\t/// A mock implementation for .").AppendLine();
+ sb.Append("\t/// A mock implementation for .")
+ .AppendLine();
sb.Append("\t/// ").AppendLine();
- sb.Append("\t[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]").AppendLine();
+ sb.Append(
+ "\t[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]")
+ .AppendLine();
#if !DEBUG
sb.Append("\t[global::System.Diagnostics.DebuggerNonUserCode]").AppendLine();
#endif
@@ -115,9 +126,13 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
sb.AppendLine();
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\t[global::System.Diagnostics.DebuggerBrowsable(global::System.Diagnostics.DebuggerBrowsableState.Never)]").AppendLine();
- sb.Append("\t\tglobal::Mockolate.MockRegistry global::Mockolate.IMock.MockRegistry => this.").Append(mockRegistryName).Append(';').AppendLine();
- sb.Append("\t\tprivate global::Mockolate.MockRegistry ").Append(mockRegistryName).Append(" { get; }").AppendLine();
+ sb.Append(
+ "\t\t[global::System.Diagnostics.DebuggerBrowsable(global::System.Diagnostics.DebuggerBrowsableState.Never)]")
+ .AppendLine();
+ sb.Append("\t\tglobal::Mockolate.MockRegistry global::Mockolate.IMock.MockRegistry => this.")
+ .Append(mockRegistryName).Append(';').AppendLine();
+ sb.Append("\t\tprivate global::Mockolate.MockRegistry ").Append(mockRegistryName).Append(" { get; }")
+ .AppendLine();
sb.AppendLine();
sb.Append("\t\t/// ").AppendLine();
@@ -141,9 +156,11 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
string methodSetupType = (delegateMethod.ReturnType == Type.Void, delegateMethod.Parameters.Count) switch
{
(true, 0) => "global::Mockolate.Setup.VoidMethodSetup",
- (true, _) => $"global::Mockolate.Setup.VoidMethodSetup<{string.Join(", ", delegateMethod.Parameters.Select(p => p.ToTypeOrWrapper()))}>",
+ (true, _) =>
+ $"global::Mockolate.Setup.VoidMethodSetup<{string.Join(", ", delegateMethod.Parameters.Select(p => p.ToTypeOrWrapper()))}>",
(_, 0) => $"global::Mockolate.Setup.ReturnMethodSetup<{delegateMethod.ReturnType.ToTypeOrWrapper()}>",
- (_, _) => $"global::Mockolate.Setup.ReturnMethodSetup<{delegateMethod.ReturnType.ToTypeOrWrapper()}, {string.Join(", ", delegateMethod.Parameters.Select(p => p.ToTypeOrWrapper()))}>",
+ (_, _) =>
+ $"global::Mockolate.Setup.ReturnMethodSetup<{delegateMethod.ReturnType.ToTypeOrWrapper()}, {string.Join(", ", delegateMethod.Parameters.Select(p => p.ToTypeOrWrapper()))}>",
};
bool hasOutParams = delegateMethod.Parameters.Any(p => p.RefKind is RefKind.Out);
bool hasRefParams = delegateMethod.Parameters.Any(p => p.RefKind is RefKind.Ref);
@@ -186,7 +203,8 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
}
string memberIdRef = memberIdPrefix + memberIds.GetMethodIdentifier(delegateMethod);
- bool isGeneric = delegateMethod.GenericParameters is not null && delegateMethod.GenericParameters.Value.Count > 0;
+ bool isGeneric = delegateMethod.GenericParameters is not null &&
+ delegateMethod.GenericParameters.Value.Count > 0;
EmitFastMethodSetupLookup(sb, "\t\t\t", $"this.{mockRegistryName}", methodSetup, methodSetupType,
memberIdRef, delegateMethod.GetUniqueNameString(), sb2.ToString(), isGeneric);
@@ -213,12 +231,14 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
{
sb.Append("\t\t\t\tif (").Append(wpc).Append(".Parameter").Append(parameterIndex)
.Append(" is not global::Mockolate.Parameters.IOutParameter<")
- .Append(parameter.Type.ToTypeOrWrapper()).Append("> ").Append(outParamBase).Append(parameterIndex)
+ .Append(parameter.Type.ToTypeOrWrapper()).Append("> ").Append(outParamBase)
+ .Append(parameterIndex)
.Append(" || !").Append(outParamBase).Append(parameterIndex).Append(".TryGetValue(out ")
.Append(parameter.Name).Append("))").AppendLine();
sb.Append("\t\t\t\t{").AppendLine();
sb.Append("\t\t\t\t\t").Append(parameter.Name).Append(" = ")
- .AppendDefaultValueGeneratorFor(parameter.Type, $"this.{mockRegistryName}.Behavior.DefaultValue")
+ .AppendDefaultValueGeneratorFor(parameter.Type,
+ $"this.{mockRegistryName}.Behavior.DefaultValue")
.Append(';').AppendLine();
sb.Append("\t\t\t\t}").AppendLine();
}
@@ -226,10 +246,12 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
{
sb.Append("\t\t\t\tif (").Append(wpc).Append(".Parameter").Append(parameterIndex)
.Append(" is global::Mockolate.Parameters.IRefParameter<")
- .Append(parameter.Type.ToTypeOrWrapper()).Append("> ").Append(refParamBase).Append(parameterIndex)
+ .Append(parameter.Type.ToTypeOrWrapper()).Append("> ").Append(refParamBase)
+ .Append(parameterIndex)
.Append(")").AppendLine();
sb.Append("\t\t\t\t{").AppendLine();
- sb.Append("\t\t\t\t\t").Append(parameter.Name).Append(" = ").Append(refParamBase).Append(parameterIndex)
+ sb.Append("\t\t\t\t\t").Append(parameter.Name).Append(" = ").Append(refParamBase)
+ .Append(parameterIndex)
.Append(".GetValue(").Append(parameter.Name).Append(");").AppendLine();
sb.Append("\t\t\t\t}").AppendLine();
}
@@ -238,13 +260,15 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
sb.Append("\t\t\t}").AppendLine();
}
- sb.Append("\t\t\tif (").Append(mockRegistryName).Append(".Behavior.SkipInteractionRecording == false)").AppendLine();
+ sb.Append("\t\t\tif (").Append(mockRegistryName).Append(".Behavior.SkipInteractionRecording == false)")
+ .AppendLine();
sb.Append("\t\t\t{").AppendLine();
sb.Append("\t\t\t\t").Append(mockRegistryName)
.Append(".RegisterInteraction(new global::Mockolate.Interactions.MethodInvocation");
if (delegateMethod.Parameters.Count > 0)
{
- sb.Append('<').Append(string.Join(", ", delegateMethod.Parameters.Select(p => p.ToTypeOrWrapper()))).Append('>');
+ sb.Append('<').Append(string.Join(", ", delegateMethod.Parameters.Select(p => p.ToTypeOrWrapper())))
+ .Append('>');
}
sb.Append("(").Append(delegateMethod.GetUniqueNameString());
@@ -256,10 +280,13 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
sb.Append("));").AppendLine();
sb.Append("\t\t\t}").AppendLine();
- string displayDelegateName = $"{delegateMethod.ContainingType}.{delegateMethod.Name}({string.Join(", ", delegateMethod.Parameters.Select(p => p.Type.DisplayName))})";
- sb.Append("\t\t\tif (").Append(methodSetup).Append(" is null && this.").Append(mockRegistryName).Append(".Behavior.ThrowWhenNotSetup)").AppendLine();
+ string displayDelegateName =
+ $"{delegateMethod.ContainingType}.{delegateMethod.Name}({string.Join(", ", delegateMethod.Parameters.Select(p => p.Type.DisplayName))})";
+ sb.Append("\t\t\tif (").Append(methodSetup).Append(" is null && this.").Append(mockRegistryName)
+ .Append(".Behavior.ThrowWhenNotSetup)").AppendLine();
sb.Append("\t\t\t{").AppendLine();
- sb.Append("\t\t\t\tthrow new global::Mockolate.Exceptions.MockNotSetupException(\"The method '").Append(displayDelegateName).Append("' was invoked without prior setup.\");").AppendLine();
+ sb.Append("\t\t\t\tthrow new global::Mockolate.Exceptions.MockNotSetupException(\"The method '")
+ .Append(displayDelegateName).Append("' was invoked without prior setup.\");").AppendLine();
sb.Append("\t\t\t}").AppendLine();
AppendTriggerCallbacks(sb, "\t\t\t", methodSetup, delegateMethod.Parameters);
@@ -274,7 +301,8 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
}
sb.Append("out var ").Append(returnValue).Append(") == true ? ").Append(returnValue).Append(" : ")
- .AppendDefaultValueGeneratorFor(delegateMethod.ReturnType, $"this.{mockRegistryName}.Behavior.DefaultValue")
+ .AppendDefaultValueGeneratorFor(delegateMethod.ReturnType,
+ $"this.{mockRegistryName}.Behavior.DefaultValue")
.Append(';').AppendLine();
}
@@ -340,18 +368,22 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
}
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tglobal::Mockolate.Verify.VerificationResult IMockFor").Append(name).Append(".VerifySetup(global::Mockolate.Setup.IMethodSetup setup)").AppendLine();
- sb.Append("\t\t\t=> this.").Append(mockRegistryName).Append(".Method(this, setup);").AppendLine();
+ sb.Append("\t\tglobal::Mockolate.Verify.VerificationResult IMockFor")
+ .Append(name).Append(".VerifySetup(global::Mockolate.Setup.IMethodSetup setup)").AppendLine();
+ sb.Append("\t\t\t=> this.").Append(mockRegistryName).Append(".Method(this, setup);").AppendLine();
sb.AppendLine();
sb.Append("\t\t/// ").AppendLine();
sb.Append("\t\tbool IMockFor").Append(name).Append(".VerifyThatAllInteractionsAreVerified()").AppendLine();
- sb.Append("\t\t\t=> this.").Append(mockRegistryName).Append(".Interactions.GetUnverifiedInteractions().Count == 0;").AppendLine();
+ sb.Append("\t\t\t=> this.").Append(mockRegistryName)
+ .Append(".Interactions.GetUnverifiedInteractions().Count == 0;").AppendLine();
sb.AppendLine();
sb.Append("\t\t/// ").AppendLine();
sb.Append("\t\tbool IMockFor").Append(name).Append(".VerifyThatAllSetupsAreUsed()").AppendLine();
- sb.Append("\t\t\t=> this.").Append(mockRegistryName).Append(".GetUnusedSetups(this.").Append(mockRegistryName).Append(".Interactions).Count == 0;").AppendLine();
+ sb.Append("\t\t\t=> this.").Append(mockRegistryName).Append(".GetUnusedSetups(this.").Append(mockRegistryName)
+ .Append(".Interactions).Count == 0;").AppendLine();
sb.AppendLine();
sb.Append("\t\t/// ").AppendLine();
@@ -360,8 +392,12 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
sb.AppendLine();
sb.Append("\t\t/// ").AppendLine();
- sb.Append("\t\tglobal::Mockolate.Monitor.MockMonitor IMockFor").Append(name).Append(".Monitor()").AppendLine();
- sb.Append("\t\t\t=> new global::Mockolate.Monitor.MockMonitor(this.").Append(mockRegistryName).Append(".Interactions, interactions => new VerifyMonitor").Append(name).Append("(new global::Mockolate.MockRegistry(this.").Append(mockRegistryName).Append(", interactions)));").AppendLine();
+ sb.Append("\t\tglobal::Mockolate.Monitor.MockMonitor IMockFor")
+ .Append(name).Append(".Monitor()").AppendLine();
+ sb.Append("\t\t\t=> new global::Mockolate.Monitor.MockMonitor(this.")
+ .Append(mockRegistryName).Append(".Interactions, interactions => new VerifyMonitor").Append(name)
+ .Append("(new global::Mockolate.MockRegistry(this.").Append(mockRegistryName).Append(", interactions)));")
+ .AppendLine();
sb.AppendLine("\t}");
sb.AppendLine();
@@ -369,9 +405,12 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
sb.Append("\t[global::System.Diagnostics.DebuggerNonUserCode]").AppendLine();
#endif
sb.Append("\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]").AppendLine();
- sb.Append("\tprivate sealed class VerifyMonitor").Append(name).Append("(global::Mockolate.MockRegistry mockRegistry) : global::Mockolate.Mock.IMockVerifyFor").Append(name).AppendLine();
+ sb.Append("\tprivate sealed class VerifyMonitor").Append(name)
+ .Append("(global::Mockolate.MockRegistry mockRegistry) : global::Mockolate.Mock.IMockVerifyFor")
+ .Append(name).AppendLine();
sb.Append("\t{").AppendLine();
- sb.Append("\t\tprivate global::Mockolate.MockRegistry ").Append(mockRegistryName).Append(" { get; } = mockRegistry;").AppendLine();
+ sb.Append("\t\tprivate global::Mockolate.MockRegistry ").Append(mockRegistryName)
+ .Append(" { get; } = mockRegistry;").AppendLine();
sb.AppendLine();
sb.Append("\t\t#region IMockVerifyFor").Append(name).AppendLine();
sb.AppendLine();
@@ -416,7 +455,8 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
sb.Append("\t\t IMockSetupFor").Append(name).Append(", IMockVerifyFor").Append(name).AppendLine();
sb.Append("\t{").AppendLine();
sb.AppendXmlSummary("Verifies the method invocations for the on the mock.");
- sb.Append("\t\tglobal::Mockolate.Verify.VerificationResult VerifySetup(global::Mockolate.Setup.IMethodSetup setup);").AppendLine();
+ sb.Append("\t\tglobal::Mockolate.Verify.VerificationResult VerifySetup(global::Mockolate.Setup.IMethodSetup setup);").AppendLine();
sb.AppendLine();
sb.AppendXmlSummary("Gets a value indicating whether all expected interactions have been verified.");
sb.Append("\t\tbool VerifyThatAllInteractionsAreVerified();").AppendLine();
@@ -427,8 +467,10 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
sb.AppendXmlSummary("Clears all interactions recorded by the mock object.");
sb.Append("\t\tvoid ClearAllInteractions();").AppendLine();
sb.AppendLine();
- sb.AppendXmlSummary("Provides monitoring capabilities for a mocked instance of the specified type, allowing inspection of accessed properties, invoked methods, and event subscriptions.");
- sb.Append("\t\tglobal::Mockolate.Monitor.MockMonitor Monitor();").AppendLine();
+ sb.AppendXmlSummary(
+ "Provides monitoring capabilities for a mocked instance of the specified type, allowing inspection of accessed properties, invoked methods, and event subscriptions.");
+ sb.Append("\t\tglobal::Mockolate.Monitor.MockMonitor Monitor();")
+ .AppendLine();
sb.Append("\t}").AppendLine();
#endregion IMockForXXX
@@ -438,7 +480,8 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
#region IMockSetupForXXX
sb.AppendXmlSummary($"Set up the mock of .", "\t");
- sb.Append("\tinternal interface IMockSetupFor").Append(name).Append(" : global::Mockolate.Setup.IMockSetup<").Append(@class.ClassFullName).Append(">").AppendLine();
+ sb.Append("\tinternal interface IMockSetupFor").Append(name).Append(" : global::Mockolate.Setup.IMockSetup<")
+ .Append(@class.ClassFullName).Append(">").AppendLine();
sb.Append("\t{").AppendLine();
AppendMethodSetupDefinition(sb, @class, delegateMethod, false, "Setup");
if (delegateMethod.Parameters.Count > 0)
@@ -471,7 +514,8 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
#region IMockVerifyForXXX
sb.AppendXmlSummary($"Verify interactions with the mock of .", "\t");
- sb.Append("\tinternal interface IMockVerifyFor").Append(name).Append(" : global::Mockolate.Verify.IMockVerify<").Append(@class.ClassFullName).Append(">").AppendLine();
+ sb.Append("\tinternal interface IMockVerifyFor").Append(name).Append(" : global::Mockolate.Verify.IMockVerify<")
+ .Append(@class.ClassFullName).Append(">").AppendLine();
sb.Append("\t{").AppendLine();
AppendMethodVerifyDefinition(sb, delegateMethod, $"IMockVerifyFor{name}", false, "Verify");
if (delegateMethod.Parameters.Count > 0)
@@ -491,7 +535,8 @@ public static string MockDelegate(string name, MockClass @class, Method delegate
bool[] allValueFlags = delegateMethod.Parameters.Select(p => p.CanUseNullableParameterOverload()).ToArray();
if (allValueFlags.Any(f => f))
{
- AppendMethodVerifyDefinition(sb, delegateMethod, $"IMockVerifyFor{name}", false, "Verify", allValueFlags);
+ AppendMethodVerifyDefinition(sb, delegateMethod, $"IMockVerifyFor{name}", false, "Verify",
+ allValueFlags);
}
}
diff --git a/Source/Mockolate/MockRegistry.cs b/Source/Mockolate/MockRegistry.cs
index 4ad8094f..991dca8a 100644
--- a/Source/Mockolate/MockRegistry.cs
+++ b/Source/Mockolate/MockRegistry.cs
@@ -20,44 +20,27 @@ public partial class MockRegistry
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly ScenarioState _scenarioState;
- ///
- /// Creates a new with the given and, optionally,
- /// for a class mock's base-class constructor.
- ///
- /// The that governs how the mock responds without a matching setup.
- /// Values forwarded to the base-class constructor, or if no base constructor call is needed.
- public MockRegistry(MockBehavior behavior, object?[]? constructorParameters = null)
- : this(behavior,
- new FastMockInteractions(0, behavior.SkipInteractionRecording),
- constructorParameters)
- {
- }
-
///
/// Creates a new with the given , a caller-provided
/// store, and optional .
///
///
/// The generator-emitted CreateMock paths use this overload to install a
- /// tailored to the mocked type. Pass any
- /// implementation (e.g. new FastMockInteractions(0))
- /// when constructing a registry by hand.
+ /// tailored to the mocked type.
///
/// The that governs how the mock responds without a matching setup.
/// The interaction collection that new invocations should be appended to.
- /// Values forwarded to the base-class constructor, or if no base constructor call is needed.
+ ///
+ /// Values forwarded to the base-class constructor, or if no
+ /// base constructor call is needed.
+ ///
public MockRegistry(MockBehavior behavior, IMockInteractions interactions,
object?[]? constructorParameters = null)
{
if (behavior.SkipInteractionRecording != interactions.SkipInteractionRecording)
{
throw new ArgumentException(
- $"{nameof(behavior)}.{nameof(MockBehavior.SkipInteractionRecording)} " +
- $"({behavior.SkipInteractionRecording}) and " +
- $"{nameof(interactions)}.{nameof(IMockInteractions.SkipInteractionRecording)} " +
- $"({interactions.SkipInteractionRecording}) must agree; recording paths gate on the " +
- "behavior flag while verification gates on the interactions flag, so a mismatch leaves " +
- "the registry in an inconsistent state.",
+ $"""{nameof(behavior)}.{nameof(MockBehavior.SkipInteractionRecording)} ({behavior.SkipInteractionRecording}) and {nameof(interactions)}.{nameof(IMockInteractions.SkipInteractionRecording)} ({interactions.SkipInteractionRecording}) must agree; recording paths gate on the behavior flag while verification gates on the interactions flag, so a mismatch leaves the registry in an inconsistent state.""",
nameof(interactions));
}
@@ -105,19 +88,17 @@ public MockRegistry(MockRegistry registry, object?[] constructorParameters)
/// Creates a that shares all state with but records
/// into the supplied collection. Used for scoped monitoring.
///
- /// The source registry whose behavior, setups, constructor parameters, scenario state, and wrapped instance are reused.
+ ///
+ /// The source registry whose behavior, setups, constructor parameters, scenario state, and wrapped
+ /// instance are reused.
+ ///
/// The interaction collection that new invocations should be appended to.
public MockRegistry(MockRegistry registry, IMockInteractions interactions)
{
if (registry.Behavior.SkipInteractionRecording != interactions.SkipInteractionRecording)
{
throw new ArgumentException(
- $"{nameof(registry)}.{nameof(Behavior)}.{nameof(MockBehavior.SkipInteractionRecording)} " +
- $"({registry.Behavior.SkipInteractionRecording}) and " +
- $"{nameof(interactions)}.{nameof(IMockInteractions.SkipInteractionRecording)} " +
- $"({interactions.SkipInteractionRecording}) must agree; recording paths gate on the " +
- "behavior flag while verification gates on the interactions flag, so a mismatch leaves " +
- "the registry in an inconsistent state.",
+ $"""{nameof(registry)}.{nameof(Behavior)}.{nameof(MockBehavior.SkipInteractionRecording)} ({registry.Behavior.SkipInteractionRecording}) and {nameof(interactions)}.{nameof(IMockInteractions.SkipInteractionRecording)} ({interactions.SkipInteractionRecording}) must agree; recording paths gate on the behavior flag while verification gates on the interactions flag, so a mismatch leaves the registry in an inconsistent state.""",
nameof(interactions));
}
@@ -187,15 +168,6 @@ public MockRegistry(MockRegistry registry, IMockInteractions interactions)
public void TransitionTo(string scenario)
=> _scenarioState.Current = scenario;
- ///
- /// Implicitly converts a to a with the given behavior and an
- /// empty interaction collection.
- ///
- public static implicit operator MockRegistry(MockBehavior behavior)
- {
- return new MockRegistry(behavior);
- }
-
private sealed class ScenarioState
{
public string Current { get; set; } = "";
diff --git a/Tests/Mockolate.Api.Tests/Expected/Mockolate_net10.0.txt b/Tests/Mockolate.Api.Tests/Expected/Mockolate_net10.0.txt
index 42a16fe6..87ad122e 100644
--- a/Tests/Mockolate.Api.Tests/Expected/Mockolate_net10.0.txt
+++ b/Tests/Mockolate.Api.Tests/Expected/Mockolate_net10.0.txt
@@ -192,7 +192,6 @@ namespace Mockolate
[System.Diagnostics.DebuggerDisplay("{Interactions} | {Setup}")]
public class MockRegistry
{
- public MockRegistry(Mockolate.MockBehavior behavior, object?[]? constructorParameters = null) { }
public MockRegistry(Mockolate.MockRegistry registry, Mockolate.Interactions.IMockInteractions interactions) { }
public MockRegistry(Mockolate.MockRegistry registry, object wraps) { }
public MockRegistry(Mockolate.MockRegistry registry, object?[] constructorParameters) { }
@@ -277,7 +276,6 @@ namespace Mockolate
public Mockolate.Verify.VerificationResult VerifyProperty(TSubject subject, int memberId, string propertyName, Mockolate.Parameters.IParameterMatch value) { }
public Mockolate.Verify.VerificationResult VerifyPropertyTyped(T subject, int memberId, string propertyName) { }
public Mockolate.Verify.VerificationResult VerifyPropertyTyped(TSubject subject, int memberId, string propertyName, Mockolate.Parameters.IParameterMatch value) { }
- public static Mockolate.MockRegistry op_Implicit(Mockolate.MockBehavior behavior) { }
}
public static class ParameterExtensions
{
diff --git a/Tests/Mockolate.Api.Tests/Expected/Mockolate_net8.0.txt b/Tests/Mockolate.Api.Tests/Expected/Mockolate_net8.0.txt
index cff39dc2..6f2f092c 100644
--- a/Tests/Mockolate.Api.Tests/Expected/Mockolate_net8.0.txt
+++ b/Tests/Mockolate.Api.Tests/Expected/Mockolate_net8.0.txt
@@ -185,7 +185,6 @@ namespace Mockolate
[System.Diagnostics.DebuggerDisplay("{Interactions} | {Setup}")]
public class MockRegistry
{
- public MockRegistry(Mockolate.MockBehavior behavior, object?[]? constructorParameters = null) { }
public MockRegistry(Mockolate.MockRegistry registry, Mockolate.Interactions.IMockInteractions interactions) { }
public MockRegistry(Mockolate.MockRegistry registry, object wraps) { }
public MockRegistry(Mockolate.MockRegistry registry, object?[] constructorParameters) { }
@@ -270,7 +269,6 @@ namespace Mockolate
public Mockolate.Verify.VerificationResult VerifyProperty(TSubject subject, int memberId, string propertyName, Mockolate.Parameters.IParameterMatch value) { }
public Mockolate.Verify.VerificationResult VerifyPropertyTyped(T subject, int memberId, string propertyName) { }
public Mockolate.Verify.VerificationResult VerifyPropertyTyped(TSubject subject, int memberId, string propertyName, Mockolate.Parameters.IParameterMatch value) { }
- public static Mockolate.MockRegistry op_Implicit(Mockolate.MockBehavior behavior) { }
}
public static class ParameterExtensions
{
diff --git a/Tests/Mockolate.Api.Tests/Expected/Mockolate_netstandard2.0.txt b/Tests/Mockolate.Api.Tests/Expected/Mockolate_netstandard2.0.txt
index 34efca92..233adbb9 100644
--- a/Tests/Mockolate.Api.Tests/Expected/Mockolate_netstandard2.0.txt
+++ b/Tests/Mockolate.Api.Tests/Expected/Mockolate_netstandard2.0.txt
@@ -172,7 +172,6 @@ namespace Mockolate
[System.Diagnostics.DebuggerDisplay("{Interactions} | {Setup}")]
public class MockRegistry
{
- public MockRegistry(Mockolate.MockBehavior behavior, object?[]? constructorParameters = null) { }
public MockRegistry(Mockolate.MockRegistry registry, Mockolate.Interactions.IMockInteractions interactions) { }
public MockRegistry(Mockolate.MockRegistry registry, object wraps) { }
public MockRegistry(Mockolate.MockRegistry registry, object?[] constructorParameters) { }
@@ -257,7 +256,6 @@ namespace Mockolate
public Mockolate.Verify.VerificationResult VerifyProperty(TSubject subject, int memberId, string propertyName, Mockolate.Parameters.IParameterMatch value) { }
public Mockolate.Verify.VerificationResult VerifyPropertyTyped(T subject, int memberId, string propertyName) { }
public Mockolate.Verify.VerificationResult VerifyPropertyTyped(TSubject subject, int memberId, string propertyName, Mockolate.Parameters.IParameterMatch value) { }
- public static Mockolate.MockRegistry op_Implicit(Mockolate.MockBehavior behavior) { }
}
public static class ParameterExtensions
{
diff --git a/Tests/Mockolate.Internal.Tests/Registry/MockRegistrySetupSnapshotTests.cs b/Tests/Mockolate.Internal.Tests/Registry/MockRegistrySetupSnapshotTests.cs
index d7980fe2..4665a1fc 100644
--- a/Tests/Mockolate.Internal.Tests/Registry/MockRegistrySetupSnapshotTests.cs
+++ b/Tests/Mockolate.Internal.Tests/Registry/MockRegistrySetupSnapshotTests.cs
@@ -1,3 +1,4 @@
+using Mockolate.Interactions;
using Mockolate.Internal.Tests.TestHelpers;
using Mockolate.Setup;
@@ -10,7 +11,7 @@ public sealed class MethodTests
[Fact]
public async Task SetupMethod_WithIncreasingMemberIds_GrowsTableLazily()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeMethodSetup setup0 = new();
FakeMethodSetup setup7 = new();
FakeMethodSetup setup3 = new();
@@ -33,7 +34,7 @@ public async Task SetupMethod_WithIncreasingMemberIds_GrowsTableLazily()
[Fact]
public async Task SetupMethod_WithMemberId_PublishesToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeMethodSetup setup = new();
registry.SetupMethod(5, setup);
@@ -47,7 +48,7 @@ public async Task SetupMethod_WithMemberId_PublishesToSnapshot()
[Fact]
public async Task SetupMethod_WithMemberIdAndDefaultScenario_PublishesToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeMethodSetup setup = new();
registry.SetupMethod(5, "", setup);
@@ -61,7 +62,7 @@ public async Task SetupMethod_WithMemberIdAndDefaultScenario_PublishesToSnapshot
[Fact]
public async Task SetupMethod_WithMemberIdAndNamedScenario_DoesNotPublishToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeMethodSetup setup = new();
registry.SetupMethod(5, "s1", setup);
@@ -72,7 +73,7 @@ public async Task SetupMethod_WithMemberIdAndNamedScenario_DoesNotPublishToSnaps
[Fact]
public async Task SetupMethod_WithMemberIdAndNamedScenario_PreservesScenarioBucket()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeMethodSetup setup = new();
registry.SetupMethod(4, "s1", setup);
@@ -85,7 +86,7 @@ public async Task SetupMethod_WithMemberIdAndNamedScenario_PreservesScenarioBuck
[Fact]
public async Task SetupMethod_WithSameMemberIdTwice_AppendsToBucket()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeMethodSetup setupA = new();
FakeMethodSetup setupB = new();
@@ -105,7 +106,7 @@ public sealed class PropertyTests
[Fact]
public async Task PublishPropertyToMemberIdBucket_WithDefaultThenUserSetup_RetainsUserSetup()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
PropertySetup defaultSetup = new PropertySetup.Default("P1", 0);
FakePropertySetup userSetup = new("P1");
@@ -118,7 +119,7 @@ public async Task PublishPropertyToMemberIdBucket_WithDefaultThenUserSetup_Retai
[Fact]
public async Task PublishPropertyToMemberIdBucket_WithUserThenDefaultSetup_RetainsUserSetup()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakePropertySetup userSetup = new("P1");
PropertySetup defaultSetup = new PropertySetup.Default("P1", 0);
@@ -131,7 +132,7 @@ public async Task PublishPropertyToMemberIdBucket_WithUserThenDefaultSetup_Retai
[Fact]
public async Task SetupProperty_WithIncreasingMemberIds_GrowsTableLazily()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakePropertySetup setup0 = new("P0");
FakePropertySetup setup7 = new("P7");
FakePropertySetup setup3 = new("P3");
@@ -148,7 +149,7 @@ public async Task SetupProperty_WithIncreasingMemberIds_GrowsTableLazily()
[Fact]
public async Task SetupProperty_WithMemberId_PublishesToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakePropertySetup setup = new("P5");
registry.SetupProperty(5, setup);
@@ -159,7 +160,7 @@ public async Task SetupProperty_WithMemberId_PublishesToSnapshot()
[Fact]
public async Task SetupProperty_WithMemberIdAndDefaultScenario_PublishesToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakePropertySetup setup = new("P5");
registry.SetupProperty(5, "", setup);
@@ -170,7 +171,7 @@ public async Task SetupProperty_WithMemberIdAndDefaultScenario_PublishesToSnapsh
[Fact]
public async Task SetupProperty_WithMemberIdAndNamedScenario_DoesNotPublishToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakePropertySetup setup = new("P5");
registry.SetupProperty(5, "s1", setup);
@@ -181,7 +182,7 @@ public async Task SetupProperty_WithMemberIdAndNamedScenario_DoesNotPublishToSna
[Fact]
public async Task SetupProperty_WithMemberIdAndNamedScenario_PreservesScenarioBucket()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakePropertySetup setup = new("P4");
registry.SetupProperty(4, "s1", setup);
@@ -195,7 +196,7 @@ public async Task SetupProperty_WithMemberIdAndNamedScenario_PreservesScenarioBu
[Fact]
public async Task SetupProperty_WithSameMemberIdTwice_RetainsLatestUserSetup()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakePropertySetup setupA = new("P2");
FakePropertySetup setupB = new("P2");
@@ -211,7 +212,7 @@ public sealed class IndexerTests
[Fact]
public async Task SetupIndexer_WithIncreasingMemberIds_GrowsTableLazily()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeIndexerSetup setup0 = new(true);
FakeIndexerSetup setup7 = new(true);
FakeIndexerSetup setup3 = new(true);
@@ -234,7 +235,7 @@ public async Task SetupIndexer_WithIncreasingMemberIds_GrowsTableLazily()
[Fact]
public async Task SetupIndexer_WithMemberId_PublishesToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeIndexerSetup setup = new(true);
registry.SetupIndexer(5, setup);
@@ -248,7 +249,7 @@ public async Task SetupIndexer_WithMemberId_PublishesToSnapshot()
[Fact]
public async Task SetupIndexer_WithMemberIdAndDefaultScenario_PublishesToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeIndexerSetup setup = new(true);
registry.SetupIndexer(5, "", setup);
@@ -262,7 +263,7 @@ public async Task SetupIndexer_WithMemberIdAndDefaultScenario_PublishesToSnapsho
[Fact]
public async Task SetupIndexer_WithMemberIdAndNamedScenario_DoesNotPublishToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeIndexerSetup setup = new(true);
registry.SetupIndexer(5, "s1", setup);
@@ -273,7 +274,7 @@ public async Task SetupIndexer_WithMemberIdAndNamedScenario_DoesNotPublishToSnap
[Fact]
public async Task SetupIndexer_WithMemberIdAndNamedScenario_PreservesScenarioBucket()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeIndexerSetup setup = new(true);
registry.SetupIndexer(4, "s1", setup);
@@ -286,7 +287,7 @@ public async Task SetupIndexer_WithMemberIdAndNamedScenario_PreservesScenarioBuc
[Fact]
public async Task SetupIndexer_WithSameMemberIdTwice_AppendsToBucket()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeIndexerSetup setupA = new(true);
FakeIndexerSetup setupB = new(true);
@@ -306,7 +307,7 @@ public sealed class EventTests
[Fact]
public async Task SetupEvent_WithIncreasingMemberIds_GrowsTableLazily()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
EventSetup setup0 = new(registry, "E0");
EventSetup setup7 = new(registry, "E7");
EventSetup setup3 = new(registry, "E3");
@@ -329,7 +330,7 @@ public async Task SetupEvent_WithIncreasingMemberIds_GrowsTableLazily()
[Fact]
public async Task SetupEvent_WithMemberId_PublishesToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
EventSetup setup = new(registry, "Evt");
registry.SetupEvent(5, setup);
@@ -343,7 +344,7 @@ public async Task SetupEvent_WithMemberId_PublishesToSnapshot()
[Fact]
public async Task SetupEvent_WithMemberIdAndDefaultScenario_PublishesToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
EventSetup setup = new(registry, "Evt");
registry.SetupEvent(5, "", setup);
@@ -357,7 +358,7 @@ public async Task SetupEvent_WithMemberIdAndDefaultScenario_PublishesToSnapshot(
[Fact]
public async Task SetupEvent_WithMemberIdAndNamedScenario_DoesNotPublishToSnapshot()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
EventSetup setup = new(registry, "Evt");
registry.SetupEvent(5, "s1", setup);
@@ -368,7 +369,7 @@ public async Task SetupEvent_WithMemberIdAndNamedScenario_DoesNotPublishToSnapsh
[Fact]
public async Task SetupEvent_WithMemberIdAndNamedScenario_PreservesScenarioBucket()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
EventSetup setup = new(registry, "Evt");
registry.SetupEvent(4, "s1", setup);
@@ -381,7 +382,7 @@ public async Task SetupEvent_WithMemberIdAndNamedScenario_PreservesScenarioBucke
[Fact]
public async Task SetupEvent_WithSameMemberIdTwice_AppendsToBucket()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
EventSetup setupA = new(registry, "Evt");
EventSetup setupB = new(registry, "Evt");
diff --git a/Tests/Mockolate.Internal.Tests/Registry/MockRegistryTests.cs b/Tests/Mockolate.Internal.Tests/Registry/MockRegistryTests.cs
index 11271517..0f38b435 100644
--- a/Tests/Mockolate.Internal.Tests/Registry/MockRegistryTests.cs
+++ b/Tests/Mockolate.Internal.Tests/Registry/MockRegistryTests.cs
@@ -50,7 +50,7 @@ await That(Act).Throws()
[Fact]
public async Task RegistryAndInteractions_WhenSkipFlagsDisagree_Throws()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FastMockInteractions skippingInteractions = new(0, true);
void Act()
@@ -84,7 +84,7 @@ public sealed class GetIndexerSetupScenarioScopingTests
[Fact]
public async Task WithActiveScenario_ShouldReturnScopedSetupOverGlobalSetup()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeIndexerSetup globalSetup = new(true);
FakeIndexerSetup scopedSetup = new(true);
registry.Setup.Indexers.Add(globalSetup);
@@ -99,7 +99,7 @@ public async Task WithActiveScenario_ShouldReturnScopedSetupOverGlobalSetup()
[Fact]
public async Task WithoutActiveScenario_ShouldFallBackToGlobalSetup()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
FakeIndexerSetup globalSetup = new(true);
FakeIndexerSetup scopedSetup = new(true);
registry.Setup.Indexers.Add(globalSetup);
@@ -116,7 +116,7 @@ public sealed class IndexerFallbackStoresValueTests
[Fact]
public async Task ApplyIndexerGetter_WithNullSetup_ShouldStoreBaseValueForLaterLookup()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
IndexerGetterAccess access1 = new(1);
IndexerGetterAccess access2 = new(1);
@@ -132,7 +132,7 @@ public async Task GetIndexerFallback_ShouldStoreDefaultForLaterLookup()
{
int counter = 0;
MockBehavior behavior = MockBehavior.Default.WithDefaultValueFor(() => ++counter);
- MockRegistry registry = new(behavior);
+ MockRegistry registry = new(behavior, new FastMockInteractions(0, behavior.SkipInteractionRecording));
IndexerGetterAccess access1 = new(1);
IndexerGetterAccess access2 = new(1);
@@ -149,7 +149,7 @@ public sealed class InitializeStorageTests
[Fact]
public async Task WithNegative_ShouldThrowWithDescriptiveMessage()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
void Act()
{
@@ -163,7 +163,7 @@ await That(Act).Throws()
[Fact]
public async Task WithZero_ShouldNotThrow()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
void Act()
{
@@ -180,7 +180,7 @@ public sealed class WrapConstructorTests
public async Task WhenBehaviorSkipsInteractionRecording_WrappedRegistryAlsoSkipsRecording()
{
MockBehavior behavior = MockBehavior.Default.SkippingInteractionRecording();
- MockRegistry original = new(behavior);
+ MockRegistry original = new(behavior, new FastMockInteractions(0, behavior.SkipInteractionRecording));
object wrapped = new();
MockRegistry wrappingRegistry = new(original, wrapped);
@@ -197,7 +197,7 @@ public sealed class VerifyPropertyStringKeyedTests
[Fact]
public async Task MockGot_WhenNameDoesNotMatch_ShouldReturnNever()
{
- MockRegistry registry = new(MockBehavior.Default);
+ MockRegistry registry = new(MockBehavior.Default, new FastMockInteractions(0));
registry.GetProperty("foo.bar", () => 0, null);
VerificationResult