Пример #1
0
        public async Task MethodInfoIsSerializedAsFullyQualifiedName()
        {
            var healthReporter = new Mock <IHealthReporter>();

            EventData e = new EventData();

            e.ProviderName = "TestProvider";
            e.Timestamp    = new DateTimeOffset(2018, 1, 2, 14, 12, 0, TimeSpan.Zero);
            e.Level        = LogLevel.Warning;
            e.Payload.Add("Method", typeof(StdOutputTests).GetMethod(nameof(MethodInfoIsSerializedAsFullyQualifiedName)));

            string    actualOutput = null;
            StdOutput stdOutput    = new StdOutput(healthReporter.Object, s => actualOutput = s);
            await stdOutput.SendEventsAsync(new EventData[] { e }, 34, CancellationToken.None);

            string expecteOutput = @"[34]
                {
                    ""Timestamp"":""2018-01-02T14:12:00+00:00"",
                    ""ProviderName"":""TestProvider"",
                    ""Level"":3,
                    ""Keywords"":0,
                    ""Payload"":{""Method"":""Microsoft.Diagnostics.EventFlow.Outputs.Tests.StdOutputTests.MethodInfoIsSerializedAsFullyQualifiedName""}
                }
            ";

            Assert.Equal(expecteOutput.RemoveAllWhitespace(), actualOutput.RemoveAllWhitespace());
            healthReporter.Verify(hr => hr.ReportWarning(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            healthReporter.Verify(hr => hr.ReportProblem(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
Пример #2
0
        public void ConstructorShouldRequireHealthReporter()
        {
            Exception ex = Assert.Throws <ArgumentNullException>(() =>
            {
                StdOutput target = new StdOutput(null);
            });

            Assert.Equal("Value cannot be null.\r\nParameter name: healthReporter", ex.Message);
        }
Пример #3
0
        public void ConstructorShouldRequireHealthReporter()
        {
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() =>
            {
                StdOutput target = new StdOutput(null);
            });

            Assert.Equal("healthReporter", ex.ParamName);
        }
Пример #4
0
        public void CopyStdio(DataHash hc)
        {
            var stderrfile = Cache.OutputCache.MakePath(hc.Hash, CompilerCacheBase.F_Stderr);
            var stdoutfile = Cache.OutputCache.MakePath(hc.Hash, CompilerCacheBase.F_Stdout);

            StdOutput.Clear();
            StdError.Clear();
            StdOutput.Append(File.ReadAllText(stdoutfile));
            StdError.Append(File.ReadAllText(stderrfile));
        }
Пример #5
0
        public void ConstructorShouldCreateTheInstance()
        {
            // Setup
            Mock <IHealthReporter> healthReporterMock = new Mock <IHealthReporter>();

            // Execute
            StdOutput sender = new StdOutput(healthReporterMock.Object);

            // Verify
            Assert.NotNull(sender);
        }
Пример #6
0
        public async Task UsesCustomJsonSerializerSettings()
        {
            var healthReporter = new Mock <IHealthReporter>();

            EventData e = new EventData();

            e.ProviderName = "TestProvider";
            e.Timestamp    = new DateTimeOffset(2018, 1, 2, 14, 12, 0, TimeSpan.Zero);
            e.Level        = LogLevel.Warning;
            e.Payload.Add("InfinityProperty", Double.PositiveInfinity);

            string    actualOutput = null;
            StdOutput stdOutput    = new StdOutput(healthReporter.Object, s => actualOutput = s);
            await stdOutput.SendEventsAsync(new EventData[] { e }, 34, CancellationToken.None);

            string expecteOutput = @"[34]
                {
                    ""Timestamp"":""2018-01-02T14:12:00+00:00"",
                    ""ProviderName"":""TestProvider"",
                    ""Level"":3,
                    ""Keywords"":0,
                    ""Payload"":{""InfinityProperty"":""Infinity""}
                }
            ";

            Assert.Equal(expecteOutput.RemoveAllWhitespace(), actualOutput.RemoveAllWhitespace());
            healthReporter.Verify(hr => hr.ReportWarning(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            healthReporter.Verify(hr => hr.ReportProblem(It.IsAny <string>(), It.IsAny <string>()), Times.Never);

            // Now verify changing serializer settings is effective
            stdOutput.SerializerSettings.FloatFormatHandling = FloatFormatHandling.DefaultValue;
            await stdOutput.SendEventsAsync(new EventData[] { e }, 36, CancellationToken.None);

            expecteOutput = @"[36]
                {
                    ""Timestamp"":""2018-01-02T14:12:00+00:00"",
                    ""ProviderName"":""TestProvider"",
                    ""Level"":3,
                    ""Keywords"":0,
                    ""Payload"":{""InfinityProperty"":0.0}
                }
            ";
            Assert.Equal(expecteOutput.RemoveAllWhitespace(), actualOutput.RemoveAllWhitespace());
            healthReporter.Verify(hr => hr.ReportWarning(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            healthReporter.Verify(hr => hr.ReportProblem(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
Пример #7
0
        public string GetDebugInfo()
        {
            var sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine("Debugging Information:");
            sb.AppendLine("----------------------");
            sb.AppendLine($"Executed command: {ExecutedCommand}");

            if (Process.HasExited)
            {
                sb.AppendLine($"Exit code: {Process.ExitCode}");
            }

            sb.AppendLine($"StdOutput: {StdOutput.ToString()}");
            sb.AppendLine($"StdError: {StdError.ToString()}");
            sb.AppendLine($"Exception: {Exception?.Message}");
            return(sb.ToString());
        }
 public void AppendToStdOutput(string data) => StdOutput.AppendLine(data);