Пример #1
0
 public void TestReadBeatmaps()
 {
     using (var osz = TestResources.GetTestBeatmapStream())
     {
         var      reader   = new ZipArchiveReader(osz);
         string[] expected =
         {
             "Soleily - Renatus (Deif) [Platter].osu",
             "Soleily - Renatus (Deif) [Rain].osu",
             "Soleily - Renatus (Deif) [Salad].osu",
             "Soleily - Renatus (ExPew) [Another].osu",
             "Soleily - Renatus (ExPew) [Hyper].osu",
             "Soleily - Renatus (ExPew) [Normal].osu",
             "Soleily - Renatus (Gamu) [Hard].osu",
             "Soleily - Renatus (Gamu) [Insane].osu",
             "Soleily - Renatus (Gamu) [Normal].osu",
             "Soleily - Renatus (MMzz) [Futsuu].osu",
             "Soleily - Renatus (MMzz) [Muzukashii].osu",
             "Soleily - Renatus (MMzz) [Oni].osu"
         };
         string[] maps = reader.Filenames.ToArray();
         foreach (string map in expected)
         {
             Assert.Contains(map, maps);
         }
     }
 }
Пример #2
0
        public void TestImportBeatmapThenCleanup()
        {
            RunTestWithRealmAsync(async(realmFactory, storage) =>
            {
                using (var importer = new BeatmapImporter(realmFactory, storage))
                    using (new RealmRulesetStore(realmFactory, storage))
                    {
                        ILive <RealmBeatmapSet>?imported;

                        using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream()))
                            imported = await importer.Import(reader);

                        Assert.AreEqual(1, realmFactory.Context.All <RealmBeatmapSet>().Count());

                        Assert.NotNull(imported);
                        Debug.Assert(imported != null);

                        imported.PerformWrite(s => s.DeletePending = true);

                        Assert.AreEqual(1, realmFactory.Context.All <RealmBeatmapSet>().Count(s => s.DeletePending));
                    }
            });

            Logger.Log("Running with no work to purge pending deletions");

            RunTestWithRealm((realmFactory, _) => { Assert.AreEqual(0, realmFactory.Context.All <RealmBeatmapSet>().Count()); });
        }
Пример #3
0
        public void TestReadMetadata()
        {
            using (var osz = TestResources.GetTestBeatmapStream())
            {
                var reader = new ZipArchiveReader(osz);

                Beatmap beatmap;

                using (var stream = new LineBufferedReader(reader.GetStream("Soleily - Renatus (Deif) [Platter].osu")))
                    beatmap = Decoder.GetDecoder <Beatmap>(stream).Decode(stream);

                var meta = beatmap.Metadata;

                Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet.OnlineBeatmapSetID);
                Assert.AreEqual("Soleily", meta.Artist);
                Assert.AreEqual("Soleily", meta.ArtistUnicode);
                Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);
                Assert.AreEqual("Deif", meta.Author.Username);
                Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile);
                Assert.AreEqual(164471, meta.PreviewTime);
                Assert.AreEqual(string.Empty, meta.Source);
                Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", meta.Tags);
                Assert.AreEqual("Renatus", meta.Title);
                Assert.AreEqual("Renatus", meta.TitleUnicode);
            }
        }
Пример #4
0
        public void TestImportBeatmapThenCleanup()
        {
            RunTestWithRealmAsync(async(realm, storage) =>
            {
                using (var importer = new BeatmapImporter(storage, realm))
                    using (new RealmRulesetStore(realm, storage))
                    {
                        var imported = await importer.Import(new ImportTask(TestResources.GetTestBeatmapStream(), "renatus.osz"));
                        EnsureLoaded(realm.Realm);

                        Assert.AreEqual(1, realm.Realm.All <BeatmapSetInfo>().Count());

                        Assert.NotNull(imported);
                        Debug.Assert(imported != null);

                        imported.PerformWrite(s => s.DeletePending = true);

                        Assert.AreEqual(1, realm.Realm.All <BeatmapSetInfo>().Count(s => s.DeletePending));
                    }
            });

            Logger.Log("Running with no work to purge pending deletions");

            RunTestWithRealm((realm, _) => { Assert.AreEqual(0, realm.Realm.All <BeatmapSetInfo>().Count()); });
        }
Пример #5
0
        public void TestAddFileToAsyncImportedBeatmap()
        {
            RunTestWithRealm((realm, storage) =>
            {
                BeatmapSetInfo?detachedSet = null;

                var manager = new ModelManager <BeatmapSetInfo>(storage, realm);

                using (var importer = new BeatmapImporter(storage, realm))
                    using (new RealmRulesetStore(realm, storage))
                    {
                        Task.Run(async() =>
                        {
                            // ReSharper disable once AccessToDisposedClosure
                            var beatmapSet = await importer.Import(new ImportTask(TestResources.GetTestBeatmapStream(), "renatus.osz"));

                            Assert.NotNull(beatmapSet);
                            Debug.Assert(beatmapSet != null);

                            // Intentionally detach on async thread as to not trigger a refresh on the main thread.
                            beatmapSet.PerformRead(s => detachedSet = s.Detach());
                        }).WaitSafely();

                        Debug.Assert(detachedSet != null);
                        manager.AddFile(detachedSet, new MemoryStream(), "test");
                    }
            });
        }
