Esempio n. 1
0
        public void TestMigrationBetweenTwoTargets()
        {
            string customPath  = prepareCustomPath();
            string customPath2 = prepareCustomPath("-2");

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    var osu = LoadOsuIntoHost(host);

                    const string database_filename = "client.db";

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));
                    Assert.That(File.Exists(Path.Combine(customPath, database_filename)));

                    Assert.DoesNotThrow(() => osu.Migrate(customPath2));
                    Assert.That(File.Exists(Path.Combine(customPath2, database_filename)));

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));
                    Assert.That(File.Exists(Path.Combine(customPath, database_filename)));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Esempio n. 2
0
        public void TestMigrationToNestedTargetFails()
        {
            string customPath = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    var osu = LoadOsuIntoHost(host);

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));

                    string subFolder = Path.Combine(customPath, "sub");

                    if (Directory.Exists(subFolder))
                    {
                        Directory.Delete(subFolder, true);
                    }

                    Directory.CreateDirectory(subFolder);

                    Assert.Throws <ArgumentException>(() => osu.Migrate(subFolder));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Esempio n. 3
0
        public void TestMigrationToSeeminglyNestedTarget()
        {
            string customPath = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    var osu = LoadOsuIntoHost(host);

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));

                    string seeminglySubFolder = customPath + "sub";

                    if (Directory.Exists(seeminglySubFolder))
                    {
                        Directory.Delete(seeminglySubFolder, true);
                    }

                    Directory.CreateDirectory(seeminglySubFolder);

                    osu.Migrate(seeminglySubFolder);
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Esempio n. 4
0
        public void TestSubDirectoryLookup()
        {
            string customPath = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                using (var storageConfig = new StorageConfigManager(host.InitialStorage))
                    storageConfig.SetValue(StorageConfig.FullPath, customPath);

                try
                {
                    var osu = LoadOsuIntoHost(host);

                    // switch to DI'd storage
                    var storage = osu.Dependencies.Get <Storage>();

                    string actualTestFile = Path.Combine(customPath, "rulesets", "test");

                    File.WriteAllText(actualTestFile, "test");

                    var rulesetStorage = storage.GetStorageForDirectory("rulesets");
                    var lookupPath     = rulesetStorage.GetFiles(".").Single();

                    Assert.That(lookupPath, Is.EqualTo("test"));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Esempio n. 5
0
        public void TestCustomDirectory()
        {
            string customPath = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                using (var storageConfig = new StorageConfigManager(host.InitialStorage))
                    storageConfig.SetValue(StorageConfig.FullPath, customPath);

                try
                {
                    var osu = LoadOsuIntoHost(host);

                    // switch to DI'd storage
                    var storage = osu.Dependencies.Get <Storage>();

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(customPath));
                }
                finally
                {
                    host.Exit();
                    cleanupPath(customPath);
                }
            }
        }
Esempio n. 6
0
        public void TestMigrationBetweenTwoTargets()
        {
            string customPath  = prepareCustomPath();
            string customPath2 = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    var osu = LoadOsuIntoHost(host);

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));
                    Assert.That(File.Exists(Path.Combine(customPath, OsuGameBase.CLIENT_DATABASE_FILENAME)));

                    Assert.DoesNotThrow(() => osu.Migrate(customPath2));
                    Assert.That(File.Exists(Path.Combine(customPath2, OsuGameBase.CLIENT_DATABASE_FILENAME)));

                    // some files may have been left behind for whatever reason, but that's not what we're testing here.
                    cleanupPath(customPath);

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));
                    Assert.That(File.Exists(Path.Combine(customPath, OsuGameBase.CLIENT_DATABASE_FILENAME)));
                }
                finally
                {
                    host.Exit();
                    cleanupPath(customPath);
                    cleanupPath(customPath2);
                }
            }
        }
