Пример #1
0
            public void GeneratesOverloadedConstructors()
            {
                // Given
                Dictionary <string, string> memberNames = new Dictionary <string, string>();
                string expected = $@"
                        public static Wyam.Core.Modules.Contents.Content Content(object content)
                        {{
                            return new Wyam.Core.Modules.Contents.Content(content);  
                        }}
                        public static Wyam.Core.Modules.Contents.Content Content(Wyam.Common.Configuration.ContextConfig content)
                        {{
                            return new Wyam.Core.Modules.Contents.Content(content);  
                        }}
                        public static Wyam.Core.Modules.Contents.Content Content(Wyam.Common.Configuration.DocumentConfig content)
                        {{
                            return new Wyam.Core.Modules.Contents.Content(content);  
                        }}
                        public static Wyam.Core.Modules.Contents.Content Content(params Wyam.Common.Modules.IModule[] modules)
                        {{
                            return new Wyam.Core.Modules.Contents.Content(modules);  
                        }}";

                // When
                string generated = ConfigCompilation.GenerateModuleConstructorMethods(typeof(Content), memberNames);

                // Then
                Assert.AreEqual(expected, generated);
            }
Пример #2
0
        internal AssemblyLoader(ConfigCompilation compilation, IReadOnlyFileSystem fileSystem, IAssemblyCollection assemblies, INamespacesCollection namespaces)
        {
            _compilation = compilation;
            _fileSystem  = fileSystem;
            _assemblies  = assemblies;
            _namespaces  = namespaces;

            // Add the Core modules
            _moduleAssemblies.Add(Assembly.GetAssembly(typeof(Engine)));

            // Manually resolve included assemblies
            AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
            AppDomain.CurrentDomain.SetupInformation.PrivateBinPathProbe = string.Empty; // non-null means exclude application base path
        }
Пример #3
0
            public void GeneratesCorrectScript(string input, string output)
            {
                // Given
                ConfigCompilation compilation = new ConfigCompilation();
                HashSet <Type>    moduleTypes = new HashSet <Type> {
                    typeof(Content)
                };

                string[] namespaces = Array.Empty <string>();
                string   expected   = $@"

                public class ConfigScript : ConfigScriptBase
                {{
                    public ConfigScript(Engine engine) : base(engine) {{ }}

                    public override void Run()
                    {{
{output}
                    }}
                        public static Wyam.Core.Modules.Contents.Content Content(object content)
                        {{
                            return new Wyam.Core.Modules.Contents.Content(content);  
                        }}
                        public static Wyam.Core.Modules.Contents.Content Content(Wyam.Common.Configuration.ContextConfig content)
                        {{
                            return new Wyam.Core.Modules.Contents.Content(content);  
                        }}
                        public static Wyam.Core.Modules.Contents.Content Content(Wyam.Common.Configuration.DocumentConfig content)
                        {{
                            return new Wyam.Core.Modules.Contents.Content(content);  
                        }}
                        public static Wyam.Core.Modules.Contents.Content Content(params Wyam.Common.Modules.IModule[] modules)
                        {{
                            return new Wyam.Core.Modules.Contents.Content(modules);  
                        }}}}";

                // When
                compilation.Generate(null, input, moduleTypes, namespaces);

                // Then
                Assert.AreEqual(expected, compilation.Code);
            }
Пример #4
0
            public void GeneratesGenericConstructors()
            {
                // Given
                Dictionary <string, string> memberNames = new Dictionary <string, string>();
                string expected = $@"
                        public static Wyam.Configuration.Tests.ConfigCompilationTests.GenericModule<T> GenericModule<T>(T input)
                        {{
                            return new Wyam.Configuration.Tests.ConfigCompilationTests.GenericModule<T>(input);  
                        }}
                        public static Wyam.Configuration.Tests.ConfigCompilationTests.GenericModule<T> GenericModule<T>(System.Action<T> input)
                        {{
                            return new Wyam.Configuration.Tests.ConfigCompilationTests.GenericModule<T>(input);  
                        }}";

                // When
                string generated = ConfigCompilation.GenerateModuleConstructorMethods(typeof(GenericModule <>), memberNames);

                // Then
                Assert.AreEqual(expected, generated);
            }