1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-28 06:12:54 +08:00

Merge branch 'master' into playlist-test-coverage

This commit is contained in:
Bartłomiej Dach 2022-01-18 20:17:48 +01:00 committed by GitHub
commit 7df18c7767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
238 changed files with 3708 additions and 5394 deletions

View File

@ -52,10 +52,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.115.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2022.115.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2022.111.0" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2022.118.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Transitive Dependencies"> <ItemGroup Label="Transitive Dependencies">
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. --> <!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->
<PackageReference Include="Realm" Version="10.7.1" /> <PackageReference Include="Realm" Version="10.8.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -29,7 +29,13 @@ namespace osu.Game.Rulesets.Catch.Tests.Editor
protected CatchSelectionBlueprintTestScene() protected CatchSelectionBlueprintTestScene()
{ {
EditorBeatmap = new EditorBeatmap(new CatchBeatmap()) { Difficulty = { CircleSize = 0 } }; EditorBeatmap = new EditorBeatmap(new CatchBeatmap
{
BeatmapInfo =
{
Ruleset = new CatchRuleset().RulesetInfo,
}
}) { Difficulty = { CircleSize = 0 } };
EditorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint EditorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint
{ {
BeatLength = 100 BeatLength = 100

View File

@ -29,7 +29,13 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
private ScrollingTestContainer.TestScrollingInfo scrollingInfo = new ScrollingTestContainer.TestScrollingInfo(); private ScrollingTestContainer.TestScrollingInfo scrollingInfo = new ScrollingTestContainer.TestScrollingInfo();
[Cached(typeof(EditorBeatmap))] [Cached(typeof(EditorBeatmap))]
private EditorBeatmap editorBeatmap = new EditorBeatmap(new ManiaBeatmap(new StageDefinition())); private EditorBeatmap editorBeatmap = new EditorBeatmap(new ManiaBeatmap(new StageDefinition())
{
BeatmapInfo =
{
Ruleset = new ManiaRuleset().RulesetInfo
}
});
private readonly ManiaBeatSnapGrid beatSnapGrid; private readonly ManiaBeatSnapGrid beatSnapGrid;

View File

@ -31,10 +31,10 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
{ {
AddStep("setup compose screen", () => AddStep("setup compose screen", () =>
{ {
var editorBeatmap = new EditorBeatmap(new ManiaBeatmap(new StageDefinition { Columns = 4 })) var editorBeatmap = new EditorBeatmap(new ManiaBeatmap(new StageDefinition { Columns = 4 })
{ {
BeatmapInfo = { Ruleset = new ManiaRuleset().RulesetInfo }, BeatmapInfo = { Ruleset = new ManiaRuleset().RulesetInfo },
}; });
Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap); Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap);

View File

@ -203,10 +203,10 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
{ {
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
EditorBeatmap = new EditorBeatmap(new ManiaBeatmap(new StageDefinition { Columns = 4 })) EditorBeatmap = new EditorBeatmap(new ManiaBeatmap(new StageDefinition { Columns = 4 })
{ {
BeatmapInfo = { Ruleset = new ManiaRuleset().RulesetInfo } BeatmapInfo = { Ruleset = new ManiaRuleset().RulesetInfo }
}, }),
Composer = new ManiaHitObjectComposer(new ManiaRuleset()) Composer = new ManiaHitObjectComposer(new ManiaRuleset())
}; };

View File

@ -40,7 +40,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
public TestSceneOsuDistanceSnapGrid() public TestSceneOsuDistanceSnapGrid()
{ {
editorBeatmap = new EditorBeatmap(new OsuBeatmap()); editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo
}
});
} }
[SetUp] [SetUp]

View File

@ -174,7 +174,7 @@ namespace osu.Game.Rulesets.Osu.Statistics
pointGrid.Content = points; pointGrid.Content = points;
if (score.HitEvents == null || score.HitEvents.Count == 0) if (score.HitEvents.Count == 0)
return; return;
// Todo: This should probably not be done like this. // Todo: This should probably not be done like this.

View File

@ -40,10 +40,10 @@ namespace osu.Game.Rulesets.Taiko.Tests.Editor
{ {
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
EditorBeatmap = new EditorBeatmap(new TaikoBeatmap()) EditorBeatmap = new EditorBeatmap(new TaikoBeatmap
{ {
BeatmapInfo = { Ruleset = new TaikoRuleset().RulesetInfo } BeatmapInfo = { Ruleset = new TaikoRuleset().RulesetInfo }
}, }),
new TaikoHitObjectComposer(new TaikoRuleset()) new TaikoHitObjectComposer(new TaikoRuleset())
}; };

View File

@ -191,6 +191,9 @@ namespace osu.Game.Rulesets.Taiko.Beatmaps
protected override Beatmap<TaikoHitObject> CreateBeatmap() => new TaikoBeatmap(); protected override Beatmap<TaikoHitObject> CreateBeatmap() => new TaikoBeatmap();
// Important to note that this is subclassing a realm object.
// Realm doesn't allow this, but for now this can work since we aren't (in theory?) persisting this to the database.
// It is only used during beatmap conversion and processing.
internal class TaikoMultiplierAppliedDifficulty : BeatmapDifficulty internal class TaikoMultiplierAppliedDifficulty : BeatmapDifficulty
{ {
public TaikoMultiplierAppliedDifficulty(IBeatmapDifficultyInfo difficulty) public TaikoMultiplierAppliedDifficulty(IBeatmapDifficultyInfo difficulty)
@ -205,6 +208,8 @@ namespace osu.Game.Rulesets.Taiko.Beatmaps
#region Overrides of BeatmapDifficulty #region Overrides of BeatmapDifficulty
public override BeatmapDifficulty Clone() => new TaikoMultiplierAppliedDifficulty(this);
public override void CopyTo(BeatmapDifficulty other) public override void CopyTo(BeatmapDifficulty other)
{ {
base.CopyTo(other); base.CopyTo(other);

View File

@ -117,7 +117,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual(string.Empty, metadata.Source); Assert.AreEqual(string.Empty, metadata.Source);
Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", metadata.Tags); Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", metadata.Tags);
Assert.AreEqual(557821, beatmapInfo.OnlineID); Assert.AreEqual(557821, beatmapInfo.OnlineID);
Assert.AreEqual(241526, beatmapInfo.BeatmapSet.OnlineID); Assert.AreEqual(241526, beatmapInfo.BeatmapSet?.OnlineID);
} }
} }

View File

@ -31,7 +31,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
{ {
var beatmap = decodeAsJson(normal); var beatmap = decodeAsJson(normal);
var meta = beatmap.BeatmapInfo.Metadata; var meta = beatmap.BeatmapInfo.Metadata;
Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet.OnlineID); Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet?.OnlineID);
Assert.AreEqual("Soleily", meta.Artist); Assert.AreEqual("Soleily", meta.Artist);
Assert.AreEqual("Soleily", meta.ArtistUnicode); Assert.AreEqual("Soleily", meta.ArtistUnicode);
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile); Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);

View File

@ -0,0 +1,86 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Tests.Database;
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Beatmaps.IO
{
public static class BeatmapImportHelper
{
public static async Task<BeatmapSetInfo> LoadQuickOszIntoOsu(OsuGameBase osu)
{
string temp = TestResources.GetQuickTestBeatmapForImport();
var manager = osu.Dependencies.Get<BeatmapManager>();
var importedSet = await manager.Import(new ImportTask(temp)).ConfigureAwait(false);
Debug.Assert(importedSet != null);
ensureLoaded(osu);
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.ID);
}
public static async Task<BeatmapSetInfo> LoadOszIntoOsu(OsuGameBase osu, string path = null, bool virtualTrack = false)
{
string temp = path ?? TestResources.GetTestBeatmapForImport(virtualTrack);
var manager = osu.Dependencies.Get<BeatmapManager>();
var importedSet = await manager.Import(new ImportTask(temp)).ConfigureAwait(false);
Debug.Assert(importedSet != null);
ensureLoaded(osu);
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.ID);
}
private static void ensureLoaded(OsuGameBase osu, int timeout = 60000)
{
var realmContextFactory = osu.Dependencies.Get<RealmContextFactory>();
using (var realm = realmContextFactory.CreateContext())
BeatmapImporterTests.EnsureLoaded(realm, timeout);
// TODO: add back some extra checks outside of the realm ones?
// var set = queryBeatmapSets().First();
// foreach (BeatmapInfo b in set.Beatmaps)
// Assert.IsTrue(set.Beatmaps.Any(c => c.OnlineID == b.OnlineID));
// Assert.IsTrue(set.Beatmaps.Count > 0);
// var beatmap = store.GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 0))?.Beatmap;
// Assert.IsTrue(beatmap?.HitObjects.Any() == true);
// beatmap = store.GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 1))?.Beatmap;
// Assert.IsTrue(beatmap?.HitObjects.Any() == true);
// beatmap = store.GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 2))?.Beatmap;
// Assert.IsTrue(beatmap?.HitObjects.Any() == true);
// beatmap = store.GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 3))?.Beatmap;
// Assert.IsTrue(beatmap?.HitObjects.Any() == true);
}
private static void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
{
Task task = Task.Run(() =>
{
while (!result()) Thread.Sleep(200);
});
Assert.IsTrue(task.Wait(timeout), failureMessage);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -56,7 +56,7 @@ namespace osu.Game.Tests.Beatmaps.IO
var meta = beatmap.Metadata; var meta = beatmap.Metadata;
Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet.OnlineID); Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet?.OnlineID);
Assert.AreEqual("Soleily", meta.Artist); Assert.AreEqual("Soleily", meta.Artist);
Assert.AreEqual("Soleily", meta.ArtistUnicode); Assert.AreEqual("Soleily", meta.ArtistUnicode);
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile); Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);

View File

@ -24,6 +24,8 @@ namespace osu.Game.Tests.Beatmaps
{ {
public const double BASE_STARS = 5.55; public const double BASE_STARS = 5.55;
private static readonly Guid guid = Guid.NewGuid();
private BeatmapSetInfo importedSet; private BeatmapSetInfo importedSet;
private TestBeatmapDifficultyCache difficultyCache; private TestBeatmapDifficultyCache difficultyCache;
@ -33,7 +35,7 @@ namespace osu.Game.Tests.Beatmaps
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase osu) private void load(OsuGameBase osu)
{ {
importedSet = ImportBeatmapTest.LoadQuickOszIntoOsu(osu).GetResultSafely(); importedSet = BeatmapImportHelper.LoadQuickOszIntoOsu(osu).GetResultSafely();
} }
[SetUpSteps] [SetUpSteps]
@ -98,8 +100,8 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestKeyEqualsWithDifferentModInstances() public void TestKeyEqualsWithDifferentModInstances()
{ {
var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = 1234 }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModHardRock(), new OsuModHidden() }); var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = guid }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModHardRock(), new OsuModHidden() });
var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = 1234 }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModHardRock(), new OsuModHidden() }); var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = guid }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModHardRock(), new OsuModHidden() });
Assert.That(key1, Is.EqualTo(key2)); Assert.That(key1, Is.EqualTo(key2));
Assert.That(key1.GetHashCode(), Is.EqualTo(key2.GetHashCode())); Assert.That(key1.GetHashCode(), Is.EqualTo(key2.GetHashCode()));
@ -108,8 +110,8 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestKeyEqualsWithDifferentModOrder() public void TestKeyEqualsWithDifferentModOrder()
{ {
var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = 1234 }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModHardRock(), new OsuModHidden() }); var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = guid }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModHardRock(), new OsuModHidden() });
var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = 1234 }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModHidden(), new OsuModHardRock() }); var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = guid }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModHidden(), new OsuModHardRock() });
Assert.That(key1, Is.EqualTo(key2)); Assert.That(key1, Is.EqualTo(key2));
Assert.That(key1.GetHashCode(), Is.EqualTo(key2.GetHashCode())); Assert.That(key1.GetHashCode(), Is.EqualTo(key2.GetHashCode()));
@ -118,8 +120,8 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestKeyDoesntEqualWithDifferentModSettings() public void TestKeyDoesntEqualWithDifferentModSettings()
{ {
var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = 1234 }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 1.1 } } }); var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = guid }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 1.1 } } });
var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = 1234 }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 1.9 } } }); var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = guid }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 1.9 } } });
Assert.That(key1, Is.Not.EqualTo(key2)); Assert.That(key1, Is.Not.EqualTo(key2));
Assert.That(key1.GetHashCode(), Is.Not.EqualTo(key2.GetHashCode())); Assert.That(key1.GetHashCode(), Is.Not.EqualTo(key2.GetHashCode()));
@ -128,8 +130,8 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestKeyEqualWithMatchingModSettings() public void TestKeyEqualWithMatchingModSettings()
{ {
var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = 1234 }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 1.25 } } }); var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = guid }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 1.25 } } });
var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = 1234 }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 1.25 } } }); var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(new BeatmapInfo { ID = guid }, new RulesetInfo { OnlineID = 0 }, new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 1.25 } } });
Assert.That(key1, Is.EqualTo(key2)); Assert.That(key1, Is.EqualTo(key2));
Assert.That(key1.GetHashCode(), Is.EqualTo(key2.GetHashCode())); Assert.That(key1.GetHashCode(), Is.EqualTo(key2.GetHashCode()));

View File

