public void TestNonGenricEnumerator()
        {
            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 ((IEnumerable)collection))
            {
                Assert.Equal(log, logs[index]);
                index++;
            }
            int collectionCount = collection.Count();

            Assert.Equal(2, collectionCount);

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

            ClearTestLogDirectory(service);
        }
        public void LogTest()
        {
            Json serializationService         = new Json();
            TextLoggingService loggingService = new TextLoggingService(Path, serializationService, LogExtension);

            ClearTestLogDirectory(loggingService);

            DateTime startLogging = DateTime.UtcNow;

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

            IEnumerable <string> logs = Directory.EnumerateFiles(Path);

            Assert.Single(logs);

            string fullLogName = logs.Single();

            Assert.StartsWith(Path, fullLogName);

            string logName = fullLogName.Split('\\', '/').Last();

            Assert.StartsWith(LogLevel.Debug + "_", logName);
            Assert.EndsWith(LogExtension, logName);

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

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

            File.Delete(logName);
            Assert.False(File.Exists(logName));
            ClearTestLogDirectory(loggingService);
        }
        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);
        }
        public void LogMessageWithObject()
        {
            Json serializationService         = new Json();
            TextLoggingService loggingService = new TextLoggingService(Path, serializationService, LogExtension);

            ClearTestLogDirectory(loggingService);

            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;

            IEnumerable <string> logs = Directory.EnumerateFiles(Path);

            Assert.Single(logs);

            string fullLogName   = logs.Single();
            string fullLogString = File.ReadAllText(fullLogName);

            Assert.NotNull(fullLogString);

            Log <Foobar> log = serializationService.DeserializeObject <Log <Foobar> >(fullLogString);

            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);
            Assert.Equal(0, log.Target.Bar);

            ClearTestLogDirectory(loggingService);
        }
        public void LogMessage()
        {
            Json serializationService         = new Json();
            TextLoggingService loggingService = new TextLoggingService(Path, serializationService, LogExtension);

            ClearTestLogDirectory(loggingService);

            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;

            IEnumerable <string> logs = Directory.EnumerateFiles(Path);

            Assert.Single(logs);

            string fullLogName   = logs.Single();
            string fullLogString = File.ReadAllText(fullLogName);

            Assert.NotNull(fullLogString);

            Log <object> log = serializationService.DeserializeObject <Log <object> >(fullLogString);

            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);

            ClearTestLogDirectory(loggingService);
        }