public void TestBasicEnumeration()
        {
            CacheLoggingService       service = GetLogsService();
            Tuple <Foobar, BarredFoo> objects = CreateObjects();

            service.LogMessage("Logging object 1", objects.Item1, LogLevel.Debug, "Foobar log");
            service.LogMessage("Logging object 2", objects.Item2, LogLevel.Debug, "BarredFoo log");
            ILogEnumerable <Foobar> collection = service.GetLogs <Foobar>();

            Assert.NotEmpty(collection);
            foreach (Log <Foobar> log in collection)
            {
                Assert.NotNull(log);
            }
            int collectionCount = collection.Count();

            Assert.Equal(1, collectionCount);

            ILogEnumerable <BarredFoo> collection2 = service.GetLogs <BarredFoo>();

            Assert.NotEmpty(collection);
            foreach (Log <BarredFoo> log in collection2)
            {
                Assert.NotNull(log);
            }
            int collectionCount2 = collection2.Count();

            Assert.Equal(1, collectionCount2);
        }
        public void TestNonGenricEnumerator()
        {
            CacheLoggingService       service = GetLogsService();
            Tuple <Foobar, BarredFoo> objects = CreateObjects();

            service.LogMessage("Logging object 1", objects.Item1, LogLevel.Debug, "Foobar log");
            service.LogMessage("Logging object 2", objects.Item2, LogLevel.Debug, "BarredFoo log");
            ILogEnumerable <Foobar> collection = service.GetLogs <Foobar>();

            Log <Foobar>[] logs  = collection.ToArray();
            int            index = 0;

            foreach (Log <Foobar> log in ((IEnumerable)collection))
            {
                Assert.Equal(log, logs[index]);
                index++;
            }
            int collectionCount = collection.Count();

            Assert.Equal(1, collectionCount);

            index = 0;
            foreach (Log <Foobar> log in ((IEnumerable)collection))
            {
                Assert.Equal(log, logs[index]);
                index++;
            }
        }
        public void TestCachedEnumeration()
        {
            TextLoggingService service = GetLogsService();

            ClearTestLogDirectory(service);
            Tuple <Foobar, BarredFoo> objects = CreateObjects();

            service.LogMessage("Logging object 1", objects.Item1, LogLevel.Debug, "Foobar log");
            service.LogMessage("Logging object 2", objects.Item2, LogLevel.Debug, "BarredFoo log");
            ILogEnumerable <object> collection = service.GetLogs <object>();

            Log <object>[] logs  = collection.ToArray();
            int            index = 0;

            foreach (Log <object> log in collection)
            {
                Assert.Equal(log, logs[index]);
                index++;
            }
            int collectionCount = collection.Count();

            Assert.Equal(2, collectionCount);

            index = 0;
            foreach (Log <object> log in collection)
            {
                Assert.Equal(log, logs[index]);
                index++;
            }

            ClearTestLogDirectory(service);
        }
        public void GetLogsGenericTest()
        {
            Mock <ILogEnumerable <object> > logsProxy      = new Mock <ILogEnumerable <object> >(MockBehavior.Strict);
            ILogEnumerable <object>         logs           = logsProxy.Object;
            Mock <ILoggingService>          loggingService = new Mock <ILoggingService>(MockBehavior.Strict);

            loggingService.Setup(x => x.GetLogs <object>()).Returns(logs);
            ILogEnumerable <object> result = loggingService.Object.GetLogs <object>();

            Assert.NotNull(result);
            // use strict equal to do a pointer comparison
            Assert.StrictEqual(logs, result);
        }
        public void TestBasicEnumeration()
        {
            TextLoggingService service = GetLogsService();

            ClearTestLogDirectory(service);
            Tuple <Foobar, BarredFoo> objects = CreateObjects();

            service.LogMessage("Logging object 1", objects.Item1, LogLevel.Debug, "Foobar log");
            service.LogMessage("Logging object 2", objects.Item2, LogLevel.Debug, "BarredFoo log");
            ILogEnumerable <object> collection = service.GetLogs <object>();

            Assert.NotEmpty(collection);
            foreach (Log <object> log in collection)
            {
                Assert.NotNull(log);
            }
            int collectionCount = collection.Count();

            Assert.Equal(2, collectionCount);

            ClearTestLogDirectory(service);
        }
 /// <param name="source">The source that the enumerable should represent</param>
 public CacheLogEnumerable(ILogEnumerable <T> source)
     : base(source)
 {
 }
        public void GetLogsTest()
        {
            MemoryCachingService cachingService = new MemoryCachingService(TimeSpan.FromMinutes(5));
            Json serializationService           = new Json();
            CacheLoggingService loggingService  = new CacheLoggingService(cachingService, serializationService, _partSeperator);

            const string title    = "Test Log";
            const string message  = "A test log";
            Foobar       original = new Foobar
            {
                Foo = 4,
                Bar = 6
            };

            InvalidOperationException exception;

            try
            {
                throw new InvalidOperationException(title);
            }
            catch (InvalidOperationException ex)
            {
                exception = ex;
            }

            string       description = "Manual Exception Log - " + message;
            Log <Foobar> originalLog = new Log <Foobar>
            {
                Target      = original,
                TimeStamp   = DateTime.UtcNow,
                Title       = title,
                Message     = message,
                LogLevel    = LogLevel.Info,
                Exception   = new SerializableException(exception),
                Description = description
            };

            loggingService.Log(originalLog);

            ILogEnumerable <Foobar> logs = loggingService.GetLogs <Foobar>();

            Assert.NotNull(logs);
            Assert.NotEmpty(logs);
            Assert.Single(logs);

            Log <Foobar> log = logs.Single();

            Assert.NotNull(log);
            Assert.True(log.TimeStamp >= log.TimeStamp.AddMilliseconds(-.5) && log.TimeStamp <= log.TimeStamp.AddMilliseconds(.5));
            Assert.Equal(originalLog.Title, log.Title);
            Assert.Equal(originalLog.Message, log.Message);
            Assert.Equal(originalLog.LogLevel, log.LogLevel);
            Assert.Equal(originalLog.Description, log.Description);

            Assert.NotNull(log.Target);

            Assert.NotNull(log.Exception);
            Assert.Equal(typeof(SerializableException), log.Exception.GetType());
            Assert.Equal(title, log.Exception.Message);
            Assert.Equal(originalLog.Exception.Message, log.Exception.Message);

            Assert.Equal(log, logs.First());
        }
 /// <param name="source">The source that the enumerable should represent</param>
 public LogEnumerableBase(ILogEnumerable <T> source)
 {
     Source = source;
 }
Exemplo n.º 9
0
 /// <param name="source">The source that the enumerable should represent</param>
 public TextLogEnumerable(ILogEnumerable <T> source)
     : base(source)
 {
 }