<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.IO;
using System.Reflection;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Testing;
using osu.Game.Beatmaps;

namespace osu.Game.Tests.Visual
{
    public abstract class OsuTestCase : TestCase
    {
        protected GameBeatmap Beatmap { get; private set; }

        private DependencyContainer dependencies;

        protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
        {
            // The beatmap is constructed here rather than load() because our children get dependencies injected before our load() runs
            Beatmap = new GameBeatmap(new DummyWorkingBeatmap(), parent.Get<AudioManager>());

            dependencies = new DependencyContainer(parent);

            dependencies.CacheAs<IGameBeatmap>(Beatmap);
            dependencies.Cache(Beatmap);

            return dependencies;
        }

        public override void Cleanup()
        {
            base.Cleanup();

            if (Beatmap != null)
            {
                Beatmap.Disabled = true;
                Beatmap.Value.Track.Stop();
            }
        }

        protected override ITestCaseTestRunner CreateRunner() => new OsuTestCaseTestRunner();

        public class OsuTestCaseTestRunner : OsuGameBase, ITestCaseTestRunner
        {
            protected override string MainResourceFile => File.Exists(base.MainResourceFile) ? base.MainResourceFile : Assembly.GetExecutingAssembly().Location;

            private TestCaseTestRunner.TestRunner runner;

            protected override void LoadAsyncComplete()
            {
                // this has to be run here rather than LoadComplete because
                // TestCase.cs is checking the IsLoaded state (on another thread) and expects
                // the runner to be loaded at that point.
                Add(runner = new TestCaseTestRunner.TestRunner());<commit_msg>Move beatmap cleanup to Dispose()<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.IO;
using System.Reflection;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Testing;
using osu.Game.Beatmaps;

namespace osu.Game.Tests.Visual
{
    public abstract class OsuTestCase : TestCase
    {
        protected GameBeatmap Beatmap { get; private set; }

        private DependencyContainer dependencies;

        protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
        {
            // The beatmap is constructed here rather than load() because our children get dependencies injected before our load() runs
            Beatmap = new GameBeatmap(new DummyWorkingBeatmap(), parent.Get<AudioManager>());

            dependencies = new DependencyContainer(parent);

            dependencies.CacheAs<IGameBeatmap>(Beatmap);
            dependencies.Cache(Beatmap);

            return dependencies;
        }

        protected override void Dispose(bool isDisposing)
        {
            base.Dispose(isDisposing);

            if (Beatmap != null)
            {
                Beatmap.Disabled = true;
                Beatmap.Value.Track.Stop();
            }
        }

        protected override ITestCaseTestRunner CreateRunner() => new OsuTestCaseTestRunner();

        public class OsuTestCaseTestRunner : OsuGameBase, ITestCaseTestRunner
        {
            protected override string MainResourceFile => File.Exists(base.MainResourceFile) ? base.MainResourceFile : Assembly.GetExecutingAssembly().Location;

            private TestCaseTestRunner.TestRunner runner;

            protected override void LoadAsyncComplete()
            {
                // this has to be run here rather than LoadComplete because
                // TestCase.cs is checking the IsLoaded state (on another thread) and expects
                // the runner to be loaded at that point.
                Add(runner = new TestCaseTestRunner.TestRunner());
{'fraction_non_alphanumeric': 0.07550731477111845, 'fraction_numerical': 0.0037753657385559227, 'mean_word_length': 2.520764119601329, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '6798258', 'n_tokens_mistral': 1065, 'n_tokens_neox': 994, 'n_words': 294}