mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 14:13:18 +08:00
Refactor to avoid duplicate code
This commit is contained in:
parent
b888185799
commit
72ee2b1556
@ -54,7 +54,7 @@ namespace osu.Game.Tests.Editing.Checks
|
||||
{
|
||||
// While this is a problem, it is out of scope for this check and is caught by a different one.
|
||||
beatmap.Metadata.BackgroundFile = string.Empty;
|
||||
var context = getContext(null, System.Array.Empty<byte>());
|
||||
var context = getContext(null, new MemoryStream(System.Array.Empty<byte>()));
|
||||
|
||||
Assert.That(check.Run(context), Is.Empty);
|
||||
}
|
||||
@ -103,7 +103,7 @@ namespace osu.Game.Tests.Editing.Checks
|
||||
[Test]
|
||||
public void TestTooUncompressed()
|
||||
{
|
||||
var context = getContext(new Texture(1920, 1080), new byte[1024 * 1024 * 3]);
|
||||
var context = getContext(new Texture(1920, 1080), new MemoryStream(new byte[1024 * 1024 * 3]));
|
||||
|
||||
var issues = check.Run(context).ToList();
|
||||
|
||||
@ -117,31 +117,26 @@ namespace osu.Game.Tests.Editing.Checks
|
||||
var background = new Texture(1920, 1080);
|
||||
var stream = new Mock<MemoryStream>(new byte[1024 * 1024]);
|
||||
|
||||
var mock = new Mock<IWorkingBeatmap>();
|
||||
mock.SetupGet(w => w.Beatmap).Returns(beatmap);
|
||||
mock.SetupGet(w => w.Background).Returns(background);
|
||||
mock.Setup(w => w.GetStream(It.IsAny<string>())).Returns(stream.Object);
|
||||
|
||||
var context = new BeatmapVerifierContext(beatmap, mock.Object);
|
||||
var context = getContext(background, stream.Object);
|
||||
|
||||
Assert.That(check.Run(context), Is.Empty);
|
||||
|
||||
stream.Verify(x => x.Close(), Times.Once());
|
||||
}
|
||||
|
||||
private BeatmapVerifierContext getContext(Texture background, [CanBeNull] byte[] fileBytes = null)
|
||||
private BeatmapVerifierContext getContext(Texture background, [CanBeNull] Stream stream = null)
|
||||
{
|
||||
return new BeatmapVerifierContext(beatmap, getMockWorkingBeatmap(background, fileBytes).Object);
|
||||
return new BeatmapVerifierContext(beatmap, getMockWorkingBeatmap(background, stream).Object);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the mock of the working beatmap with the given background and filesize.
|
||||
/// Returns the mock of the working beatmap with the given background and its file stream.
|
||||
/// </summary>
|
||||
/// <param name="background">The texture of the background.</param>
|
||||
/// <param name="fileBytes">The bytes that represent the background file.</param>
|
||||
private Mock<IWorkingBeatmap> getMockWorkingBeatmap(Texture background, [CanBeNull] byte[] fileBytes = null)
|
||||
/// <param name="stream">The stream representing the background file.</param>
|
||||
private Mock<IWorkingBeatmap> getMockWorkingBeatmap(Texture background, [CanBeNull] Stream stream = null)
|
||||
{
|
||||
var stream = new MemoryStream(fileBytes ?? new byte[1024 * 1024]);
|
||||
stream ??= new MemoryStream(new byte[1024 * 1024]);
|
||||
|
||||
var mock = new Mock<IWorkingBeatmap>();
|
||||
mock.SetupGet(w => w.Beatmap).Returns(beatmap);
|
||||
|
Loading…
Reference in New Issue
Block a user