/// <summary>
 /// Initializes a new instane of <see cref="LoggingEventArgs"/> class that includes the kind and source of the message
 /// </summary>
 /// <param name="message"> The message being logged </param>
 /// <param name="kind"> The type of message <see cref="ChannelMessageKind"/> </param>
 /// <param name="source"> The source of the message </param>
 public LoggingEventArgs(string message, ChannelMessageKind kind, string source)
 {
     RawMessage = message;
     Kind       = kind;
     Source     = source;
     Message    = $"[Source={Source}, Kind={Kind}] {RawMessage}";
 }
        public BaseTestClass(ITestOutputHelper output)
        {
            //This locale is currently set for tests only so that the produced output
            //files can be compared on systems with other locales to give set of known
            //correct results that are on en-US locale.
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

#if NETFRAMEWORK
            string codeBaseUri             = typeof(BaseTestClass).Assembly.CodeBase;
            string path                    = new Uri(codeBaseUri).AbsolutePath;
            var    currentAssemblyLocation = new FileInfo(Directory.GetParent(path).FullName);
#else
            // There is an extra folder in the netfx path representing the runtime identifier.
            var currentAssemblyLocation = new FileInfo(typeof(BaseTestClass).Assembly.Location);
#endif
            OutDir = Path.Combine(currentAssemblyLocation.Directory.FullName, "TestOutput");
            Directory.CreateDirectory(OutDir);
            Output = output;

            ITest test = (ITest)output.GetType().GetField("test", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(output);
            FullTestName = test.TestCase.TestMethod.TestClass.Class.Name + "." + test.TestCase.TestMethod.Method.Name;
            TestName     = test.TestCase.TestMethod.Method.Name;

            MessageKindToLog = ChannelMessageKind.Error;
            var attributes = test.TestCase.TestMethod.Method.GetCustomAttributes(typeof(LogMessageKind));
            foreach (var attrib in attributes)
            {
                MessageKindToLog = attrib.GetNamedArgument <ChannelMessageKind>("MessageKind");
            }

            // write to the console when a test starts and stops so we can identify any test hangs/deadlocks in CI
            Console.WriteLine($"Starting test: {FullTestName}");
            Initialize();
        }
Beispiel #3
0
 public ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string message)
 {
     Contracts.CheckNonEmpty(message, nameof(message));
     Kind        = kind;
     Sensitivity = sensitivity;
     _message    = message;
     _args       = null;
 }
Beispiel #4
0
 public ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string fmt, params object[] args)
 {
     Contracts.CheckNonEmpty(fmt, nameof(fmt));
     Contracts.CheckNonEmpty(args, nameof(args));
     Kind        = kind;
     Sensitivity = sensitivity;
     _message    = fmt;
     _args       = args;
 }
Beispiel #5
0
 public LogMessageKind(ChannelMessageKind messageKind)
 {
     MessageKind = messageKind;
 }