Esempio n. 7
0
        public void TestMigrationBetweenTwoTargets()
        {
            string customPath  = prepareCustomPath();
            string customPath2 = prepareCustomPath("-2");

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    var osu = LoadOsuIntoHost(host);

                    const string database_filename = "client.db";

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));
                    Assert.That(File.Exists(Path.Combine(customPath, database_filename)));

                    Assert.DoesNotThrow(() => osu.Migrate(customPath2));
                    Assert.That(File.Exists(Path.Combine(customPath2, database_filename)));

                    // some files may have been left behind for whatever reason, but that's not what we're testing here.
                    customPath = prepareCustomPath();

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));
                    Assert.That(File.Exists(Path.Combine(customPath, database_filename)));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
        public void TestMigration()
        {
            string customPath = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    string defaultStorageLocation = getDefaultLocationFor(nameof(TestMigration));

                    var osu     = LoadOsuIntoHost(host);
                    var storage = osu.Dependencies.Get <Storage>();

                    // Store the current storage's path. We'll need to refer to this for assertions in the original directory after the migration completes.
                    string originalDirectory = storage.GetFullPath(".");

                    // ensure we perform a save
                    host.Dependencies.Get <FrameworkConfigManager>().Save();

                    // ensure we "use" cache
                    host.Storage.GetStorageForDirectory("cache");

                    // for testing nested files are not ignored (only top level)
                    host.Storage.GetStorageForDirectory("test-nested").GetStorageForDirectory("cache");

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));

                    osu.Migrate(customPath);

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(customPath));

                    // ensure cache was not moved
                    Assert.That(Directory.Exists(Path.Combine(originalDirectory, "cache")));

                    // ensure nested cache was moved
                    Assert.That(!Directory.Exists(Path.Combine(originalDirectory, "test-nested", "cache")));
                    Assert.That(storage.ExistsDirectory(Path.Combine("test-nested", "cache")));

                    foreach (var file in OsuStorage.IGNORE_FILES)
                    {
                        Assert.That(File.Exists(Path.Combine(originalDirectory, file)));
                        Assert.That(storage.Exists(file), Is.False);
                    }

                    foreach (var dir in OsuStorage.IGNORE_DIRECTORIES)
                    {
                        Assert.That(Directory.Exists(Path.Combine(originalDirectory, dir)));
                        Assert.That(storage.ExistsDirectory(dir), Is.False);
                    }

                    Assert.That(new StreamReader(Path.Combine(originalDirectory, "storage.ini")).ReadToEnd().Contains($"FullPath = {customPath}"));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Esempio n. 9
0
        public void TestDefaultDirectory()
        {
            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    string defaultStorageLocation = getDefaultLocationFor(nameof(TestDefaultDirectory));

                    var osu     = LoadOsuIntoHost(host);
                    var storage = osu.Dependencies.Get <Storage>();

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Esempio n. 10
0
        public void TestMigrationToSameTargetFails()
        {
            string customPath = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    var osu = LoadOsuIntoHost(host);

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));
                    Assert.Throws <ArgumentException>(() => osu.Migrate(customPath));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Esempio n. 11
0
        public void TestMigrationFailsOnExistingData()
        {
            string customPath  = prepareCustomPath();
            string customPath2 = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    var osu = LoadOsuIntoHost(host);

                    var storage    = osu.Dependencies.Get <Storage>();
                    var osuStorage = storage as OsuStorage;

                    string originalDirectory = storage.GetFullPath(".");

                    Assert.DoesNotThrow(() => osu.Migrate(customPath));
                    Assert.That(File.Exists(Path.Combine(customPath, OsuGameBase.CLIENT_DATABASE_FILENAME)));

                    Directory.CreateDirectory(customPath2);
                    File.Copy(Path.Combine(customPath, OsuGameBase.CLIENT_DATABASE_FILENAME), Path.Combine(customPath2, OsuGameBase.CLIENT_DATABASE_FILENAME));

                    // Fails because file already exists.
                    Assert.Throws <ArgumentException>(() => osu.Migrate(customPath2));

                    osuStorage?.ChangeDataPath(customPath2);

                    Assert.That(osuStorage?.CustomStoragePath, Is.EqualTo(customPath2));
                    Assert.That(new StreamReader(Path.Combine(originalDirectory, "storage.ini")).ReadToEnd().Contains($"FullPath = {customPath2}"));
                }
                finally
                {
                    host.Exit();
                    cleanupPath(customPath);
                    cleanupPath(customPath2);
                }
            }
        }