@ -7,6 +7,7 @@ using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Beatmaps; using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
@ -30,7 +31,13 @@ namespace osu.Game.Tests.Beatmaps
AddStep("add beatmap", () => AddStep("add beatmap", () =>
{ {
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap()); Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
});
editorBeatmap.HitObjectAdded += h => addedObject = h; editorBeatmap.HitObjectAdded += h => addedObject = h;
}); });
@ -49,7 +56,14 @@ namespace osu.Game.Tests.Beatmaps
EditorBeatmap editorBeatmap = null; EditorBeatmap editorBeatmap = null;
AddStep("add beatmap", () => AddStep("add beatmap", () =>
{ {
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } }); Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects = { hitCircle }
});
editorBeatmap.HitObjectRemoved += h => removedObject = h; editorBeatmap.HitObjectRemoved += h => removedObject = h;
}); });
AddStep("remove hitobject", () => editorBeatmap.Remove(editorBeatmap.HitObjects.First())); AddStep("remove hitobject", () => editorBeatmap.Remove(editorBeatmap.HitObjects.First()));
@ -71,7 +85,14 @@ namespace osu.Game.Tests.Beatmaps
{ {
EditorBeatmap editorBeatmap; EditorBeatmap editorBeatmap;
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } }); Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects = { hitCircle }
});
editorBeatmap.HitObjectUpdated += h => changedObject = h; editorBeatmap.HitObjectUpdated += h => changedObject = h;
}); });
@ -91,7 +112,13 @@ namespace osu.Game.Tests.Beatmaps
AddStep("add beatmap", () => AddStep("add beatmap", () =>
{ {
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap()); Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
});
editorBeatmap.HitObjectUpdated += h => changedObject = h; editorBeatmap.HitObjectUpdated += h => changedObject = h;
}); });
@ -111,7 +138,14 @@ namespace osu.Game.Tests.Beatmaps
public void TestRemovedHitObjectStartTimeChangeEvent() public void TestRemovedHitObjectStartTimeChangeEvent()
{ {
var hitCircle = new HitCircle(); var hitCircle = new HitCircle();
var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } }); var editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects = { hitCircle }
});
HitObject changedObject = null; HitObject changedObject = null;
editorBeatmap.HitObjectUpdated += h => changedObject = h; editorBeatmap.HitObjectUpdated += h => changedObject = h;
@ -131,6 +165,10 @@ namespace osu.Game.Tests.Beatmaps
{ {
var editorBeatmap = new EditorBeatmap(new OsuBeatmap var editorBeatmap = new EditorBeatmap(new OsuBeatmap
{ {
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects = HitObjects =
{ {
new HitCircle(), new HitCircle(),
@ -156,6 +194,10 @@ namespace osu.Game.Tests.Beatmaps
var editorBeatmap = new EditorBeatmap(new OsuBeatmap var editorBeatmap = new EditorBeatmap(new OsuBeatmap
{ {
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects = HitObjects =
{ {
new HitCircle(), new HitCircle(),
@ -185,7 +227,13 @@ namespace osu.Game.Tests.Beatmaps
{ {
updatedObjects.Clear(); updatedObjects.Clear();
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap()); Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
});
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
@ -220,7 +268,13 @@ namespace osu.Game.Tests.Beatmaps
{ {
updatedObjects.Clear(); updatedObjects.Clear();
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap()); Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
});
editorBeatmap.Add(new HitCircle()); editorBeatmap.Add(new HitCircle());
}); });

View File

@ -3,7 +3,7 @@
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Models;
namespace osu.Game.Tests.Beatmaps namespace osu.Game.Tests.Beatmaps
{ {
@ -34,7 +34,7 @@ namespace osu.Game.Tests.Beatmaps
{ {
Artist = "artist", Artist = "artist",
Title = "title", Title = "title",
Author = new APIUser { Username = "creator" } Author = new RealmUser { Username = "creator" }
} }
}; };
@ -50,7 +50,7 @@ namespace osu.Game.Tests.Beatmaps
{ {
Artist = "artist", Artist = "artist",
Title = "title", Title = "title",
Author = new APIUser { Username = "creator" } Author = new RealmUser { Username = "creator" }
}, },
DifficultyName = "difficulty" DifficultyName = "difficulty"
}; };

View File

@ -19,6 +19,7 @@ using osu.Game.Extensions;
using osu.Game.IO.Archives; using osu.Game.IO.Archives;
using osu.Game.Models; using osu.Game.Models;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets;
using osu.Game.Stores; using osu.Game.Stores;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
using Realms; using Realms;
@ -34,33 +35,132 @@ namespace osu.Game.Tests.Database
[TestFixture] [TestFixture]
public class BeatmapImporterTests : RealmTest public class BeatmapImporterTests : RealmTest
{ {
[Test]
public void TestDetachBeatmapSet()
{
RunTestWithRealmAsync(async (realmFactory, storage) =>
{
using (var importer = new BeatmapModelManager(realmFactory, storage))
using (new RulesetStore(realmFactory, storage))
{
ILive<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();
Assert.AreEqual(live.Files.Count, detachedBeatmapSet.Files.Count);
Assert.AreEqual(live.Files.Select(f => f.File).Count(), detachedBeatmapSet.Files.Select(f => f.File).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.NotNull(detachedBeatmapSet.Files.Count);
Assert.NotZero(detachedBeatmapSet.Files.Select(f => f.File).Count());
Assert.NotNull(detachedBeatmapSet.Beatmaps.Count);
Assert.NotZero(detachedBeatmapSet.Beatmaps.Select(f => f.Difficulty).Count());
Assert.NotNull(detachedBeatmapSet.Beatmaps.First().Path);
Assert.NotNull(detachedBeatmapSet.Metadata);
// Check cyclic reference to beatmap set
Assert.AreEqual(detachedBeatmapSet, detachedBeatmapSet.Beatmaps.First().BeatmapSet);
}
});
}
[Test]
public void TestUpdateDetachedBeatmapSet()
{
RunTestWithRealmAsync(async (realmFactory, storage) =>
{
using (var importer = new BeatmapModelManager(realmFactory, storage))
using (new RulesetStore(realmFactory, storage))
{
ILive<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(s => detachedBeatmapSet = s.Detach());
Debug.Assert(detachedBeatmapSet != null);
var newUser = new RealmUser { Username = "peppy", 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);
});
}
});
}
[Test] [Test]
public void TestImportBeatmapThenCleanup() public void TestImportBeatmapThenCleanup()
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using (var importer = new BeatmapImporter(realmFactory, storage)) using (var importer = new BeatmapModelManager(realmFactory, storage))
using (new RealmRulesetStore(realmFactory, storage)) using (new RulesetStore(realmFactory, storage))
{ {
ILive<RealmBeatmapSet>? imported; ILive<BeatmapSetInfo>? imported;
using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream())) using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream()))
imported = await importer.Import(reader); imported = await importer.Import(reader);
Assert.AreEqual(1, realmFactory.Context.All<RealmBeatmapSet>().Count()); Assert.AreEqual(1, realmFactory.Context.All<BeatmapSetInfo>().Count());
Assert.NotNull(imported); Assert.NotNull(imported);
Debug.Assert(imported != null); Debug.Assert(imported != null);
imported.PerformWrite(s => s.DeletePending = true); imported.PerformWrite(s => s.DeletePending = true);
Assert.AreEqual(1, realmFactory.Context.All<RealmBeatmapSet>().Count(s => s.DeletePending)); Assert.AreEqual(1, realmFactory.Context.All<BeatmapSetInfo>().Count(s => s.DeletePending));
} }
}); });
Logger.Log("Running with no work to purge pending deletions"); Logger.Log("Running with no work to purge pending deletions");
RunTestWithRealm((realmFactory, _) => { Assert.AreEqual(0, realmFactory.Context.All<RealmBeatmapSet>().Count()); }); RunTestWithRealm((realmFactory, _) => { Assert.AreEqual(0, realmFactory.Context.All<BeatmapSetInfo>().Count()); });
} }
[Test] [Test]
@ -68,8 +168,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
await LoadOszIntoStore(importer, realmFactory.Context); await LoadOszIntoStore(importer, realmFactory.Context);
}); });
@ -80,8 +180,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var imported = await LoadOszIntoStore(importer, realmFactory.Context); var imported = await LoadOszIntoStore(importer, realmFactory.Context);
@ -98,8 +198,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var imported = await LoadOszIntoStore(importer, realmFactory.Context); var imported = await LoadOszIntoStore(importer, realmFactory.Context);
@ -112,17 +212,17 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? tempPath = TestResources.GetTestBeatmapForImport(); string? tempPath = TestResources.GetTestBeatmapForImport();
ILive<RealmBeatmapSet>? importedSet; ILive<BeatmapSetInfo>? importedSet;
using (var stream = File.OpenRead(tempPath)) using (var stream = File.OpenRead(tempPath))
{ {
importedSet = await importer.Import(new ImportTask(stream, Path.GetFileName(tempPath))); importedSet = await importer.Import(new ImportTask(stream, Path.GetFileName(tempPath)));
ensureLoaded(realmFactory.Context); EnsureLoaded(realmFactory.Context);
} }
Assert.NotNull(importedSet); Assert.NotNull(importedSet);
@ -131,7 +231,7 @@ namespace osu.Game.Tests.Database
Assert.IsTrue(File.Exists(tempPath), "Stream source file somehow went missing"); Assert.IsTrue(File.Exists(tempPath), "Stream source file somehow went missing");
File.Delete(tempPath); File.Delete(tempPath);
var imported = realmFactory.Context.All<RealmBeatmapSet>().First(beatmapSet => beatmapSet.ID == importedSet.ID); var imported = realmFactory.Context.All<BeatmapSetInfo>().First(beatmapSet => beatmapSet.ID == importedSet.ID);
deleteBeatmapSet(imported, realmFactory.Context); deleteBeatmapSet(imported, realmFactory.Context);
}); });
@ -142,8 +242,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var imported = await LoadOszIntoStore(importer, realmFactory.Context); var imported = await LoadOszIntoStore(importer, realmFactory.Context);
var importedSecondTime = await LoadOszIntoStore(importer, realmFactory.Context); var importedSecondTime = await LoadOszIntoStore(importer, realmFactory.Context);
@ -162,8 +262,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? temp = TestResources.GetTestBeatmapForImport(); string? temp = TestResources.GetTestBeatmapForImport();
@ -190,7 +290,7 @@ namespace osu.Game.Tests.Database
var importedSecondTime = await importer.Import(new ImportTask(temp)); var importedSecondTime = await importer.Import(new ImportTask(temp));
ensureLoaded(realmFactory.Context); EnsureLoaded(realmFactory.Context);
Assert.NotNull(importedSecondTime); Assert.NotNull(importedSecondTime);
Debug.Assert(importedSecondTime != null); Debug.Assert(importedSecondTime != null);
@ -211,8 +311,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? temp = TestResources.GetTestBeatmapForImport(); string? temp = TestResources.GetTestBeatmapForImport();
@ -241,7 +341,7 @@ namespace osu.Game.Tests.Database
var importedSecondTime = await importer.Import(new ImportTask(temp)); var importedSecondTime = await importer.Import(new ImportTask(temp));
ensureLoaded(realmFactory.Context); EnsureLoaded(realmFactory.Context);
// check the newly "imported" beatmap is not the original. // check the newly "imported" beatmap is not the original.
Assert.NotNull(importedSecondTime); Assert.NotNull(importedSecondTime);
@ -263,8 +363,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? temp = TestResources.GetTestBeatmapForImport(); string? temp = TestResources.GetTestBeatmapForImport();
@ -290,7 +390,7 @@ namespace osu.Game.Tests.Database
var importedSecondTime = await importer.Import(new ImportTask(temp)); var importedSecondTime = await importer.Import(new ImportTask(temp));
ensureLoaded(realmFactory.Context); EnsureLoaded(realmFactory.Context);
Assert.NotNull(importedSecondTime); Assert.NotNull(importedSecondTime);
Debug.Assert(importedSecondTime != null); Debug.Assert(importedSecondTime != null);
@ -311,8 +411,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? temp = TestResources.GetTestBeatmapForImport(); string? temp = TestResources.GetTestBeatmapForImport();
@ -338,7 +438,7 @@ namespace osu.Game.Tests.Database
var importedSecondTime = await importer.Import(new ImportTask(temp)); var importedSecondTime = await importer.Import(new ImportTask(temp));
ensureLoaded(realmFactory.Context); EnsureLoaded(realmFactory.Context);
Assert.NotNull(importedSecondTime); Assert.NotNull(importedSecondTime);
Debug.Assert(importedSecondTime != null); Debug.Assert(importedSecondTime != null);
@ -360,8 +460,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var imported = await LoadOszIntoStore(importer, realmFactory.Context); var imported = await LoadOszIntoStore(importer, realmFactory.Context);
@ -393,8 +493,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var progressNotification = new ImportProgressNotification(); var progressNotification = new ImportProgressNotification();
@ -429,8 +529,8 @@ namespace osu.Game.Tests.Database
Interlocked.Increment(ref loggedExceptionCount); Interlocked.Increment(ref loggedExceptionCount);
}; };
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var imported = await LoadOszIntoStore(importer, realmFactory.Context); var imported = await LoadOszIntoStore(importer, realmFactory.Context);
@ -479,8 +579,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var imported = await LoadOszIntoStore(importer, realmFactory.Context); var imported = await LoadOszIntoStore(importer, realmFactory.Context);
@ -504,7 +604,7 @@ namespace osu.Game.Tests.Database
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new NonOptimisedBeatmapImporter(realmFactory, storage); using var importer = new NonOptimisedBeatmapImporter(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var imported = await LoadOszIntoStore(importer, realmFactory.Context); var imported = await LoadOszIntoStore(importer, realmFactory.Context);
@ -527,8 +627,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var imported = await LoadOszIntoStore(importer, realmFactory.Context); var imported = await LoadOszIntoStore(importer, realmFactory.Context);
@ -553,10 +653,10 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
var metadata = new RealmBeatmapMetadata var metadata = new BeatmapMetadata
{ {
Artist = "SomeArtist", Artist = "SomeArtist",
Author = Author =
@ -565,18 +665,18 @@ namespace osu.Game.Tests.Database
} }
}; };
var ruleset = realmFactory.Context.All<RealmRuleset>().First(); var ruleset = realmFactory.Context.All<RulesetInfo>().First();
var toImport = new RealmBeatmapSet var toImport = new BeatmapSetInfo
{ {
OnlineID = 1, OnlineID = 1,
Beatmaps = Beatmaps =
{ {
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata)
{ {
OnlineID = 2, OnlineID = 2,
}, },
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata)
{ {
OnlineID = 2, OnlineID = 2,
Status = BeatmapOnlineStatus.Loved, Status = BeatmapOnlineStatus.Loved,
@ -599,13 +699,13 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? temp = TestResources.GetTestBeatmapForImport(); string? temp = TestResources.GetTestBeatmapForImport();
using (File.OpenRead(temp)) using (File.OpenRead(temp))
await importer.Import(temp); await importer.Import(temp);
ensureLoaded(realmFactory.Context); EnsureLoaded(realmFactory.Context);
File.Delete(temp); File.Delete(temp);
Assert.IsFalse(File.Exists(temp), "We likely held a read lock on the file when we shouldn't"); Assert.IsFalse(File.Exists(temp), "We likely held a read lock on the file when we shouldn't");
}); });
@ -616,8 +716,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? temp = TestResources.GetTestBeatmapForImport(); string? temp = TestResources.GetTestBeatmapForImport();
@ -638,7 +738,7 @@ namespace osu.Game.Tests.Database
await importer.Import(temp); await importer.Import(temp);
ensureLoaded(realmFactory.Context); EnsureLoaded(realmFactory.Context);
} }
finally finally
{ {
@ -652,8 +752,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? temp = TestResources.GetTestBeatmapForImport(); string? temp = TestResources.GetTestBeatmapForImport();
@ -678,7 +778,7 @@ namespace osu.Game.Tests.Database
Assert.NotNull(imported); Assert.NotNull(imported);
Debug.Assert(imported != null); Debug.Assert(imported != null);
ensureLoaded(realmFactory.Context); EnsureLoaded(realmFactory.Context);
Assert.IsFalse(imported.PerformRead(s => s.Files.Any(f => f.Filename.Contains("subfolder"))), "Files contain common subfolder"); Assert.IsFalse(imported.PerformRead(s => s.Files.Any(f => f.Filename.Contains("subfolder"))), "Files contain common subfolder");
} }
@ -694,8 +794,8 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? temp = TestResources.GetTestBeatmapForImport(); string? temp = TestResources.GetTestBeatmapForImport();
@ -728,7 +828,7 @@ namespace osu.Game.Tests.Database
Assert.NotNull(imported); Assert.NotNull(imported);
Debug.Assert(imported != null); Debug.Assert(imported != null);
ensureLoaded(realmFactory.Context); EnsureLoaded(realmFactory.Context);
Assert.IsFalse(imported.PerformRead(s => s.Files.Any(f => f.Filename.Contains("__MACOSX"))), "Files contain resource fork folder, which should be ignored"); Assert.IsFalse(imported.PerformRead(s => s.Files.Any(f => f.Filename.Contains("__MACOSX"))), "Files contain resource fork folder, which should be ignored");
Assert.IsFalse(imported.PerformRead(s => s.Files.Any(f => f.Filename.Contains("actual_data"))), "Files contain common subfolder"); Assert.IsFalse(imported.PerformRead(s => s.Files.Any(f => f.Filename.Contains("actual_data"))), "Files contain common subfolder");
@ -745,25 +845,25 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealmAsync(async (realmFactory, storage) => RunTestWithRealmAsync(async (realmFactory, storage) =>
{ {
using var importer = new BeatmapImporter(realmFactory, storage); using var importer = new BeatmapModelManager(realmFactory, storage);
using var store = new RealmRulesetStore(realmFactory, storage); using var store = new RulesetStore(realmFactory, storage);
string? temp = TestResources.GetTestBeatmapForImport(); string? temp = TestResources.GetTestBeatmapForImport();
await importer.Import(temp); await importer.Import(temp);
// Update via the beatmap, not the beatmap info, to ensure correct linking // Update via the beatmap, not the beatmap info, to ensure correct linking
RealmBeatmapSet setToUpdate = realmFactory.Context.All<RealmBeatmapSet>().First(); BeatmapSetInfo setToUpdate = realmFactory.Context.All<BeatmapSetInfo>().First();
var beatmapToUpdate = setToUpdate.Beatmaps.First(); var beatmapToUpdate = setToUpdate.Beatmaps.First();
realmFactory.Context.Write(() => beatmapToUpdate.DifficultyName = "updated"); realmFactory.Context.Write(() => beatmapToUpdate.DifficultyName = "updated");
RealmBeatmap updatedInfo = realmFactory.Context.All<RealmBeatmap>().First(b => b.ID == beatmapToUpdate.ID); BeatmapInfo updatedInfo = realmFactory.Context.All<BeatmapInfo>().First(b => b.ID == beatmapToUpdate.ID);
Assert.That(updatedInfo.DifficultyName, Is.EqualTo("updated")); Assert.That(updatedInfo.DifficultyName, Is.EqualTo("updated"));
}); });
} }
public static async Task<RealmBeatmapSet?> LoadQuickOszIntoOsu(BeatmapImporter importer, Realm realm) public static async Task<BeatmapSetInfo?> LoadQuickOszIntoOsu(BeatmapImporter importer, Realm realm)
{ {
string? temp = TestResources.GetQuickTestBeatmapForImport(); string? temp = TestResources.GetQuickTestBeatmapForImport();
@ -771,14 +871,14 @@ namespace osu.Game.Tests.Database
Assert.NotNull(importedSet); Assert.NotNull(importedSet);
ensureLoaded(realm); EnsureLoaded(realm);
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000); waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
return realm.All<RealmBeatmapSet>().FirstOrDefault(beatmapSet => beatmapSet.ID == importedSet!.ID); return realm.All<BeatmapSetInfo>().FirstOrDefault(beatmapSet => beatmapSet.ID == importedSet!.ID);
} }
public static async Task<RealmBeatmapSet> LoadOszIntoStore(BeatmapImporter importer, Realm realm, string? path = null, bool virtualTrack = false) public static async Task<BeatmapSetInfo> LoadOszIntoStore(BeatmapImporter importer, Realm realm, string? path = null, bool virtualTrack = false)
{ {
string? temp = path ?? TestResources.GetTestBeatmapForImport(virtualTrack); string? temp = path ?? TestResources.GetTestBeatmapForImport(virtualTrack);
@ -787,24 +887,24 @@ namespace osu.Game.Tests.Database
Assert.NotNull(importedSet); Assert.NotNull(importedSet);
Debug.Assert(importedSet != null); Debug.Assert(importedSet != null);
ensureLoaded(realm); EnsureLoaded(realm);
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000); waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
return realm.All<RealmBeatmapSet>().First(beatmapSet => beatmapSet.ID == importedSet.ID); return realm.All<BeatmapSetInfo>().First(beatmapSet => beatmapSet.ID == importedSet.ID);
} }
private void deleteBeatmapSet(RealmBeatmapSet imported, Realm realm) private void deleteBeatmapSet(BeatmapSetInfo imported, Realm realm)
{ {
realm.Write(() => imported.DeletePending = true); realm.Write(() => imported.DeletePending = true);
checkBeatmapSetCount(realm, 0); checkBeatmapSetCount(realm, 0);
checkBeatmapSetCount(realm, 1, true); checkBeatmapSetCount(realm, 1, true);
Assert.IsTrue(realm.All<RealmBeatmapSet>().First(_ => true).DeletePending); Assert.IsTrue(realm.All<BeatmapSetInfo>().First(_ => true).DeletePending);
} }
private static Task createScoreForBeatmap(Realm realm, RealmBeatmap beatmap) private static Task createScoreForBeatmap(Realm realm, BeatmapInfo beatmap)
{ {
// TODO: reimplement when we have score support in realm. // TODO: reimplement when we have score support in realm.
// return ImportScoreTest.LoadScoreIntoOsu(osu, new ScoreInfo // return ImportScoreTest.LoadScoreIntoOsu(osu, new ScoreInfo
@ -820,8 +920,8 @@ namespace osu.Game.Tests.Database
private static void checkBeatmapSetCount(Realm realm, int expected, bool includeDeletePending = false) private static void checkBeatmapSetCount(Realm realm, int expected, bool includeDeletePending = false)
{ {
Assert.AreEqual(expected, includeDeletePending Assert.AreEqual(expected, includeDeletePending
? realm.All<RealmBeatmapSet>().Count() ? realm.All<BeatmapSetInfo>().Count()
: realm.All<RealmBeatmapSet>().Count(s => !s.DeletePending)); : realm.All<BeatmapSetInfo>().Count(s => !s.DeletePending));
} }
private static string hashFile(string filename) private static string hashFile(string filename)
@ -832,7 +932,7 @@ namespace osu.Game.Tests.Database
private static void checkBeatmapCount(Realm realm, int expected) private static void checkBeatmapCount(Realm realm, int expected)
{ {
Assert.AreEqual(expected, realm.All<RealmBeatmap>().Where(_ => true).ToList().Count); Assert.AreEqual(expected, realm.All<BeatmapInfo>().Where(_ => true).ToList().Count);
} }
private static void checkSingleReferencedFileCount(Realm realm, int expected) private static void checkSingleReferencedFileCount(Realm realm, int expected)
@ -848,26 +948,25 @@ namespace osu.Game.Tests.Database
Assert.AreEqual(expected, singleReferencedCount); Assert.AreEqual(expected, singleReferencedCount);
} }
private static void ensureLoaded(Realm realm, int timeout = 60000) internal static void EnsureLoaded(Realm realm, int timeout = 60000)
{ {
IQueryable<RealmBeatmapSet>? resultSets = null; IQueryable<BeatmapSetInfo>? resultSets = null;
waitForOrAssert(() => waitForOrAssert(() =>
{ {
realm.Refresh(); realm.Refresh();
return (resultSets = realm.All<RealmBeatmapSet>().Where(s => !s.DeletePending && s.OnlineID == 241526)).Any(); return (resultSets = realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending && s.OnlineID == 241526)).Any();
}, }, @"BeatmapSet did not import to the database in allocated time.", timeout);
@"BeatmapSet did not import to the database in allocated time.", timeout);
// ensure we were stored to beatmap database backing... // ensure we were stored to beatmap database backing...
Assert.IsTrue(resultSets?.Count() == 1, $@"Incorrect result count found ({resultSets?.Count()} but should be 1)."); Assert.IsTrue(resultSets?.Count() == 1, $@"Incorrect result count found ({resultSets?.Count()} but should be 1).");
IEnumerable<RealmBeatmapSet> queryBeatmapSets() => realm.All<RealmBeatmapSet>().Where(s => !s.DeletePending && s.OnlineID == 241526); IEnumerable<BeatmapSetInfo> queryBeatmapSets() => realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending && s.OnlineID == 241526);
var set = queryBeatmapSets().First(); var set = queryBeatmapSets().First();
// ReSharper disable once PossibleUnintendedReferenceComparison // ReSharper disable once PossibleUnintendedReferenceComparison
IEnumerable<RealmBeatmap> queryBeatmaps() => realm.All<RealmBeatmap>().Where(s => s.BeatmapSet != null && s.BeatmapSet == set); IEnumerable<BeatmapInfo> queryBeatmaps() => realm.All<BeatmapInfo>().Where(s => s.BeatmapSet != null && s.BeatmapSet == set);
Assert.AreEqual(12, queryBeatmaps().Count(), @"Beatmap count was not correct"); Assert.AreEqual(12, queryBeatmaps().Count(), @"Beatmap count was not correct");
Assert.AreEqual(1, queryBeatmapSets().Count(), @"Beatmapset count was not correct"); Assert.AreEqual(1, queryBeatmapSets().Count(), @"Beatmapset count was not correct");
@ -880,7 +979,7 @@ namespace osu.Game.Tests.Database
countBeatmaps = queryBeatmaps().Count(), countBeatmaps = queryBeatmaps().Count(),
$@"Incorrect database beatmap count post-import ({countBeatmaps} but should be {countBeatmapSetBeatmaps})."); $@"Incorrect database beatmap count post-import ({countBeatmaps} but should be {countBeatmapSetBeatmaps}).");
foreach (RealmBeatmap b in set.Beatmaps) foreach (BeatmapInfo b in set.Beatmaps)
Assert.IsTrue(set.Beatmaps.Any(c => c.OnlineID == b.OnlineID)); Assert.IsTrue(set.Beatmaps.Any(c => c.OnlineID == b.OnlineID));
Assert.IsTrue(set.Beatmaps.Count > 0); Assert.IsTrue(set.Beatmaps.Count > 0);
} }

