Ejemplo n.º 1
0
        private static ISubstitutionContext InstallDiagContext(ISubstitutionContext newCtx, IDiagnosticsLogger logger)
        {
            if (!IsDiagContext(newCtx))
            {
                throw new ArgumentException($"Diagnostics context is expected. Actual context type: {newCtx.GetType().FullName}");
            }

            var oldContext = SubstitutionContext.Current;

            if (IsDiagContext(oldContext))
            {
                throw new InvalidOperationException(
                          "You are trying to install diagnostics context while other diagnostics context is already installed. " +
                          "This scenario is not supported and might indicate that something is going wrong." +
                          Environment.NewLine +
                          "Notice, the issue might also happen due to concurrency if you run multiple tests with diagnostics in parallel. " +
                          "In that case please ensure that you run tests sequentially or install the hook globally on an assembly level.");
            }

            SubstitutionContext.Current = newCtx;
            Log("Installed diagnostics context", logger);

            return(oldContext);
        }