protected override void Given()
        {
            base.Given();

            this.localDbConnection.ChangeDatabase(this.dbName);

            using (var cmd = new SqlCommand(Resources.CreateTracesTable, this.localDbConnection))
            {
                cmd.ExecuteNonQuery();
            }

            this.eventListener = new ObservableEventListener();
            this.subscription = this.eventListener.LogToSqlDatabase("test", this.GetSqlConnectionString(), bufferingCount: NumberOfEntries); //@"Data Source=.\sqlexpress;Initial Catalog=SemanticLoggingTests;Integrated Security=True"
            this.eventListener.EnableEvents(TestEventSource.Log, EventLevel.LogAlways);
        }
Ejemplo n.º 2
0
        public void FilteredEventSourceTest()
        {
            const int               _bufferSize   = 10;
            List <EventEntry>       _lastEvent    = new List <EventEntry>();
            ObservableEventListener _listener     = new ObservableEventListener();
            IDisposable             _subscription =
                _listener.
                FlushOnTrigger(entry => entry.Schema.Level <= EventLevel.Error, bufferSize: _bufferSize).
                Subscribe(x => _lastEvent.Add(x));

            using (SinkSubscription <ObservableEventListener> _sink = new SinkSubscription <ObservableEventListener>(_subscription, _listener))
            {
                _sink.Sink.EnableEvents(SemanticEventSource.Log, EventLevel.LogAlways, Keywords.All);
                SemanticEventUser _logUser = new SemanticEventUser();

                _logUser.LongDataProcessing();
                Assert.AreEqual <int>(_bufferSize + 1, _lastEvent.Count);
            }
        }
Ejemplo n.º 3
0
        public void ReferenceApplicationEventSourceExtensionsTest()
        {
            List <EventEntry>       _lastEvents  = new List <EventEntry>();
            ObservableEventListener _listener    = new ObservableEventListener();
            IDisposable             subscription = _listener.Subscribe(x => { _lastEvents.Add(x); });

            using (SinkSubscription <ObservableEventListener> _sinkSubscription = new SinkSubscription <ObservableEventListener>(subscription, _listener))
            {
                Assert.IsNotNull(_sinkSubscription.Sink);

                ReferenceApplicationEventSource _log = ReferenceApplicationEventSource.Log;
                _sinkSubscription.Sink.EnableEvents(_log, EventLevel.LogAlways, EventKeywords.All);

                Assert.AreEqual <int>(0, _lastEvents.Count);
                NotImplementedException _ex = new NotImplementedException("testing exception", new NotImplementedException());
                _log.LogException(_ex);
                Assert.AreEqual <int>(2, _lastEvents.Count);

                //_lastEvent content
                Assert.AreEqual <int>(1, _lastEvents[0].EventId);
                Assert.AreEqual <Guid>(Guid.Empty, _lastEvents[0].ActivityId);
                string _message = "Application Failure: An exception has benn caught: of type NotImplementedException capturing the message: testing exception";
                Assert.AreEqual <string>(_message, _lastEvents[0].FormattedMessage);
                //schema
                EventSchema _Schema = _lastEvents[0].Schema;
                Assert.AreEqual <string>("InfrastructureInfo", _Schema.EventName);
                Assert.AreEqual <int>(1, _Schema.Id);
                //Assert.IsTrue((_Schema.Keywords & SemanticEventSource.Keywords.Diagnostic2) > 0);
                //Assert.AreEqual<string>("PackageContent", _Schema.KeywordsDescription);
                Assert.AreEqual <EventLevel>(EventLevel.Error, _Schema.Level);
                Assert.AreEqual <string>("Info", _Schema.OpcodeName);
                Assert.AreEqual <EventOpcode>(EventOpcode.Info, _Schema.Opcode);
                Assert.AreEqual <Guid>(new Guid("D8637D00-5EAD-4538-9286-8C6DE346D8C8"), _Schema.ProviderId);
                Assert.AreEqual <string>("UAOOI-Networking-ReferenceApplication-Diagnostic", _Schema.ProviderName);
                Assert.AreEqual <string>("Infrastructure", _Schema.TaskName);
                Assert.AreEqual <EventTask>(Tasks.Infrastructure, _Schema.Task);
                Assert.AreEqual <int>(0, _Schema.Version);

                //Payload
                Assert.AreEqual <string>("System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object]", _lastEvents[0].Payload.ToString(), _lastEvents[0].Payload.ToString());
                Assert.AreEqual <int>(1, _lastEvents[0].Payload.Count);
            }
        }