View File

@ -5,8 +5,8 @@ using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Models;
#nullable enable #nullable enable
@ -48,7 +48,7 @@ namespace osu.Game.Tests.Database
using (var context = realmFactory.CreateContext()) using (var context = realmFactory.CreateContext())
{ {
var subscription = context.All<RealmBeatmap>().QueryAsyncWithNotifications((sender, changes, error) => var subscription = context.All<BeatmapInfo>().QueryAsyncWithNotifications((sender, changes, error) =>
{ {
using (realmFactory.CreateContext()) using (realmFactory.CreateContext())
{ {

View File

@ -8,8 +8,8 @@ using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Models;
using Realms; using Realms;
#nullable enable #nullable enable
@ -23,9 +23,9 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, _) => RunTestWithRealm((realmFactory, _) =>
{ {
ILive<RealmBeatmap> beatmap = realmFactory.CreateContext().Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))).ToLive(realmFactory); ILive<BeatmapInfo> beatmap = realmFactory.CreateContext().Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata()))).ToLive(realmFactory);
ILive<RealmBeatmap> beatmap2 = realmFactory.CreateContext().All<RealmBeatmap>().First().ToLive(realmFactory); ILive<BeatmapInfo> beatmap2 = realmFactory.CreateContext().All<BeatmapInfo>().First().ToLive(realmFactory);
Assert.AreEqual(beatmap, beatmap2); Assert.AreEqual(beatmap, beatmap2);
}); });
@ -36,9 +36,9 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, storage) => RunTestWithRealm((realmFactory, storage) =>
{ {
var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()); var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
ILive<RealmBeatmap> liveBeatmap; ILive<BeatmapInfo> liveBeatmap;
using (var context = realmFactory.CreateContext()) using (var context = realmFactory.CreateContext())
{ {
@ -63,7 +63,7 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, _) => RunTestWithRealm((realmFactory, _) =>
{ {
var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()); var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
var liveBeatmap = beatmap.ToLive(realmFactory); var liveBeatmap = beatmap.ToLive(realmFactory);
@ -77,7 +77,7 @@ namespace osu.Game.Tests.Database
[Test] [Test]
public void TestAccessNonManaged() public void TestAccessNonManaged()
{ {
var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()); var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
var liveBeatmap = beatmap.ToLiveUnmanaged(); var liveBeatmap = beatmap.ToLiveUnmanaged();
Assert.IsFalse(beatmap.Hidden); Assert.IsFalse(beatmap.Hidden);
@ -96,12 +96,12 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, _) => RunTestWithRealm((realmFactory, _) =>
{ {
ILive<RealmBeatmap>? liveBeatmap = null; ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
using (var threadContext = realmFactory.CreateContext()) using (var threadContext = realmFactory.CreateContext())
{ {
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory); liveBeatmap = beatmap.ToLive(realmFactory);
} }
@ -125,12 +125,12 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, _) => RunTestWithRealm((realmFactory, _) =>
{ {
ILive<RealmBeatmap>? liveBeatmap = null; ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
using (var threadContext = realmFactory.CreateContext()) using (var threadContext = realmFactory.CreateContext())
{ {
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory); liveBeatmap = beatmap.ToLive(realmFactory);
} }
@ -151,7 +151,7 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, _) => RunTestWithRealm((realmFactory, _) =>
{ {
var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()); var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
var liveBeatmap = beatmap.ToLive(realmFactory); var liveBeatmap = beatmap.ToLive(realmFactory);
Assert.DoesNotThrow(() => Assert.DoesNotThrow(() =>
@ -166,13 +166,13 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, _) => RunTestWithRealm((realmFactory, _) =>
{ {
ILive<RealmBeatmap>? liveBeatmap = null; ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
using (var threadContext = realmFactory.CreateContext()) using (var threadContext = realmFactory.CreateContext())
{ {
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory); liveBeatmap = beatmap.ToLive(realmFactory);
} }
@ -205,12 +205,12 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, _) => RunTestWithRealm((realmFactory, _) =>
{ {
ILive<RealmBeatmap>? liveBeatmap = null; ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
using (var threadContext = realmFactory.CreateContext()) using (var threadContext = realmFactory.CreateContext())
{ {
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory); liveBeatmap = beatmap.ToLive(realmFactory);
} }
@ -237,19 +237,19 @@ namespace osu.Game.Tests.Database
using (var updateThreadContext = realmFactory.CreateContext()) using (var updateThreadContext = realmFactory.CreateContext())
{ {
updateThreadContext.All<RealmBeatmap>().QueryAsyncWithNotifications(gotChange); updateThreadContext.All<BeatmapInfo>().QueryAsyncWithNotifications(gotChange);
ILive<RealmBeatmap>? liveBeatmap = null; ILive<BeatmapInfo>? liveBeatmap = null;
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
using (var threadContext = realmFactory.CreateContext()) using (var threadContext = realmFactory.CreateContext())
{ {
var ruleset = CreateRuleset(); var ruleset = CreateRuleset();
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(ruleset, new BeatmapDifficulty(), new BeatmapMetadata())));
// add a second beatmap to ensure that a full refresh occurs below. // add a second beatmap to ensure that a full refresh occurs below.
// not just a refresh from the resolved Live. // not just a refresh from the resolved Live.
threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))); threadContext.Write(r => r.Add(new BeatmapInfo(ruleset, new BeatmapDifficulty(), new BeatmapMetadata())));
liveBeatmap = beatmap.ToLive(realmFactory); liveBeatmap = beatmap.ToLive(realmFactory);
} }
@ -258,14 +258,14 @@ namespace osu.Game.Tests.Database
Debug.Assert(liveBeatmap != null); Debug.Assert(liveBeatmap != null);
// not yet seen by main context // not yet seen by main context
Assert.AreEqual(0, updateThreadContext.All<RealmBeatmap>().Count()); Assert.AreEqual(0, updateThreadContext.All<BeatmapInfo>().Count());
Assert.AreEqual(0, changesTriggered); Assert.AreEqual(0, changesTriggered);
liveBeatmap.PerformRead(resolved => liveBeatmap.PerformRead(resolved =>
{ {
// retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point. // retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point.
// ReSharper disable once AccessToDisposedClosure // ReSharper disable once AccessToDisposedClosure
Assert.AreEqual(2, updateThreadContext.All<RealmBeatmap>().Count()); Assert.AreEqual(2, updateThreadContext.All<BeatmapInfo>().Count());
Assert.AreEqual(1, changesTriggered); Assert.AreEqual(1, changesTriggered);
// can access properties without a crash. // can access properties without a crash.
@ -280,7 +280,7 @@ namespace osu.Game.Tests.Database
}); });
} }
void gotChange(IRealmCollection<RealmBeatmap> sender, ChangeSet changes, Exception error) void gotChange(IRealmCollection<BeatmapInfo> sender, ChangeSet changes, Exception error)
{ {
changesTriggered++; changesTriggered++;
} }

View File

@ -9,9 +9,11 @@ using osu.Framework.Extensions;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Models; using osu.Game.Models;
using osu.Game.Rulesets;
#nullable enable #nullable enable
@ -74,24 +76,24 @@ namespace osu.Game.Tests.Database
} }
} }
protected static RealmBeatmapSet CreateBeatmapSet(RealmRuleset ruleset) protected static BeatmapSetInfo CreateBeatmapSet(RulesetInfo ruleset)
{ {
RealmFile createRealmFile() => new RealmFile { Hash = Guid.NewGuid().ToString().ComputeSHA2Hash() }; RealmFile createRealmFile() => new RealmFile { Hash = Guid.NewGuid().ToString().ComputeSHA2Hash() };
var metadata = new RealmBeatmapMetadata var metadata = new BeatmapMetadata
{ {
Title = "My Love", Title = "My Love",
Artist = "Kuba Oms" Artist = "Kuba Oms"
}; };
var beatmapSet = new RealmBeatmapSet var beatmapSet = new BeatmapSetInfo
{ {
Beatmaps = Beatmaps =
{ {
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Easy", }, new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata) { DifficultyName = "Easy", },
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Normal", }, new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata) { DifficultyName = "Normal", },
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Hard", }, new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata) { DifficultyName = "Hard", },
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Insane", } new BeatmapInfo(ruleset, new BeatmapDifficulty(), metadata) { DifficultyName = "Insane", }
}, },
Files = Files =
{ {
@ -111,8 +113,8 @@ namespace osu.Game.Tests.Database
return beatmapSet; return beatmapSet;
} }
protected static RealmRuleset CreateRuleset() => protected static RulesetInfo CreateRuleset() =>
new RealmRuleset(0, "osu!", "osu", true); new RulesetInfo(0, "osu!", "osu", true);
private class RealmTestGame : Framework.Game private class RealmTestGame : Framework.Game
{ {

View File

@ -3,8 +3,7 @@
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Models; using osu.Game.Rulesets;
using osu.Game.Stores;
namespace osu.Game.Tests.Database namespace osu.Game.Tests.Database
{ {
@ -15,10 +14,10 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, storage) => RunTestWithRealm((realmFactory, storage) =>
{ {
var rulesets = new RealmRulesetStore(realmFactory, storage); var rulesets = new RulesetStore(realmFactory, storage);
Assert.AreEqual(4, rulesets.AvailableRulesets.Count()); Assert.AreEqual(4, rulesets.AvailableRulesets.Count());
Assert.AreEqual(4, realmFactory.Context.All<RealmRuleset>().Count()); Assert.AreEqual(4, realmFactory.Context.All<RulesetInfo>().Count());
}); });
} }
@ -27,14 +26,14 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, storage) => RunTestWithRealm((realmFactory, storage) =>
{ {
var rulesets = new RealmRulesetStore(realmFactory, storage); var rulesets = new RulesetStore(realmFactory, storage);
var rulesets2 = new RealmRulesetStore(realmFactory, storage); var rulesets2 = new RulesetStore(realmFactory, storage);
Assert.AreEqual(4, rulesets.AvailableRulesets.Count()); Assert.AreEqual(4, rulesets.AvailableRulesets.Count());
Assert.AreEqual(4, rulesets2.AvailableRulesets.Count()); Assert.AreEqual(4, rulesets2.AvailableRulesets.Count());
Assert.AreEqual(rulesets.AvailableRulesets.First(), rulesets2.AvailableRulesets.First()); Assert.AreEqual(rulesets.AvailableRulesets.First(), rulesets2.AvailableRulesets.First());
Assert.AreEqual(4, realmFactory.Context.All<RealmRuleset>().Count()); Assert.AreEqual(4, realmFactory.Context.All<RulesetInfo>().Count());
}); });
} }
@ -43,7 +42,7 @@ namespace osu.Game.Tests.Database
{ {
RunTestWithRealm((realmFactory, storage) => RunTestWithRealm((realmFactory, storage) =>
{ {
var rulesets = new RealmRulesetStore(realmFactory, storage); var rulesets = new RulesetStore(realmFactory, storage);
Assert.IsFalse(rulesets.AvailableRulesets.First().IsManaged); Assert.IsFalse(rulesets.AvailableRulesets.First().IsManaged);
Assert.IsFalse(rulesets.GetRuleset(0)?.IsManaged); Assert.IsFalse(rulesets.GetRuleset(0)?.IsManaged);

View File

@ -74,7 +74,7 @@ namespace osu.Game.Tests.Editing.Checks
[Test] [Test]
public void TestMissingFile() public void TestMissingFile()
{ {
beatmap.BeatmapInfo.BeatmapSet.Files.Clear(); beatmap.BeatmapInfo.BeatmapSet?.Files.Clear();
var issues = check.Run(getContext(null)).ToList(); var issues = check.Run(getContext(null)).ToList();

View File

@ -46,7 +46,7 @@ namespace osu.Game.Tests.Editing.Checks
[Test] [Test]
public void TestBackgroundSetAndNotInFiles() public void TestBackgroundSetAndNotInFiles()
{ {
beatmap.BeatmapInfo.BeatmapSet.Files.Clear(); beatmap.BeatmapInfo.BeatmapSet?.Files.Clear();
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap)); var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
var issues = check.Run(context).ToList(); var issues = check.Run(context).ToList();

View File

@ -1,18 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Game.Beatmaps; using osu.Game.Models;
using osu.Game.IO;
namespace osu.Game.Tests.Editing.Checks namespace osu.Game.Tests.Editing.Checks
{ {
public static class CheckTestHelpers public static class CheckTestHelpers
{ {
public static BeatmapSetFileInfo CreateMockFile(string extension) => public static RealmNamedFileUsage CreateMockFile(string extension) =>
new BeatmapSetFileInfo new RealmNamedFileUsage(new RealmFile { Hash = "abcdef" }, $"abc123.{extension}");
{
Filename = $"abc123.{extension}",
FileInfo = new FileInfo { Hash = "abcdef" }
};
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using ManagedBass; using ManagedBass;
@ -45,6 +46,8 @@ namespace osu.Game.Tests.Editing.Checks
[Test] [Test]
public void TestDifferentExtension() public void TestDifferentExtension()
{ {
Debug.Assert(beatmap.BeatmapInfo.BeatmapSet != null);
beatmap.BeatmapInfo.BeatmapSet.Files.Clear(); beatmap.BeatmapInfo.BeatmapSet.Files.Clear();
beatmap.BeatmapInfo.BeatmapSet.Files.Add(CheckTestHelpers.CreateMockFile("jpg")); beatmap.BeatmapInfo.BeatmapSet.Files.Add(CheckTestHelpers.CreateMockFile("jpg"));

View File

@ -2,7 +2,8 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Beatmaps; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
@ -158,7 +159,13 @@ namespace osu.Game.Tests.Editing
private (EditorChangeHandler, EditorBeatmap) createChangeHandler() private (EditorChangeHandler, EditorBeatmap) createChangeHandler()
{ {
var beatmap = new EditorBeatmap(new Beatmap()); var beatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
});
var changeHandler = new EditorChangeHandler(beatmap); var changeHandler = new EditorChangeHandler(beatmap);

View File

@ -35,7 +35,13 @@ namespace osu.Game.Tests.Editing
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
editorBeatmap = new EditorBeatmap(new OsuBeatmap()), editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
}),
Content = new Container Content = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Extensions; using osu.Game.Extensions;
@ -23,8 +24,10 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestDatabasedWithDatabased() public void TestDatabasedWithDatabased()
{ {
var ourInfo = new BeatmapSetInfo { ID = 123 }; var guid = Guid.NewGuid();
var otherInfo = new BeatmapSetInfo { ID = 123 };
var ourInfo = new BeatmapSetInfo { ID = guid };
var otherInfo = new BeatmapSetInfo { ID = guid };
Assert.AreEqual(ourInfo, otherInfo); Assert.AreEqual(ourInfo, otherInfo);
} }
@ -32,7 +35,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestDatabasedWithOnline() public void TestDatabasedWithOnline()
{ {
var ourInfo = new BeatmapSetInfo { ID = 123, OnlineID = 12 }; var ourInfo = new BeatmapSetInfo { ID = Guid.NewGuid(), OnlineID = 12 };
var otherInfo = new BeatmapSetInfo { OnlineID = 12 }; var otherInfo = new BeatmapSetInfo { OnlineID = 12 };
Assert.AreNotEqual(ourInfo, otherInfo); Assert.AreNotEqual(ourInfo, otherInfo);

View File

@ -179,7 +179,7 @@ namespace osu.Game.Tests.NonVisual
{ {
var osu = LoadOsuIntoHost(host); var osu = LoadOsuIntoHost(host);
const string database_filename = "client.db"; const string database_filename = "client.realm";
Assert.DoesNotThrow(() => osu.Migrate(customPath)); Assert.DoesNotThrow(() => osu.Migrate(customPath));
Assert.That(File.Exists(Path.Combine(customPath, database_filename))); Assert.That(File.Exists(Path.Combine(customPath, database_filename)));

View File

@ -17,7 +17,6 @@ namespace osu.Game.Tests.NonVisual.Filtering
private BeatmapInfo getExampleBeatmap() => new BeatmapInfo private BeatmapInfo getExampleBeatmap() => new BeatmapInfo
{ {
Ruleset = new RulesetInfo { OnlineID = 0 }, Ruleset = new RulesetInfo { OnlineID = 0 },
RulesetID = 0,
StarRating = 4.0d, StarRating = 4.0d,
BaseDifficulty = new BeatmapDifficulty BaseDifficulty = new BeatmapDifficulty
{ {

View File

@ -9,10 +9,12 @@ using osu.Framework.Bindables;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Solo; using osu.Game.Online.Solo;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Scoring; using osu.Game.Scoring;
@ -93,7 +95,11 @@ namespace osu.Game.Tests.Online
[Test] [Test]
public void TestDeserialiseSubmittableScoreWithEmptyMods() public void TestDeserialiseSubmittableScoreWithEmptyMods()
{ {
var score = new SubmittableScore(new ScoreInfo()); var score = new SubmittableScore(new ScoreInfo
{
User = new APIUser(),
Ruleset = new OsuRuleset().RulesetInfo,
});
var deserialised = JsonConvert.DeserializeObject<SubmittableScore>(JsonConvert.SerializeObject(score)); var deserialised = JsonConvert.DeserializeObject<SubmittableScore>(JsonConvert.SerializeObject(score));
@ -105,7 +111,9 @@ namespace osu.Game.Tests.Online
{ {
var score = new SubmittableScore(new ScoreInfo var score = new SubmittableScore(new ScoreInfo
{ {
Mods = new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 2 } } } Mods = new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 2 } } },
User = new APIUser(),
Ruleset = new OsuRuleset().RulesetInfo,
}); });
var deserialised = JsonConvert.DeserializeObject<SubmittableScore>(JsonConvert.SerializeObject(score)); var deserialised = JsonConvert.DeserializeObject<SubmittableScore>(JsonConvert.SerializeObject(score));

View File

@ -5,6 +5,7 @@ using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Models;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
@ -20,13 +21,19 @@ namespace osu.Game.Tests.Online
private static readonly BeatmapSetInfo test_db_model = new BeatmapSetInfo private static readonly BeatmapSetInfo test_db_model = new BeatmapSetInfo
{ {
OnlineID = 1, OnlineID = 1,
Metadata = new BeatmapMetadata Beatmaps =
{ {
Artist = "test author", new BeatmapInfo
Title = "test title",
Author = new APIUser
{ {
Username = "mapper" Metadata = new BeatmapMetadata
{
Artist = "test author",
Title = "test title",
Author = new RealmUser
{
Username = "mapper"
}
}
} }
} }
}; };

View File

@ -60,9 +60,8 @@ namespace osu.Game.Tests.Online
testBeatmapInfo = getTestBeatmapInfo(testBeatmapFile); testBeatmapInfo = getTestBeatmapInfo(testBeatmapFile);
testBeatmapSet = testBeatmapInfo.BeatmapSet; testBeatmapSet = testBeatmapInfo.BeatmapSet;
var existing = beatmaps.QueryBeatmapSet(s => s.OnlineID == testBeatmapSet.OnlineID); ContextFactory.Context.Write(r => r.RemoveAll<BeatmapSetInfo>());
if (existing != null) ContextFactory.Context.Write(r => r.RemoveAll<BeatmapInfo>());
beatmaps.Delete(existing);
selectedItem.Value = new PlaylistItem selectedItem.Value = new PlaylistItem
{ {
@ -103,10 +102,10 @@ namespace osu.Game.Tests.Online
AddStep("import beatmap", () => beatmaps.Import(testBeatmapFile).WaitSafely()); AddStep("import beatmap", () => beatmaps.Import(testBeatmapFile).WaitSafely());
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable); addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
AddStep("delete beatmap", () => beatmaps.Delete(beatmaps.QueryBeatmapSet(b => b.OnlineID == testBeatmapSet.OnlineID))); AddStep("delete beatmap", () => beatmaps.Delete(beatmaps.QueryBeatmapSet(b => b.OnlineID == testBeatmapSet.OnlineID)!.Value));
addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded); addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded);
AddStep("undelete beatmap", () => beatmaps.Undelete(beatmaps.QueryBeatmapSet(b => b.OnlineID == testBeatmapSet.OnlineID))); AddStep("undelete beatmap", () => beatmaps.Undelete(beatmaps.QueryBeatmapSet(b => b.OnlineID == testBeatmapSet.OnlineID)!.Value));
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable); addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
} }
@ -154,7 +153,6 @@ namespace osu.Game.Tests.Online
Debug.Assert(info.BeatmapSet != null); Debug.Assert(info.BeatmapSet != null);
info.BeatmapSet.Beatmaps.Add(info); info.BeatmapSet.Beatmaps.Add(info);
info.BeatmapSet.Metadata = info.Metadata;
info.MD5Hash = stream.ComputeMD5Hash(); info.MD5Hash = stream.ComputeMD5Hash();
info.Hash = stream.ComputeSHA2Hash(); info.Hash = stream.ComputeSHA2Hash();
} }
@ -168,22 +166,22 @@ namespace osu.Game.Tests.Online
public Task<ILive<BeatmapSetInfo>> CurrentImportTask { get; private set; } public Task<ILive<BeatmapSetInfo>> CurrentImportTask { get; private set; }
public TestBeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host = null, WorkingBeatmap defaultBeatmap = null) public TestBeatmapManager(Storage storage, RealmContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host = null, WorkingBeatmap defaultBeatmap = null)
: base(storage, contextFactory, rulesets, api, audioManager, resources, host, defaultBeatmap) : base(storage, contextFactory, rulesets, api, audioManager, resources, host, defaultBeatmap)
{ {
} }
protected override BeatmapModelManager CreateBeatmapModelManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, GameHost host) protected override BeatmapModelManager CreateBeatmapModelManager(Storage storage, RealmContextFactory contextFactory, RulesetStore rulesets, BeatmapOnlineLookupQueue onlineLookupQueue)
{ {
return new TestBeatmapModelManager(this, storage, contextFactory, rulesets, api, host); return new TestBeatmapModelManager(this, storage, contextFactory, rulesets, onlineLookupQueue);
} }
internal class TestBeatmapModelManager : BeatmapModelManager internal class TestBeatmapModelManager : BeatmapModelManager
{ {
private readonly TestBeatmapManager testBeatmapManager; private readonly TestBeatmapManager testBeatmapManager;
public TestBeatmapModelManager(TestBeatmapManager testBeatmapManager, Storage storage, IDatabaseContextFactory databaseContextFactory, RulesetStore rulesetStore, IAPIProvider apiProvider, GameHost gameHost) public TestBeatmapModelManager(TestBeatmapManager testBeatmapManager, Storage storage, RealmContextFactory databaseContextFactory, RulesetStore rulesetStore, BeatmapOnlineLookupQueue beatmapOnlineLookupQueue)
: base(storage, databaseContextFactory, rulesetStore, gameHost) : base(databaseContextFactory, storage, beatmapOnlineLookupQueue)
{ {
this.testBeatmapManager = testBeatmapManager; this.testBeatmapManager = testBeatmapManager;
} }

View File

@ -97,7 +97,6 @@ namespace osu.Game.Tests.Resources
OnlineID = setId, OnlineID = setId,
Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(), Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(),
DateAdded = DateTimeOffset.UtcNow, DateAdded = DateTimeOffset.UtcNow,
Metadata = metadata
}; };
foreach (var b in getBeatmaps(difficultyCount ?? RNG.Next(1, 20))) foreach (var b in getBeatmaps(difficultyCount ?? RNG.Next(1, 20)))
@ -131,8 +130,8 @@ namespace osu.Game.Tests.Resources
StarRating = diff, StarRating = diff,
Length = length, Length = length,
BPM = bpm, BPM = bpm,
Hash = Guid.NewGuid().ToString().ComputeMD5Hash(),
Ruleset = rulesetInfo, Ruleset = rulesetInfo,
RulesetID = rulesetInfo.ID ?? -1,
Metadata = metadata, Metadata = metadata,
BaseDifficulty = new BeatmapDifficulty BaseDifficulty = new BeatmapDifficulty
{ {
@ -166,7 +165,6 @@ namespace osu.Game.Tests.Resources
}, },
BeatmapInfo = beatmap, BeatmapInfo = beatmap,
Ruleset = beatmap.Ruleset, Ruleset = beatmap.Ruleset,
RulesetID = beatmap.Ruleset.ID ?? 0,
Mods = new Mod[] { new TestModHardRock(), new TestModDoubleTime() }, Mods = new Mod[] { new TestModHardRock(), new TestModDoubleTime() },
TotalScore = 2845370, TotalScore = 2845370,
Accuracy = 0.95, Accuracy = 0.95,

View File

@ -8,8 +8,8 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.IO.Archives; using osu.Game.IO.Archives;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
@ -17,6 +17,8 @@ using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Scores.IO namespace osu.Game.Tests.Scores.IO
{ {
@ -31,6 +33,8 @@ namespace osu.Game.Tests.Scores.IO
{ {
var osu = LoadOsuIntoHost(host, true); var osu = LoadOsuIntoHost(host, true);
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
var toImport = new ScoreInfo var toImport = new ScoreInfo
{ {
Rank = ScoreRank.B, Rank = ScoreRank.B,
@ -41,6 +45,8 @@ namespace osu.Game.Tests.Scores.IO
User = new APIUser { Username = "Test user" }, User = new APIUser { Username = "Test user" },
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
OnlineID = 12345, OnlineID = 12345,
Ruleset = new OsuRuleset().RulesetInfo,
BeatmapInfo = beatmap.Beatmaps.First()
}; };
var imported = await LoadScoreIntoOsu(osu, toImport); var imported = await LoadScoreIntoOsu(osu, toImport);
@ -49,7 +55,6 @@ namespace osu.Game.Tests.Scores.IO
Assert.AreEqual(toImport.TotalScore, imported.TotalScore); Assert.AreEqual(toImport.TotalScore, imported.TotalScore);
Assert.AreEqual(toImport.Accuracy, imported.Accuracy); Assert.AreEqual(toImport.Accuracy, imported.Accuracy);
Assert.AreEqual(toImport.MaxCombo, imported.MaxCombo); Assert.AreEqual(toImport.MaxCombo, imported.MaxCombo);
Assert.AreEqual(toImport.Combo, imported.Combo);
Assert.AreEqual(toImport.User.Username, imported.User.Username); Assert.AreEqual(toImport.User.Username, imported.User.Username);
Assert.AreEqual(toImport.Date, imported.Date); Assert.AreEqual(toImport.Date, imported.Date);
Assert.AreEqual(toImport.OnlineID, imported.OnlineID); Assert.AreEqual(toImport.OnlineID, imported.OnlineID);
@ -70,8 +75,13 @@ namespace osu.Game.Tests.Scores.IO
{ {
var osu = LoadOsuIntoHost(host, true); var osu = LoadOsuIntoHost(host, true);
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
var toImport = new ScoreInfo var toImport = new ScoreInfo
{ {
User = new APIUser { Username = "Test user" },
BeatmapInfo = beatmap.Beatmaps.First(),
Ruleset = new OsuRuleset().RulesetInfo,
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() }, Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
}; };
@ -96,8 +106,13 @@ namespace osu.Game.Tests.Scores.IO
{ {
var osu = LoadOsuIntoHost(host, true); var osu = LoadOsuIntoHost(host, true);
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
var toImport = new ScoreInfo var toImport = new ScoreInfo
{ {
User = new APIUser { Username = "Test user" },
BeatmapInfo = beatmap.Beatmaps.First(),
Ruleset = new OsuRuleset().RulesetInfo,
Statistics = new Dictionary<HitResult, int> Statistics = new Dictionary<HitResult, int>
{ {
{ HitResult.Perfect, 100 }, { HitResult.Perfect, 100 },
@ -117,43 +132,6 @@ namespace osu.Game.Tests.Scores.IO
} }
} }
[Test]
public async Task TestImportWithDeletedBeatmapSet()
{
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
{
try
{
var osu = LoadOsuIntoHost(host, true);
var toImport = new ScoreInfo
{
Hash = Guid.NewGuid().ToString(),
Statistics = new Dictionary<HitResult, int>
{
{ HitResult.Perfect, 100 },
{ HitResult.Miss, 50 }
}
};
var imported = await LoadScoreIntoOsu(osu, toImport);
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
var scoreManager = osu.Dependencies.Get<ScoreManager>();
beatmapManager.Delete(beatmapManager.QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == imported.BeatmapInfo.ID)));
Assert.That(scoreManager.Query(s => s.Equals(imported)).DeletePending, Is.EqualTo(true));
var secondImport = await LoadScoreIntoOsu(osu, imported);
Assert.That(secondImport, Is.Null);
}
finally
{
host.Exit();
}
}
}
[Test] [Test]
public async Task TestOnlineScoreIsAvailableLocally() public async Task TestOnlineScoreIsAvailableLocally()
{ {
@ -163,12 +141,25 @@ namespace osu.Game.Tests.Scores.IO
{ {
var osu = LoadOsuIntoHost(host, true); var osu = LoadOsuIntoHost(host, true);
await LoadScoreIntoOsu(osu, new ScoreInfo { OnlineID = 2 }, new TestArchiveReader()); var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
await LoadScoreIntoOsu(osu, new ScoreInfo
{
User = new APIUser { Username = "Test user" },
BeatmapInfo = beatmap.Beatmaps.First(),
Ruleset = new OsuRuleset().RulesetInfo,
OnlineID = 2
}, new TestArchiveReader());
var scoreManager = osu.Dependencies.Get<ScoreManager>(); var scoreManager = osu.Dependencies.Get<ScoreManager>();
// Note: A new score reference is used here since the import process mutates the original object to set an ID // Note: A new score reference is used here since the import process mutates the original object to set an ID
Assert.That(scoreManager.IsAvailableLocally(new ScoreInfo { OnlineID = 2 })); Assert.That(scoreManager.IsAvailableLocally(new ScoreInfo
{
User = new APIUser { Username = "Test user" },
BeatmapInfo = beatmap.Beatmaps.First(),
OnlineID = 2
}));
} }
finally finally
{ {
@ -179,15 +170,13 @@ namespace osu.Game.Tests.Scores.IO
public static async Task<ScoreInfo> LoadScoreIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null) public static async Task<ScoreInfo> LoadScoreIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null)
{ {
var beatmapManager = osu.Dependencies.Get<BeatmapManager>(); // clone to avoid attaching the input score to realm.
score = score.DeepClone();
score.BeatmapInfo ??= beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();
score.Ruleset ??= new OsuRuleset().RulesetInfo;
var scoreManager = osu.Dependencies.Get<ScoreManager>(); var scoreManager = osu.Dependencies.Get<ScoreManager>();
await scoreManager.Import(score, archive); await scoreManager.Import(score, archive);
return scoreManager.GetAllUsableScores().FirstOrDefault(); return scoreManager.Query(_ => true);
} }
internal class TestArchiveReader : ArchiveReader internal class TestArchiveReader : ArchiveReader

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Scoring; using osu.Game.Scoring;
@ -29,8 +30,8 @@ namespace osu.Game.Tests.Scores.IO
[Test] [Test]
public void TestNonMatchingByPrimaryKey() public void TestNonMatchingByPrimaryKey()
{ {
ScoreInfo score1 = new ScoreInfo { ID = 1 }; ScoreInfo score1 = new ScoreInfo { ID = Guid.NewGuid() };
ScoreInfo score2 = new ScoreInfo { ID = 2 }; ScoreInfo score2 = new ScoreInfo { ID = Guid.NewGuid() };
Assert.That(score1, Is.Not.EqualTo(score2)); Assert.That(score1, Is.Not.EqualTo(score2));
} }
@ -38,8 +39,10 @@ namespace osu.Game.Tests.Scores.IO
[Test] [Test]
public void TestMatchingByPrimaryKey() public void TestMatchingByPrimaryKey()
{ {
ScoreInfo score1 = new ScoreInfo { ID = 1 }; Guid id = Guid.NewGuid();
ScoreInfo score2 = new ScoreInfo { ID = 1 };
ScoreInfo score1 = new ScoreInfo { ID = id };
ScoreInfo score2 = new ScoreInfo { ID = id };
Assert.That(score1, Is.EqualTo(score2)); Assert.That(score1, Is.EqualTo(score2));
} }

View File

@ -26,8 +26,12 @@ namespace osu.Game.Tests.Skins
private void load() private void load()
{ {
var imported = beatmaps.Import(new ZipArchiveReader(TestResources.OpenResource("Archives/ogg-beatmap.osz"))).GetResultSafely(); var imported = beatmaps.Import(new ZipArchiveReader(TestResources.OpenResource("Archives/ogg-beatmap.osz"))).GetResultSafely();
beatmap = beatmaps.GetWorkingBeatmap(imported.Value.Beatmaps[0]);
beatmap.LoadTrack(); imported?.PerformRead(s =>
{
beatmap = beatmaps.GetWorkingBeatmap(s.Beatmaps[0]);
beatmap.LoadTrack();
});
} }
[Test] [Test]

View File

@ -50,6 +50,7 @@ namespace osu.Game.Tests.Visual.Background
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(new OsuConfigManager(LocalStorage)); Dependencies.Cache(new OsuConfigManager(LocalStorage));
Dependencies.Cache(ContextFactory);
manager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); manager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
@ -387,6 +388,9 @@ namespace osu.Game.Tests.Visual.Background
while (BlockLoad && !token.IsCancellationRequested) while (BlockLoad && !token.IsCancellationRequested)
Thread.Sleep(1); Thread.Sleep(1);
if (!LoadedBeatmapSuccessfully)
return;
StoryboardEnabled = config.GetBindable<bool>(OsuSetting.ShowStoryboard); StoryboardEnabled = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
DrawableRuleset.IsPaused.BindTo(IsPaused); DrawableRuleset.IsPaused.BindTo(IsPaused);
} }

View File

@ -204,7 +204,7 @@ namespace osu.Game.Tests.Visual.Beatmaps
{ {
var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineID == online_id); var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineID == online_id);
if (beatmap != null) beatmaps.Delete(beatmap); if (beatmap != null) beatmaps.Delete(beatmap.Value);
}); });
} }

View File

@ -38,6 +38,7 @@ namespace osu.Game.Tests.Visual.Collections
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, Audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, Audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics.UserInterface;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Setup; using osu.Game.Screens.Edit.Setup;
using osuTK.Input; using osuTK.Input;
@ -25,7 +26,13 @@ namespace osu.Game.Tests.Visual.Editing
[SetUpSteps] [SetUpSteps]
public void SetUp() public void SetUp()
{ {
AddStep("create blank beatmap", () => editorBeatmap = new EditorBeatmap(new Beatmap())); AddStep("create blank beatmap", () => editorBeatmap = new EditorBeatmap(new Beatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo
}
}));
AddStep("create section", () => Child = new DependencyProvidingContainer AddStep("create section", () => Child = new DependencyProvidingContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,

View File

@ -33,7 +33,7 @@ namespace osu.Game.Tests.Visual.Editing
public override void SetUpSteps() public override void SetUpSteps()
{ {
AddStep("import test beatmap", () => importedBeatmapSet = ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).GetResultSafely()); AddStep("import test beatmap", () => importedBeatmapSet = BeatmapImportHelper.LoadOszIntoOsu(game, virtualTrack: true).GetResultSafely());
base.SetUpSteps(); base.SetUpSteps();
} }

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Beatmaps; using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose.Components; using osu.Game.Screens.Edit.Compose.Components;
@ -29,7 +30,13 @@ namespace osu.Game.Tests.Visual.Editing
public TestSceneDistanceSnapGrid() public TestSceneDistanceSnapGrid()
{ {
editorBeatmap = new EditorBeatmap(new OsuBeatmap()); editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo
}
});
editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beat_length }); editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beat_length });
} }

View File

@ -49,8 +49,7 @@ namespace osu.Game.Tests.Visual.Editing
public void TestCreateNewBeatmap() public void TestCreateNewBeatmap()
{ {
AddStep("save beatmap", () => Editor.Save()); AddStep("save beatmap", () => Editor.Save());
AddAssert("new beatmap persisted", () => EditorBeatmap.BeatmapInfo.IsManaged); AddAssert("new beatmap in database", () => beatmapManager.QueryBeatmapSet(s => s.ID == EditorBeatmap.BeatmapInfo.BeatmapSet.ID)?.Value.DeletePending == false);
AddAssert("new beatmap in database", () => beatmapManager.QueryBeatmapSet(s => s.ID == EditorBeatmap.BeatmapInfo.BeatmapSet.ID)?.DeletePending == false);
} }
[Test] [Test]
@ -66,7 +65,7 @@ namespace osu.Game.Tests.Visual.Editing
}); });
AddUntilStep("wait for exit", () => !Editor.IsCurrentScreen()); AddUntilStep("wait for exit", () => !Editor.IsCurrentScreen());
AddAssert("new beatmap not persisted", () => beatmapManager.QueryBeatmapSet(s => s.ID == editorBeatmap.BeatmapInfo.BeatmapSet.ID)?.DeletePending == true); AddAssert("new beatmap not persisted", () => beatmapManager.QueryBeatmapSet(s => s.ID == editorBeatmap.BeatmapInfo.BeatmapSet.ID)?.Value.DeletePending == true);
} }
[Test] [Test]

