diff --git a/osu.Game.Tests/Beatmaps/BeatmapUpdaterMetadataLookupTest.cs b/osu.Game.Tests/Beatmaps/BeatmapUpdaterMetadataLookupTest.cs index f1eab065c0..64f44c9922 100644 --- a/osu.Game.Tests/Beatmaps/BeatmapUpdaterMetadataLookupTest.cs +++ b/osu.Game.Tests/Beatmaps/BeatmapUpdaterMetadataLookupTest.cs @@ -28,6 +28,7 @@ namespace osu.Game.Tests.Beatmaps [Test] public void TestLocalCacheQueriedFirst() { + localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true); localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny())) .Returns(new OnlineBeatmapMetadata { BeatmapID = 123456, BeatmapStatus = BeatmapOnlineStatus.Ranked }); apiMetadataSourceMock.Setup(src => src.Available).Returns(true); @@ -46,6 +47,7 @@ namespace osu.Game.Tests.Beatmaps [Test] public void TestAPIQueriedSecond() { + localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true); localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny())) .Returns((OnlineBeatmapMetadata?)null); apiMetadataSourceMock.Setup(src => src.Available).Returns(true); @@ -66,6 +68,7 @@ namespace osu.Game.Tests.Beatmaps [Test] public void TestPreferOnlineFetch() { + localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true); localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny())) .Returns(new OnlineBeatmapMetadata { BeatmapID = 123456, BeatmapStatus = BeatmapOnlineStatus.Ranked }); apiMetadataSourceMock.Setup(src => src.Available).Returns(true); @@ -86,6 +89,7 @@ namespace osu.Game.Tests.Beatmaps [Test] public void TestPreferOnlineFetchFallsBackToLocalCacheIfOnlineSourceUnavailable() { + localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true); localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny())) .Returns(new OnlineBeatmapMetadata { BeatmapID = 123456, BeatmapStatus = BeatmapOnlineStatus.Ranked }); apiMetadataSourceMock.Setup(src => src.Available).Returns(false); @@ -104,6 +108,7 @@ namespace osu.Game.Tests.Beatmaps [Test] public void TestMetadataLookupFailed() { + localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true); localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny())) .Returns((OnlineBeatmapMetadata?)null); apiMetadataSourceMock.Setup(src => src.Available).Returns(true); @@ -121,5 +126,52 @@ namespace osu.Game.Tests.Beatmaps localCachedMetadataSourceMock.Verify(src => src.Lookup(beatmap), Times.Once); apiMetadataSourceMock.Verify(src => src.Lookup(beatmap), Times.Once); } + + /// + /// For the time being, if we fail to find a match in the local cache but online retrieval is not available, we trust the incoming beatmap verbatim wrt online ID. + /// While this is suboptimal as it implicitly trusts the contents of the beatmap, + /// throwing away the online data would be anti-user as it would make all beatmaps imported offline stop working in online. + /// TODO: revisit if/when we have a better flow of queueing metadata retrieval. + /// + [Test] + public void TestLocalMetadataLookupFailedAndOnlineLookupIsUnavailable([Values] bool preferOnlineFetch) + { + localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true); + localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny())) + .Returns((OnlineBeatmapMetadata?)null); + apiMetadataSourceMock.Setup(src => src.Available).Returns(false); + + var beatmap = new BeatmapInfo { OnlineID = 123456 }; + var beatmapSet = new BeatmapSetInfo(beatmap.Yield()); + beatmap.BeatmapSet = beatmapSet; + + metadataLookup.Update(beatmapSet, preferOnlineFetch); + + Assert.That(beatmap.Status, Is.EqualTo(BeatmapOnlineStatus.None)); + Assert.That(beatmap.OnlineID, Is.EqualTo(123456)); + } + + /// + /// For the time being, if there are no available metadata lookup sources, we trust the incoming beatmap verbatim wrt online ID. + /// While this is suboptimal as it implicitly trusts the contents of the beatmap, + /// throwing away the online data would be anti-user as it would make all beatmaps imported offline stop working in online. + /// TODO: revisit if/when we have a better flow of queueing metadata retrieval. + /// + [Test] + public void TestNoAvailableSources() + { + localCachedMetadataSourceMock.Setup(src => src.Available).Returns(false); + apiMetadataSourceMock.Setup(src => src.Available).Returns(false); + + var beatmap = new BeatmapInfo { OnlineID = 123456 }; + var beatmapSet = new BeatmapSetInfo(beatmap.Yield()); + beatmap.BeatmapSet = beatmapSet; + + metadataLookup.Update(beatmapSet, preferOnlineFetch: false); + + Assert.That(beatmap.OnlineID, Is.EqualTo(123456)); + localCachedMetadataSourceMock.Verify(src => src.Lookup(beatmap), Times.Never); + apiMetadataSourceMock.Verify(src => src.Lookup(beatmap), Times.Never); + } } }