mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 20:22:55 +08:00
Add test coverage for edge cases
This commit is contained in:
parent
f0ec264bbc
commit
af579be0e4
@ -28,6 +28,7 @@ namespace osu.Game.Tests.Beatmaps
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestLocalCacheQueriedFirst()
|
public void TestLocalCacheQueriedFirst()
|
||||||
{
|
{
|
||||||
|
localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
||||||
.Returns(new OnlineBeatmapMetadata { BeatmapID = 123456, BeatmapStatus = BeatmapOnlineStatus.Ranked });
|
.Returns(new OnlineBeatmapMetadata { BeatmapID = 123456, BeatmapStatus = BeatmapOnlineStatus.Ranked });
|
||||||
apiMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
apiMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
@ -46,6 +47,7 @@ namespace osu.Game.Tests.Beatmaps
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestAPIQueriedSecond()
|
public void TestAPIQueriedSecond()
|
||||||
{
|
{
|
||||||
|
localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
||||||
.Returns((OnlineBeatmapMetadata?)null);
|
.Returns((OnlineBeatmapMetadata?)null);
|
||||||
apiMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
apiMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
@ -66,6 +68,7 @@ namespace osu.Game.Tests.Beatmaps
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestPreferOnlineFetch()
|
public void TestPreferOnlineFetch()
|
||||||
{
|
{
|
||||||
|
localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
||||||
.Returns(new OnlineBeatmapMetadata { BeatmapID = 123456, BeatmapStatus = BeatmapOnlineStatus.Ranked });
|
.Returns(new OnlineBeatmapMetadata { BeatmapID = 123456, BeatmapStatus = BeatmapOnlineStatus.Ranked });
|
||||||
apiMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
apiMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
@ -86,6 +89,7 @@ namespace osu.Game.Tests.Beatmaps
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestPreferOnlineFetchFallsBackToLocalCacheIfOnlineSourceUnavailable()
|
public void TestPreferOnlineFetchFallsBackToLocalCacheIfOnlineSourceUnavailable()
|
||||||
{
|
{
|
||||||
|
localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
||||||
.Returns(new OnlineBeatmapMetadata { BeatmapID = 123456, BeatmapStatus = BeatmapOnlineStatus.Ranked });
|
.Returns(new OnlineBeatmapMetadata { BeatmapID = 123456, BeatmapStatus = BeatmapOnlineStatus.Ranked });
|
||||||
apiMetadataSourceMock.Setup(src => src.Available).Returns(false);
|
apiMetadataSourceMock.Setup(src => src.Available).Returns(false);
|
||||||
@ -104,6 +108,7 @@ namespace osu.Game.Tests.Beatmaps
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestMetadataLookupFailed()
|
public void TestMetadataLookupFailed()
|
||||||
{
|
{
|
||||||
|
localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
||||||
.Returns((OnlineBeatmapMetadata?)null);
|
.Returns((OnlineBeatmapMetadata?)null);
|
||||||
apiMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
apiMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
@ -121,5 +126,52 @@ namespace osu.Game.Tests.Beatmaps
|
|||||||
localCachedMetadataSourceMock.Verify(src => src.Lookup(beatmap), Times.Once);
|
localCachedMetadataSourceMock.Verify(src => src.Lookup(beatmap), Times.Once);
|
||||||
apiMetadataSourceMock.Verify(src => src.Lookup(beatmap), Times.Once);
|
apiMetadataSourceMock.Verify(src => src.Lookup(beatmap), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <remarks>
|
||||||
|
/// 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.
|
||||||
|
/// </remarks>
|
||||||
|
[Test]
|
||||||
|
public void TestLocalMetadataLookupFailedAndOnlineLookupIsUnavailable([Values] bool preferOnlineFetch)
|
||||||
|
{
|
||||||
|
localCachedMetadataSourceMock.Setup(src => src.Available).Returns(true);
|
||||||
|
localCachedMetadataSourceMock.Setup(src => src.Lookup(It.IsAny<BeatmapInfo>()))
|
||||||
|
.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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <remarks>
|
||||||
|
/// 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.
|
||||||
|
/// </remarks>
|
||||||
|
[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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user