View File

@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Editing
public override void SetUpSteps() public override void SetUpSteps()
{ {
AddStep("import test beatmap", () => importedBeatmapSet = ImportBeatmapTest.LoadOszIntoOsu(game).GetResultSafely()); AddStep("import test beatmap", () => importedBeatmapSet = BeatmapImportHelper.LoadOszIntoOsu(game).GetResultSafely());
base.SetUpSteps(); base.SetUpSteps();
} }

View File

@ -39,9 +39,16 @@ namespace osu.Game.Tests.Visual.Editing
{ {
Beatmap.Value = CreateWorkingBeatmap(new Beatmap Beatmap.Value = CreateWorkingBeatmap(new Beatmap
{ {
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo
},
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
new HitCircle { Position = new Vector2(256, 192), Scale = 0.5f }, new HitCircle
{
Position = new Vector2(256, 192), Scale = 0.5f
},
new HitCircle { Position = new Vector2(344, 148), Scale = 0.5f }, new HitCircle { Position = new Vector2(344, 148), Scale = 0.5f },
new Slider new Slider
{ {

View File

@ -5,6 +5,7 @@ using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Setup; using osu.Game.Screens.Edit.Setup;
@ -13,7 +14,13 @@ namespace osu.Game.Tests.Visual.Editing
public class TestSceneMetadataSection : OsuTestScene public class TestSceneMetadataSection : OsuTestScene
{ {
[Cached] [Cached]
private EditorBeatmap editorBeatmap = new EditorBeatmap(new Beatmap()); private EditorBeatmap editorBeatmap = new EditorBeatmap(new Beatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo
},
});
private TestMetadataSection metadataSection; private TestMetadataSection metadataSection;

View File

@ -29,7 +29,13 @@ namespace osu.Game.Tests.Visual.Editing
public TestSceneSetupScreen() public TestSceneSetupScreen()
{ {
editorBeatmap = new EditorBeatmap(new OsuBeatmap()); editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo
}
});
} }
[Test] [Test]

View File

@ -237,7 +237,7 @@ namespace osu.Game.Tests.Visual.Gameplay
createPlayerTest(false, r => createPlayerTest(false, r =>
{ {
var beatmap = createTestBeatmap(r); var beatmap = createTestBeatmap(r);
beatmap.BeatmapInfo.OnlineID = null; beatmap.BeatmapInfo.OnlineID = -1;
return beatmap; return beatmap;
}); });
@ -255,7 +255,15 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
prepareTestAPI(true); prepareTestAPI(true);
createPlayerTest(false, createRuleset: () => new OsuRuleset { RulesetInfo = { OnlineID = rulesetId ?? -1 } }); createPlayerTest(false, createRuleset: () => new OsuRuleset
{
RulesetInfo =
{
Name = "custom",
ShortName = $"custom{rulesetId}",
OnlineID = rulesetId ?? -1
}
});
AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddUntilStep("wait for token request", () => Player.TokenCreationRequested);

View File

@ -6,16 +6,18 @@ using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Scoring;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
using osu.Game.Tests.Resources;
using osuTK.Input; using osuTK.Input;
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser; using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
@ -29,6 +31,18 @@ namespace osu.Game.Tests.Visual.Gameplay
private TestReplayDownloadButton downloadButton; private TestReplayDownloadButton downloadButton;
[Resolved]
private BeatmapManager beatmapManager { get; set; }
[Resolved]
private ScoreManager scoreManager { get; set; }
[BackgroundDependencyLoader]
private void load()
{
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
}
[Test] [Test]
public void TestDisplayStates() public void TestDisplayStates()
{ {
@ -115,9 +129,6 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value); AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
} }
[Resolved]
private ScoreManager scoreManager { get; set; }
[Test] [Test]
public void TestScoreImportThenDelete() public void TestScoreImportThenDelete()
{ {
@ -176,7 +187,7 @@ namespace osu.Game.Tests.Visual.Gameplay
Id = 39828, Id = 39828,
Username = @"WubWoofWolf", Username = @"WubWoofWolf",
} }
}.CreateScoreInfo(rulesets, CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo); }.CreateScoreInfo(rulesets, beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First());
} }
private class TestReplayDownloadButton : ReplayDownloadButton private class TestReplayDownloadButton : ReplayDownloadButton

