public void ConstructorShouldRequireHealthReporter()
        {
            var configurationMock = new Mock <IConfiguration>();

            configurationMock.Setup(section => section["type"]).Returns("Trace");
            Exception ex = Assert.Throws <ArgumentNullException>(() =>
            {
                using (TraceInput target = new TraceInput(configurationMock.Object, null)) { }
            });

            Assert.Equal("Value cannot be null.\r\nParameter name: healthReporter", ex.Message);
        }
        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));
                }
        }
        public void ConstructorShouldRequireConfiguration()
        {
            var healthReporterMock = new Mock <IHealthReporter>();

            Exception ex = Assert.Throws <ArgumentNullException>(() =>
            {
                using (TraceInput target = new TraceInput((TraceInputConfiguration)null, healthReporterMock.Object)) { }
            });

            Assert.Equal("Value cannot be null.\r\nParameter name: traceInputConfiguration", ex.Message);

            ex = Assert.Throws <ArgumentNullException>(() =>
            {
                using (TraceInput target = new TraceInput((IConfiguration)null, healthReporterMock.Object)) { }
            });
            Assert.Equal("Value cannot be null.\r\nParameter name: configuration", ex.Message);
        }
        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));
                }
        }
Ejemplo n.º 5
0
        public void ConstructorShouldRequireConfiguration()
        {
            var healthReporterMock = new Mock <IHealthReporter>();

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() =>
            {
                using (TraceInput target = new TraceInput((TraceInputConfiguration)null, healthReporterMock.Object)) { }
            });

            Assert.Equal("traceInputConfiguration", ex.ParamName);

            ex = Assert.Throws <ArgumentNullException>(() =>
            {
                using (TraceInput target = new TraceInput((IConfiguration)null, healthReporterMock.Object)) { }
            });
            Assert.Equal("configuration", ex.ParamName);
        }
        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));
                }
        }
        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));
                }
        }
        public void ConstructorShouldCheckConfigurationSectionType()
        {
            IConfiguration configuration = (new ConfigurationBuilder()).AddInMemoryCollection(new Dictionary <string, string>()
            {
                ["type"] = "Trace"
            }).Build();
            var        healthReporterMock = new Mock <IHealthReporter>();
            TraceInput target             = null;

            using (target = new TraceInput(configuration, healthReporterMock.Object))
            {
                Assert.NotNull(target);
            }

            configuration = (new ConfigurationBuilder()).AddInMemoryCollection(new Dictionary <string, string>()
            {
                ["type"] = "NonTrace"
            }).Build();

            using (target = new TraceInput(configuration, healthReporterMock.Object))
            {
                healthReporterMock.Verify(o => o.ReportWarning(It.IsAny <string>(), It.Is <string>(s => s == EventFlowContextIdentifiers.Configuration)), Times.Exactly(1));
            }
        }
Ejemplo n.º 9
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));
                }
        }