Ejemplo n.º 1
0
 ResolverImpl(ITestHelperConfiguration config)
 {
     _container = new SimpleServiceContainer();
     _container.Add(config);
     _config       = config;
     TransientMode = config.GetBoolean("TestHelper/TransientMode") ?? false;
     string[] assemblies = config.Get("TestHelper/PreLoadedAssemblies", String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
     if (assemblies.Length > 0)
     {
         using (WeakAssemblyNameResolver.TemporaryInstall())
         {
             var types = new List <Type>();
             foreach (var n in assemblies)
             {
                 var a = Assembly.Load(n);
                 types.AddRange(a.GetExportedTypes().Where(t => t.IsInterface && typeof(IMixinTestHelper).IsAssignableFrom(t)));
             }
             _preLoadedTypes = types;
             if (!TransientMode)
             {
                 var ctx = new Context(_container);
                 foreach (var preLoad in _preLoadedTypes)
                 {
                     Resolve(ctx, preLoad);
                 }
             }
         }
     }
     else
     {
         _preLoadedTypes = Type.EmptyTypes;
     }
 }
Ejemplo n.º 2
0
        internal MonitorTestHelper(ITestHelperConfiguration config, IBasicTestHelper basic)
        {
            _config = config;
            _basic  = basic;

            basic.OnlyOnce(() =>
            {
                _logToBinFile = _config.GetBoolean("Monitor/LogToBinFile")
                                ?? _config.GetBoolean("Monitor/LogToBinFiles")
                                ?? false;
                _logToTextFile = _config.GetBoolean("Monitor/LogToTextFile")
                                 ?? _config.GetBoolean("Monitor/LogToTextFiles")
                                 ?? false;

                string logLevel = _config.Get("Monitor/LogLevel");
                if (logLevel != null)
                {
                    var lf = LogFilter.Parse(logLevel);
                    ActivityMonitor.DefaultFilter = lf;
                }
                LogFile.RootLogPath = basic.LogFolder;
                var conf            = new GrandOutputConfiguration();
                if (_logToBinFile)
                {
                    var binConf = new BinaryFileConfiguration
                    {
                        UseGzipCompression = true,
                        Path = FileUtil.CreateUniqueTimedFolder(LogFile.RootLogPath + "CKMon/", null, DateTime.UtcNow)
                    };
                    conf.AddHandler(binConf);
                }
                if (_logToTextFile)
                {
                    var txtConf = new TextFileConfiguration
                    {
                        Path = FileUtil.CreateUniqueTimedFolder(LogFile.RootLogPath + "Text/", null, DateTime.UtcNow)
                    };
                    conf.AddHandler(txtConf);
                }
                GrandOutput.EnsureActiveDefault(conf, clearExistingTraceListeners: false);
                var monitorListener = Trace.Listeners.OfType <MonitorTraceListener>().FirstOrDefault(m => m.GrandOutput == GrandOutput.Default);
                // (Defensive programming) There is no real reason for this listener to not be in the listeners, but it can be.
                if (monitorListener != null)
                {
                    // If our standard MonitorTraceListener has been injected, then we remove the StaticBasicTestHelper.SafeTraceListener
                    // that throws Exceptions instead of callinf FailFast.
                    Trace.Listeners.Remove("CK.Testing.SafeTraceListener");
                }
            });
            _monitor               = new ActivityMonitor("MonitorTestHelper");
            _console               = new ActivityMonitorConsoleClient();
            LogToConsole           = _config.GetBoolean("Monitor/LogToConsole") ?? false;
            basic.OnCleanupFolder += OnCleanupFolder;
            basic.OnlyOnce(() =>
            {
                var basePath = LogFile.RootLogPath + "Text" + FileUtil.DirectorySeparatorString;
                if (Directory.Exists(basePath))
                {
                    CleanupTimedFolders(_monitor, _basic, basePath, MaxCurrentLogFolderCount, MaxArchivedLogFolderCount);
                }
                basePath = LogFile.RootLogPath + "CKMon" + FileUtil.DirectorySeparatorString;
                if (Directory.Exists(basePath))
                {
                    CleanupTimedFolders(_monitor, _basic, basePath, MaxCurrentLogFolderCount, MaxArchivedLogFolderCount);
                }
            });
        }