View File

@ -64,7 +64,11 @@ namespace osu.Game.Tests.Visual.Gameplay
Recorder = recorder = new TestReplayRecorder(new Score Recorder = recorder = new TestReplayRecorder(new Score
{ {
Replay = replay, Replay = replay,
ScoreInfo = { BeatmapInfo = gameplayState.Beatmap.BeatmapInfo } ScoreInfo =
{
BeatmapInfo = gameplayState.Beatmap.BeatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
}
}) })
{ {
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos), ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos),

View File

@ -61,8 +61,8 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("import beatmap", () => AddStep("import beatmap", () =>
{ {
importedBeatmap = ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).GetResultSafely(); importedBeatmap = BeatmapImportHelper.LoadOszIntoOsu(game, virtualTrack: true).GetResultSafely();
importedBeatmapId = importedBeatmap.Beatmaps.First(b => b.RulesetID == 0).OnlineID ?? -1; importedBeatmapId = importedBeatmap.Beatmaps.First(b => b.RulesetID == 0).OnlineID;
}); });
} }

View File

@ -372,7 +372,14 @@ namespace osu.Game.Tests.Visual.Gameplay
internal class TestReplayRecorder : ReplayRecorder<TestAction> internal class TestReplayRecorder : ReplayRecorder<TestAction>
{ {
public TestReplayRecorder() public TestReplayRecorder()
: base(new Score { ScoreInfo = { BeatmapInfo = new BeatmapInfo() } }) : base(new Score
{
ScoreInfo =
{
BeatmapInfo = new BeatmapInfo(),
Ruleset = new OsuRuleset().RulesetInfo,
}
})
{ {
} }

View File

@ -39,7 +39,10 @@ namespace osu.Game.Tests.Visual.Menus
AddStep("import beatmap with track", () => AddStep("import beatmap with track", () =>
{ {
var setWithTrack = Game.BeatmapManager.Import(new ImportTask(TestResources.GetTestBeatmapForImport())).GetResultSafely(); var setWithTrack = Game.BeatmapManager.Import(new ImportTask(TestResources.GetTestBeatmapForImport())).GetResultSafely();
Beatmap.Value = Game.BeatmapManager.GetWorkingBeatmap(setWithTrack.Value.Beatmaps.First()); setWithTrack?.PerformRead(s =>
{
Beatmap.Value = Game.BeatmapManager.GetWorkingBeatmap(s.Beatmaps.First());
});
}); });
AddStep("bind to track change", () => AddStep("bind to track change", () =>

View File

@ -49,6 +49,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
} }
public override void SetUpSteps() public override void SetUpSteps()
@ -58,7 +59,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("import beatmap", () => AddStep("import beatmap", () =>
{ {
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
InitialBeatmap = importedSet.Beatmaps.First(b => b.RulesetID == 0); InitialBeatmap = importedSet.Beatmaps.First(b => b.RulesetID == 0);
OtherBeatmap = importedSet.Beatmaps.Last(b => b.RulesetID == 0); OtherBeatmap = importedSet.Beatmaps.Last(b => b.RulesetID == 0);
}); });

View File

@ -17,7 +17,7 @@ using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Models;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
@ -45,6 +45,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
} }
[Test] [Test]
@ -153,17 +154,20 @@ namespace osu.Game.Tests.Visual.Multiplayer
public void TestDownloadButtonHiddenWhenBeatmapExists() public void TestDownloadButtonHiddenWhenBeatmapExists()
{ {
var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo; var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;
ILive<BeatmapSetInfo> imported = null;
AddStep("import beatmap", () => manager.Import(beatmap.BeatmapSet).WaitSafely()); Debug.Assert(beatmap.BeatmapSet != null);
createPlaylistWithBeatmaps(beatmap); AddStep("import beatmap", () => imported = manager.Import(beatmap.BeatmapSet).GetResultSafely());
createPlaylistWithBeatmaps(() => imported.PerformRead(s => s.Beatmaps.Detach()));
assertDownloadButtonVisible(false); assertDownloadButtonVisible(false);
AddStep("delete beatmap set", () => manager.Delete(manager.QueryBeatmapSets(_ => true).Single())); AddStep("delete beatmap set", () => imported.PerformWrite(s => s.DeletePending = true));
assertDownloadButtonVisible(true); assertDownloadButtonVisible(true);
AddStep("undelete beatmap set", () => manager.Undelete(manager.QueryBeatmapSets(_ => true).Single())); AddStep("undelete beatmap set", () => imported.PerformWrite(s => s.DeletePending = false));
assertDownloadButtonVisible(false); assertDownloadButtonVisible(false);
void assertDownloadButtonVisible(bool visible) => AddUntilStep($"download button {(visible ? "shown" : "hidden")}", void assertDownloadButtonVisible(bool visible) => AddUntilStep($"download button {(visible ? "shown" : "hidden")}",
@ -179,7 +183,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
var byChecksum = CreateAPIBeatmap(); var byChecksum = CreateAPIBeatmap();
byChecksum.Checksum = "1337"; // Some random checksum that does not exist locally. byChecksum.Checksum = "1337"; // Some random checksum that does not exist locally.
createPlaylistWithBeatmaps(byOnlineId, byChecksum); createPlaylistWithBeatmaps(() => new[] { byOnlineId, byChecksum });
AddAssert("download buttons shown", () => playlist.ChildrenOfType<BeatmapDownloadButton>().All(d => d.IsPresent)); AddAssert("download buttons shown", () => playlist.ChildrenOfType<BeatmapDownloadButton>().All(d => d.IsPresent));
} }
@ -193,7 +197,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
beatmap.BeatmapSet.HasExplicitContent = true; beatmap.BeatmapSet.HasExplicitContent = true;
createPlaylistWithBeatmaps(beatmap); createPlaylistWithBeatmaps(() => new[] { beatmap });
} }
[Test] [Test]
@ -305,7 +309,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
{ {
Artist = "Artist", Artist = "Artist",
Author = new APIUser { Username = "Creator name here" }, Author = new RealmUser { Username = "Creator name here" },
Title = "Long title used to check background colour", Title = "Long title used to check background colour",
}, },
BeatmapSet = new BeatmapSetInfo() BeatmapSet = new BeatmapSetInfo()
@ -325,7 +329,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddUntilStep("wait for items to load", () => playlist.ItemMap.Values.All(i => i.IsLoaded)); AddUntilStep("wait for items to load", () => playlist.ItemMap.Values.All(i => i.IsLoaded));
} }
private void createPlaylistWithBeatmaps(params IBeatmapInfo[] beatmaps) private void createPlaylistWithBeatmaps(Func<IEnumerable<IBeatmapInfo>> beatmaps)
{ {
AddStep("create playlist", () => AddStep("create playlist", () =>
{ {
@ -338,7 +342,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
int index = 0; int index = 0;
foreach (var b in beatmaps) foreach (var b in beatmaps())
{ {
playlist.Items.Add(new PlaylistItem playlist.Items.Add(new PlaylistItem
{ {

View File

@ -47,9 +47,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
importedSet = ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).GetResultSafely(); importedSet = BeatmapImportHelper.LoadOszIntoOsu(game, virtualTrack: true).GetResultSafely();
importedBeatmap = importedSet.Beatmaps.First(b => b.RulesetID == 0); importedBeatmap = importedSet.Beatmaps.First(b => b.RulesetID == 0);
importedBeatmapId = importedBeatmap.OnlineID ?? -1; importedBeatmapId = importedBeatmap.OnlineID;
} }
[SetUp] [SetUp]

View File

@ -62,7 +62,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
private void load(GameHost host, AudioManager audio) private void load(GameHost host, AudioManager audio)
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, API, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
} }
public override void SetUpSteps() public override void SetUpSteps()
@ -72,7 +73,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("import beatmap", () => AddStep("import beatmap", () =>
{ {
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
}); });
AddStep("load multiplayer", () => LoadScreen(multiplayerComponents = new TestMultiplayerComponents())); AddStep("load multiplayer", () => LoadScreen(multiplayerComponents = new TestMultiplayerComponents()));
@ -588,7 +589,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("restore beatmap", () => AddStep("restore beatmap", () =>
{ {
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
}); });
AddUntilStep("play started", () => multiplayerComponents.CurrentScreen is SpectatorScreen); AddUntilStep("play started", () => multiplayerComponents.CurrentScreen is SpectatorScreen);
@ -827,7 +828,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("join other user", () => client.AddUser(new APIUser { Id = 1234 })); AddStep("join other user", () => client.AddUser(new APIUser { Id = 1234 }));
AddStep("add item as other user", () => client.AddUserPlaylistItem(1234, new MultiplayerPlaylistItem(new PlaylistItem AddStep("add item as other user", () => client.AddUserPlaylistItem(1234, new MultiplayerPlaylistItem(new PlaylistItem
{ {
BeatmapID = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo.OnlineID ?? -1 BeatmapID = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo.OnlineID
}))); })));
AddUntilStep("item arrived in playlist", () => client.Room?.Playlist.Count == 2); AddUntilStep("item arrived in playlist", () => client.Room?.Playlist.Count == 2);
@ -858,7 +859,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("join other user", () => client.AddUser(new APIUser { Id = 1234 })); AddStep("join other user", () => client.AddUser(new APIUser { Id = 1234 }));
AddStep("add item as other user", () => client.AddUserPlaylistItem(1234, new MultiplayerPlaylistItem(new PlaylistItem AddStep("add item as other user", () => client.AddUserPlaylistItem(1234, new MultiplayerPlaylistItem(new PlaylistItem
{ {
BeatmapID = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo.OnlineID ?? -1 BeatmapID = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo.OnlineID
}))); })));
AddUntilStep("item arrived in playlist", () => client.Room?.Playlist.Count == 2); AddUntilStep("item arrived in playlist", () => client.Room?.Playlist.Count == 2);

View File

@ -58,7 +58,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
foreach (int user in users) foreach (int user in users)
{ {
SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineID ?? 0); SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineID);
multiplayerUsers.Add(OnlinePlayDependencies.Client.AddUser(new APIUser { Id = user }, true)); multiplayerUsers.Add(OnlinePlayDependencies.Client.AddUser(new APIUser { Id = user }, true));
} }

View File

@ -62,7 +62,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
foreach (int user in users) foreach (int user in users)
{ {
SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineID ?? 0); SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineID);
var roomUser = OnlinePlayDependencies.Client.AddUser(new APIUser { Id = user }, true); var roomUser = OnlinePlayDependencies.Client.AddUser(new APIUser { Id = user }, true);
roomUser.MatchState = new TeamVersusUserState roomUser.MatchState = new TeamVersusUserState

View File

@ -44,6 +44,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
beatmaps = new List<BeatmapInfo>(); beatmaps = new List<BeatmapInfo>();
@ -58,7 +59,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
OnlineID = 10, OnlineID = 10,
Hash = Guid.NewGuid().ToString().ComputeMD5Hash(), Hash = Guid.NewGuid().ToString().ComputeMD5Hash(),
Metadata = metadata,
DateAdded = DateTimeOffset.UtcNow DateAdded = DateTimeOffset.UtcNow
}; };
@ -71,7 +71,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
var beatmap = new BeatmapInfo var beatmap = new BeatmapInfo
{ {
Ruleset = rulesets.GetRuleset(i % 4), Ruleset = rulesets.GetRuleset(i % 4) ?? throw new InvalidOperationException(),
OnlineID = beatmapId, OnlineID = beatmapId,
Length = length, Length = length,
BPM = bpm, BPM = bpm,

View File

@ -40,9 +40,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
} }
[SetUp] [SetUp]

View File

@ -35,6 +35,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
} }
[SetUp] [SetUp]
@ -55,7 +56,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("import beatmap", () => AddStep("import beatmap", () =>
{ {
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
importedBeatmap = importedSet.Beatmaps.First(b => b.RulesetID == 0); importedBeatmap = importedSet.Beatmaps.First(b => b.RulesetID == 0);
}); });
@ -169,7 +170,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
private void addItemStep(bool expired = false) => AddStep("add item", () => Client.AddPlaylistItem(new MultiplayerPlaylistItem(new PlaylistItem private void addItemStep(bool expired = false) => AddStep("add item", () => Client.AddPlaylistItem(new MultiplayerPlaylistItem(new PlaylistItem
{ {
Beatmap = { Value = importedBeatmap }, Beatmap = { Value = importedBeatmap },
BeatmapID = importedBeatmap.OnlineID ?? -1, BeatmapID = importedBeatmap.OnlineID,
Expired = expired, Expired = expired,
PlayedAt = DateTimeOffset.Now PlayedAt = DateTimeOffset.Now
}))); })));

View File

@ -39,7 +39,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
private void load(GameHost host, AudioManager audio) private void load(GameHost host, AudioManager audio)
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, API, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
} }
public override void SetUpSteps() public override void SetUpSteps()
@ -60,7 +61,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("import beatmap", () => AddStep("import beatmap", () =>
{ {
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
importedBeatmap = importedSet.Beatmaps.First(b => b.RulesetID == 0); importedBeatmap = importedSet.Beatmaps.First(b => b.RulesetID == 0);
}); });
@ -126,7 +127,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
MultiplayerPlaylistItem item = new MultiplayerPlaylistItem(new PlaylistItem MultiplayerPlaylistItem item = new MultiplayerPlaylistItem(new PlaylistItem
{ {
Beatmap = { Value = importedBeatmap }, Beatmap = { Value = importedBeatmap },
BeatmapID = importedBeatmap.OnlineID ?? -1, BeatmapID = importedBeatmap.OnlineID,
}); });
Client.AddUserPlaylistItem(userId(), item); Client.AddUserPlaylistItem(userId(), item);

