<commit_before>﻿using Moq;
using NUnit.Framework;
using Serilog;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Logging;
using StackExchange.Profiling.Internal;
using Umbraco.Core;
using Umbraco.Core.Logging.Viewer;
using Umbraco.Tests.TestHelpers;

namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Logging
{
    [TestFixture]
    public class LogviewerTests
    {
        private ILogViewer _logViewer;

        const string _logfileName = "UmbracoTraceLog.UNITTEST.20181112.json";
        const string _searchfileName = "logviewer.searches.config.js";

        private string _newLogfilePath;
        private string _newLogfileDirPath;

        private string _newSearchfilePath;
        private string _newSearchfileDirPath;

        private LogTimePeriod _logTimePeriod = new LogTimePeriod(
            new DateTime(year: 2018, month: 11, day: 12, hour:0, minute:0, second:0),
            new DateTime(year: 2018, month: 11, day: 13, hour: 0, minute: 0, second: 0)
            );
        [OneTimeSetUp]
        public void Setup()
        {
            var testRoot = TestContext.CurrentContext.TestDirectory.Split("bin")[0];
            //Create an example JSON log file to check results
            //As a one time setup for all tets in this class/fixture
            var ioHelper = TestHelper.IOHelper;
            var hostingEnv = TestHelper.GetHostingEnvironment();

            var loggingConfiguration = TestHelper.GetLoggingConfiguration(hostingEnv);

            var exampleLogfilePath = Path.Combine(testRoot, "TestHelpers","Assets", _logfileName);
            _newLogfileDirPath = loggingConfiguration.LogDirectory;
            _newLogfilePath = Path.Combine(_newLogfileDirPath, _logfileName);

            var exampleSearchfilePath = Path.Combine(testRoot, "TestHelpers","Assets", _searchfileName);
            _newSearchfileDirPath = Path.Combine(hostingEnv.ApplicationPhysicalPath, @"Config");
            _newSearchfilePath = Path.Combine(_newSearchfileDirPath, _searchfileName);

            //Create/ensure Directory exists
            ioHelper.EnsurePathExists(_newLogfileDirPath);
            ioHelper.EnsurePathExists(_newSearchfileDirPath);

            //Copy the sample files
            File.Copy(exampleLogfilePath, _newLogfilePath, true);
            File.Copy(exampleSearchfilePath, _newSearchfilePath, true);

            var logger = Mock.Of<ILogger<SerilogJsonLogViewer>>();<commit_msg>Fix test for linux: config folder is lowercase<commit_after>﻿using Moq;
using NUnit.Framework;
using Serilog;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Logging;
using StackExchange.Profiling.Internal;
using Umbraco.Core;
using Umbraco.Core.Logging.Viewer;
using Umbraco.Tests.TestHelpers;

namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Logging
{
    [TestFixture]
    public class LogviewerTests
    {
        private ILogViewer _logViewer;

        const string _logfileName = "UmbracoTraceLog.UNITTEST.20181112.json";
        const string _searchfileName = "logviewer.searches.config.js";

        private string _newLogfilePath;
        private string _newLogfileDirPath;

        private string _newSearchfilePath;
        private string _newSearchfileDirPath;

        private LogTimePeriod _logTimePeriod = new LogTimePeriod(
            new DateTime(year: 2018, month: 11, day: 12, hour:0, minute:0, second:0),
            new DateTime(year: 2018, month: 11, day: 13, hour: 0, minute: 0, second: 0)
            );
        [OneTimeSetUp]
        public void Setup()
        {
            var testRoot = TestContext.CurrentContext.TestDirectory.Split("bin")[0];
            //Create an example JSON log file to check results
            //As a one time setup for all tets in this class/fixture
            var ioHelper = TestHelper.IOHelper;
            var hostingEnv = TestHelper.GetHostingEnvironment();

            var loggingConfiguration = TestHelper.GetLoggingConfiguration(hostingEnv);

            var exampleLogfilePath = Path.Combine(testRoot, "TestHelpers","Assets", _logfileName);
            _newLogfileDirPath = loggingConfiguration.LogDirectory;
            _newLogfilePath = Path.Combine(_newLogfileDirPath, _logfileName);

            var exampleSearchfilePath = Path.Combine(testRoot, "TestHelpers","Assets", _searchfileName);
            _newSearchfileDirPath = Path.Combine(hostingEnv.ApplicationPhysicalPath, @"config");
            _newSearchfilePath = Path.Combine(_newSearchfileDirPath, _searchfileName);

            //Create/ensure Directory exists
            ioHelper.EnsurePathExists(_newLogfileDirPath);
            ioHelper.EnsurePathExists(_newSearchfileDirPath);

            //Copy the sample files
            File.Copy(exampleLogfilePath, _newLogfilePath, true);
            File.Copy(exampleSearchfilePath, _newSearchfilePath, true);

            var logger = Mock.Of<ILogger<SerilogJsonLogViewer>>();
{'fraction_non_alphanumeric': 0.08258348330333934, 'fraction_numerical': 0.012397520495900819, 'mean_word_length': 3.133884297520661, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '536081', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1389, 'n_words': 318}