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 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 LogMessage()
        {
            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";

            DateTime startLogging = DateTime.UtcNow;

            loggingService.LogMessage(title, message, LogLevel.Debug);
            DateTime endLogging = DateTime.UtcNow;

            Assert.Single(cachingService);

            string fullLogName = cachingService.EnumerateDictionary().Single().Key;

            Assert.NotNull(fullLogName);

            Log <object> log = (Log <object>)cachingService.EnumerateDictionary().Single().Value.UntypedValue;

            Assert.NotNull(log);
            Assert.Null(log.Target);
            Assert.True(log.TimeStamp >= startLogging.AddMilliseconds(-5) && log.TimeStamp <= endLogging.AddMilliseconds(5));
            Assert.Equal(title, log.Title);
            Assert.Equal(message, log.Message);
            Assert.Equal(LogLevel.Debug, log.LogLevel);
            Assert.Null(log.Exception);
            Assert.Equal("Message Log", log.Description);
        }
        public void TestBasicEnumeration()
        {
            CacheLoggingService       service = TestMemoryCacheProvider.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");
            ILogBaseEnumerable collection = service.GetLogs();

            Assert.NotEmpty(collection);
            foreach (LogBase log in collection)
            {
                Assert.NotNull(log);
            }
            int collectionCount = collection.Count();

            Assert.Equal(2, collectionCount);
        }
        public void LogMessageWithObject()
        {
            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
            };

            DateTime startLogging = DateTime.UtcNow;

            loggingService.LogMessage(title, original, LogLevel.Debug, message);
            DateTime endLogging = DateTime.UtcNow;

            Assert.Single(cachingService);

            string fullLogName = cachingService.EnumerateDictionary().Single().Key;

            Assert.NotNull(fullLogName);

            Log <Foobar> log = (Log <Foobar>)cachingService.EnumerateDictionary().Single().Value.UntypedValue;

            string description = "Message Log with object - " + typeof(Foobar).FullName;

            Assert.NotNull(log);
            Assert.True(log.TimeStamp >= startLogging.AddMilliseconds(-5) && log.TimeStamp <= endLogging.AddMilliseconds(5));
            Assert.Equal(title, log.Title);
            Assert.Equal(message, log.Message);
            Assert.Equal(LogLevel.Debug, log.LogLevel);
            Assert.Null(log.Exception);
            Assert.Equal(description, log.Description);

            Assert.NotNull(log.Target);
            Assert.Equal(original.Foo, log.Target.Foo);
            // The memory caching service never serializes or deserializes so the non-serialized values won't change
            //Assert.Equal(0, log.Target.Bar);
        }
        public void LogTest()
        {
            MemoryCachingService cachingService = new MemoryCachingService(TimeSpan.FromMinutes(5));
            Json serializationService           = new Json();
            CacheLoggingService loggingService  = new CacheLoggingService(cachingService, serializationService, _partSeperator);

            DateTime startLogging = DateTime.UtcNow;

            loggingService.LogMessage("Test Log", "A test log", LogLevel.Debug);
            DateTime endLogging = DateTime.UtcNow;

            Assert.Single(cachingService);

            string fullLogName = cachingService.EnumerateDictionary().Single().Key;

            Assert.StartsWith(LogLevel.Debug.ToString() + _partSeperator, fullLogName);

            string   timestampString = fullLogName.Split('_')[1];
            DateTime timeStamp       = DateTime.FromFileTimeUtc(long.Parse(timestampString));

            Assert.True(timeStamp >= startLogging.AddMilliseconds(-5) && timeStamp <= endLogging.AddMilliseconds(5));
        }