View File

@ -42,6 +42,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
} }
@ -50,7 +52,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
AvailabilityTracker.SelectedItem.BindTo(selectedItem); AvailabilityTracker.SelectedItem.BindTo(selectedItem);
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First()); Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
selectedItem.Value = new PlaylistItem selectedItem.Value = new PlaylistItem
{ {

View File

@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
PlaylistItem playlistItem = new PlaylistItem PlaylistItem playlistItem = new PlaylistItem
{ {
BeatmapID = beatmapInfo.OnlineID ?? -1, BeatmapID = beatmapInfo.OnlineID,
}; };
Stack.Push(screen = new MultiplayerResultsScreen(score, 1, playlistItem)); Stack.Push(screen = new MultiplayerResultsScreen(score, 1, playlistItem));

View File

@ -43,6 +43,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
} }
@ -51,7 +53,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
AvailabilityTracker.SelectedItem.BindTo(selectedItem); AvailabilityTracker.SelectedItem.BindTo(selectedItem);
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First()); Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
selectedItem.Value = new PlaylistItem selectedItem.Value = new PlaylistItem
{ {

View File

@ -28,7 +28,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
PlaylistItem playlistItem = new PlaylistItem PlaylistItem playlistItem = new PlaylistItem
{ {
BeatmapID = beatmapInfo.OnlineID ?? -1, BeatmapID = beatmapInfo.OnlineID,
}; };
SortedDictionary<int, BindableInt> teamScores = new SortedDictionary<int, BindableInt> SortedDictionary<int, BindableInt> teamScores = new SortedDictionary<int, BindableInt>

View File

@ -12,7 +12,7 @@ using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Models;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
@ -155,7 +155,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
{ {
Artist = "Artist", Artist = "Artist",
Author = new APIUser { Username = "Creator name here" }, Author = new RealmUser { Username = "Creator name here" },
Title = "Long title used to check background colour", Title = "Long title used to check background colour",
}, },
BeatmapSet = new BeatmapSetInfo() BeatmapSet = new BeatmapSetInfo()

View File

@ -36,6 +36,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
var beatmapSet = TestResources.CreateTestBeatmapSetInfo(); var beatmapSet = TestResources.CreateTestBeatmapSetInfo();

View File

@ -44,6 +44,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
} }
public override void SetUpSteps() public override void SetUpSteps()
@ -53,7 +54,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("import beatmap", () => AddStep("import beatmap", () =>
{ {
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
}); });
AddStep("load multiplayer", () => LoadScreen(multiplayerComponents = new TestMultiplayerComponents())); AddStep("load multiplayer", () => LoadScreen(multiplayerComponents = new TestMultiplayerComponents()));

View File

@ -49,7 +49,7 @@ namespace osu.Game.Tests.Visual.Navigation
AddStep("close settings", () => Game.Settings.Hide()); AddStep("close settings", () => Game.Settings.Hide());
AddStep("import beatmap", () => ImportBeatmapTest.LoadQuickOszIntoOsu(Game).WaitSafely()); AddStep("import beatmap", () => BeatmapImportHelper.LoadQuickOszIntoOsu(Game).WaitSafely());
PushAndConfirm(() => new PlaySongSelect()); PushAndConfirm(() => new PlaySongSelect());
AddStep("enter gameplay", () => InputManager.Key(Key.Enter)); AddStep("enter gameplay", () => InputManager.Key(Key.Enter));

View File

@ -83,7 +83,7 @@ namespace osu.Game.Tests.Visual.Navigation
PushAndConfirm(() => songSelect = new TestSceneScreenNavigation.TestPlaySongSelect()); PushAndConfirm(() => songSelect = new TestSceneScreenNavigation.TestPlaySongSelect());
AddUntilStep("wait for song select", () => songSelect.BeatmapSetsLoaded); AddUntilStep("wait for song select", () => songSelect.BeatmapSetsLoaded);
AddStep("import beatmap", () => ImportBeatmapTest.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely()); AddStep("import beatmap", () => BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault); AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
AddStep("press enter", () => InputManager.Key(Key.Enter)); AddStep("press enter", () => InputManager.Key(Key.Enter));

View File

@ -12,11 +12,9 @@ using osu.Framework.Platform;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Input; using osu.Game.Input;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.IO;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -58,7 +56,6 @@ namespace osu.Game.Tests.Visual.Navigation
private IReadOnlyList<Type> requiredGameBaseDependencies => new[] private IReadOnlyList<Type> requiredGameBaseDependencies => new[]
{ {
typeof(OsuGameBase), typeof(OsuGameBase),
typeof(DatabaseContextFactory),
typeof(Bindable<RulesetInfo>), typeof(Bindable<RulesetInfo>),
typeof(IBindable<RulesetInfo>), typeof(IBindable<RulesetInfo>),
typeof(Bindable<IReadOnlyList<Mod>>), typeof(Bindable<IReadOnlyList<Mod>>),
@ -69,7 +66,6 @@ namespace osu.Game.Tests.Visual.Navigation
typeof(ISkinSource), typeof(ISkinSource),
typeof(IAPIProvider), typeof(IAPIProvider),
typeof(RulesetStore), typeof(RulesetStore),
typeof(FileStore),
typeof(ScoreManager), typeof(ScoreManager),
typeof(BeatmapManager), typeof(BeatmapManager),
typeof(IRulesetConfigCache), typeof(IRulesetConfigCache),

View File

@ -173,7 +173,7 @@ namespace osu.Game.Tests.Visual.Navigation
private void importAndWaitForSongSelect() private void importAndWaitForSongSelect()
{ {
AddStep("import beatmap", () => ImportBeatmapTest.LoadQuickOszIntoOsu(Game).WaitSafely()); AddStep("import beatmap", () => BeatmapImportHelper.LoadQuickOszIntoOsu(Game).WaitSafely());
PushAndConfirm(() => new TestPlaySongSelect()); PushAndConfirm(() => new TestPlaySongSelect());
AddUntilStep("beatmap updated", () => Game.Beatmap.Value.BeatmapSetInfo.OnlineID == 241526); AddUntilStep("beatmap updated", () => Game.Beatmap.Value.BeatmapSetInfo.OnlineID == 241526);
} }

View File

@ -97,7 +97,6 @@ namespace osu.Game.Tests.Visual.Navigation
BeatmapSetInfo imported = null; BeatmapSetInfo imported = null;
AddStep($"import beatmap {i}", () => AddStep($"import beatmap {i}", () =>
{ {
var difficulty = new BeatmapDifficulty();
var metadata = new BeatmapMetadata var metadata = new BeatmapMetadata
{ {
Artist = "SomeArtist", Artist = "SomeArtist",
@ -109,25 +108,24 @@ namespace osu.Game.Tests.Visual.Navigation
{ {
Hash = Guid.NewGuid().ToString(), Hash = Guid.NewGuid().ToString(),
OnlineID = i, OnlineID = i,
Metadata = metadata,
Beatmaps = Beatmaps =
{ {
new BeatmapInfo new BeatmapInfo
{ {
OnlineID = i * 1024, OnlineID = i * 1024,
Metadata = metadata, Metadata = metadata,
BaseDifficulty = difficulty, BaseDifficulty = new BeatmapDifficulty(),
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
}, },
new BeatmapInfo new BeatmapInfo
{ {
OnlineID = i * 2048, OnlineID = i * 2048,
Metadata = metadata, Metadata = metadata,
BaseDifficulty = difficulty, BaseDifficulty = new BeatmapDifficulty(),
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
}, },
} }
}).GetResultSafely().Value; }).GetResultSafely()?.Value;
}); });
AddAssert($"import {i} succeeded", () => imported != null); AddAssert($"import {i} succeeded", () => imported != null);

View File

@ -8,6 +8,7 @@ using osu.Framework.Extensions;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mania; using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
@ -28,37 +29,38 @@ namespace osu.Game.Tests.Visual.Navigation
{ {
AddStep("import beatmap", () => AddStep("import beatmap", () =>
{ {
var difficulty = new BeatmapDifficulty();
var metadata = new BeatmapMetadata
{
Artist = "SomeArtist",
AuthorString = "SomeAuthor",
Title = "import"
};
beatmap = Game.BeatmapManager.Import(new BeatmapSetInfo beatmap = Game.BeatmapManager.Import(new BeatmapSetInfo
{ {
Hash = Guid.NewGuid().ToString(), Hash = Guid.NewGuid().ToString(),
OnlineID = 1, OnlineID = 1,
Metadata = metadata,
Beatmaps = Beatmaps =
{ {
new BeatmapInfo new BeatmapInfo
{ {
OnlineID = 1 * 1024, OnlineID = 1 * 1024,
Metadata = metadata, Metadata = new BeatmapMetadata
BaseDifficulty = difficulty, {
Artist = "SomeArtist",
AuthorString = "SomeAuthor",
Title = "import"
},
BaseDifficulty = new BeatmapDifficulty(),
Ruleset = new OsuRuleset().RulesetInfo Ruleset = new OsuRuleset().RulesetInfo
}, },
new BeatmapInfo new BeatmapInfo
{ {
OnlineID = 1 * 2048, OnlineID = 1 * 2048,
Metadata = metadata, Metadata = new BeatmapMetadata
BaseDifficulty = difficulty, {
Artist = "SomeArtist",
AuthorString = "SomeAuthor",
Title = "import"
},
BaseDifficulty = new BeatmapDifficulty(),
Ruleset = new OsuRuleset().RulesetInfo Ruleset = new OsuRuleset().RulesetInfo
}, },
} }
}).GetResultSafely().Value; }).GetResultSafely()?.Value;
}); });
} }
@ -131,7 +133,8 @@ namespace osu.Game.Tests.Visual.Navigation
Hash = Guid.NewGuid().ToString(), Hash = Guid.NewGuid().ToString(),
OnlineID = i, OnlineID = i,
BeatmapInfo = beatmap.Beatmaps.First(), BeatmapInfo = beatmap.Beatmaps.First(),
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo Ruleset = ruleset ?? new OsuRuleset().RulesetInfo,
User = new GuestUser(),
}).GetResultSafely().Value; }).GetResultSafely().Value;
}); });

View File

@ -71,7 +71,7 @@ namespace osu.Game.Tests.Visual.Navigation
PushAndConfirm(() => songSelect = new TestPlaySongSelect()); PushAndConfirm(() => songSelect = new TestPlaySongSelect());
AddUntilStep("wait for song select", () => songSelect.BeatmapSetsLoaded); AddUntilStep("wait for song select", () => songSelect.BeatmapSetsLoaded);
AddStep("import beatmap", () => ImportBeatmapTest.LoadQuickOszIntoOsu(Game).WaitSafely()); AddStep("import beatmap", () => BeatmapImportHelper.LoadQuickOszIntoOsu(Game).WaitSafely());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault); AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
@ -105,7 +105,7 @@ namespace osu.Game.Tests.Visual.Navigation
PushAndConfirm(() => songSelect = new TestPlaySongSelect()); PushAndConfirm(() => songSelect = new TestPlaySongSelect());
AddUntilStep("wait for song select", () => songSelect.BeatmapSetsLoaded); AddUntilStep("wait for song select", () => songSelect.BeatmapSetsLoaded);
AddStep("import beatmap", () => ImportBeatmapTest.LoadQuickOszIntoOsu(Game).WaitSafely()); AddStep("import beatmap", () => BeatmapImportHelper.LoadQuickOszIntoOsu(Game).WaitSafely());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault); AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
@ -139,7 +139,7 @@ namespace osu.Game.Tests.Visual.Navigation
PushAndConfirm(() => songSelect = new TestPlaySongSelect()); PushAndConfirm(() => songSelect = new TestPlaySongSelect());
AddUntilStep("wait for song select", () => songSelect.BeatmapSetsLoaded); AddUntilStep("wait for song select", () => songSelect.BeatmapSetsLoaded);
AddStep("import beatmap", () => ImportBeatmapTest.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely()); AddStep("import beatmap", () => BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault); AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);

View File

@ -0,0 +1,32 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Development;
using osu.Game.Configuration;
namespace osu.Game.Tests.Visual.Navigation
{
[TestFixture]
public class TestSceneStartupRuleset : OsuGameTestScene
{
protected override TestOsuGame CreateTestGame()
{
// Must be done in this function due to the RecycleLocalStorage call just before.
var config = DebugUtils.IsDebugBuild
? new DevelopmentOsuConfigManager(LocalStorage)
: new OsuConfigManager(LocalStorage);
config.SetValue(OsuSetting.Ruleset, "mania");
config.Save();
return base.CreateTestGame();
}
[Test]
public void TestRulesetConsumed()
{
AddUntilStep("ruleset correct", () => Game.Ruleset.Value.ShortName == "mania");
}
}
}

View File

@ -59,7 +59,7 @@ namespace osu.Game.Tests.Visual.Online
{ {
var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineID == 241526); var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineID == 241526);
if (beatmap != null) beatmaps.Delete(beatmap); if (beatmap != null) beatmaps.Delete(beatmap.Value);
}); });
} }

View File

