コード例 #1
0
        public void TraceShouldSubmitTheData()
        {
            IConfiguration configuration = (new ConfigurationBuilder()).AddInMemoryCollection(new Dictionary <string, string>()
            {
                ["type"]       = "Trace",
                ["traceLevel"] = "All"
            }).Build();
            var healthReporterMock = new Mock <IHealthReporter>();
            var subject            = new Mock <IObserver <EventData> >();

            using (TraceInput target = new TraceInput(configuration, healthReporterMock.Object))
                using (target.Subscribe(subject.Object))
                {
                    Trace.TraceInformation("Message for unit test");
                    subject.Verify(s => s.OnNext(It.IsAny <EventData>()), Times.Exactly(1));
                }
        }
コード例 #2
0
        public void TraceInputShouldOverrideWriteLine()
        {
            IConfiguration configuration = (new ConfigurationBuilder()).AddInMemoryCollection(new Dictionary <string, string>()
            {
                ["type"]       = "Trace",
                ["traceLevel"] = "All"
            }).Build();
            var healthReporterMock = new Mock <IHealthReporter>();
            var subject            = new Mock <IObserver <EventData> >();

            using (TraceInput target = new TraceInput(configuration, healthReporterMock.Object))
                using (target.Subscribe(subject.Object))
                {
                    target.WriteLine("UnitTest info");
                    subject.Verify(s => s.OnNext(It.Is <EventData>(data => data.Payload["Message"].Equals("UnitTest info"))), Times.Exactly(1));
                }
        }
コード例 #3
0
        public void TraceInputShouldOverrideTraceSingleEvent()
        {
            IConfiguration configuration = (new ConfigurationBuilder()).AddInMemoryCollection(new Dictionary <string, string>()
            {
                ["type"]       = "Trace",
                ["traceLevel"] = "All"
            }).Build();
            var healthReporterMock = new Mock <IHealthReporter>();
            var subject            = new Mock <IObserver <EventData> >();

            using (TraceInput target = new TraceInput(configuration, healthReporterMock.Object))
                using (target.Subscribe(subject.Object))
                {
                    string message = GetRandomString();
                    int    id      = (new Random()).Next();
                    target.TraceEvent(null, null, TraceEventType.Warning, id, message);
                    subject.Verify(s =>
                                   s.OnNext(It.Is <EventData>(data => data.Payload["Message"].Equals(message) && data.Payload["EventId"].Equals(id))),
                                   Times.Exactly(1));
                }
        }
コード例 #4
0
        public void TraceInputShouldOverrideFailWithDetails()
        {
            IConfiguration configuration = (new ConfigurationBuilder()).AddInMemoryCollection(new Dictionary <string, string>()
            {
                ["type"]       = "Trace",
                ["traceLevel"] = "All"
            }).Build();
            var healthReporterMock = new Mock <IHealthReporter>();
            var subject            = new Mock <IObserver <EventData> >();

            using (TraceInput target = new TraceInput(configuration, healthReporterMock.Object))
                using (target.Subscribe(subject.Object))
                {
                    string message = "Failure message";
                    string details = "Details";
                    target.Fail(message, details);
                    subject.Verify(s =>
                                   s.OnNext(It.Is <EventData>(data => data.Payload["Message"].Equals(message + Environment.NewLine + details) && data.Level == LogLevel.Error)),
                                   Times.Exactly(1));
                }
        }
コード例 #5
0
        public void TraceInputTracksActivityID()
        {
            IConfiguration configuration = (new ConfigurationBuilder()).AddInMemoryCollection(new Dictionary <string, string>()
            {
                ["type"]       = "Trace",
                ["traceLevel"] = "All"
            }).Build();
            var healthReporterMock = new Mock <IHealthReporter>();
            var subject            = new Mock <IObserver <EventData> >();

            using (TraceInput target = new TraceInput(configuration, healthReporterMock.Object))
                using (target.Subscribe(subject.Object))
                {
                    string message    = GetRandomString();
                    int    id         = (new Random()).Next();
                    Guid   activityID = Guid.NewGuid();
                    Trace.CorrelationManager.ActivityId = activityID;

                    target.TraceData(null, null, TraceEventType.Information, id, message);
                    subject.Verify(s =>
                                   s.OnNext(It.Is <EventData>(data => data.Payload["EventId"].Equals(id) && data.Payload["ActivityID"].Equals(activityID) && data.Payload["Message"].Equals(message))),
                                   Times.Exactly(1));
                }
        }