<commit_before>﻿using AutofacContrib.NSubstitute;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NSpec.VsAdapter.Logging;
using NSpec.VsAdapter.Settings;
using NSubstitute;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NSpec.VsAdapter.UnitTests.Logging
{
    [TestFixture]
    [Category("OutputLogger")]
    public abstract class OutputLogger_desc_base
    {
        protected OutputLogger logger;

        protected AutoSubstitute autoSubstitute;
        protected IMessageLogger messageLogger;
        protected ISettingsRepository settingsRepo;

        protected const string someMessage = "whatever";

        [SetUp]
        public virtual void before_each()
        {
            autoSubstitute = new AutoSubstitute();

            messageLogger = autoSubstitute.Resolve<IMessageLogger>();

            settingsRepo = autoSubstitute.Resolve<ISettingsRepository>();
        }

        [TearDown]
        public virtual void after_each()
        {
            autoSubstitute.Dispose();
        }

        protected void VerifyMessageSent(LogMethod logMethod, TestMessageLevel messageLevel)
        {
            logMethod(someMessage);

            messageLogger.Received(1).SendMessage(messageLevel, Arg.Any<string>());
        }

        protected void VerifyMessageNotSent(LogMethod logMethod)
        {
            logMethod(someMessage);

            messageLogger.DidNotReceive().SendMessage(Arg.Any<TestMessageLevel>(), Arg.Any<string>());
        }

        protected delegate void LogMethod(string message);
    }

    public class OutputLogger_when_min_level_is_debug : OutputLogger_desc_base
    {
        public override void before_each()
        {
            base.before_each();

            settingsRepo.LogLevel.Returns("Debug");

            logger = autoSubstitute.Resolve<OutputLogger>();
        }

        [Test]
        public void it_should_report_debug()
        {
            VerifyMessageSent(logger.Debug, TestMessageLevel.Informational);
        }

        [Test]
        public void it_should_report_info()
        {
            VerifyMessageSent(logger.Info, TestMessageLevel.Informational);
        }

        [Test]
        public void it_should_report_warning()
        {
            VerifyMessageSent(logger.Warn, TestMessageLevel.Warning);
        }

        [Test]
        public void it_should_report_error()
        {
            VerifyMessageSent(logger.Error, TestMessageLevel.Error);
        }
    }

    public class OutputLogger_when_min_level_is_info : OutputLogger_desc_base
    {
        public override void before_each()
        {
            base.before_each();

            settingsRepo.LogLevel.Returns("Info");

            logger = autoSubstitute.Resolve<OutputLogger>();
        }

        [Test]
        public void it_should_not_report_debug()
        {
            VerifyMessageNotSent(logger.Debug);
        }

        [Test]
        public void it_should_report_info()
        {
            VerifyMessageSent(logger.Info, TestMessageLevel.Informational);
        }

        [Test]
        public void it_should_report_warning()
        {
            VerifyMessageSent(logger.Warn, TestMessageLevel.Warning);
        }

        [Test]
        public void it_should_report_error()
        {
            VerifyMessageSent(logger.Error, TestMessageLevel.Error);
        }
    }

    public class OutputLogger_when_min_level_is_warning : OutputLogger_desc_base
    {
        public override void before_each()
        {
            base.before_each();

            settingsRepo.LogLevel.Returns("Warning");

            logger = autoSubstitute.Resolve<OutputLogger>();
        }

        [Test]
        public void it_should_not_report_debug()
        {
            VerifyMessageNotSent(logger.Debug);
        }

        [Test]
        public void it_should_not_report_info()
        {
            VerifyMessageNotSent(logger.Info);
        }

        [Test]
        public void it_should_report_warning()
        {
            VerifyMessageSent(logger.Warn, TestMessageLevel.Warning);
        }

        [Test]
        public void it_should_report_error()
        {
            VerifyMessageSent(logger.Error, TestMessageLevel.Error);
        }
    }

    public class OutputLogger_when_min_level_is_error : OutputLogger_desc_base
    {
        public override void before_each()
        {
            base.before_each();

            settingsRepo.LogLevel.Returns("Error");

            logger = autoSubstitute.Resolve<OutputLogger>();
        }

        [Test]
        public void it_should_not_report_debug()
        {
            VerifyMessageNotSent(logger.Debug);
        }

        [Test]<commit_msg>Add unit tests on trace logging level<commit_after>﻿using AutofacContrib.NSubstitute;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NSpec.VsAdapter.Logging;
using NSpec.VsAdapter.Settings;
using NSubstitute;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NSpec.VsAdapter.UnitTests.Logging
{
    [TestFixture]
    [Category("OutputLogger")]
    public abstract class OutputLogger_desc_base
    {
        protected OutputLogger logger;

        protected AutoSubstitute autoSubstitute;
        protected IMessageLogger messageLogger;
        protected ISettingsRepository settingsRepo;

        protected const string someMessage = "whatever";

        [SetUp]
        public virtual void before_each()
        {
            autoSubstitute = new AutoSubstitute();

            messageLogger = autoSubstitute.Resolve<IMessageLogger>();

            settingsRepo = autoSubstitute.Resolve<ISettingsRepository>();
        }

        [TearDown]
        public virtual void after_each()
        {
            autoSubstitute.Dispose();
        }

        protected void VerifyMessageSent(LogMethod logMethod, TestMessageLevel messageLevel)
        {
            logMethod(someMessage);

            messageLogger.Received(1).SendMessage(messageLevel, Arg.Any<string>());
        }

        protected void VerifyMessageNotSent(LogMethod logMethod)
        {
            logMethod(someMessage);

            messageLogger.DidNotReceive().SendMessage(Arg.Any<TestMessageLevel>(), Arg.Any<string>());
        }

        protected delegate void LogMethod(string message);
    }

    public class OutputLogger_when_min_level_is_trace : OutputLogger_desc_base
    {
        public override void before_each()
        {
            base.before_each();

            settingsRepo.LogLevel.Returns("Trace");

            logger = autoSubstitute.Resolve<OutputLogger>();
        }

        [Test]
        public void it_should_report_trace()
        {
            VerifyMessageSent(logger.Trace, TestMessageLevel.Informational);
        }

        [Test]
        public void it_should_report_debug()
        {
            VerifyMessageSent(logger.Debug, TestMessageLevel.Informational);
        }

        [Test]
        public void it_should_report_info()
        {
            VerifyMessageSent(logger.Info, TestMessageLevel.Informational);
        }

        [Test]
        public void it_should_report_warning()
        {
            VerifyMessageSent(logger.Warn, TestMessageLevel.Warning);
        }

        [Test]
        public void it_should_report_error()
        {
            VerifyMessageSent(logger.Error, TestMessageLevel.Error);
        }
    }

    public class OutputLogger_when_min_level_is_debug : OutputLogger_desc_base
    {
        public override void before_each()
        {
            base.before_each();

            settingsRepo.LogLevel.Returns("Debug");

            logger = autoSubstitute.Resolve<OutputLogger>();
        }

        [Test]
        public void it_should_not_report_trace()
        {
            VerifyMessageNotSent(logger.Trace);
        }

        [Test]
        public void it_should_report_debug()
        {
            VerifyMessageSent(logger.Debug, TestMessageLevel.Informational);
        }

        [Test]
        public void it_should_report_info()
        {
            VerifyMessageSent(logger.Info, TestMessageLevel.Informational);
        }

        [Test]
        public void it_should_report_warning()
        {
            VerifyMessageSent(logger.Warn, TestMessageLevel.Warning);
        }

        [Test]
        public void it_should_report_error()
        {
            VerifyMessageSent(logger.Error, TestMessageLevel.Error);
        }
    }

    public class OutputLogger_when_min_level_is_info : OutputLogger_desc_base
    {
        public override void before_each()
        {
            base.before_each();

            settingsRepo.LogLevel.Returns("Info");

            logger = autoSubstitute.Resolve<OutputLogger>();
        }

        [Test]
        public void it_should_not_report_trace()
        {
            VerifyMessageNotSent(logger.Trace);
        }

        [Test]
        public void it_should_not_report_debug()
        {
            VerifyMessageNotSent(logger.Debug);
        }

        [Test]
        public void it_should_report_info()
        {
            VerifyMessageSent(logger.Info, TestMessageLevel.Informational);
        }

        [Test]
        public void it_should_report_warning()
        {
            VerifyMessageSent(logger.Warn, TestMessageLevel.Warning);
        }

        [Test]
        public void it_should_report_error()
        {
            VerifyMessageSent(logger.Error, TestMessageLevel.Error);
        }
    }

    public class OutputLogger_when_min_level_is_warning : OutputLogger_desc_base
    {
        public override void before_each()
        {
            base.before_each();

            settingsRepo.LogLevel.Returns("Warning");

            logger = autoSubstitute.Resolve<OutputLogger>();
        }

        [Test]
        public void it_should_not_report_trace()
        {
            VerifyMessageNotSent(logger.Trace);
        }

        [Test]
        public void it_should_not_report_debug()
        {
            VerifyMessageNotSent(logger.Debug);
        }

        [Test]
        public void it_should_not_report_info()
        {
            VerifyMessageNotSent(logger.Info);
        }

        [Test]
        public void it_should_report_warning()
        {
            VerifyMessageSent(logger.Warn, TestMessageLevel.Warning);
        }

        [Test]
        public void it_should_report_error()
        {
            VerifyMessageSent(logger.Error, TestMessageLevel.Error);
        }
    }

    public class OutputLogger_when_min_level_is_error : OutputLogger_desc_base
    {
        public override void before_each()
        {
            base.before_each();

            settingsRepo.LogLevel.Returns("Error");

            logger = autoSubstitute.Resolve<OutputLogger>();
        }

        [Test]
        public void it_should_not_report_trace()
        {
            VerifyMessageNotSent(logger.Trace);
        }

        [Test]
        public void it_should_not_report_debug()
        {
            VerifyMessageNotSent(logger.Debug);
        }

        [Test]
{'fraction_non_alphanumeric': 0.07976116210676411, 'fraction_numerical': 0.00017823723375813208, 'mean_word_length': 2.0957241379310343, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3636716', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2947, 'n_words': 485}