using GFramework.SourceGenerators.Architectures; using GFramework.SourceGenerators.Tests.Core; namespace GFramework.SourceGenerators.Tests.Architectures; [TestFixture] public class AutoRegisterModuleGeneratorTests { [Test] public async Task Generates_Module_Install_Method_In_Attribute_Order() { const string source = """ using System; using GFramework.SourceGenerators.Abstractions.Architectures; namespace GFramework.SourceGenerators.Abstractions.Architectures { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public sealed class AutoRegisterModuleAttribute : Attribute { } [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] public sealed class RegisterModelAttribute : Attribute { public RegisterModelAttribute(Type modelType) { } } [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] public sealed class RegisterSystemAttribute : Attribute { public RegisterSystemAttribute(Type systemType) { } } [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] public sealed class RegisterUtilityAttribute : Attribute { public RegisterUtilityAttribute(Type utilityType) { } } } namespace GFramework.Core.Abstractions.Architectures { public interface IArchitecture { T RegisterModel(T model) where T : GFramework.Core.Abstractions.Model.IModel; T RegisterSystem(T system) where T : GFramework.Core.Abstractions.Systems.ISystem; T RegisterUtility(T utility) where T : GFramework.Core.Abstractions.Utility.IUtility; } } namespace GFramework.Core.Abstractions.Model { public interface IModel { } } namespace GFramework.Core.Abstractions.Systems { public interface ISystem { } } namespace GFramework.Core.Abstractions.Utility { public interface IUtility { } } namespace TestApp { using GFramework.Core.Abstractions.Model; using GFramework.Core.Abstractions.Systems; using GFramework.Core.Abstractions.Utility; using GFramework.SourceGenerators.Abstractions.Architectures; public sealed class PlayerModel : IModel { } public sealed class CombatSystem : ISystem { } public sealed class AudioUtility : IUtility { } [AutoRegisterModule] [RegisterSystem(typeof(CombatSystem))] [RegisterModel(typeof(PlayerModel))] [RegisterUtility(typeof(AudioUtility))] public partial class GameplayModule { } } """; const string expected = """ // #nullable enable namespace TestApp; partial class GameplayModule { public void Install(global::GFramework.Core.Abstractions.Architectures.IArchitecture architecture) { architecture.RegisterSystem(new global::TestApp.CombatSystem()); architecture.RegisterModel(new global::TestApp.PlayerModel()); architecture.RegisterUtility(new global::TestApp.AudioUtility()); } } """; await GeneratorTest.RunAsync( source, ("TestApp_GameplayModule.AutoRegisterModule.g.cs", expected)); } }