Пример #1
0
        private static (int, string) GetSeed(int?seedArg, ITestOutputHelper xUnitOutputHelper)
        {
            if (seedArg.HasValue)
            {
                return(seedArg.Value, "passed as argument");
            }

            var config = TestingConfig.ReadFromFromEnvVars(xUnitOutputHelper);

            // ReSharper disable once ConvertIfStatementToReturnStatement
            if (config.RandomSeed.HasValue)
            {
                return(config.RandomSeed.Value, "configured via environment variables");
            }

            return(new Random().Next(), "randomly generated");
        }
Пример #2
0
        protected LoggingTestBase(ITestOutputHelper xUnitOutputHelper)
        {
            TestOutputHelper = xUnitOutputHelper;
            CurrentXunitTest = GetCurrentXunitTest(xUnitOutputHelper);

            var lineWriters = new List <ILineWriter>();

            var testId = TestIdCounter.Increment();

            var config = TestingConfig.ReadFromFromEnvVars(xUnitOutputHelper);

            if (config.LogToSysDiagTraceEnabled)
            {
                lineWriters.Add(new SystemDiagnosticsTraceLineWriter(string.Format(config.LogToSysDiagTraceLinePrefix, testId)));
            }

            if (config.LogToConsoleEnabled)
            {
                lineWriters.Add(new FlushingTextWriterToLineWriterAdaptor(Console.Out, string.Format(config.LogToConsoleLinePrefix, testId)));
            }

            var writerForStartFinish = lineWriters.ToArray();

            if (config.LogToXunitEnabled)
            {
                lineWriters.Add(new XunitOutputToLineWriterAdaptor(xUnitOutputHelper, string.Format(config.LogToXunitLinePrefix, testId)));
                if (!TestingConfig.IsRunningInIde)
                {
                    writerForStartFinish = lineWriters.ToArray();
                }
            }

            _loggerForStartFinish = new LineWriterToLoggerAdaptor(new SplittingLineWriter(writerForStartFinish), config.LogLevel);

            LogProgress("Starting test: {UnitTestDisplayName}...");

            LoggerBase = new LineWriterToLoggerAdaptor(new SplittingLineWriter(lineWriters.ToArray()), config.LogLevel);
        }