@ -44,6 +44,10 @@ namespace osu.Game.Tests.Visual.Playlists
requestComplete = false; requestComplete = false;
totalCount = 0; totalCount = 0;
bindHandler(); bindHandler();
// beatmap is required to be an actual beatmap so the scores can get their scores correctly calculated for standardised scoring.
// else the tests that rely on ordering will fall over.
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
}); });
[Test] [Test]

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Diagnostics;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -18,6 +19,7 @@ using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.OnlinePlay.Playlists; using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Beatmaps;
@ -33,13 +35,14 @@ namespace osu.Game.Tests.Visual.Playlists
private TestPlaylistsRoomSubScreen match; private TestPlaylistsRoomSubScreen match;
private ILive<BeatmapSetInfo> importedBeatmap; private BeatmapSetInfo importedBeatmap;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio) private void load(GameHost host, AudioManager audio)
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, API, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
} }
[SetUpSteps] [SetUpSteps]
@ -64,13 +67,15 @@ namespace osu.Game.Tests.Visual.Playlists
room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5); room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5);
room.Playlist.Add(new PlaylistItem room.Playlist.Add(new PlaylistItem
{ {
Beatmap = { Value = importedBeatmap.Value.Beatmaps.First() }, Beatmap = { Value = importedBeatmap.Beatmaps.First() },
Ruleset = { Value = new OsuRuleset().RulesetInfo } Ruleset = { Value = new OsuRuleset().RulesetInfo }
}); });
}); });
AddUntilStep("Progress details are hidden", () => match.ChildrenOfType<RoomLocalUserInfo>().FirstOrDefault()?.Parent.Alpha == 0); AddUntilStep("Progress details are hidden", () => match.ChildrenOfType<RoomLocalUserInfo>().FirstOrDefault()?.Parent.Alpha == 0);
AddUntilStep("Leaderboard shows two aggregate scores", () => match.ChildrenOfType<MatchLeaderboardScore>().Count(s => s.ScoreText.Text != "0") == 2);
AddStep("start match", () => match.ChildrenOfType<PlaylistsReadyButton>().First().TriggerClick()); AddStep("start match", () => match.ChildrenOfType<PlaylistsReadyButton>().First().TriggerClick());
AddUntilStep("player loader loaded", () => Stack.CurrentScreen is PlayerLoader); AddUntilStep("player loader loaded", () => Stack.CurrentScreen is PlayerLoader);
} }
@ -87,7 +92,7 @@ namespace osu.Game.Tests.Visual.Playlists
room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5); room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5);
room.Playlist.Add(new PlaylistItem room.Playlist.Add(new PlaylistItem
{ {
Beatmap = { Value = importedBeatmap.Value.Beatmaps.First() }, Beatmap = { Value = importedBeatmap.Beatmaps.First() },
Ruleset = { Value = new OsuRuleset().RulesetInfo } Ruleset = { Value = new OsuRuleset().RulesetInfo }
}); });
}); });
@ -104,7 +109,7 @@ namespace osu.Game.Tests.Visual.Playlists
room.Host.Value = API.LocalUser.Value; room.Host.Value = API.LocalUser.Value;
room.Playlist.Add(new PlaylistItem room.Playlist.Add(new PlaylistItem
{ {
Beatmap = { Value = importedBeatmap.Value.Beatmaps.First() }, Beatmap = { Value = importedBeatmap.Beatmaps.First() },
Ruleset = { Value = new OsuRuleset().RulesetInfo } Ruleset = { Value = new OsuRuleset().RulesetInfo }
}); });
}); });
@ -121,9 +126,9 @@ namespace osu.Game.Tests.Visual.Playlists
AddStep("store real beatmap values", () => AddStep("store real beatmap values", () =>
{ {
realHash = importedBeatmap.Value.Beatmaps[0].MD5Hash; realHash = importedBeatmap.Beatmaps[0].MD5Hash;
realOnlineId = importedBeatmap.Value.Beatmaps[0].OnlineID ?? -1; realOnlineId = importedBeatmap.Beatmaps[0].OnlineID;
realOnlineSetId = importedBeatmap.Value.OnlineID ?? -1; realOnlineSetId = importedBeatmap.OnlineID;
}); });
AddStep("import modified beatmap", () => AddStep("import modified beatmap", () =>
@ -133,6 +138,7 @@ namespace osu.Game.Tests.Visual.Playlists
BeatmapInfo = BeatmapInfo =
{ {
OnlineID = realOnlineId, OnlineID = realOnlineId,
Metadata = new BeatmapMetadata(),
BeatmapSet = BeatmapSet =
{ {
OnlineID = realOnlineSetId OnlineID = realOnlineSetId
@ -143,6 +149,8 @@ namespace osu.Game.Tests.Visual.Playlists
modifiedBeatmap.HitObjects.Clear(); modifiedBeatmap.HitObjects.Clear();
modifiedBeatmap.HitObjects.Add(new HitCircle { StartTime = 5000 }); modifiedBeatmap.HitObjects.Add(new HitCircle { StartTime = 5000 });
Debug.Assert(modifiedBeatmap.BeatmapInfo.BeatmapSet != null);
manager.Import(modifiedBeatmap.BeatmapInfo.BeatmapSet).WaitSafely(); manager.Import(modifiedBeatmap.BeatmapInfo.BeatmapSet).WaitSafely();
}); });
@ -159,6 +167,7 @@ namespace osu.Game.Tests.Visual.Playlists
{ {
MD5Hash = realHash, MD5Hash = realHash,
OnlineID = realOnlineId, OnlineID = realOnlineId,
Metadata = new BeatmapMetadata(),
BeatmapSet = new BeatmapSetInfo BeatmapSet = new BeatmapSetInfo
{ {
OnlineID = realOnlineSetId, OnlineID = realOnlineSetId,
@ -185,6 +194,8 @@ namespace osu.Game.Tests.Visual.Playlists
}, },
}; };
Debug.Assert(originalBeatmap.BeatmapInfo.BeatmapSet != null);
manager.Import(originalBeatmap.BeatmapInfo.BeatmapSet).WaitSafely(); manager.Import(originalBeatmap.BeatmapInfo.BeatmapSet).WaitSafely();
}); });
@ -202,7 +213,14 @@ namespace osu.Game.Tests.Visual.Playlists
}); });
} }
private void importBeatmap() => AddStep("import beatmap", () => importedBeatmap = manager.Import(CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapSet).GetResultSafely()); private void importBeatmap() => AddStep("import beatmap", () =>
{
var beatmap = CreateBeatmap(new OsuRuleset().RulesetInfo);
Debug.Assert(beatmap.BeatmapInfo.BeatmapSet != null);
importedBeatmap = manager.Import(beatmap.BeatmapInfo.BeatmapSet).GetResultSafely()?.Value.Detach();
});
private class TestPlaylistsRoomSubScreen : PlaylistsRoomSubScreen private class TestPlaylistsRoomSubScreen : PlaylistsRoomSubScreen
{ {

View File

@ -72,6 +72,7 @@ namespace osu.Game.Tests.Visual.Ranking
Username = "peppy", Username = "peppy",
}, },
BeatmapInfo = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo, BeatmapInfo = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() }, Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
TotalScore = 2845370, TotalScore = 2845370,
Accuracy = accuracy, Accuracy = accuracy,

View File

@ -12,7 +12,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Models;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
@ -33,7 +33,7 @@ namespace osu.Game.Tests.Visual.Ranking
[Test] [Test]
public void TestMapWithKnownMapper() public void TestMapWithKnownMapper()
{ {
var author = new APIUser { Username = "mapper_name" }; var author = new RealmUser { Username = "mapper_name" };
AddStep("show example score", () => showPanel(TestResources.CreateTestScoreInfo(createTestBeatmap(author)))); AddStep("show example score", () => showPanel(TestResources.CreateTestScoreInfo(createTestBeatmap(author))));
} }
@ -43,7 +43,7 @@ namespace osu.Game.Tests.Visual.Ranking
{ {
AddStep("show excess mods score", () => AddStep("show excess mods score", () =>
{ {
var author = new APIUser { Username = "mapper_name" }; var author = new RealmUser { Username = "mapper_name" };
var score = TestResources.CreateTestScoreInfo(createTestBeatmap(author)); var score = TestResources.CreateTestScoreInfo(createTestBeatmap(author));
score.Mods = score.BeatmapInfo.Ruleset.CreateInstance().CreateAllMods().ToArray(); score.Mods = score.BeatmapInfo.Ruleset.CreateInstance().CreateAllMods().ToArray();
@ -57,7 +57,7 @@ namespace osu.Game.Tests.Visual.Ranking
[Test] [Test]
public void TestMapWithUnknownMapper() public void TestMapWithUnknownMapper()
{ {
AddStep("show example score", () => showPanel(TestResources.CreateTestScoreInfo(createTestBeatmap(new APIUser())))); AddStep("show example score", () => showPanel(TestResources.CreateTestScoreInfo(createTestBeatmap(new RealmUser()))));
AddAssert("mapped by text not present", () => AddAssert("mapped by text not present", () =>
this.ChildrenOfType<OsuSpriteText>().All(spriteText => !containsAny(spriteText.Text.ToString(), "mapped", "by"))); this.ChildrenOfType<OsuSpriteText>().All(spriteText => !containsAny(spriteText.Text.ToString(), "mapped", "by")));
@ -73,7 +73,7 @@ namespace osu.Game.Tests.Visual.Ranking
var ruleset = new OsuRuleset(); var ruleset = new OsuRuleset();
var mods = new Mod[] { ruleset.GetAutoplayMod() }; var mods = new Mod[] { ruleset.GetAutoplayMod() };
var beatmap = createTestBeatmap(new APIUser()); var beatmap = createTestBeatmap(new RealmUser());
var score = TestResources.CreateTestScoreInfo(beatmap); var score = TestResources.CreateTestScoreInfo(beatmap);
@ -89,7 +89,7 @@ namespace osu.Game.Tests.Visual.Ranking
private void showPanel(ScoreInfo score) => private void showPanel(ScoreInfo score) =>
Child = new ExpandedPanelMiddleContentContainer(score); Child = new ExpandedPanelMiddleContentContainer(score);
private BeatmapInfo createTestBeatmap([NotNull] APIUser author) private BeatmapInfo createTestBeatmap([NotNull] RealmUser author)
{ {
var beatmap = new TestBeatmap(rulesetStore.GetRuleset(0)).BeatmapInfo; var beatmap = new TestBeatmap(rulesetStore.GetRuleset(0)).BeatmapInfo;

View File

@ -13,8 +13,10 @@ using osu.Framework.Screens;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Rulesets;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
@ -23,6 +25,7 @@ using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
using Realms;
namespace osu.Game.Tests.Visual.Ranking namespace osu.Game.Tests.Visual.Ranking
{ {
@ -32,13 +35,22 @@ namespace osu.Game.Tests.Visual.Ranking
[Resolved] [Resolved]
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }
[Resolved]
private RealmContextFactory realmContextFactory { get; set; }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
var beatmapInfo = beatmaps.QueryBeatmap(b => b.RulesetID == 0); using (var realm = realmContextFactory.CreateContext())
if (beatmapInfo != null) {
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo); var beatmapInfo = realm.All<BeatmapInfo>()
.Filter($"{nameof(BeatmapInfo.Ruleset)}.{nameof(RulesetInfo.OnlineID)} = $0", 0)
.FirstOrDefault();
if (beatmapInfo != null)
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo);
}
} }
[Test] [Test]

View File

@ -7,6 +7,7 @@ using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Models;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
@ -157,10 +158,10 @@ namespace osu.Game.Tests.Visual.Ranking
public void TestSelectMultipleScores() public void TestSelectMultipleScores()
{ {
var firstScore = TestResources.CreateTestScoreInfo(); var firstScore = TestResources.CreateTestScoreInfo();
var secondScore = TestResources.CreateTestScoreInfo(); firstScore.RealmUser = new RealmUser { Username = "A" };
firstScore.UserString = "A"; var secondScore = TestResources.CreateTestScoreInfo();
secondScore.UserString = "B"; secondScore.RealmUser = new RealmUser { Username = "B" };
createListStep(() => new ScorePanelList()); createListStep(() => new ScorePanelList());
@ -178,7 +179,7 @@ namespace osu.Game.Tests.Visual.Ranking
AddStep("select second score", () => AddStep("select second score", () =>
{ {
InputManager.MoveMouseTo(list.ChildrenOfType<ScorePanel>().Single(p => p.Score == secondScore)); InputManager.MoveMouseTo(list.ChildrenOfType<ScorePanel>().Single(p => p.Score.Equals(secondScore)));
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
@ -303,6 +304,6 @@ namespace osu.Game.Tests.Visual.Ranking
=> AddUntilStep("first panel centred", () => Precision.AlmostEquals(list.ChildrenOfType<ScorePanel>().First().ScreenSpaceDrawQuad.Centre.X, list.ScreenSpaceDrawQuad.Centre.X, 1)); => AddUntilStep("first panel centred", () => Precision.AlmostEquals(list.ChildrenOfType<ScorePanel>().First().ScreenSpaceDrawQuad.Centre.X, list.ScreenSpaceDrawQuad.Centre.X, 1));
private void assertScoreState(ScoreInfo score, bool expanded) private void assertScoreState(ScoreInfo score, bool expanded)
=> AddUntilStep($"score expanded = {expanded}", () => (list.ChildrenOfType<ScorePanel>().Single(p => p.Score == score).State == PanelState.Expanded) == expanded); => AddUntilStep($"score expanded = {expanded}", () => (list.ChildrenOfType<ScorePanel>().Single(p => p.Score.Equals(score)).State == PanelState.Expanded) == expanded);
} }
} }

View File

@ -37,7 +37,6 @@ namespace osu.Game.Tests.Visual.SongSelect
private BeatmapInfo exampleBeatmapInfo => new BeatmapInfo private BeatmapInfo exampleBeatmapInfo => new BeatmapInfo
{ {
RulesetID = 0,
Ruleset = rulesets.AvailableRulesets.First(), Ruleset = rulesets.AvailableRulesets.First(),
BaseDifficulty = new BeatmapDifficulty BaseDifficulty = new BeatmapDifficulty
{ {
@ -68,7 +67,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
AddStep("set beatmap", () => advancedStats.BeatmapInfo = new BeatmapInfo AddStep("set beatmap", () => advancedStats.BeatmapInfo = new BeatmapInfo
{ {
Ruleset = rulesets.GetRuleset(3), Ruleset = rulesets.GetRuleset(3) ?? throw new InvalidOperationException(),
BaseDifficulty = new BeatmapDifficulty BaseDifficulty = new BeatmapDifficulty
{ {
CircleSize = 5, CircleSize = 5,

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -27,7 +28,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private RulesetStore rulesets; private RulesetStore rulesets;
private readonly Stack<BeatmapSetInfo> selectedSets = new Stack<BeatmapSetInfo>(); private readonly Stack<BeatmapSetInfo> selectedSets = new Stack<BeatmapSetInfo>();
private readonly HashSet<int> eagerSelectedIDs = new HashSet<int>(); private readonly HashSet<Guid> eagerSelectedIDs = new HashSet<Guid>();
private BeatmapInfo currentSelection => carousel.SelectedBeatmapInfo; private BeatmapInfo currentSelection => carousel.SelectedBeatmapInfo;
@ -75,7 +76,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
AddStep("store selection", () => selection = carousel.SelectedBeatmapInfo); AddStep("store selection", () => selection = carousel.SelectedBeatmapInfo);
if (isIterating) if (isIterating)
AddUntilStep("selection changed", () => !carousel.SelectedBeatmapInfo.Equals(selection)); AddUntilStep("selection changed", () => !carousel.SelectedBeatmapInfo?.Equals(selection) == true);
else else
AddUntilStep("selection not changed", () => carousel.SelectedBeatmapInfo.Equals(selection)); AddUntilStep("selection not changed", () => carousel.SelectedBeatmapInfo.Equals(selection));
} }
@ -377,11 +378,7 @@ namespace osu.Game.Tests.Visual.SongSelect
var rulesetBeatmapSet = TestResources.CreateTestBeatmapSetInfo(1); var rulesetBeatmapSet = TestResources.CreateTestBeatmapSetInfo(1);
var taikoRuleset = rulesets.AvailableRulesets.ElementAt(1); var taikoRuleset = rulesets.AvailableRulesets.ElementAt(1);
rulesetBeatmapSet.Beatmaps.ForEach(b => rulesetBeatmapSet.Beatmaps.ForEach(b => b.Ruleset = taikoRuleset);
{
b.Ruleset = taikoRuleset;
b.RulesetID = 1;
});
sets.Add(rulesetBeatmapSet); sets.Add(rulesetBeatmapSet);
}); });
@ -409,10 +406,10 @@ namespace osu.Game.Tests.Visual.SongSelect
var set = TestResources.CreateTestBeatmapSetInfo(); var set = TestResources.CreateTestBeatmapSetInfo();
if (i == 4) if (i == 4)
set.Metadata.Artist = zzz_string; set.Beatmaps.ForEach(b => b.Metadata.Artist = zzz_string);
if (i == 16) if (i == 16)
set.Metadata.AuthorString = zzz_string; set.Beatmaps.ForEach(b => b.Metadata.AuthorString = zzz_string);
sets.Add(set); sets.Add(set);
} }
@ -433,12 +430,17 @@ namespace osu.Game.Tests.Visual.SongSelect
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
{ {
var set = TestResources.CreateTestBeatmapSetInfo(); var set = TestResources.CreateTestBeatmapSetInfo();
set.Metadata.Artist = "same artist";
set.Metadata.Title = "same title"; // only need to set the first as they are a shared reference.
var beatmap = set.Beatmaps.First();
beatmap.Metadata.Artist = "same artist";
beatmap.Metadata.Title = "same title";
sets.Add(set); sets.Add(set);
} }
int idOffset = sets.First().OnlineID ?? 0; int idOffset = sets.First().OnlineID;
loadBeatmaps(sets); loadBeatmaps(sets);
@ -577,7 +579,6 @@ namespace osu.Game.Tests.Visual.SongSelect
for (int i = 0; i <= 2; i++) for (int i = 0; i <= 2; i++)
{ {
testMixed.Beatmaps[i].Ruleset = rulesets.AvailableRulesets.ElementAt(i); testMixed.Beatmaps[i].Ruleset = rulesets.AvailableRulesets.ElementAt(i);
testMixed.Beatmaps[i].RulesetID = i;
} }
carousel.UpdateBeatmapSet(testMixed); carousel.UpdateBeatmapSet(testMixed);
@ -599,7 +600,6 @@ namespace osu.Game.Tests.Visual.SongSelect
testSingle.Beatmaps.ForEach(b => testSingle.Beatmaps.ForEach(b =>
{ {
b.Ruleset = rulesets.AvailableRulesets.ElementAt(1); b.Ruleset = rulesets.AvailableRulesets.ElementAt(1);
b.RulesetID = b.Ruleset.ID ?? 1;
}); });
carousel.UpdateBeatmapSet(testSingle); carousel.UpdateBeatmapSet(testSingle);
@ -674,7 +674,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("Restore different ruleset filter", () => AddStep("Restore different ruleset filter", () =>
{ {
carousel.Filter(new FilterCriteria { Ruleset = rulesets.GetRuleset(1) }, false); carousel.Filter(new FilterCriteria { Ruleset = rulesets.GetRuleset(1) }, false);
eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.OnlineID ?? -1); eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.ID);
}); });
AddAssert("selection changed", () => !carousel.SelectedBeatmapInfo.Equals(manySets.First().Beatmaps.First())); AddAssert("selection changed", () => !carousel.SelectedBeatmapInfo.Equals(manySets.First().Beatmaps.First()));
@ -697,10 +697,9 @@ namespace osu.Game.Tests.Visual.SongSelect
for (int i = 1; i <= 15; i++) for (int i = 1; i <= 15; i++)
{ {
set.Beatmaps.Add(new BeatmapInfo set.Beatmaps.Add(new BeatmapInfo(new OsuRuleset().RulesetInfo, new BeatmapDifficulty(), new BeatmapMetadata())
{ {
DifficultyName = $"Stars: {i}", DifficultyName = $"Stars: {i}",
Ruleset = new OsuRuleset().RulesetInfo,
StarRating = i, StarRating = i,
}); });
} }
@ -872,8 +871,6 @@ namespace osu.Game.Tests.Visual.SongSelect
} }
} }
} }
protected override IEnumerable<BeatmapSetInfo> GetLoadableBeatmaps() => Enumerable.Empty<BeatmapSetInfo>();
} }
} }
} }

