Пример #1
0
        public void WriteLine(string output)
        {
            if (string.IsNullOrWhiteSpace(output))
            {
                return;
            }

            var lines = output.Split('\r', '\n');

            for (int i = 0; i < lines.Length; i += 1)
            {
                var line = lines[i];

                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                line = (i == 0)
                    ? string.Format(InvariantCulture, "{0:HH:mm:ss.ffffff} {1}", DateTime.Now, line)
                    : string.Format(InvariantCulture, "                {0}", line);

                _other.WriteLine(line);
            }
        }
Пример #2
0
        protected UnitTestBase(IUnitTestTrace output, string projectDirectory, [CallerFilePath] string filePath = "")
            : base(RuntimeContext.Create())
        {
            if (output is null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            if (string.IsNullOrWhiteSpace(filePath))
            {
                filePath = Invariant($"{nameof(UnitTestBase)}.cs");
            }

            TestMode = ProjectTestMode;

            _filePath         = filePath;
            _iteration        = -1;
            _projectDirectory = projectDirectory ?? Directory.GetParent(filePath).FullName;
            _tempDirectory    = Path.GetTempPath();
            _testInstanceName = Guid.NewGuid().ToString("N");

            while (_projectDirectory != null &&
                   !Directory.EnumerateFiles(_projectDirectory)
                   .Any(x => OrdinalIgnoreCase.Equals(Path.GetExtension(x), ".csproj")))
            {
                _projectDirectory = Path.GetDirectoryName(_projectDirectory);
            }

            _solutionDirectory = FindSolutionDirectory(_projectDirectory);

            Context.Trace = new UnitTestTrace(Context.Trace, output);

            _output = output;

            _output.WriteLine($"Starting {GetType().FullName}.");
        }