Пример #6
0
 public WaveformTestBeatmap(AudioManager audioManager)
     : base(new BeatmapInfo(), audioManager)
 {
     stream     = TestResources.GetTestBeatmapStream();
     reader     = new ZipArchiveReader(stream);
     trackStore = audioManager.GetTrackStore(reader);
 }
Пример #7
0
        public void TestUpdateDetachedBeatmapSet()
        {
            RunTestWithRealmAsync(async(realm, storage) =>
            {
                using (var importer = new BeatmapModelManager(realm, storage))
                    using (new RealmRulesetStore(realm, storage))
                    {
                        Live <BeatmapSetInfo>?beatmapSet;

                        using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream()))
                            beatmapSet = await importer.Import(reader);

                        Assert.NotNull(beatmapSet);
                        Debug.Assert(beatmapSet != null);

                        // Detach at the BeatmapInfo point, similar to what GetWorkingBeatmap does.
                        BeatmapInfo?detachedBeatmap = null;

                        beatmapSet.PerformRead(s => detachedBeatmap = s.Beatmaps.First().Detach());

                        BeatmapSetInfo?detachedBeatmapSet = detachedBeatmap?.BeatmapSet;

                        Debug.Assert(detachedBeatmapSet != null);

                        var newUser = new RealmUser {
                            Username = "******", OnlineID = 2
                        };

                        detachedBeatmapSet.Beatmaps.First().Metadata.Artist = "New Artist";
                        detachedBeatmapSet.Beatmaps.First().Metadata.Author = newUser;

                        Assert.AreNotEqual(detachedBeatmapSet.Status, BeatmapOnlineStatus.Ranked);
                        detachedBeatmapSet.Status = BeatmapOnlineStatus.Ranked;

                        beatmapSet.PerformWrite(s =>
                        {
                            detachedBeatmapSet.CopyChangesToRealm(s);
                        });

                        beatmapSet.PerformRead(s =>
                        {
                            // Check above changes explicitly.
                            Assert.AreEqual(BeatmapOnlineStatus.Ranked, s.Status);
                            Assert.AreEqual("New Artist", s.Beatmaps.First().Metadata.Artist);
                            Assert.AreEqual(newUser, s.Beatmaps.First().Metadata.Author);
                            Assert.NotZero(s.Files.Count);

                            // Check nothing was lost in the copy operation.
                            Assert.AreEqual(s.Files.Count, detachedBeatmapSet.Files.Count);
                            Assert.AreEqual(s.Files.Select(f => f.File).Count(), detachedBeatmapSet.Files.Select(f => f.File).Count());
                            Assert.AreEqual(s.Beatmaps.Count, detachedBeatmapSet.Beatmaps.Count);
                            Assert.AreEqual(s.Beatmaps.Select(f => f.Difficulty).Count(), detachedBeatmapSet.Beatmaps.Select(f => f.Difficulty).Count());
                            Assert.AreEqual(s.Metadata, detachedBeatmapSet.Metadata);
                        });
                    }
            });
        }
Пример #8
0
        public void TestReadFile()
        {
            using (var osz = TestResources.GetTestBeatmapStream())
            {
                var reader = new ZipArchiveReader(osz);

                using (var stream = new StreamReader(reader.GetStream("Soleily - Renatus (Deif) [Platter].osu")))
                {
                    Assert.AreEqual("osu file format v13", stream.ReadLine()?.Trim());
                }
            }
        }
Пример #9
0
        public void TestDetachBeatmapSet()
        {
            RunTestWithRealmAsync(async(realm, storage) =>
            {
                using (var importer = new BeatmapModelManager(realm, storage))
                    using (new RealmRulesetStore(realm, storage))
                    {
                        Live <BeatmapSetInfo>?beatmapSet;

                        using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream()))
                            beatmapSet = await importer.Import(reader);

                        Assert.NotNull(beatmapSet);
                        Debug.Assert(beatmapSet != null);

                        BeatmapSetInfo?detachedBeatmapSet = null;

                        beatmapSet.PerformRead(live =>
                        {
                            detachedBeatmapSet = live.Detach();

                            // files are omitted
                            Assert.AreEqual(0, detachedBeatmapSet.Files.Count);

                            Assert.AreEqual(live.Beatmaps.Count, detachedBeatmapSet.Beatmaps.Count);
                            Assert.AreEqual(live.Beatmaps.Select(f => f.Difficulty).Count(), detachedBeatmapSet.Beatmaps.Select(f => f.Difficulty).Count());
                            Assert.AreEqual(live.Metadata, detachedBeatmapSet.Metadata);
                        });

                        Debug.Assert(detachedBeatmapSet != null);

                        // Check detached instances can all be accessed without throwing.
                        Assert.AreEqual(0, detachedBeatmapSet.Files.Count);
                        Assert.NotNull(detachedBeatmapSet.Beatmaps.Count);
                        Assert.NotZero(detachedBeatmapSet.Beatmaps.Select(f => f.Difficulty).Count());
                        Assert.NotNull(detachedBeatmapSet.Metadata);

                        // Check cyclic reference to beatmap set
                        Assert.AreEqual(detachedBeatmapSet, detachedBeatmapSet.Beatmaps.First().BeatmapSet);
                    }
            });
        }
Пример #10
0
 private static Stream getStream() => TestResources.GetTestBeatmapStream();
Пример #11
0
 public WaveformTestBeatmap()
     : base(new BeatmapInfo())
 {
     stream = TestResources.GetTestBeatmapStream();
     reader = new ZipArchiveReader(stream);
 }