Esempio n. 12
0
        public void TestMigration()
        {
            string customPath = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    string defaultStorageLocation = getDefaultLocationFor(nameof(TestMigration));

                    var osu        = LoadOsuIntoHost(host);
                    var storage    = osu.Dependencies.Get <Storage>();
                    var osuStorage = storage as MigratableStorage;

                    // Store the current storage's path. We'll need to refer to this for assertions in the original directory after the migration completes.
                    string originalDirectory = storage.GetFullPath(".");

                    // ensure we perform a save
                    host.Dependencies.Get <FrameworkConfigManager>().Save();

                    // ensure we "use" cache
                    host.Storage.GetStorageForDirectory("cache");

                    // for testing nested files are not ignored (only top level)
                    host.Storage.GetStorageForDirectory("test-nested").GetStorageForDirectory("cache");

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));

                    osu.Migrate(customPath);

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(customPath));

                    // ensure cache was not moved
                    Assert.That(Directory.Exists(Path.Combine(originalDirectory, "cache")));

                    // ensure nested cache was moved
                    Assert.That(!Directory.Exists(Path.Combine(originalDirectory, "test-nested", "cache")));
                    Assert.That(storage.ExistsDirectory(Path.Combine("test-nested", "cache")));

                    Assert.That(osuStorage, Is.Not.Null);

                    foreach (var file in osuStorage.IgnoreFiles)
                    {
                        // avoid touching realm files which may be a pipe and break everything.
                        // this is also done locally inside OsuStorage via the IgnoreFiles list.
                        if (file.EndsWith(".ini", StringComparison.Ordinal))
                        {
                            Assert.That(File.Exists(Path.Combine(originalDirectory, file)));
                        }
                        Assert.That(storage.Exists(file), Is.False);
                    }

                    foreach (var dir in osuStorage.IgnoreDirectories)
                    {
                        Assert.That(Directory.Exists(Path.Combine(originalDirectory, dir)));
                        Assert.That(storage.ExistsDirectory(dir), Is.False);
                    }

                    Assert.That(new StreamReader(Path.Combine(originalDirectory, "storage.ini")).ReadToEnd().Contains($"FullPath = {customPath}"));
                }
                finally
                {
                    host.Exit();
                }
            }
        }
Esempio n. 13
0
        public void TestMigration()
        {
            string customPath = prepareCustomPath();

            using (var host = new CustomTestHeadlessGameHost())
            {
                try
                {
                    string defaultStorageLocation = getDefaultLocationFor(host);

                    var osu        = LoadOsuIntoHost(host);
                    var storage    = osu.Dependencies.Get <Storage>();
                    var osuStorage = storage as MigratableStorage;

                    // Store the current storage's path. We'll need to refer to this for assertions in the original directory after the migration completes.
                    string originalDirectory = storage.GetFullPath(".");

                    // ensure we perform a save
                    host.Dependencies.Get <FrameworkConfigManager>().Save();

                    // ensure we "use" cache
                    host.Storage.GetStorageForDirectory("cache");

                    // for testing nested files are not ignored (only top level)
                    host.Storage.GetStorageForDirectory("test-nested").GetStorageForDirectory("cache");

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));

                    osu.Migrate(customPath);

                    Assert.That(storage.GetFullPath("."), Is.EqualTo(customPath));

                    // ensure cache was not moved
                    Assert.That(Directory.Exists(Path.Combine(originalDirectory, "cache")));

                    // ensure nested cache was moved
                    Assert.That(!Directory.Exists(Path.Combine(originalDirectory, "test-nested", "cache")));
                    Assert.That(storage.ExistsDirectory(Path.Combine("test-nested", "cache")));

                    Assert.That(osuStorage, Is.Not.Null);

                    // In the following tests, realm files are ignored as
                    // - in the case of checking the source, interacting with the pipe files (.realm.note) may
                    //   lead to unexpected behaviour.
                    // - in the case of checking the destination, the files may have already been recreated by the game
                    //   as part of the standard migration flow.

                    foreach (string file in osuStorage.IgnoreFiles)
                    {
                        if (!file.Contains(".realm", StringComparison.Ordinal))
                        {
                            Assert.That(File.Exists(Path.Combine(originalDirectory, file)));
                            Assert.That(storage.Exists(file), Is.False, () => $"{file} exists in destination when it was expected to be ignored");
                        }
                    }

                    foreach (string dir in osuStorage.IgnoreDirectories)
                    {
                        if (!dir.Contains(".realm", StringComparison.Ordinal))
                        {
                            Assert.That(Directory.Exists(Path.Combine(originalDirectory, dir)));
                            Assert.That(storage.Exists(dir), Is.False, () => $"{dir} exists in destination when it was expected to be ignored");
                        }
                    }

                    Assert.That(new StreamReader(Path.Combine(originalDirectory, "storage.ini")).ReadToEnd().Contains($"FullPath = {customPath}"));
                }
                finally
                {
                    host.Exit();
                    cleanupPath(customPath);
                }
            }
        }