public virtual IBeanDefinitionCollection EnableUnityAddonMoq(UnityAddonTest testcase)
        {
            IBeanDefinitionCollection beanDefCol = new BeanDefinitionCollection();

            testcase.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
            .Select(p => new { p.PropertyType, Attribute = p.GetCustomAttribute <MockAttribute>() })
            .Where(p => p.Attribute != null)
            .ToList()
            .ForEach(p =>
            {
                if (!(p.PropertyType.IsConstructedGenericType && p.PropertyType.GetGenericTypeDefinition().Equals(typeof(Mock <>))))
                {
                    throw new ArgumentException("property type must be Mock<>");
                }

                beanDefCol.AddSingleton(p.PropertyType, (sp, type, name) => Activator.CreateInstance(type), null);
                beanDefCol.AddSingleton(p.PropertyType.GetGenericArguments()[0], (sp, type, name) => ((dynamic)sp.GetRequiredService(p.PropertyType)).Object);
            });

            testcase.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
            .Where(p => p.GetCustomAttribute <TestSubjectAttribute>() != null)
            .ToList()
            .ForEach(p => beanDefCol.AddSingleton(p.PropertyType, p.PropertyType));

            return(beanDefCol);
        }
        public void ConfigureBeans(Action <IBeanDefinitionCollection> config)
        {
            var defCol = new BeanDefinitionCollection();

            config(defCol);

            ConfigureBeans(defCol);
        }
        public IBeanDefinitionCollection Create(Type type)
        {
            IBeanDefinitionCollection col = new BeanDefinitionCollection();

            col.AddComponent(type);

            return(col);
        }
Exemple #4
0
        public virtual IBeanDefinitionCollection BeanDefinitions()
        {
            IBeanDefinitionCollection defs = new BeanDefinitionCollection();

            defs.Add(new InstanceBeanDefintion(typeof(string), "test", null, ScopeType.Singleton));

            return(defs);
        }
Exemple #5
0
        public virtual IBeanDefinitionCollection UnityAddonEfBeans()
        {
            IBeanDefinitionCollection col = new BeanDefinitionCollection();

            col.AddFromComponentScanner(Assembly.GetExecutingAssembly(), "UnityAddon.Ef");

            return(col);
        }
Exemple #6
0
        public virtual IBeanDefinitionCollection EnableUnityAddonHangfire()
        {
            IBeanDefinitionCollection col = new BeanDefinitionCollection();

            col.AddFromComponentScanner(Assembly.GetExecutingAssembly(), "UnityAddon.Hangfire");

            return(col);
        }
        public void ScanComponents()
        {
            IBeanDefinitionCollection defCol = new BeanDefinitionCollection();

            defCol.AddFromComponentScanner(GetType().Assembly, GetType().Namespace);

            Assert.NotNull(defCol.Where(def => def.Type == typeof(Service)).Single());
            Assert.NotNull(defCol.Where(def => def.Type == typeof(Config)).Single());
            Assert.Equal(2, defCol.Count());
        }
        public virtual IBeanDefinitionCollection ComponentScan(UnityAddonTest testcase, [Dependency("Namespaces")] string[] namespaces)
        {
            IBeanDefinitionCollection col = new BeanDefinitionCollection();

            var nsmerge = new[] { testcase.GetType().Namespace }.Union(namespaces).ToArray();

            col.AddFromComponentScanner(testcase.GetType().Assembly, nsmerge);

            return(col);
        }
Exemple #9
0
        public virtual IBeanDefinitionCollection EnableUnityAddonCache()
        {
            IBeanDefinitionCollection col = new BeanDefinitionCollection();

            col.AddFromComponentScanner(Assembly.GetExecutingAssembly(), "UnityAddon.Cache");
            col.AddFromServiceCollection(config =>
            {
                config.AddMemoryCache();
            });

            return(col);
        }
Exemple #10
0
        public virtual IBeanDefinitionCollection Serilog(HostBuilderContext hostBuilderContext, [OptionalDependency] LoggerConfiguration loggerConfig)
        {
            IBeanDefinitionCollection defCol = new BeanDefinitionCollection();

            loggerConfig ??= new LoggerConfiguration();

            Log.Logger = loggerConfig.CreateLogger();

            defCol.AddFromServiceCollection(services => services.AddLogging(logging => logging.AddSerilog(Log.Logger)));

            return(defCol);
        }
        public virtual IBeanDefinitionCollection Col()
        {
            var moduleRootPath = Path.Join(Directory.GetCurrentDirectory(), ModuleBasePath);
            var col            = new BeanDefinitionCollection();

            ModuleCollection.ImportFromFolder(moduleRootPath);

            foreach (var entry in ModuleCollection)
            {
                var startup = entry.Assembly.GetType(entry.ModuleDescriptor.StartupClass);
                col.AddComponent(startup);
            }

            return(col);
        }
Exemple #12
0
        public IBeanDefinitionCollection ScanAssembly(Assembly asm, params string[] baseNamespaces)
        {
            var regexes    = BuildBaseNamespacesRegexes(baseNamespaces);
            var beanDefCol = new BeanDefinitionCollection();

            beanDefCol.AddRange(asm.GetTypes()
                                .Where(t => t.Namespace != null && regexes.Any(regex => regex.IsMatch(t.Namespace)))
                                .Where(t => IsCandidate(t))
                                .Where(t => t.HasAttribute <ComponentAttribute>(true))
                                .SkipWhile(t => !_scannerStrategies.Any(stg => stg.IsMatch(t)))
                                .SelectMany(t => _scannerStrategies.First(stg => stg.IsMatch(t)).Create(t))
                                .ToArray());

            return(beanDefCol);
        }
        public IBeanDefinitionCollection ParseBeanMethods(Type configType)
        {
            var defCol = new BeanDefinitionCollection();

            defCol.AddRange(MethodSelector.GetAllMethodsByAttribute <BeanAttribute>(configType)
                            .SelectMany(beanMethod =>
            {
                var def = new MemberMethodBeanDefinition(beanMethod);

                return(new[] { def, new MemberMethodFactoryBeanDefinition(def) });
            })
                            .ToArray());

            return(defCol);
        }
Exemple #14
0
        public virtual IBeanDefinitionCollection BeanDefinitions()
        {
            IBeanDefinitionCollection defs = new BeanDefinitionCollection();

            return(defs);
        }