Ejemplo n.º 4
0
        public void FlatFileSinkTest()
        {
            string   _filePath = $"{nameof(FlatFileSinkTest)}.log";
            FileInfo _logFile  = new FileInfo(_filePath);

            if (_logFile.Exists)
            {
                _logFile.Delete();
            }
            SinkSubscription <FlatFileSink> m_FileSubscription = SinkExtensions.CreateSink(SemanticEventSource.Log, _filePath);

            _logFile.Refresh();
            Assert.IsTrue(_logFile.Exists);
            Assert.AreEqual <long>(0, _logFile.Length);
            SemanticEventUser _logUser = new SemanticEventUser();

            _logUser.DataProcessing();
            m_FileSubscription.Sink.FlushAsync();
            _logFile.Refresh();
            Assert.IsTrue(_logFile.Length > 100);
            m_FileSubscription.Dispose();
        }
        public void ReactiveSubscribeTest()
        {
            EventEntry _lastEvent                = null;
            int        _calls                    = 0;
            ObservableEventListener _listener    = new ObservableEventListener();
            IDisposable             subscription = _listener.Subscribe(x => { _calls++; _lastEvent = x; });

            using (SinkSubscription <ObservableEventListener> _sinkSubscription = new SinkSubscription <ObservableEventListener>(subscription, _listener))
            {
                Assert.IsNotNull(_sinkSubscription.Sink);

                UDPMessageHandlerSemanticEventSource _log = UDPMessageHandlerSemanticEventSource.Log;
                _sinkSubscription.Sink.EnableEvents(_log, EventLevel.LogAlways, Keywords.All);

                Assert.IsNull(_lastEvent);
                _log.ReceivedMessageContent(new IPEndPoint(new IPAddress(new byte[] { 192, 168, 0, 0 }), 25), 100, new byte[] { 1, 2, 3, 4 });
                Assert.AreEqual <int>(1, _calls);
                Assert.IsNotNull(_lastEvent);

                //_lastEvent content
                Assert.AreEqual <int>(5, _lastEvent.EventId);
                Assert.AreEqual <Guid>(Guid.Empty, _lastEvent.ActivityId);
                string _message = "Received message: 192.168.0.0:25 [100]: 1,2,3,4";
                Assert.AreEqual <string>(_message, _lastEvent.FormattedMessage, _lastEvent.FormattedMessage);

                Assert.AreEqual <string>("System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object]", _lastEvent.Payload.ToString(), _lastEvent.Payload.ToString());
                Assert.AreEqual <int>(1, _lastEvent.Payload.Count);
                Assert.IsInstanceOfType(_lastEvent.Payload[0], typeof(String));
                Assert.AreEqual <string>("192.168.0.0:25 [100]: 1,2,3,4", _lastEvent.Payload[0].ToString());
                Assert.AreEqual <string>("payload0", _lastEvent.Schema.Payload[0]);

                Assert.AreEqual <string>("Info", _lastEvent.Schema.OpcodeName);
                Assert.AreEqual <EventOpcode>(EventOpcode.Info, _lastEvent.Schema.Opcode);
                Assert.AreEqual <string>("Consumer", _lastEvent.Schema.TaskName);
                Assert.AreEqual <EventTask>(Tasks.Consumer, _lastEvent.Schema.Task);
            }
        }