Пример #1
0
		public void SyslogLogger_TwoLoggers_WillNotInterefereWithEachOther()
		{
			var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);
			var logger1 = new SyslogLogger(FakeAppName + "1");
			var logger2 = new SyslogLogger(FakeAppName + "2");
			watcher.StartWatching();
			string[] messages = 
			{
				"First log message",
				"Second log message",
				"Third log message",
				"Fourth log message",
				"Fifth log message"
			};
			foreach (string s in messages)
			{
				logger1.Error(s);
				logger2.Error(s);
			}
			string[] data = watcher.WaitForData(10).ToArray();
			watcher.StopWatching();
			for (int i = 0; i < messages.Length; i++)
			{
				// Expect messages perfectly interleaved, logger1 followed by logger2 all five times
				string expectedAppName = FakeAppName + (i % 2 == 0 ? "1" : "2");
				Assert.That(data[i], Is.StringContaining(expectedAppName));
				Assert.That(data[i], Is.StringContaining(messages[i / 2]));
			}
		}
Пример #2
0
        public void SyslogLogger_TwoLogManyCalls_WillRunSequentially()
        {
            var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);
            var logger1 = new SyslogLogger(FakeAppName + "1");
            var logger2 = new SyslogLogger(FakeAppName + "2");

            watcher.StartWatching();
            string[] messages =
            {
                "First log message",
                "Second log message",
                "Third log message",
                "Fourth log message",
                "Fifth log message"
            };
            logger1.LogMany(SyslogPriority.Error, messages);
            logger2.LogMany(SyslogPriority.Error, messages);
            string[] data = watcher.WaitForData(10).ToArray();
            watcher.StopWatching();
            for (int i = 0; i < messages.Length; i++)
            {
                // Expect messages in sequence, logger1's five lines followed by logger2's five lines
                string expectedAppName = FakeAppName + (i / 5 == 0 ? "1" : "2");
                Assert.That(data[i], Is.StringContaining(expectedAppName));
                Assert.That(data[i], Is.StringContaining(messages[i % 5]));
            }
        }
Пример #3
0
        public void SyslogLogger_TwoLoggers_WillNotInterefereWithEachOther()
        {
            var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);
            var logger1 = new SyslogLogger(FakeAppName + "1");
            var logger2 = new SyslogLogger(FakeAppName + "2");

            watcher.StartWatching();
            string[] messages =
            {
                "First log message",
                "Second log message",
                "Third log message",
                "Fourth log message",
                "Fifth log message"
            };
            foreach (string s in messages)
            {
                logger1.Error(s);
                logger2.Error(s);
            }
            string[] data = watcher.WaitForData(10).ToArray();
            watcher.StopWatching();
            for (int i = 0; i < messages.Length; i++)
            {
                // Expect messages perfectly interleaved, logger1 followed by logger2 all five times
                string expectedAppName = FakeAppName + (i % 2 == 0 ? "1" : "2");
                Assert.That(data[i], Is.StringContaining(expectedAppName));
                Assert.That(data[i], Is.StringContaining(messages[i / 2]));
            }
        }
Пример #4
0
		public void SyslogLogger_WritesOneLine()
		{
			var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);
			var logger = new SyslogLogger(FakeAppName);
			watcher.StartWatching();
			logger.Error("This string should be in the results");
			IEnumerable<string> data = watcher.WaitForData();
			watcher.StopWatching();
			Assert.That(data, Has.Some.StringContaining("This string should be in the results"));
		}
		public void SyslogLogger_CatchesDivisionByZeroError()
		{
			var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);
			watcher.StartWatching();
			Thread errorThread = new Thread(DivideByZero);
			errorThread.Start();
			IEnumerable<string> data = watcher.WaitForData();
			Assert.That(data, Is.Not.Empty);
			Assert.That(data.First(), Is.StringContaining("Division by zero"));
		}
Пример #6
0
        public void SyslogLogger_WritesOneLine()
        {
            var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);
            var logger  = new SyslogLogger(FakeAppName);

            watcher.StartWatching();
            logger.Error("This string should be in the results");
            IEnumerable <string> data = watcher.WaitForData();

            watcher.StopWatching();
            Assert.That(data, Has.Some.StringContaining("This string should be in the results"));
        }
Пример #7
0
        public void SyslogLogger_CatchesDivisionByZeroError()
        {
            var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);

            watcher.StartWatching();
            Thread errorThread = new Thread(DivideByZero);

            errorThread.Start();
            IEnumerable <string> data = watcher.WaitForData();

            Assert.That(data, Is.Not.Empty);
            Assert.That(data.First(), Is.StringContaining("Division by zero"));
        }
Пример #8
0
		public void SyslogLogger_LogMany_WritesManyLines()
		{
			var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);
			var logger = new SyslogLogger(FakeAppName);
			watcher.StartWatching();
			string[] messages = 
			{
				"First log message",
				"Second log message",
				"Third log message",
				"Fourth log message",
				"Fifth log message"
			};
			logger.LogMany(SyslogPriority.Error, messages);
			string[] data = watcher.WaitForData(5).ToArray();
			watcher.StopWatching();
			for (int i = 0; i < messages.Length; i++)
				Assert.That(data[i], Is.StringContaining(messages[i]));
		}
Пример #9
0
        public void SyslogLogger_LogMany_WritesManyLines()
        {
            var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);
            var logger  = new SyslogLogger(FakeAppName);

            watcher.StartWatching();
            string[] messages =
            {
                "First log message",
                "Second log message",
                "Third log message",
                "Fourth log message",
                "Fifth log message"
            };
            logger.LogMany(SyslogPriority.Error, messages);
            string[] data = watcher.WaitForData(5).ToArray();
            watcher.StopWatching();
            for (int i = 0; i < messages.Length; i++)
            {
                Assert.That(data[i], Is.StringContaining(messages[i]));
            }
        }
Пример #10
0
		public void SyslogLogger_TwoLogManyCalls_WillRunSequentially()
		{
			var watcher = new SyslogWatcher(FakeAppName, SyslogFileToWatch);
			var logger1 = new SyslogLogger(FakeAppName + "1");
			var logger2 = new SyslogLogger(FakeAppName + "2");
			watcher.StartWatching();
			string[] messages = 
			{
				"First log message",
				"Second log message",
				"Third log message",
				"Fourth log message",
				"Fifth log message"
			};
			logger1.LogMany(SyslogPriority.Error, messages);
			logger2.LogMany(SyslogPriority.Error, messages);
			string[] data = watcher.WaitForData(10).ToArray();
			watcher.StopWatching();
			for (int i = 0; i < messages.Length; i++)
			{
				// Expect messages in sequence, logger1's five lines followed by logger2's five lines
				string expectedAppName = FakeAppName + (i / 5 == 0 ? "1" : "2");
				Assert.That(data[i], Is.StringContaining(expectedAppName));
				Assert.That(data[i], Is.StringContaining(messages[i % 5]));
			}
		}