public void ReceiveMSMQMessage()
        {
            SendMessageToQ(CommonUtil.MsgBody);

            msmqDistributor.CheckForMessages();

            Assert.AreEqual(1, MockTraceListener.Entries.Count);
            Assert.AreEqual(CommonUtil.MsgBody, MockTraceListener.LastEntry.Message, "Body");
        }
Beispiel #2
0
        public void EntryIsWrittenWhenMSMQGeneralCategory()
        {
            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();
            var msmqListener = new MsmqTraceListener("TestMSMQProg", MsmqUtil.MessageQueuePath, new BinaryLogFormatter(),
                                                     MessagePriority.Normal, false, new TimeSpan(0, 1, 0), new TimeSpan(0, 1, 0),
                                                     false, true, false, MessageQueueTransactionType.None);

            msmqListener.Filter = new EventTypeFilter(SourceLevels.All);

            MsmqUtil.ValidateMsmqIsRunning();
            MsmqUtil.DeletePrivateTestQ();
            MsmqUtil.CreatePrivateTestQ();

            LogSource clientSource      = new LogSource("TestMSMQProg", new[] { msmqListener }, SourceLevels.All);
            LogSource distributorSource = new LogSource("TestMSMQProg", new[] { new MockTraceListener() }, SourceLevels.All);

            Dictionary <string, LogSource> traceSources = new Dictionary <string, LogSource>();

            this.writer = new LogWriter(new List <ILogFilter>(), traceSources, distributorSource, null, new LogSource("errors"), "General", false, false);
            Logger.SetLogWriter(this.writer);

            DistributorEventLogger eventLogger     = new DistributorEventLogger();
            MsmqLogDistributor     msmqDistributor = new MsmqLogDistributor(MsmqUtil.MessageQueuePath, eventLogger);

            msmqDistributor.StopReceiving = false;

            LogEntry logEntry = MsmqUtil.GetDefaultLogEntry();

            logEntry.Categories = new string[] { "MockCategoryOne" };
            logEntry.Message    = MsmqUtil.MsgBody;
            logEntry.Severity   = TraceEventType.Information;

            clientSource.TraceData(logEntry.Severity, 1, logEntry);

            msmqDistributor.CheckForMessages();

            Assert.AreEqual(1, MockTraceListener.Entries.Count);
            Assert.AreEqual(MsmqUtil.MsgBody, MockTraceListener.LastEntry.Message, "Body");
        }