<commit_before>﻿// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Platform;
using osu.Game.IPC;
using osu.Framework.Allocation;
using osu.Game.Beatmaps;

namespace osu.Game.Tests.Beatmaps.IO
{
    [TestFixture]
    public class ImportBeatmapTest
    {
        private const string osz_path = @"../../../osu-resources/osu.Game.Resources/Beatmaps/241526 Soleily - Renatus.osz";

        [Test]
        public void TestImportWhenClosed()
        {
            //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
            using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportWhenClosed"))
            {
                try
                {
                    var osu = loadOsu(host);

                    var temp = prepareTempCopy(osz_path);

                    Assert.IsTrue(File.Exists(temp));

                    osu.Dependencies.Get<BeatmapManager>().Import(temp);

                    ensureLoaded(osu);

                    waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
                }
                finally
                {
                    host.Exit();
                }
            }
        }

        [Test]
        public void TestImportThenDelete()
        {
            //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
            using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenDelete"))
            {
                try
                {
                    var osu = loadOsu(host);

                    var temp = prepareTempCopy(osz_path);
                    Assert.IsTrue(File.Exists(temp));

                    var manager = osu.Dependencies.Get<BeatmapManager>();

                    var imported = manager.Import(temp);

                    ensureLoaded(osu);

                    manager.Delete(imported.First());

                    Assert.IsTrue(manager.GetAllUsableBeatmapSets().Count == 0);
                    Assert.IsTrue(manager.QueryBeatmapSets(_ => true).ToList().Count == 1);
                    Assert.IsTrue(manager.QueryBeatmapSets(_ => true).First().DeletePending);

                    waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
                }
                finally
                {
                    host.Exit();
                }
            }
        }

        [Test]
        public void TestImportThenDeleteThenImport()
        {
            //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
            using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenDeleteThenImport"))
            {
                try
                {
                    var osu = loadOsu(host);

                    var temp = prepareTempCopy(osz_path);
                    Assert.IsTrue(File.Exists(temp));

                    var manager = osu.Dependencies.Get<BeatmapManager>();

                    var imported = manager.Import(temp);

                    ensureLoaded(osu);

                    manager.Delete(imported.First());

                    Assert.IsTrue(manager.GetAllUsableBeatmapSets().Count == 0);
                    Assert.IsTrue(manager.QueryBeatmapSets(_ => true).ToList().Count() == 1);
                    Assert.IsTrue(manager.QueryBeatmapSets(_ => true).First().DeletePending);

                    temp = prepareTempCopy(osz_path);
                    Assert.IsTrue(File.Exists(temp));
                    var importedSecondTime = manager.Import(temp);

                    ensureLoaded(osu);<commit_msg>Count() -> Count<commit_after>﻿// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Platform;
using osu.Game.IPC;
using osu.Framework.Allocation;
using osu.Game.Beatmaps;

namespace osu.Game.Tests.Beatmaps.IO
{
    [TestFixture]
    public class ImportBeatmapTest
    {
        private const string osz_path = @"../../../osu-resources/osu.Game.Resources/Beatmaps/241526 Soleily - Renatus.osz";

        [Test]
        public void TestImportWhenClosed()
        {
            //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
            using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportWhenClosed"))
            {
                try
                {
                    var osu = loadOsu(host);

                    var temp = prepareTempCopy(osz_path);

                    Assert.IsTrue(File.Exists(temp));

                    osu.Dependencies.Get<BeatmapManager>().Import(temp);

                    ensureLoaded(osu);

                    waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
                }
                finally
                {
                    host.Exit();
                }
            }
        }

        [Test]
        public void TestImportThenDelete()
        {
            //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
            using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenDelete"))
            {
                try
                {
                    var osu = loadOsu(host);

                    var temp = prepareTempCopy(osz_path);
                    Assert.IsTrue(File.Exists(temp));

                    var manager = osu.Dependencies.Get<BeatmapManager>();

                    var imported = manager.Import(temp);

                    ensureLoaded(osu);

                    manager.Delete(imported.First());

                    Assert.IsTrue(manager.GetAllUsableBeatmapSets().Count == 0);
                    Assert.IsTrue(manager.QueryBeatmapSets(_ => true).ToList().Count == 1);
                    Assert.IsTrue(manager.QueryBeatmapSets(_ => true).First().DeletePending);

                    waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
                }
                finally
                {
                    host.Exit();
                }
            }
        }

        [Test]
        public void TestImportThenDeleteThenImport()
        {
            //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
            using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenDeleteThenImport"))
            {
                try
                {
                    var osu = loadOsu(host);

                    var temp = prepareTempCopy(osz_path);
                    Assert.IsTrue(File.Exists(temp));

                    var manager = osu.Dependencies.Get<BeatmapManager>();

                    var imported = manager.Import(temp);

                    ensureLoaded(osu);

                    manager.Delete(imported.First());

                    Assert.IsTrue(manager.GetAllUsableBeatmapSets().Count == 0);
                    Assert.IsTrue(manager.QueryBeatmapSets(_ => true).ToList().Count == 1);
                    Assert.IsTrue(manager.QueryBeatmapSets(_ => true).First().DeletePending);

                    temp = prepareTempCopy(osz_path);
                    Assert.IsTrue(File.Exists(temp));
                    var importedSecondTime = manager.Import(temp);

                    ensureLoaded(osu);
{'fraction_non_alphanumeric': 0.09780564263322884, 'fraction_numerical': 0.006520376175548589, 'mean_word_length': 1.618516086671044, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 2, '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': '3306136', 'n_tokens_mistral': 2143, 'n_tokens_neox': 1938, 'n_words': 416}