mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Remove CollectionManager
This commit is contained in:
@ -5,12 +5,14 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Tests.Resources;
|
||||
|
||||
@ -30,7 +32,11 @@ namespace osu.Game.Tests.Collections.IO
|
||||
|
||||
await importCollectionsFromStream(osu, new MemoryStream());
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections.Count, Is.Zero);
|
||||
osu.Realm.Run(realm =>
|
||||
{
|
||||
var collections = realm.All<RealmBeatmapCollection>().ToList();
|
||||
Assert.That(collections.Count, Is.Zero);
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -50,18 +56,22 @@ namespace osu.Game.Tests.Collections.IO
|
||||
|
||||
await importCollectionsFromStream(osu, TestResources.OpenResource("Collections/collections.db"));
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2));
|
||||
osu.Realm.Run(realm =>
|
||||
{
|
||||
var collections = realm.All<RealmBeatmapCollection>().ToList();
|
||||
Assert.That(collections.Count, Is.EqualTo(2));
|
||||
|
||||
// Even with no beatmaps imported, collections are tracking the hashes and will continue to.
|
||||
// In the future this whole mechanism will be replaced with having the collections in realm,
|
||||
// but until that happens it makes rough sense that we want to track not-yet-imported beatmaps
|
||||
// and have them associate with collections if/when they become available.
|
||||
// Even with no beatmaps imported, collections are tracking the hashes and will continue to.
|
||||
// In the future this whole mechanism will be replaced with having the collections in realm,
|
||||
// but until that happens it makes rough sense that we want to track not-yet-imported beatmaps
|
||||
// and have them associate with collections if/when they become available.
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections[0].Name.Value, Is.EqualTo("First"));
|
||||
Assert.That(osu.CollectionManager.Collections[0].BeatmapHashes.Count, Is.EqualTo(1));
|
||||
Assert.That(collections[0].Name, Is.EqualTo("First"));
|
||||
Assert.That(collections[0].BeatmapMD5Hashes.Count, Is.EqualTo(1));
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections[1].Name.Value, Is.EqualTo("Second"));
|
||||
Assert.That(osu.CollectionManager.Collections[1].BeatmapHashes.Count, Is.EqualTo(12));
|
||||
Assert.That(collections[1].Name, Is.EqualTo("Second"));
|
||||
Assert.That(collections[1].BeatmapMD5Hashes.Count, Is.EqualTo(12));
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -81,13 +91,18 @@ namespace osu.Game.Tests.Collections.IO
|
||||
|
||||
await importCollectionsFromStream(osu, TestResources.OpenResource("Collections/collections.db"));
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2));
|
||||
osu.Realm.Run(realm =>
|
||||
{
|
||||
var collections = realm.All<RealmBeatmapCollection>().ToList();
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections[0].Name.Value, Is.EqualTo("First"));
|
||||
Assert.That(osu.CollectionManager.Collections[0].BeatmapHashes.Count, Is.EqualTo(1));
|
||||
Assert.That(collections.Count, Is.EqualTo(2));
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections[1].Name.Value, Is.EqualTo("Second"));
|
||||
Assert.That(osu.CollectionManager.Collections[1].BeatmapHashes.Count, Is.EqualTo(12));
|
||||
Assert.That(collections[0].Name, Is.EqualTo("First"));
|
||||
Assert.That(collections[0].BeatmapMD5Hashes.Count, Is.EqualTo(1));
|
||||
|
||||
Assert.That(collections[1].Name, Is.EqualTo("Second"));
|
||||
Assert.That(collections[1].BeatmapMD5Hashes.Count, Is.EqualTo(12));
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -124,7 +139,11 @@ namespace osu.Game.Tests.Collections.IO
|
||||
}
|
||||
|
||||
Assert.That(exceptionThrown, Is.False);
|
||||
Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(0));
|
||||
osu.Realm.Run(realm =>
|
||||
{
|
||||
var collections = realm.All<RealmBeatmapCollection>().ToList();
|
||||
Assert.That(collections.Count, Is.EqualTo(0));
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -149,12 +168,18 @@ namespace osu.Game.Tests.Collections.IO
|
||||
|
||||
await importCollectionsFromStream(osu, TestResources.OpenResource("Collections/collections.db"));
|
||||
|
||||
// Move first beatmap from second collection into the first.
|
||||
osu.CollectionManager.Collections[0].BeatmapHashes.Add(osu.CollectionManager.Collections[1].BeatmapHashes[0]);
|
||||
osu.CollectionManager.Collections[1].BeatmapHashes.RemoveAt(0);
|
||||
// ReSharper disable once MethodHasAsyncOverload
|
||||
osu.Realm.Write(realm =>
|
||||
{
|
||||
var collections = realm.All<RealmBeatmapCollection>().ToList();
|
||||
|
||||
// Rename the second collecction.
|
||||
osu.CollectionManager.Collections[1].Name.Value = "Another";
|
||||
// Move first beatmap from second collection into the first.
|
||||
collections[0].BeatmapMD5Hashes.Add(collections[1].BeatmapMD5Hashes[0]);
|
||||
collections[1].BeatmapMD5Hashes.RemoveAt(0);
|
||||
|
||||
// Rename the second collecction.
|
||||
collections[1].Name = "Another";
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -169,13 +194,17 @@ namespace osu.Game.Tests.Collections.IO
|
||||
{
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2));
|
||||
osu.Realm.Run(realm =>
|
||||
{
|
||||
var collections = realm.All<RealmBeatmapCollection>().ToList();
|
||||
Assert.That(collections.Count, Is.EqualTo(2));
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections[0].Name.Value, Is.EqualTo("First"));
|
||||
Assert.That(osu.CollectionManager.Collections[0].BeatmapHashes.Count, Is.EqualTo(2));
|
||||
Assert.That(collections[0].Name, Is.EqualTo("First"));
|
||||
Assert.That(collections[0].BeatmapMD5Hashes.Count, Is.EqualTo(2));
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections[1].Name.Value, Is.EqualTo("Another"));
|
||||
Assert.That(osu.CollectionManager.Collections[1].BeatmapHashes.Count, Is.EqualTo(11));
|
||||
Assert.That(collections[1].Name, Is.EqualTo("Another"));
|
||||
Assert.That(collections[1].BeatmapMD5Hashes.Count, Is.EqualTo(11));
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -188,7 +217,7 @@ namespace osu.Game.Tests.Collections.IO
|
||||
{
|
||||
// intentionally spin this up on a separate task to avoid disposal deadlocks.
|
||||
// see https://github.com/EventStore/EventStore/issues/1179
|
||||
await Task.Factory.StartNew(() => new LegacyCollectionImporter(osu.CollectionManager).Import(stream).WaitSafely(), TaskCreationOptions.LongRunning);
|
||||
await Task.Factory.StartNew(() => new LegacyCollectionImporter(osu.Realm).Import(stream).WaitSafely(), TaskCreationOptions.LongRunning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user