diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/GenerateMock_Attribute_With_Concrete_Class.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/GenerateMock_Attribute_With_Concrete_Class.verified.txt index 7a2df6ebc9..d28c2aff42 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/GenerateMock_Attribute_With_Concrete_Class.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/GenerateMock_Attribute_With_Concrete_Class.verified.txt @@ -3,34 +3,7 @@ namespace TUnit.Mocks.Generated { - internal static class MyServicePartialMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new MyServiceMockImpl(engine); - engine.Raisable = impl; - var mock = new global::TUnit.Mocks.Mock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class MyServiceMockImpl : global::MyService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class MyServiceMockImpl : global::MyService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -66,6 +39,24 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class MyServicePartialMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new MyServiceMockImpl(engine); + engine.Raisable = impl; + var mock = new global::TUnit.Mocks.Mock(impl, engine); + return mock; + } + } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Generic_Interface_Extension_Discovery.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Generic_Interface_Extension_Discovery.verified.txt index e32e1439a4..1b6eec6cad 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Generic_Interface_Extension_Discovery.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Generic_Interface_Extension_Discovery.verified.txt @@ -26,35 +26,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IRepository_string_MockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory>(Create); - } - - internal static global::TUnit.Mocks.Mock> Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IRepository' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine>(behavior); - var impl = new IRepository_string_MockImpl(engine); - engine.Raisable = impl; - var mock = new IRepository_string_Mock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IRepository_string_MockImpl : global::IRepository, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IRepository_string_MockImpl : global::IRepository, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine> _engine; @@ -82,6 +54,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IRepository_string_MockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory>(Create); + } + + internal static global::TUnit.Mocks.Mock> Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IRepository' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine>(behavior); + var impl = new IRepository_string_MockImpl(engine); + engine.Raisable = impl; + var mock = new IRepository_string_Mock(impl, engine); + return mock; + } + } } @@ -286,7 +277,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IRepository_string_Mock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IRepository_string_Mock)global::TUnit.Mocks.Generated.IRepository_string_MockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IRepository_string_Mock)global::TUnit.Mocks.Mock.Of>(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_Inheriting_Multiple_Interfaces.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_Inheriting_Multiple_Interfaces.verified.txt index d4cfc8013b..9cd676094c 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_Inheriting_Multiple_Interfaces.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_Inheriting_Multiple_Interfaces.verified.txt @@ -31,35 +31,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IReadWriterMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IReadWriter' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IReadWriterMockImpl(engine); - engine.Raisable = impl; - var mock = new IReadWriterMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IReadWriterMockImpl : global::IReadWriter, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IReadWriterMockImpl : global::IReadWriter, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -92,6 +64,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IReadWriterMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IReadWriter' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IReadWriterMockImpl(engine); + engine.Raisable = impl; + var mock = new IReadWriterMock(impl, engine); + return mock; + } + } } @@ -215,7 +206,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IReadWriterMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IReadWriterMock)global::TUnit.Mocks.Generated.IReadWriterMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IReadWriterMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Async_Methods.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Async_Methods.verified.txt index 4df15adb27..1f0dbff165 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Async_Methods.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Async_Methods.verified.txt @@ -1,4 +1,4 @@ -// +// #nullable enable namespace TUnit.Mocks.Generated @@ -27,35 +27,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IAsyncServiceMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IAsyncService' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IAsyncServiceMockImpl(engine); - engine.Raisable = impl; - var mock = new IAsyncServiceMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IAsyncServiceMockImpl : global::IAsyncService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IAsyncServiceMockImpl : global::IAsyncService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -145,6 +117,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IAsyncServiceMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IAsyncService' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IAsyncServiceMockImpl(engine); + engine.Raisable = impl; + var mock = new IAsyncServiceMock(impl, engine); + return mock; + } + } } @@ -542,7 +533,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IAsyncServiceMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IAsyncServiceMock)global::TUnit.Mocks.Generated.IAsyncServiceMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IAsyncServiceMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Events.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Events.verified.txt index 5217f29ae1..71c2792229 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Events.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Events.verified.txt @@ -57,35 +57,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class INotifierMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::INotifier' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new INotifierMockImpl(engine); - engine.Raisable = impl; - var mock = new INotifierMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class INotifierMockImpl : global::INotifier, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class INotifierMockImpl : global::INotifier, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -129,6 +101,25 @@ namespace TUnit.Mocks.Generated } } } + + file static class INotifierMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::INotifier' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new INotifierMockImpl(engine); + engine.Raisable = impl; + var mock = new INotifierMock(impl, engine); + return mock; + } + } } @@ -248,7 +239,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.INotifierMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.INotifierMock)global::TUnit.Mocks.Generated.INotifierMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.INotifierMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Generic_Methods.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Generic_Methods.verified.txt index 8c306bcfa9..06185cf045 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Generic_Methods.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Generic_Methods.verified.txt @@ -28,35 +28,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IRepositoryMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IRepository' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IRepositoryMockImpl(engine); - engine.Raisable = impl; - var mock = new IRepositoryMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IRepositoryMockImpl : global::IRepository, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IRepositoryMockImpl : global::IRepository, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -89,6 +61,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IRepositoryMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IRepository' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IRepositoryMockImpl(engine); + engine.Raisable = impl; + var mock = new IRepositoryMock(impl, engine); + return mock; + } + } } @@ -156,7 +147,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IRepositoryMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IRepositoryMock)global::TUnit.Mocks.Generated.IRepositoryMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IRepositoryMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Inherited_Static_Abstract_Members.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Inherited_Static_Abstract_Members.verified.txt index bc8a8024fe..87a193d525 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Inherited_Static_Abstract_Members.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Inherited_Static_Abstract_Members.verified.txt @@ -36,35 +36,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IMyServiceMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::TUnit.Mocks.Generated.IMyServiceMockable' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IMyServiceMockImpl(engine); - engine.Raisable = impl; - var mock = new global::TUnit.Mocks.Mock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IMyServiceMockImpl : global::TUnit.Mocks.Generated.IMyServiceMockable, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IMyServiceMockImpl : global::TUnit.Mocks.Generated.IMyServiceMockable, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -94,6 +66,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IMyServiceMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::TUnit.Mocks.Generated.IMyServiceMockable' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IMyServiceMockImpl(engine); + engine.Raisable = impl; + var mock = new global::TUnit.Mocks.Mock(impl, engine); + return mock; + } + } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Keyword_Parameter_Names.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Keyword_Parameter_Names.verified.txt index 0943343984..6022556ec1 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Keyword_Parameter_Names.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Keyword_Parameter_Names.verified.txt @@ -26,35 +26,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class ITestMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::ITest' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new ITestMockImpl(engine); - engine.Raisable = impl; - var mock = new ITestMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class ITestMockImpl : global::ITest, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class ITestMockImpl : global::ITest, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -82,6 +54,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class ITestMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::ITest' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new ITestMockImpl(engine); + engine.Raisable = impl; + var mock = new ITestMock(impl, engine); + return mock; + } + } } @@ -301,7 +292,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.ITestMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.ITestMock)global::TUnit.Mocks.Generated.ITestMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.ITestMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Mixed_Members.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Mixed_Members.verified.txt index 8702830a1b..fe3891fd6b 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Mixed_Members.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Mixed_Members.verified.txt @@ -1,4 +1,4 @@ -// +// #nullable enable namespace TUnit.Mocks.Generated @@ -63,35 +63,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IServiceMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IService' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IServiceMockImpl(engine); - engine.Raisable = impl; - var mock = new IServiceMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IServiceMockImpl : global::IService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IServiceMockImpl : global::IService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -164,6 +136,25 @@ namespace TUnit.Mocks.Generated } } } + + file static class IServiceMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IService' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IServiceMockImpl(engine); + engine.Raisable = impl; + var mock = new IServiceMock(impl, engine); + return mock; + } + } } @@ -400,7 +391,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IServiceMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IServiceMock)global::TUnit.Mocks.Generated.IServiceMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IServiceMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Nullable_Reference_Type_Parameters.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Nullable_Reference_Type_Parameters.verified.txt index 4cfc27fa1a..c0b3c48dd3 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Nullable_Reference_Type_Parameters.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Nullable_Reference_Type_Parameters.verified.txt @@ -35,35 +35,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IFooMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IFoo' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IFooMockImpl(engine); - engine.Raisable = impl; - var mock = new IFooMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IFooMockImpl : global::IFoo, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IFooMockImpl : global::IFoo, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -120,6 +92,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IFooMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IFoo' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IFooMockImpl(engine); + engine.Raisable = impl; + var mock = new IFooMock(impl, engine); + return mock; + } + } } @@ -580,7 +571,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IFooMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IFooMock)global::TUnit.Mocks.Generated.IFooMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IFooMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Out_Ref_Parameters.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Out_Ref_Parameters.verified.txt index f4d291c793..afcc3331a7 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Out_Ref_Parameters.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Out_Ref_Parameters.verified.txt @@ -26,35 +26,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IDictionaryMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IDictionary' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IDictionaryMockImpl(engine); - engine.Raisable = impl; - var mock = new IDictionaryMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IDictionaryMockImpl : global::IDictionary, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IDictionaryMockImpl : global::IDictionary, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -95,6 +67,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IDictionaryMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IDictionary' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IDictionaryMockImpl(engine); + engine.Raisable = impl; + var mock = new IDictionaryMock(impl, engine); + return mock; + } + } } @@ -300,7 +291,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IDictionaryMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IDictionaryMock)global::TUnit.Mocks.Generated.IDictionaryMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IDictionaryMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Overloaded_Methods.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Overloaded_Methods.verified.txt index 936a7b3246..590c864d0a 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Overloaded_Methods.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Overloaded_Methods.verified.txt @@ -27,35 +27,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IFormatterMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IFormatter' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IFormatterMockImpl(engine); - engine.Raisable = impl; - var mock = new IFormatterMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IFormatterMockImpl : global::IFormatter, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IFormatterMockImpl : global::IFormatter, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -93,6 +65,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IFormatterMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IFormatter' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IFormatterMockImpl(engine); + engine.Raisable = impl; + var mock = new IFormatterMock(impl, engine); + return mock; + } + } } @@ -555,7 +546,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IFormatterMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IFormatterMock)global::TUnit.Mocks.Generated.IFormatterMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IFormatterMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Properties.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Properties.verified.txt index 2bc986ff3b..2e46369e93 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Properties.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Properties.verified.txt @@ -25,35 +25,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IRepositoryMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IRepository' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IRepositoryMockImpl(engine); - engine.Raisable = impl; - var mock = new IRepositoryMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IRepositoryMockImpl : global::IRepository, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IRepositoryMockImpl : global::IRepository, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -87,6 +59,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IRepositoryMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IRepository' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IRepositoryMockImpl(engine); + engine.Raisable = impl; + var mock = new IRepositoryMock(impl, engine); + return mock; + } + } } @@ -127,7 +118,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IRepositoryMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IRepositoryMock)global::TUnit.Mocks.Generated.IRepositoryMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IRepositoryMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_RefStruct_Parameters.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_RefStruct_Parameters.verified.txt index fd6af71d4a..8544081ae7 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_RefStruct_Parameters.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_RefStruct_Parameters.verified.txt @@ -28,35 +28,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IBufferProcessorMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IBufferProcessor' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IBufferProcessorMockImpl(engine); - engine.Raisable = impl; - var mock = new IBufferProcessorMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IBufferProcessorMockImpl : global::IBufferProcessor, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IBufferProcessorMockImpl : global::IBufferProcessor, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -99,6 +71,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IBufferProcessorMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IBufferProcessor' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IBufferProcessorMockImpl(engine); + engine.Raisable = impl; + var mock = new IBufferProcessorMock(impl, engine); + return mock; + } + } } @@ -161,7 +152,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IBufferProcessorMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IBufferProcessorMock)global::TUnit.Mocks.Generated.IBufferProcessorMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IBufferProcessorMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Members.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Members.verified.txt index 7b6c815fb9..83a61c9cb5 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Members.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Members.verified.txt @@ -52,35 +52,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IServiceFactoryMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::TUnit.Mocks.Generated.IServiceFactoryMockable' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IServiceFactoryMockImpl(engine); - engine.Raisable = impl; - var mock = new global::TUnit.Mocks.Mock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IServiceFactoryMockImpl : global::TUnit.Mocks.Generated.IServiceFactoryMockable, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IServiceFactoryMockImpl : global::TUnit.Mocks.Generated.IServiceFactoryMockable, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -110,6 +82,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IServiceFactoryMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::TUnit.Mocks.Generated.IServiceFactoryMockable' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IServiceFactoryMockImpl(engine); + engine.Raisable = impl; + var mock = new global::TUnit.Mocks.Mock(impl, engine); + return mock; + } + } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Transitive_Return_Type.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Transitive_Return_Type.verified.txt index fc66f06353..df4a7ab7f7 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Transitive_Return_Type.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Transitive_Return_Type.verified.txt @@ -23,35 +23,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IMyServiceMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IMyService' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IMyServiceMockImpl(engine); - engine.Raisable = impl; - var mock = new IMyServiceMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IMyServiceMockImpl : global::IMyService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IMyServiceMockImpl : global::IMyService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -79,6 +51,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IMyServiceMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IMyService' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IMyServiceMockImpl(engine); + engine.Raisable = impl; + var mock = new IMyServiceMock(impl, engine); + return mock; + } + } } @@ -212,7 +203,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IMyServiceMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IMyServiceMock)global::TUnit.Mocks.Generated.IMyServiceMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IMyServiceMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Unconstrained_Nullable_Generic.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Unconstrained_Nullable_Generic.verified.txt index f555f82417..2b53f3db10 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Unconstrained_Nullable_Generic.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Unconstrained_Nullable_Generic.verified.txt @@ -25,35 +25,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IFooMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IFoo' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IFooMockImpl(engine); - engine.Raisable = impl; - var mock = new IFooMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IFooMockImpl : global::IFoo, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IFooMockImpl : global::IFoo, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -99,6 +71,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IFooMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IFoo' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IFooMockImpl(engine); + engine.Raisable = impl; + var mock = new IFooMock(impl, engine); + return mock; + } + } } @@ -145,7 +136,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IFooMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IFooMock)global::TUnit.Mocks.Generated.IFooMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IFooMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Multi_Method_Interface.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Multi_Method_Interface.verified.txt index 0b8f728f36..de3108a4d6 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Multi_Method_Interface.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Multi_Method_Interface.verified.txt @@ -28,35 +28,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class ICalculatorMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::ICalculator' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new ICalculatorMockImpl(engine); - engine.Raisable = impl; - var mock = new ICalculatorMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class ICalculatorMockImpl : global::ICalculator, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class ICalculatorMockImpl : global::ICalculator, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -89,6 +61,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class ICalculatorMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::ICalculator' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new ICalculatorMockImpl(engine); + engine.Raisable = impl; + var mock = new ICalculatorMock(impl, engine); + return mock; + } + } } @@ -339,7 +330,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.ICalculatorMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.ICalculatorMock)global::TUnit.Mocks.Generated.ICalculatorMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.ICalculatorMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt index 51ebef6461..627bce21df 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt @@ -3,34 +3,7 @@ namespace TUnit.Mocks.Generated.ExternalLib { - internal static class ExternalClientPartialMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new ExternalClientMockImpl(engine); - engine.Raisable = impl; - var mock = new global::TUnit.Mocks.Mock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated.ExternalLib -{ - internal sealed class ExternalClientMockImpl : global::ExternalLib.ExternalClient, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class ExternalClientMockImpl : global::ExternalLib.ExternalClient, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -85,6 +58,24 @@ namespace TUnit.Mocks.Generated.ExternalLib throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class ExternalClientPartialMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new ExternalClientMockImpl(engine); + engine.Raisable = impl; + var mock = new global::TUnit.Mocks.Mock(impl, engine); + return mock; + } + } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Members_With_Internal_Signature_Types.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Members_With_Internal_Signature_Types.verified.txt index a4dea2f03c..60890a5cae 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Members_With_Internal_Signature_Types.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Members_With_Internal_Signature_Types.verified.txt @@ -3,34 +3,7 @@ namespace TUnit.Mocks.Generated.ExternalLib { - internal static class ServiceClientPartialMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new ServiceClientMockImpl(engine); - engine.Raisable = impl; - var mock = new global::TUnit.Mocks.Mock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated.ExternalLib -{ - internal sealed class ServiceClientMockImpl : global::ExternalLib.ServiceClient, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class ServiceClientMockImpl : global::ExternalLib.ServiceClient, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -57,6 +30,24 @@ namespace TUnit.Mocks.Generated.ExternalLib throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class ServiceClientPartialMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new ServiceClientMockImpl(engine); + engine.Raisable = impl; + var mock = new global::TUnit.Mocks.Mock(impl, engine); + return mock; + } + } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_With_Generic_Constrained_Virtual_Methods.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_With_Generic_Constrained_Virtual_Methods.verified.txt index 04f0df874b..52519c6564 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_With_Generic_Constrained_Virtual_Methods.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_With_Generic_Constrained_Virtual_Methods.verified.txt @@ -3,34 +3,7 @@ namespace TUnit.Mocks.Generated { - internal static class BaseServicePartialMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new BaseServiceMockImpl(engine); - engine.Raisable = impl; - var mock = new global::TUnit.Mocks.Mock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class BaseServiceMockImpl : global::BaseService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class BaseServiceMockImpl : global::BaseService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -80,6 +53,24 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class BaseServicePartialMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new BaseServiceMockImpl(engine); + engine.Raisable = impl; + var mock = new global::TUnit.Mocks.Mock(impl, engine); + return mock; + } + } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Simple_Interface_With_One_Method.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Simple_Interface_With_One_Method.verified.txt index 2e4d7d1f58..94a8cfbaba 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Simple_Interface_With_One_Method.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Simple_Interface_With_One_Method.verified.txt @@ -21,35 +21,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class IGreeterMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IGreeter' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new IGreeterMockImpl(engine); - engine.Raisable = impl; - var mock = new IGreeterMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class IGreeterMockImpl : global::IGreeter, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class IGreeterMockImpl : global::IGreeter, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -72,6 +44,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class IGreeterMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::IGreeter' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new IGreeterMockImpl(engine); + engine.Raisable = impl; + var mock = new IGreeterMock(impl, engine); + return mock; + } + } } @@ -193,7 +184,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.IGreeterMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.IGreeterMock)global::TUnit.Mocks.Generated.IGreeterMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.IGreeterMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Static_Extension_Discovery_Without_Mock_Of.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Static_Extension_Discovery_Without_Mock_Of.verified.txt index 1d16875c4a..a2f4245afe 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Static_Extension_Discovery_Without_Mock_Of.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Static_Extension_Discovery_Without_Mock_Of.verified.txt @@ -26,35 +26,7 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal static class INotifierMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); - } - - internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) - { - if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::INotifier' does not support constructor arguments, but {constructorArgs.Length} were provided."); - var engine = new global::TUnit.Mocks.MockEngine(behavior); - var impl = new INotifierMockImpl(engine); - engine.Raisable = impl; - var mock = new INotifierMock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal sealed class INotifierMockImpl : global::INotifier, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class INotifierMockImpl : global::INotifier, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; @@ -82,6 +54,25 @@ namespace TUnit.Mocks.Generated throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class INotifierMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterFactory(Create); + } + + internal static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, object[] constructorArgs) + { + if (constructorArgs.Length > 0) throw new global::System.ArgumentException($"Interface mock 'global::INotifier' does not support constructor arguments, but {constructorArgs.Length} were provided."); + var engine = new global::TUnit.Mocks.MockEngine(behavior); + var impl = new INotifierMockImpl(engine); + engine.Raisable = impl; + var mock = new INotifierMock(impl, engine); + return mock; + } + } } @@ -199,7 +190,7 @@ namespace TUnit.Mocks { public static global::TUnit.Mocks.Generated.INotifierMock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose) { - return (global::TUnit.Mocks.Generated.INotifierMock)global::TUnit.Mocks.Generated.INotifierMockFactory.Create(behavior, []); + return (global::TUnit.Mocks.Generated.INotifierMock)global::TUnit.Mocks.Mock.Of(behavior); } } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Wrap_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Wrap_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt index 3ad6412a78..b8485e4f70 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Wrap_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Wrap_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt @@ -1,61 +1,9 @@ // #nullable enable -namespace TUnit.Mocks.Generated -{ - public static class ExternalLib_ExternalService_MockMemberExtensions - { - public static global::TUnit.Mocks.MockMethodCall PublicMethod(this global::TUnit.Mocks.Mock mock) - { - var matchers = global::System.Array.Empty(); - return new global::TUnit.Mocks.MockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 0, "PublicMethod", matchers); - } - - extension(global::TUnit.Mocks.Mock mock) - { - public global::TUnit.Mocks.PropertyMockCall PublicProperty - => new(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 1, 2, "PublicProperty", true, true); - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - namespace TUnit.Mocks.Generated.ExternalLib { - internal static class ExternalServiceWrapMockFactory - { - [global::System.Runtime.CompilerServices.ModuleInitializer] - internal static void Register() - { - global::TUnit.Mocks.MockRegistry.RegisterWrapFactory(Create); - } - - private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, global::ExternalLib.ExternalService instance) - { - var engine = new global::TUnit.Mocks.MockEngine(behavior); - engine.IsWrapMock = true; - var impl = new ExternalServiceWrapMockImpl(engine, instance); - engine.Raisable = impl; - var mock = new global::TUnit.Mocks.Mock(impl, engine); - return mock; - } - } -} - - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated.ExternalLib -{ - internal sealed class ExternalServiceWrapMockImpl : global::ExternalLib.ExternalService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + file sealed class ExternalServiceWrapMockImpl : global::ExternalLib.ExternalService, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { private readonly global::TUnit.Mocks.MockEngine _engine; private readonly global::ExternalLib.ExternalService _wrappedInstance; @@ -103,6 +51,49 @@ namespace TUnit.Mocks.Generated.ExternalLib throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } + + file static class ExternalServiceWrapMockFactory + { + [global::System.Runtime.CompilerServices.ModuleInitializer] + internal static void Register() + { + global::TUnit.Mocks.MockRegistry.RegisterWrapFactory(Create); + } + + private static global::TUnit.Mocks.Mock Create(global::TUnit.Mocks.MockBehavior behavior, global::ExternalLib.ExternalService instance) + { + var engine = new global::TUnit.Mocks.MockEngine(behavior); + engine.IsWrapMock = true; + var impl = new ExternalServiceWrapMockImpl(engine, instance); + engine.Raisable = impl; + var mock = new global::TUnit.Mocks.Mock(impl, engine); + return mock; + } + } +} + + +// ===== FILE SEPARATOR ===== + +// +#nullable enable + +namespace TUnit.Mocks.Generated +{ + public static class ExternalLib_ExternalService_MockMemberExtensions + { + public static global::TUnit.Mocks.MockMethodCall PublicMethod(this global::TUnit.Mocks.Mock mock) + { + var matchers = global::System.Array.Empty(); + return new global::TUnit.Mocks.MockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 0, "PublicMethod", matchers); + } + + extension(global::TUnit.Mocks.Mock mock) + { + public global::TUnit.Mocks.PropertyMockCall PublicProperty + => new(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 1, 2, "PublicProperty", true, true); + } + } } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Wrap_Mock_With_Generic_Constrained_Virtual_Methods.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Wrap_Mock_With_Generic_Constrained_Virtual_Methods.verified.txt index 917447e26c..dcf36e227d 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Wrap_Mock_With_Generic_Constrained_Virtual_Methods.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Wrap_Mock_With_Generic_Constrained_Virtual_Methods.verified.txt @@ -3,45 +3,46 @@ namespace TUnit.Mocks.Generated { - public static class Repository_MockMemberExtensions + file sealed class RepositoryWrapMockImpl : global::Repository, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject { - public static global::TUnit.Mocks.MockMethodCall Get(this global::TUnit.Mocks.Mock mock, global::TUnit.Mocks.Arguments.Arg id) where T : class + private readonly global::TUnit.Mocks.MockEngine _engine; + private readonly global::Repository _wrappedInstance; + + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + global::TUnit.Mocks.IMock? global::TUnit.Mocks.IMockObject.MockWrapper { get; set; } + + internal RepositoryWrapMockImpl(global::TUnit.Mocks.MockEngine engine, global::Repository wrappedInstance) : base() { - var matchers = new global::TUnit.Mocks.Arguments.IArgumentMatcher[] { id.Matcher }; - return new global::TUnit.Mocks.MockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 0, "Get", matchers); + _engine = engine; + _wrappedInstance = wrappedInstance; } - public static global::TUnit.Mocks.MockMethodCall Get(this global::TUnit.Mocks.Mock mock, global::System.Func id) where T : class + public override T Get(int id) { - global::TUnit.Mocks.Arguments.Arg __fa_id = id; - var matchers = new global::TUnit.Mocks.Arguments.IArgumentMatcher[] { __fa_id.Matcher }; - return new global::TUnit.Mocks.MockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 0, "Get", matchers); + if (_engine.TryHandleCallWithReturn(0, "Get", new object?[] { id }, default!, out var __result)) + { + return __result; + } + return _wrappedInstance.Get(id); } - public static global::TUnit.Mocks.VoidMockMethodCall Store(this global::TUnit.Mocks.Mock mock, global::TUnit.Mocks.Arguments.Arg item) where T : class, new() + public override void Store(T item) { - var matchers = new global::TUnit.Mocks.Arguments.IArgumentMatcher[] { item.Matcher }; - return new global::TUnit.Mocks.VoidMockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 1, "Store", matchers); + if (_engine.TryHandleCall(1, "Store", new object?[] { item })) + { + return; + } + _wrappedInstance.Store(item); } - public static global::TUnit.Mocks.VoidMockMethodCall Store(this global::TUnit.Mocks.Mock mock, global::System.Func item) where T : class, new() + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public void RaiseEvent(string eventName, object? args) { - global::TUnit.Mocks.Arguments.Arg __fa_item = item; - var matchers = new global::TUnit.Mocks.Arguments.IArgumentMatcher[] { __fa_item.Matcher }; - return new global::TUnit.Mocks.VoidMockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 1, "Store", matchers); + throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); } } -} - -// ===== FILE SEPARATOR ===== - -// -#nullable enable - -namespace TUnit.Mocks.Generated -{ - internal static class RepositoryWrapMockFactory + file static class RepositoryWrapMockFactory { [global::System.Runtime.CompilerServices.ModuleInitializer] internal static void Register() @@ -69,42 +70,32 @@ namespace TUnit.Mocks.Generated namespace TUnit.Mocks.Generated { - internal sealed class RepositoryWrapMockImpl : global::Repository, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject + public static class Repository_MockMemberExtensions { - private readonly global::TUnit.Mocks.MockEngine _engine; - private readonly global::Repository _wrappedInstance; - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - global::TUnit.Mocks.IMock? global::TUnit.Mocks.IMockObject.MockWrapper { get; set; } - - internal RepositoryWrapMockImpl(global::TUnit.Mocks.MockEngine engine, global::Repository wrappedInstance) : base() + public static global::TUnit.Mocks.MockMethodCall Get(this global::TUnit.Mocks.Mock mock, global::TUnit.Mocks.Arguments.Arg id) where T : class { - _engine = engine; - _wrappedInstance = wrappedInstance; + var matchers = new global::TUnit.Mocks.Arguments.IArgumentMatcher[] { id.Matcher }; + return new global::TUnit.Mocks.MockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 0, "Get", matchers); } - public override T Get(int id) + public static global::TUnit.Mocks.MockMethodCall Get(this global::TUnit.Mocks.Mock mock, global::System.Func id) where T : class { - if (_engine.TryHandleCallWithReturn(0, "Get", new object?[] { id }, default!, out var __result)) - { - return __result; - } - return _wrappedInstance.Get(id); + global::TUnit.Mocks.Arguments.Arg __fa_id = id; + var matchers = new global::TUnit.Mocks.Arguments.IArgumentMatcher[] { __fa_id.Matcher }; + return new global::TUnit.Mocks.MockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 0, "Get", matchers); } - public override void Store(T item) + public static global::TUnit.Mocks.VoidMockMethodCall Store(this global::TUnit.Mocks.Mock mock, global::TUnit.Mocks.Arguments.Arg item) where T : class, new() { - if (_engine.TryHandleCall(1, "Store", new object?[] { item })) - { - return; - } - _wrappedInstance.Store(item); + var matchers = new global::TUnit.Mocks.Arguments.IArgumentMatcher[] { item.Matcher }; + return new global::TUnit.Mocks.VoidMockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 1, "Store", matchers); } - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public void RaiseEvent(string eventName, object? args) + public static global::TUnit.Mocks.VoidMockMethodCall Store(this global::TUnit.Mocks.Mock mock, global::System.Func item) where T : class, new() { - throw new global::System.InvalidOperationException($"No event named '{eventName}' exists on this mock."); + global::TUnit.Mocks.Arguments.Arg __fa_item = item; + var matchers = new global::TUnit.Mocks.Arguments.IArgumentMatcher[] { __fa_item.Matcher }; + return new global::TUnit.Mocks.VoidMockMethodCall(global::TUnit.Mocks.MockRegistry.GetEngine(mock), 1, "Store", matchers); } } } diff --git a/TUnit.Mocks.SourceGenerator/Builders/MockDelegateFactoryBuilder.cs b/TUnit.Mocks.SourceGenerator/Builders/MockDelegateFactoryBuilder.cs index 19b8052dc7..666fde8e40 100644 --- a/TUnit.Mocks.SourceGenerator/Builders/MockDelegateFactoryBuilder.cs +++ b/TUnit.Mocks.SourceGenerator/Builders/MockDelegateFactoryBuilder.cs @@ -19,7 +19,7 @@ public static string Build(MockTypeModel model) using (writer.Block($"namespace {mockNamespace}")) { - using (writer.Block($"internal static class {safeName}MockDelegateFactory")) + using (writer.Block($"file static class {safeName}MockDelegateFactory")) { writer.AppendLine("[global::System.Runtime.CompilerServices.ModuleInitializer]"); using (writer.Block("internal static void Register()")) diff --git a/TUnit.Mocks.SourceGenerator/Builders/MockFactoryBuilder.cs b/TUnit.Mocks.SourceGenerator/Builders/MockFactoryBuilder.cs index 453937127e..80f050135b 100644 --- a/TUnit.Mocks.SourceGenerator/Builders/MockFactoryBuilder.cs +++ b/TUnit.Mocks.SourceGenerator/Builders/MockFactoryBuilder.cs @@ -4,33 +4,22 @@ namespace TUnit.Mocks.SourceGenerator.Builders; internal static class MockFactoryBuilder { - public static string Build(MockTypeModel model) + public static void BuildInto(CodeWriter writer, MockTypeModel model) { - var writer = new CodeWriter(); var safeName = MockImplBuilder.GetCompositeShortSafeName(model); - var mockNamespace = MockImplBuilder.GetMockNamespace(model); - writer.AppendLine("// "); - writer.AppendLine("#nullable enable"); - writer.AppendLine(); - - using (writer.Block($"namespace {mockNamespace}")) + if (model.IsWrapMock) { - if (model.IsWrapMock) - { - BuildWrapFactory(writer, model, safeName); - } - else if (model.IsPartialMock) - { - BuildPartialFactory(writer, model, safeName); - } - else - { - BuildInterfaceFactory(writer, model, safeName); - } + BuildWrapFactory(writer, model, safeName); + } + else if (model.IsPartialMock) + { + BuildPartialFactory(writer, model, safeName); + } + else + { + BuildInterfaceFactory(writer, model, safeName); } - - return writer.ToString(); } private static void BuildInterfaceFactory(CodeWriter writer, MockTypeModel model, string safeName) @@ -40,7 +29,7 @@ private static void BuildInterfaceFactory(CodeWriter writer, MockTypeModel model ? $"{safeName}MultiMockFactory" : $"{safeName}MockFactory"; - using (writer.Block($"internal static class {factoryClassName}")) + using (writer.Block($"file static class {factoryClassName}")) { writer.AppendLine("[global::System.Runtime.CompilerServices.ModuleInitializer]"); using (writer.Block("internal static void Register()")) @@ -82,7 +71,7 @@ private static void BuildInterfaceFactory(CodeWriter writer, MockTypeModel model private static void BuildWrapFactory(CodeWriter writer, MockTypeModel model, string safeName) { - using (writer.Block($"internal static class {safeName}WrapMockFactory")) + using (writer.Block($"file static class {safeName}WrapMockFactory")) { writer.AppendLine("[global::System.Runtime.CompilerServices.ModuleInitializer]"); using (writer.Block("internal static void Register()")) @@ -105,7 +94,7 @@ private static void BuildWrapFactory(CodeWriter writer, MockTypeModel model, str private static void BuildPartialFactory(CodeWriter writer, MockTypeModel model, string safeName) { - using (writer.Block($"internal static class {safeName}PartialMockFactory")) + using (writer.Block($"file static class {safeName}PartialMockFactory")) { writer.AppendLine("[global::System.Runtime.CompilerServices.ModuleInitializer]"); using (writer.Block("internal static void Register()")) @@ -118,7 +107,6 @@ private static void BuildPartialFactory(CodeWriter writer, MockTypeModel model, { writer.AppendLine($"var engine = new global::TUnit.Mocks.MockEngine<{model.FullyQualifiedName}>(behavior);"); - // Generate constructor dispatch based on available constructors GenerateConstructorDispatch(writer, model, safeName); writer.AppendLine("engine.Raisable = impl;"); diff --git a/TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs b/TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs index ca2fef5dab..158bec78f6 100644 --- a/TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs +++ b/TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs @@ -5,33 +5,22 @@ namespace TUnit.Mocks.SourceGenerator.Builders; internal static class MockImplBuilder { - public static string Build(MockTypeModel model) + public static void BuildInto(CodeWriter writer, MockTypeModel model) { - var writer = new CodeWriter(); var safeName = GetCompositeShortSafeName(model); - var mockNamespace = GetMockNamespace(model); - writer.AppendLine("// "); - writer.AppendLine("#nullable enable"); - writer.AppendLine(); - - using (writer.Block($"namespace {mockNamespace}")) + if (model.IsWrapMock) { - if (model.IsWrapMock) - { - BuildWrapMockImpl(writer, model, safeName); - } - else if (model.IsPartialMock) - { - BuildPartialMockImpl(writer, model, safeName); - } - else - { - BuildInterfaceMockImpl(writer, model, safeName); - } + BuildWrapMockImpl(writer, model, safeName); + } + else if (model.IsPartialMock) + { + BuildPartialMockImpl(writer, model, safeName); + } + else + { + BuildInterfaceMockImpl(writer, model, safeName); } - - return writer.ToString(); } private static void BuildInterfaceMockImpl(CodeWriter writer, MockTypeModel model, string safeName) @@ -46,7 +35,7 @@ private static void BuildInterfaceMockImpl(CodeWriter writer, MockTypeModel mode baseTypes += ", " + string.Join(", ", model.AdditionalInterfaceNames); } - using (writer.Block($"internal sealed class {safeName}MockImpl : {baseTypes}, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject")) + using (writer.Block($"file sealed class {safeName}MockImpl : {baseTypes}, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject")) { writer.AppendLine($"private readonly global::TUnit.Mocks.MockEngine<{mockableType}> _engine;"); writer.AppendLine(); @@ -98,7 +87,7 @@ private static void BuildWrapMockImpl(CodeWriter writer, MockTypeModel model, st { var mockableType = GetMockableTypeName(model); - using (writer.Block($"internal sealed class {safeName}WrapMockImpl : {model.FullyQualifiedName}, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject")) + using (writer.Block($"file sealed class {safeName}WrapMockImpl : {model.FullyQualifiedName}, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject")) { writer.AppendLine($"private readonly global::TUnit.Mocks.MockEngine<{mockableType}> _engine;"); writer.AppendLine($"private readonly {model.FullyQualifiedName} _wrappedInstance;"); @@ -426,7 +415,7 @@ private static void BuildPartialMockImpl(CodeWriter writer, MockTypeModel model, { var mockableType = GetMockableTypeName(model); - using (writer.Block($"internal sealed class {safeName}MockImpl : {model.FullyQualifiedName}, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject")) + using (writer.Block($"file sealed class {safeName}MockImpl : {model.FullyQualifiedName}, global::TUnit.Mocks.IRaisable, global::TUnit.Mocks.IMockObject")) { writer.AppendLine($"private readonly global::TUnit.Mocks.MockEngine<{mockableType}> _engine;"); writer.AppendLine(); diff --git a/TUnit.Mocks.SourceGenerator/Builders/MockStaticExtensionBuilder.cs b/TUnit.Mocks.SourceGenerator/Builders/MockStaticExtensionBuilder.cs index 073fb51a1c..1f829d4c0f 100644 --- a/TUnit.Mocks.SourceGenerator/Builders/MockStaticExtensionBuilder.cs +++ b/TUnit.Mocks.SourceGenerator/Builders/MockStaticExtensionBuilder.cs @@ -12,9 +12,10 @@ public static string Build(MockTypeModel model) var writer = new CodeWriter(); // Use full FQN-based safe name for the extension class (in shared TUnit.Mocks namespace, must be globally unique) var extensionClassName = MockImplBuilder.GetCompositeSafeName(model); - // Use short names for the wrapper and factory types (in namespace-specific namespace) + // Use short names for the wrapper type (in namespace-specific namespace) var shortName = MockImplBuilder.GetCompositeShortSafeName(model); var mockNamespace = MockImplBuilder.GetMockNamespace(model); + var mockableType = MockImplBuilder.GetMockableTypeName(model); writer.AppendLine("// "); writer.AppendLine("#nullable enable"); @@ -28,7 +29,7 @@ public static string Build(MockTypeModel model) { using (writer.Block($"public static global::{mockNamespace}.{shortName}Mock Mock(global::TUnit.Mocks.MockBehavior behavior = global::TUnit.Mocks.MockBehavior.Loose)")) { - writer.AppendLine($"return (global::{mockNamespace}.{shortName}Mock)global::{mockNamespace}.{shortName}MockFactory.Create(behavior, []);"); + writer.AppendLine($"return (global::{mockNamespace}.{shortName}Mock)global::TUnit.Mocks.Mock.Of<{mockableType}>(behavior);"); } } } diff --git a/TUnit.Mocks.SourceGenerator/MockGenerator.cs b/TUnit.Mocks.SourceGenerator/MockGenerator.cs index 372e4fc77b..d0d86d8c68 100644 --- a/TUnit.Mocks.SourceGenerator/MockGenerator.cs +++ b/TUnit.Mocks.SourceGenerator/MockGenerator.cs @@ -90,34 +90,14 @@ private static void GenerateSingleTypeMock(SourceProductionContext spc, MockType { var fileName = GetSafeFileName(model); - // Generate bridge interface for types with static abstract members (resolves CS8920) if (model.HasStaticAbstractMembers) { var bridgeSource = MockBridgeBuilder.Build(model); spc.AddSource($"{fileName}_MockBridge.g.cs", bridgeSource); } - // Generate mock implementation - var implSource = MockImplBuilder.Build(model); - spc.AddSource($"{fileName}_MockImpl.g.cs", implSource); + GenerateImplFactoryMembersAndEvents(spc, model, fileName); - // Generate unified members surface (setup + verify) - var membersSource = MockMembersBuilder.Build(model); - spc.AddSource($"{fileName}_MockMembers.g.cs", membersSource); - - // Generate events surface (if type has events) - if (model.Events.Length > 0) - { - var eventsSource = MockEventsBuilder.Build(model); - spc.AddSource($"{fileName}_MockEvents.g.cs", eventsSource); - } - - // Generate factory - var factorySource = MockFactoryBuilder.Build(model); - spc.AddSource($"{fileName}_MockFactory.g.cs", factorySource); - - // Generate wrapper type and static extension for interface mocks. - // The static extension references the wrapper type, so both are emitted together. if (model.IsInterface) { var wrapperSource = MockWrapperTypeBuilder.Build(model); @@ -138,11 +118,9 @@ private static void GenerateDelegateMock(SourceProductionContext spc, MockTypeMo { var fileName = GetSafeFileName(model); - // Generate unified members surface (setup + verify) var membersSource = MockMembersBuilder.Build(model); spc.AddSource($"{fileName}_MockMembers.g.cs", membersSource); - // Generate delegate factory (creates the delegate lambda + wraps in Mock) var factorySource = MockDelegateFactoryBuilder.Build(model); spc.AddSource($"{fileName}_MockDelegateFactory.g.cs", factorySource); } @@ -150,38 +128,48 @@ private static void GenerateDelegateMock(SourceProductionContext spc, MockTypeMo private static void GenerateWrapMock(SourceProductionContext spc, MockTypeModel model) { var fileName = GetSafeFileName(model); + GenerateImplFactoryMembersAndEvents(spc, model, fileName); + } - // Generate wrap mock implementation (delegates to wrapped instance for unconfigured calls) - var implSource = MockImplBuilder.Build(model); - spc.AddSource($"{fileName}_WrapMockImpl.g.cs", implSource); + private static void GenerateMultiInterfaceMock(SourceProductionContext spc, MockTypeModel model) + { + var fileName = GetSafeFileName(model); + var implFactorySource = BuildCombinedImplAndFactory(model); + spc.AddSource($"{fileName}_MockImplFactory.g.cs", implFactorySource); + } + + private static void GenerateImplFactoryMembersAndEvents(SourceProductionContext spc, MockTypeModel model, string fileName) + { + var implFactorySource = BuildCombinedImplAndFactory(model); + spc.AddSource($"{fileName}_MockImplFactory.g.cs", implFactorySource); - // Generate unified members surface (setup + verify) var membersSource = MockMembersBuilder.Build(model); spc.AddSource($"{fileName}_MockMembers.g.cs", membersSource); - // Generate events surface (if type has events) if (model.Events.Length > 0) { var eventsSource = MockEventsBuilder.Build(model); spc.AddSource($"{fileName}_MockEvents.g.cs", eventsSource); } - - // Generate wrap factory - var factorySource = MockFactoryBuilder.Build(model); - spc.AddSource($"{fileName}_WrapMockFactory.g.cs", factorySource); } - private static void GenerateMultiInterfaceMock(SourceProductionContext spc, MockTypeModel model) + private static string BuildCombinedImplAndFactory(MockTypeModel model) { - var fileName = GetSafeFileName(model); + var writer = new CodeWriter(); + var mockNamespace = MockImplBuilder.GetMockNamespace(model); + + writer.AppendLine("// "); + writer.AppendLine("#nullable enable"); + writer.AppendLine(); - // Generate combined impl (implements all interfaces) - var implSource = MockImplBuilder.Build(model); - spc.AddSource($"{fileName}_MockImpl.g.cs", implSource); + using (writer.Block($"namespace {mockNamespace}")) + { + MockImplBuilder.BuildInto(writer, model); + writer.AppendLine(); + MockFactoryBuilder.BuildInto(writer, model); + } - // Generate multi-interface factory - var factorySource = MockFactoryBuilder.Build(model); - spc.AddSource($"{fileName}_MockFactory.g.cs", factorySource); + return writer.ToString(); } private static string GetSafeFileName(MockTypeModel model)