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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,517 changes: 1,634 additions & 1,883 deletions Source/Mockolate.SourceGenerators/Sources/Sources.MockClass.cs

Large diffs are not rendered by default.

440 changes: 224 additions & 216 deletions Source/Mockolate.SourceGenerators/Sources/Sources.MockCombination.cs

Large diffs are not rendered by default.

342 changes: 149 additions & 193 deletions Source/Mockolate.SourceGenerators/Sources/Sources.MockDelegate.cs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,108 +10,6 @@
#nullable enable annotations
namespace Mockolate;

/// <summary>
/// Mock extensions for <see cref="global::Mockolate.Tests.GeneratorCoverage.ComprehensiveAbstractClass">ComprehensiveAbstractClass</see> that also implements<br />
/// - <see cref="global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA">ICombinationMockA</see>.
/// </summary>
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static partial class MockExtensionsForComprehensiveAbstractClass__ICombinationMockA
{
/// <summary>
/// Extends this mock so the returned instance also implements <see cref="global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA">ICombinationMockA</see>.
/// </summary>
/// <remarks>
/// The returned instance is a brand-new mock that shares the mock registry (recorded interactions, scenario state, setups) of this one. Cast it to <see cref="global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA">ICombinationMockA</see> to exercise the extra surface or use <c>.Mock.As&lt;ICombinationMockA&gt;()</c> to reach the Setup/Verify surface of the additional interface.
/// </remarks>
/// <param name="sut">The mock instance to extend.</param>
/// <param name="setups">Optional setup callbacks registered on the additional interface before the mock is returned.</param>
/// <returns>A mock of the original type that additionally implements <see cref="global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA">ICombinationMockA</see>.</returns>
public static global::Mockolate.Tests.GeneratorCoverage.ComprehensiveAbstractClass Implementing<TInterface>(this global::Mockolate.Tests.GeneratorCoverage.ComprehensiveAbstractClass sut, params global::System.Action<global::Mockolate.Mock.IMockSetupForICombinationMockA>[] setups)
where TInterface : global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA
{
if (sut is not global::Mockolate.IMock mock)
{
throw new global::Mockolate.Exceptions.MockException("The subject is no mock.");
}
global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA value;
if (mock.MockRegistry.ConstructorParameters is null || mock.MockRegistry.ConstructorParameters.Length == 0)
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry);
}
else if (mock.MockRegistry.ConstructorParameters.Length == 0)
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry);
}
else if (mock.MockRegistry.ConstructorParameters.Length >= 1 && mock.MockRegistry.ConstructorParameters.Length <= 2
&& TryCast(mock.MockRegistry.ConstructorParameters, 0, mock.MockRegistry.Behavior, out int c2p1)
&& TryCastWithDefaultValue(mock.MockRegistry.ConstructorParameters, 1, "x", mock.MockRegistry.Behavior, out string c2p2))
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry, c2p1, c2p2);
}
else if (mock.MockRegistry.ConstructorParameters.Length == 2
&& TryCast(mock.MockRegistry.ConstructorParameters, 0, mock.MockRegistry.Behavior, out int c3p1)
&& TryCast(mock.MockRegistry.ConstructorParameters, 1, mock.MockRegistry.Behavior, out bool c3p2))
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry, c3p1, c3p2);
}
else if (mock.MockRegistry.ConstructorParameters.Length == 1
&& TryCast(mock.MockRegistry.ConstructorParameters, 0, mock.MockRegistry.Behavior, out string c4p1))
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry, c4p1);
}
else
{
throw new global::Mockolate.Exceptions.MockException($"Could not find any constructor for 'Mockolate.Tests.GeneratorCoverage.ComprehensiveAbstractClass' that matches the {mock.MockRegistry.ConstructorParameters.Length} given parameters ({string.Join(", ", mock.MockRegistry.ConstructorParameters)}).");
}
IMockBehaviorAccess mockBehaviorAccess = (global::Mockolate.IMockBehaviorAccess)mock.MockRegistry.Behavior;
if (mockBehaviorAccess.TryGet<global::System.Action<global::Mockolate.Mock.IMockSetupForICombinationMockA>[]?>(out var additionalSetups))
{
if (setups.Length > 0)
{
var concatenatedSetups = new global::System.Action<global::Mockolate.Mock.IMockSetupForICombinationMockA>[additionalSetups.Length + setups.Length];
additionalSetups.CopyTo(concatenatedSetups, 0);
setups.CopyTo(concatenatedSetups, additionalSetups.Length);
setups = concatenatedSetups;
}
else
{
setups = additionalSetups;
}
}
if (setups.Length > 0)
{
foreach (var setup in setups)
{
setup.Invoke(value);
}
}
return value;
static bool TryCast<TValue>(object?[] values, int index, global::Mockolate.MockBehavior behavior, out TValue result)
{
var value = values[index];
if (value is TValue typedValue)
{
result = typedValue;
return true;
}

result = default!;
return value is null;
}
static bool TryCastWithDefaultValue<TValue>(object?[] values, int index, TValue defaultValue, global::Mockolate.MockBehavior behavior, out TValue result)
{
if (values.Length > index && values[index] is TValue typedValue)
{
result = typedValue;
return true;
}

result = defaultValue;
return true;
}
}
}