View File

@ -16,6 +16,7 @@ using osu.Game.Online.Leaderboards;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Select.Leaderboards; using osu.Game.Screens.Select.Leaderboards;
@ -44,6 +45,7 @@ namespace osu.Game.Tests.Visual.SongSelect
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory)); dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default)); dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, ContextFactory, Scheduler)); dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, ContextFactory, Scheduler));
Dependencies.Cache(ContextFactory);
return dependencies; return dependencies;
} }
@ -135,6 +137,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock() }, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock() },
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 6602580, Id = 6602580,
@ -157,6 +160,7 @@ namespace osu.Game.Tests.Visual.SongSelect
Accuracy = 1, Accuracy = 1,
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
Ruleset = new OsuRuleset().RulesetInfo,
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
User = new APIUser User = new APIUser
{ {
@ -182,7 +186,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private void clearScores() private void clearScores()
{ {
AddStep("Clear all scores", () => scoreManager.Delete(scoreManager.GetAllUsableScores())); AddStep("Clear all scores", () => scoreManager.Delete());
} }
private void checkCount(int expected) => private void checkCount(int expected) =>
@ -199,6 +203,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Ruleset = new OsuRuleset().RulesetInfo,
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
User = new APIUser User = new APIUser
{ {
@ -219,6 +224,7 @@ namespace osu.Game.Tests.Visual.SongSelect
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 4608074, Id = 4608074,
@ -238,6 +244,8 @@ namespace osu.Game.Tests.Visual.SongSelect
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 1014222, Id = 1014222,
@ -257,6 +265,8 @@ namespace osu.Game.Tests.Visual.SongSelect
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 1541390, Id = 1541390,
@ -276,6 +286,8 @@ namespace osu.Game.Tests.Visual.SongSelect
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 2243452, Id = 2243452,
@ -295,6 +307,8 @@ namespace osu.Game.Tests.Visual.SongSelect
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 2705430, Id = 2705430,
@ -314,6 +328,8 @@ namespace osu.Game.Tests.Visual.SongSelect
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 7151382, Id = 7151382,
@ -333,6 +349,8 @@ namespace osu.Game.Tests.Visual.SongSelect
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 2051389, Id = 2051389,
@ -352,6 +370,8 @@ namespace osu.Game.Tests.Visual.SongSelect
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 6169483, Id = 6169483,
@ -371,6 +391,8 @@ namespace osu.Game.Tests.Visual.SongSelect
TotalScore = 1707827, TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, //Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
BeatmapInfo = beatmapInfo, BeatmapInfo = beatmapInfo,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 6702666, Id = 6702666,

View File

@ -77,7 +77,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
showMetadataForBeatmap(() => showMetadataForBeatmap(() =>
{ {
var allBeatmapSets = manager.GetAllUsableBeatmapSets(IncludedDetails.Minimal); var allBeatmapSets = manager.GetAllUsableBeatmapSets();
if (allBeatmapSets.Count == 0) if (allBeatmapSets.Count == 0)
return manager.DefaultBeatmap; return manager.DefaultBeatmap;

View File

@ -113,6 +113,8 @@ namespace osu.Game.Tests.Visual.SongSelect
// Switch to catch // Switch to catch
presentAndConfirm(() => catchSet, 1); presentAndConfirm(() => catchSet, 1);
AddAssert("game-wide ruleset changed", () => Game.Ruleset.Value.Equals(catchSet.Beatmaps.First().Ruleset));
// Present mixed difficulty set, expect current ruleset to be selected // Present mixed difficulty set, expect current ruleset to be selected
presentAndConfirm(() => mixedSet, 2); presentAndConfirm(() => mixedSet, 2);
} }
@ -182,7 +184,7 @@ namespace osu.Game.Tests.Visual.SongSelect
beatmap.DifficultyName = $"SR{i + 1}"; beatmap.DifficultyName = $"SR{i + 1}";
} }
return Game.BeatmapManager.Import(beatmapSet).GetResultSafely().Value; return Game.BeatmapManager.Import(beatmapSet).GetResultSafely()?.Value;
} }
private bool ensureAllBeatmapSetsImported(IEnumerable<BeatmapSetInfo> beatmapSets) => beatmapSets.All(set => set != null); private bool ensureAllBeatmapSetsImported(IEnumerable<BeatmapSetInfo> beatmapSets) => beatmapSets.All(set => set != null);

View File

@ -38,6 +38,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, Audio, Resources, host, Beatmap.Default)); Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, Audio, Resources, host, Beatmap.Default));
Dependencies.Cache(ContextFactory);
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();

View File

@ -45,7 +45,10 @@ namespace osu.Game.Tests.Visual.SongSelect
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio) private void load(GameHost host, AudioManager audio)
{ {
// These DI caches are required to ensure for interactive runs this test scene doesn't nuke all user beatmaps in the local install.
// At a point we have isolated interactive test runs enough, this can likely be removed.
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(ContextFactory);
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, defaultBeatmap = Beatmap.Default)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, defaultBeatmap = Beatmap.Default));
Dependencies.Cache(music = new MusicController()); Dependencies.Cache(music = new MusicController());
@ -585,7 +588,7 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestHideSetSelectsCorrectBeatmap() public void TestHideSetSelectsCorrectBeatmap()
{ {
int? previousID = null; Guid? previousID = null;
createSongSelect(); createSongSelect();
addRulesetImportStep(0); addRulesetImportStep(0);
AddStep("Move to last difficulty", () => songSelect.Carousel.SelectBeatmap(songSelect.Carousel.BeatmapSets.First().Beatmaps.Last())); AddStep("Move to last difficulty", () => songSelect.Carousel.SelectBeatmap(songSelect.Carousel.BeatmapSets.First().Beatmaps.Last()));
@ -637,8 +640,9 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("Get filtered icon", () => AddStep("Get filtered icon", () =>
{ {
filteredBeatmap = songSelect.Carousel.SelectedBeatmapSet.Beatmaps.First(b => b.BPM < maxBPM); var selectedSet = songSelect.Carousel.SelectedBeatmapSet;
int filteredBeatmapIndex = getBeatmapIndex(filteredBeatmap.BeatmapSet, filteredBeatmap); filteredBeatmap = selectedSet.Beatmaps.First(b => b.BPM < maxBPM);
int filteredBeatmapIndex = getBeatmapIndex(selectedSet, filteredBeatmap);
filteredIcon = set.ChildrenOfType<FilterableDifficultyIcon>().ElementAt(filteredBeatmapIndex); filteredIcon = set.ChildrenOfType<FilterableDifficultyIcon>().ElementAt(filteredBeatmapIndex);
}); });
@ -744,7 +748,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddUntilStep("Check ruleset changed to mania", () => Ruleset.Value.OnlineID == 3); AddUntilStep("Check ruleset changed to mania", () => Ruleset.Value.OnlineID == 3);
AddAssert("Selected beatmap still same set", () => songSelect.Carousel.SelectedBeatmapInfo.BeatmapSet.OnlineID == previousSetID); AddAssert("Selected beatmap still same set", () => songSelect.Carousel.SelectedBeatmapInfo.BeatmapSet?.OnlineID == previousSetID);
AddAssert("Selected beatmap is mania", () => Beatmap.Value.BeatmapInfo.Ruleset.OnlineID == 3); AddAssert("Selected beatmap is mania", () => Beatmap.Value.BeatmapInfo.Ruleset.OnlineID == 3);
} }
@ -760,7 +764,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("import huge difficulty count map", () => AddStep("import huge difficulty count map", () =>
{ {
var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray(); var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
imported = manager.Import(TestResources.CreateTestBeatmapSetInfo(50, usableRulesets)).GetResultSafely().Value; imported = manager.Import(TestResources.CreateTestBeatmapSetInfo(50, usableRulesets)).GetResultSafely()?.Value;
}); });
AddStep("select the first beatmap of import", () => Beatmap.Value = manager.GetWorkingBeatmap(imported.Beatmaps.First())); AddStep("select the first beatmap of import", () => Beatmap.Value = manager.GetWorkingBeatmap(imported.Beatmaps.First()));
@ -796,8 +800,8 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestChangeRulesetWhilePresentingScore() public void TestChangeRulesetWhilePresentingScore()
{ {
BeatmapInfo getPresentBeatmap() => manager.QueryBeatmap(b => !b.BeatmapSet.DeletePending && b.RulesetID == 0); BeatmapInfo getPresentBeatmap() => manager.GetAllUsableBeatmapSets().Where(s => !s.DeletePending).SelectMany(s => s.Beatmaps).First(b => b.RulesetID == 0);
BeatmapInfo getSwitchBeatmap() => manager.QueryBeatmap(b => !b.BeatmapSet.DeletePending && b.RulesetID == 1); BeatmapInfo getSwitchBeatmap() => manager.GetAllUsableBeatmapSets().Where(s => !s.DeletePending).SelectMany(s => s.Beatmaps).First(b => b.RulesetID == 1);
changeRuleset(0); changeRuleset(0);
@ -828,8 +832,8 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestChangeBeatmapWhilePresentingScore() public void TestChangeBeatmapWhilePresentingScore()
{ {
BeatmapInfo getPresentBeatmap() => manager.QueryBeatmap(b => !b.BeatmapSet.DeletePending && b.RulesetID == 0); BeatmapInfo getPresentBeatmap() => manager.GetAllUsableBeatmapSets().Where(s => !s.DeletePending).SelectMany(s => s.Beatmaps).First(b => b.RulesetID == 0);
BeatmapInfo getSwitchBeatmap() => manager.QueryBeatmap(b => !b.BeatmapSet.DeletePending && b.RulesetID == 1); BeatmapInfo getSwitchBeatmap() => manager.GetAllUsableBeatmapSets().Where(s => !s.DeletePending).SelectMany(s => s.Beatmaps).First(b => b.RulesetID == 1);
changeRuleset(0); changeRuleset(0);

View File

@ -10,6 +10,7 @@ using osuTK.Graphics;
using osu.Game.Online.Leaderboards; using osu.Game.Online.Leaderboards;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Users; using osu.Game.Users;
@ -61,6 +62,7 @@ namespace osu.Game.Tests.Visual.SongSelect
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 6602580, Id = 6602580,
@ -79,6 +81,7 @@ namespace osu.Game.Tests.Visual.SongSelect
Accuracy = 1, Accuracy = 1,
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 4608074, Id = 4608074,
@ -97,6 +100,7 @@ namespace osu.Game.Tests.Visual.SongSelect
Accuracy = 1, Accuracy = 1,
MaxCombo = 244, MaxCombo = 244,
TotalScore = 1707827, TotalScore = 1707827,
Ruleset = new OsuRuleset().RulesetInfo,
User = new APIUser User = new APIUser
{ {
Id = 1541390, Id = 1541390,

View File

@ -1,13 +1,14 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Testing; using osu.Framework.Testing;
@ -16,10 +17,12 @@ using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Models;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards; using osu.Game.Online.Leaderboards;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Select.Leaderboards; using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
@ -41,6 +44,9 @@ namespace osu.Game.Tests.Visual.UserInterface
private BeatmapInfo beatmapInfo; private BeatmapInfo beatmapInfo;
[Resolved]
private RealmContextFactory realmFactory { get; set; }
[Cached] [Cached]
private readonly DialogOverlay dialogOverlay; private readonly DialogOverlay dialogOverlay;
@ -59,13 +65,12 @@ namespace osu.Game.Tests.Visual.UserInterface
Scope = BeatmapLeaderboardScope.Local, Scope = BeatmapLeaderboardScope.Local,
BeatmapInfo = new BeatmapInfo BeatmapInfo = new BeatmapInfo
{ {
ID = 1, ID = Guid.NewGuid(),
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
{ {
ID = 1,
Title = "TestSong", Title = "TestSong",
Artist = "TestArtist", Artist = "TestArtist",
Author = new APIUser Author = new RealmUser
{ {
Username = "TestAuthor" Username = "TestAuthor"
}, },
@ -84,26 +89,32 @@ namespace osu.Game.Tests.Visual.UserInterface
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory)); dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default)); dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, ContextFactory, Scheduler)); dependencies.Cache(scoreManager = new ScoreManager(dependencies.Get<RulesetStore>(), () => beatmapManager, LocalStorage, ContextFactory, Scheduler));
Dependencies.Cache(ContextFactory);
beatmapInfo = beatmapManager.Import(new ImportTask(TestResources.GetQuickTestBeatmapForImport())).GetResultSafely().Value.Beatmaps[0]; var imported = beatmapManager.Import(new ImportTask(TestResources.GetQuickTestBeatmapForImport())).GetResultSafely();
for (int i = 0; i < 50; i++) imported?.PerformRead(s =>
{ {
var score = new ScoreInfo beatmapInfo = s.Beatmaps[0];
{
OnlineID = i,
BeatmapInfo = beatmapInfo,
BeatmapInfoID = beatmapInfo.ID,
Accuracy = RNG.NextDouble(),
TotalScore = RNG.Next(1, 1000000),
MaxCombo = RNG.Next(1, 1000),
Rank = ScoreRank.XH,
User = new APIUser { Username = "TestUser" },
};
importedScores.Add(scoreManager.Import(score).GetResultSafely().Value); for (int i = 0; i < 50; i++)
} {
var score = new ScoreInfo
{
OnlineID = i,
BeatmapInfo = beatmapInfo,
Accuracy = RNG.NextDouble(),
TotalScore = RNG.Next(1, 1000000),
MaxCombo = RNG.Next(1, 1000),
Rank = ScoreRank.XH,
User = new APIUser { Username = "TestUser" },
Ruleset = new OsuRuleset().RulesetInfo,
};
importedScores.Add(scoreManager.Import(score).GetResultSafely().Value);
}
});
return dependencies; return dependencies;
} }
@ -111,8 +122,11 @@ namespace osu.Game.Tests.Visual.UserInterface
[SetUp] [SetUp]
public void Setup() => Schedule(() => public void Setup() => Schedule(() =>
{ {
// Due to soft deletions, we can re-use deleted scores between test runs using (var realm = realmFactory.CreateContext())
scoreManager.Undelete(scoreManager.QueryScores(s => s.DeletePending).ToList()); {
// Due to soft deletions, we can re-use deleted scores between test runs
scoreManager.Undelete(realm.All<ScoreInfo>().Where(s => s.DeletePending).ToList());
}
leaderboard.Scores = null; leaderboard.Scores = null;
leaderboard.FinishTransforms(true); // After setting scores, we may be waiting for transforms to expire drawables leaderboard.FinishTransforms(true); // After setting scores, we may be waiting for transforms to expire drawables

View File

@ -459,6 +459,8 @@ namespace osu.Game.Tests.Visual.UserInterface
private class TestUnimplementedModOsuRuleset : OsuRuleset private class TestUnimplementedModOsuRuleset : OsuRuleset
{ {
public override string ShortName => "unimplemented";
public override IEnumerable<Mod> GetModsFor(ModType type) public override IEnumerable<Mod> GetModsFor(ModType type)
{ {
if (type == ModType.Conversion) return base.GetModsFor(type).Concat(new[] { new TestUnimplementedMod() }); if (type == ModType.Conversion) return base.GetModsFor(type).Concat(new[] { new TestUnimplementedMod() });

View File

@ -71,7 +71,7 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.MoveMouseTo(item.ScreenSpaceDrawQuad.Centre); InputManager.MoveMouseTo(item.ScreenSpaceDrawQuad.Centre);
}); });
AddAssert("song 1 is 5th", () => beatmapSets[4] == first); AddAssert("song 1 is 5th", () => beatmapSets[4].Equals(first));
AddStep("release handle", () => InputManager.ReleaseButton(MouseButton.Left)); AddStep("release handle", () => InputManager.ReleaseButton(MouseButton.Left));
} }

View File

@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
this.api = api; this.api = api;
testBeatmap = ImportBeatmapTest.LoadOszIntoOsu(osu).GetResultSafely(); testBeatmap = BeatmapImportHelper.LoadOszIntoOsu(osu).GetResultSafely();
} }
[Test] [Test]

View File

@ -81,8 +81,9 @@ namespace osu.Game.Tournament
ladder ??= new LadderInfo(); ladder ??= new LadderInfo();
ladder.Ruleset.Value = RulesetStore.GetRuleset(ladder.Ruleset.Value?.ShortName) ladder.Ruleset.Value = ladder.Ruleset.Value != null
?? RulesetStore.AvailableRulesets.First(); ? RulesetStore.GetRuleset(ladder.Ruleset.Value.ShortName)
: RulesetStore.AvailableRulesets.First();
bool addedInfo = false; bool addedInfo = false;

Some files were not shown because too many files have changed in this diff Show More