public TestHostContext(object testClass, [CallerMemberName] string testName = "") { ArgUtil.NotNull(testClass, nameof(testClass)); ArgUtil.NotNullOrEmpty(testName, nameof(testName)); _loadContext = AssemblyLoadContext.GetLoadContext(typeof(TestHostContext).GetTypeInfo().Assembly); _loadContext.Unloading += LoadContext_Unloading; _testName = testName; // Trim the test assembly's root namespace from the test class's full name. _suiteName = testClass.GetType().FullName.Substring( startIndex: typeof(Tests.TestHostContext).FullName.LastIndexOf(nameof(TestHostContext))); _suiteName = _suiteName.Replace(".", "_"); // Setup the trace manager. TraceFileName = Path.Combine( Path.Combine(TestUtil.GetSrcPath(), "Test", "TestLogs"), $"trace_{_suiteName}_{_testName}.log"); if (File.Exists(TraceFileName)) { File.Delete(TraceFileName); } var traceListener = new HostTraceListener(TraceFileName); traceListener.DisableConsoleReporting = true; _secretMasker = new LoggedSecretMasker(new SecretMasker()); _secretMasker.AddValueEncoder(ValueEncoders.JsonStringEscape); _secretMasker.AddValueEncoder(ValueEncoders.UriDataEscape); _secretMasker.AddValueEncoder(ValueEncoders.BackslashEscape); _traceManager = new TraceManager(traceListener, _secretMasker); _trace = GetTrace(nameof(TestHostContext)); // inject a terminal in silent mode so all console output // goes to the test trace file _term = new Terminal(); _term.Silent = true; SetSingleton <ITerminal>(_term); EnqueueInstance <ITerminal>(_term); if (!TestUtil.IsWindows()) { string eulaFile = Path.Combine(GetDirectory(WellKnownDirectory.Root), "license.html"); File.WriteAllText(eulaFile, "testeulafile"); } }
public Variables(IHostContext hostContext, IDictionary <string, VariableValue> copy, out List <string> warnings) { ArgUtil.NotNull(hostContext, nameof(hostContext)); // Store/Validate args. _hostContext = hostContext; _secretMasker = _hostContext.SecretMasker; _trace = _hostContext.GetTrace(nameof(Variables)); // Validate the dictionary, remove any variable with empty variable name. ArgUtil.NotNull(copy, nameof(copy)); if (copy.Keys.Any(k => string.IsNullOrWhiteSpace(k))) { _trace.Info($"Remove {copy.Keys.Count(k => string.IsNullOrWhiteSpace(k))} variables with empty variable name."); } // Initialize the variable dictionary. List <Variable> variables = new List <Variable>(); foreach (var variable in copy) { if (!string.IsNullOrWhiteSpace(variable.Key)) { variables.Add(new Variable(variable.Key, variable.Value.Value, variable.Value.IsSecret, variable.Value.IsReadOnly)); } } foreach (Variable variable in variables) { // Store the variable. The initial secret values have already been // registered by the Worker class. _nonexpanded[variable.Name] = variable; } // Recursively expand the variables. RecalculateExpanded(out warnings); }