internal static partial class Mock
{
/// <summary>
Expand Down Expand Up @@ -580,4 +478,106 @@ protected override int P()
}
}

/// <summary>
/// Mock extensions for <see cref="global::Mockolate.Tests.GeneratorCoverage.ComprehensiveAbstractClass">ComprehensiveAbstractClass</see> that also implements<br />
/// - <see cref="global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA">ICombinationMockA</see>.
/// </summary>
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static partial class MockExtensionsForComprehensiveAbstractClass__ICombinationMockA
{
/// <summary>
/// Extends this mock so the returned instance also implements <see cref="global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA">ICombinationMockA</see>.
/// </summary>
/// <remarks>
/// The returned instance is a brand-new mock that shares the mock registry (recorded interactions, scenario state, setups) of this one. Cast it to <see cref="global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA">ICombinationMockA</see> to exercise the extra surface or use <c>.Mock.As&lt;ICombinationMockA&gt;()</c> to reach the Setup/Verify surface of the additional interface.
/// </remarks>
/// <param name="sut">The mock instance to extend.</param>
/// <param name="setups">Optional setup callbacks registered on the additional interface before the mock is returned.</param>
/// <returns>A mock of the original type that additionally implements <see cref="global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA">ICombinationMockA</see>.</returns>
public static global::Mockolate.Tests.GeneratorCoverage.ComprehensiveAbstractClass Implementing<TInterface>(this global::Mockolate.Tests.GeneratorCoverage.ComprehensiveAbstractClass sut, params global::System.Action<global::Mockolate.Mock.IMockSetupForICombinationMockA>[] setups)
where TInterface : global::Mockolate.Tests.GeneratorCoverage.ICombinationMockA
{
if (sut is not global::Mockolate.IMock mock)
{
throw new global::Mockolate.Exceptions.MockException("The subject is no mock.");
}
global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA value;
if (mock.MockRegistry.ConstructorParameters is null || mock.MockRegistry.ConstructorParameters.Length == 0)
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry);
}
else if (mock.MockRegistry.ConstructorParameters.Length == 0)
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry);
}
else if (mock.MockRegistry.ConstructorParameters.Length >= 1 && mock.MockRegistry.ConstructorParameters.Length <= 2
&& TryCast(mock.MockRegistry.ConstructorParameters, 0, mock.MockRegistry.Behavior, out int c2p1)
&& TryCastWithDefaultValue(mock.MockRegistry.ConstructorParameters, 1, "x", mock.MockRegistry.Behavior, out string c2p2))
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry, c2p1, c2p2);
}
else if (mock.MockRegistry.ConstructorParameters.Length == 2
&& TryCast(mock.MockRegistry.ConstructorParameters, 0, mock.MockRegistry.Behavior, out int c3p1)
&& TryCast(mock.MockRegistry.ConstructorParameters, 1, mock.MockRegistry.Behavior, out bool c3p2))
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry, c3p1, c3p2);
}
else if (mock.MockRegistry.ConstructorParameters.Length == 1
&& TryCast(mock.MockRegistry.ConstructorParameters, 0, mock.MockRegistry.Behavior, out string c4p1))
{
value = new global::Mockolate.Mock.ComprehensiveAbstractClass__ICombinationMockA(mock.MockRegistry, c4p1);
}
else
{
throw new global::Mockolate.Exceptions.MockException($"Could not find any constructor for 'Mockolate.Tests.GeneratorCoverage.ComprehensiveAbstractClass' that matches the {mock.MockRegistry.ConstructorParameters.Length} given parameters ({string.Join(", ", mock.MockRegistry.ConstructorParameters)}).");
}
IMockBehaviorAccess mockBehaviorAccess = (global::Mockolate.IMockBehaviorAccess)mock.MockRegistry.Behavior;
if (mockBehaviorAccess.TryGet<global::System.Action<global::Mockolate.Mock.IMockSetupForICombinationMockA>[]?>(out var additionalSetups))
{
if (setups.Length > 0)
{
var concatenatedSetups = new global::System.Action<global::Mockolate.Mock.IMockSetupForICombinationMockA>[additionalSetups.Length + setups.Length];
additionalSetups.CopyTo(concatenatedSetups, 0);
setups.CopyTo(concatenatedSetups, additionalSetups.Length);
setups = concatenatedSetups;
}
else
{
setups = additionalSetups;
}
}
if (setups.Length > 0)
{
foreach (var setup in setups)
{
setup.Invoke(value);
}
}
return value;
static bool TryCast<TValue>(object?[] values, int index, global::Mockolate.MockBehavior behavior, out TValue result)
{
var value = values[index];
if (value is TValue typedValue)
{
result = typedValue;
return true;
}

result = default!;
return value is null;
}
static bool TryCastWithDefaultValue<TValue>(object?[] values, int index, TValue defaultValue, global::Mockolate.MockBehavior behavior, out TValue result)
{
if (values.Length > index && values[index] is TValue typedValue)
{
result = typedValue;
return true;
}

result = defaultValue;
return true;
}
}
}

#nullable disable annotations
Loading
Loading