public static ITestHelperResolver Create(ITestHelperConfiguration config = null) { using (WeakAssemblyNameResolver.TemporaryInstall()) { return(new ResolverImpl(config ?? TestHelperConfiguration.Default)); } }
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; } }
/// <summary> /// Gets the configuration value from semi colon (;) separated paths as a set of paths /// (see <see cref="TestHelperConfigurationValue.GetValueAsPath"/>). /// </summary> /// <param name="this">This configuration.</param> /// <param name="key">The configuration entry key.</param> /// <returns>The values as paths.</returns> public static IEnumerable <NormalizedPath> GetMultiPaths(this ITestHelperConfiguration @this, NormalizedPath key) { var p = @this.GetConfigValue(key); if (!p.HasValue || p.Value.Value.Length == 0) { return(Array.Empty <NormalizedPath>()); } return(p.Value.Value.Split(';') .Select(x => new TestHelperConfigurationValue(p.Value.BasePath, x.Trim())) .Where(x => x.Value.Length > 0) .Select(x => x.GetValueAsPath()) .Select(x => new NormalizedPath(x))); }
/// <summary> /// Gets an integer configuration value. /// </summary> /// <param name="this">This configuration.</param> /// <param name="key">The configuration entry key.</param> /// <returns>The value or null if not found.</returns> public static int?GetInt32(this ITestHelperConfiguration @this, NormalizedPath key) { var s = @this.Get(key); return(s == null ? (int?)null : Int32.Parse(s)); }
/// <summary> /// Gets a boolean configuration value. /// </summary> /// <param name="this">This configuration.</param> /// <param name="key">The configuration entry key.</param> /// <returns>The value or null if not found.</returns> public static bool?GetBoolean(this ITestHelperConfiguration @this, NormalizedPath key) { var s = @this.Get(key); return(s == null ? (bool?)null : StringComparer.OrdinalIgnoreCase.Equals(s, "true")); }
/// <summary> /// Creates a new <see cref="ITestHelperResolver"/> bound to a specific configuration. /// </summary> /// <param name="config">An optional configuration: when null the <see cref="TestHelperConfiguration.Default"/> is used.</param> /// <returns>A new resolver.</returns> public static ITestHelperResolver Create(ITestHelperConfiguration config = null) => ResolverImpl.Create(config);
internal SqlServerTestHelper(ITestHelperConfiguration config, IMonitorTestHelper monitor) { _config = config; _monitor = monitor; }
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); } }); }