﻿using Common.Logging;
using NLog;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FinnAngelo.Tomfoolery.MiscTests
{
    public class LoggingTests
    {
        [Test]
        [Category("Logging: NLog Test")]
        public void GivenAnNlogLogger_WhenNLogTrace_ThenDoesntThrowException()
        {
            //Given
            Logger logger = NLog.LogManager.GetCurrentClassLogger();
            var now = DateTime.Now;
            var logMessage = String.Format("Test NLog - {0}", now);

            //When
            logger.Trace(logMessage);

            //Then
            var logName = String.Format("logs/{0:yyyy-MM-dd}.log", now);
            Assert.IsTrue(File.Exists(logName), "File Exists");

            var allLogText = File.ReadAllText(logName);
            Assert.IsTrue(allLogText.Contains(logMessage), "Log contains logmessage");        

        }

        [Test]
        [Category("Logging: Common.Logging Test")]
        public void GivenACommonLoggingNlogInterface_WhenNLogTrace_ThenDoesntThrowException()
        {
            //Given
            ILog log = Common.Logging.LogManager.GetLogger(this.GetType());
            var now = DateTime.Now;
            var logMessage = String.Format("Test Common.Logging - {0}", now);

            //When
            log.Trace(logMessage);

            //Then
            var logName = String.Format("logs/{0:yyyy-MM-dd}.log", now);
            Assert.IsTrue(File.Exists(logName), "File Exists");

            var allLogText = File.ReadAllText(logName);
            Assert.IsTrue(allLogText.Contains(logMessage), "Log contains logmessage");

        }
    }
}
