<commit_before>﻿using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Tests.Integration.Implementations;
using Umbraco.Tests.Integration.Testing;
using Umbraco.Tests.Testing;

namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories
{
    [TestFixture]
    [UmbracoTest(Database = UmbracoTestOptions.Database.None, Logger = UmbracoTestOptions.Logger.Console)]
    public class StylesheetRepositoryTest : UmbracoIntegrationTest
    {
        private IFileSystems _fileSystems;
        private IFileSystem _fileSystem;

        private IIOHelper IOHelper => GetRequiredService<IIOHelper>();
        private IHostingEnvironment HostingEnvironment => GetRequiredService<IHostingEnvironment>();

        [SetUp]
        public void SetUpFileSystem()
        {
            _fileSystems = Mock.Of<IFileSystems>();
            var path = HostingEnvironment.MapPathWebRoot(GlobalSettings.UmbracoCssPath);
            _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory.CreateLogger<PhysicalFileSystem>(), path, "/css");
            Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem);
            var stream = CreateStream("body {background:#EE7600; color:#FFF;}");
            _fileSystem.AddFile("styles.css", stream);
        }

        [TearDown]
        public void TearDownFileSystem()
        {
            //Delete all files
            Purge((PhysicalFileSystem) _fileSystem, "");
            _fileSystem = null;
        }

        private IStylesheetRepository CreateRepository()
        {
            var globalSettings = new GlobalSettings();
            return new StylesheetRepository(Mock.Of<ILogger<StylesheetRepository>>(), _fileSystems, IOHelper, Microsoft.Extensions.Options.Options.Create(globalSettings));
        }

        [Test]
        public void Can_Instantiate_Repository()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                // Act
                var repository = CreateRepository();


                // Assert
                Assert.That(repository, Is.Not.Null);
            }
        }

        [Test]
        public void Can_Perform_Add()
        {
            // Arrange
            using (ScopeProvider.CreateScope())<commit_msg>Add temp logging, to debug azure pipeline<commit_after>﻿using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Tests.Integration.Implementations;
using Umbraco.Tests.Integration.Testing;
using Umbraco.Tests.Testing;

namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories
{
    [TestFixture]
    [UmbracoTest(Database = UmbracoTestOptions.Database.None, Logger = UmbracoTestOptions.Logger.Console)]
    public class StylesheetRepositoryTest : UmbracoIntegrationTest
    {
        private IFileSystems _fileSystems;
        private IFileSystem _fileSystem;

        private IIOHelper IOHelper => GetRequiredService<IIOHelper>();
        private IHostingEnvironment HostingEnvironment => GetRequiredService<IHostingEnvironment>();

        [SetUp]
        public void SetUpFileSystem()
        {
            _fileSystems = Mock.Of<IFileSystems>();
            var path = HostingEnvironment.MapPathWebRoot(GlobalSettings.UmbracoCssPath);
            _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, GetRequiredService<ILogger<PhysicalFileSystem>>(), path, "/css");
            Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem);
            var stream = CreateStream("body {background:#EE7600; color:#FFF;}");
            _fileSystem.AddFile("styles.css", stream);
        }

        [TearDown]
        public void TearDownFileSystem()
        {
            //Delete all files
            Purge((PhysicalFileSystem) _fileSystem, "");
            _fileSystem = null;
        }

        private IStylesheetRepository CreateRepository()
        {
            var globalSettings = new GlobalSettings();
            return new StylesheetRepository(GetRequiredService<ILogger<StylesheetRepository>>(), _fileSystems, IOHelper, Microsoft.Extensions.Options.Options.Create(globalSettings));
        }

        [Test]
        public void Can_Instantiate_Repository()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                // Act
                var repository = CreateRepository();


                // Assert
                Assert.That(repository, Is.Not.Null);
            }
        }

        [Test]
        public void Can_Perform_Add()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
{'fraction_non_alphanumeric': 0.0931501693639443, 'fraction_numerical': 0.0015054572826496049, 'mean_word_length': 2.7829181494661923, 'pattern_counts': {'":': 0, '<': 16, '<?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': '2283017', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1432, 'n_words': 263}