mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:17:26 +08:00
Tidy up new test method code quality
This commit is contained in:
parent
810712386d
commit
415220a447
@ -3,6 +3,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Database;
|
||||
@ -11,11 +12,11 @@ namespace osu.Game.Tests.Database
|
||||
{
|
||||
public class LegacyExporterTest
|
||||
{
|
||||
private TestLegacyExporter? legacyExporter;
|
||||
private TemporaryNativeStorage? storage;
|
||||
private TestLegacyExporter legacyExporter = null!;
|
||||
private TemporaryNativeStorage storage = null!;
|
||||
|
||||
[SetUp]
|
||||
public void SetupLegacyExporter()
|
||||
public void SetUp()
|
||||
{
|
||||
storage = new TemporaryNativeStorage("export-storage");
|
||||
legacyExporter = new TestLegacyExporter(storage);
|
||||
@ -24,24 +25,24 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void ExportFileWithNormalNameTest()
|
||||
{
|
||||
var exportStorage = storage?.GetStorageForDirectory(@"exports");
|
||||
var exportStorage = storage.GetStorageForDirectory(@"exports");
|
||||
|
||||
const string filename = "normal file name";
|
||||
var item = new TestPathInfo(filename);
|
||||
|
||||
Assert.That(item.FileName.Length < TestLegacyExporter.GetMaxPath(), Is.True);
|
||||
Assert.That(item.Filename.Length < TestLegacyExporter.GetMaxPath(), Is.True);
|
||||
exportItemAndAssert(item, exportStorage, filename);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExportFileWithNormalNameMultipleTimesTest()
|
||||
{
|
||||
var exportStorage = storage?.GetStorageForDirectory(@"exports");
|
||||
var exportStorage = storage.GetStorageForDirectory(@"exports");
|
||||
|
||||
const string filename = "normal file name";
|
||||
var item = new TestPathInfo(filename);
|
||||
|
||||
Assert.That(item.FileName.Length < TestLegacyExporter.GetMaxPath(), Is.True);
|
||||
Assert.That(item.Filename.Length < TestLegacyExporter.GetMaxPath(), Is.True);
|
||||
|
||||
//Export multiple times
|
||||
for (int i = 0; i < 10; i++)
|
||||
@ -54,59 +55,65 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void ExportFileWithSuperLongNameTest()
|
||||
{
|
||||
var exportStorage = storage?.GetStorageForDirectory(@"exports");
|
||||
var exportStorage = storage.GetStorageForDirectory(@"exports");
|
||||
|
||||
const string fullname = "some file with super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name";
|
||||
const string fullname =
|
||||
"some file with super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name";
|
||||
|
||||
int expectedLength = TestLegacyExporter.GetMaxPath() - (legacyExporter?.GetExtension().Length ?? 0);
|
||||
int expectedLength = TestLegacyExporter.GetMaxPath() - (legacyExporter.GetExtension().Length);
|
||||
string expectedName = fullname.Remove(expectedLength);
|
||||
|
||||
var item = new TestPathInfo(fullname);
|
||||
|
||||
Assert.That(item.FileName.Length > TestLegacyExporter.GetMaxPath(), Is.True);
|
||||
Assert.That(item.Filename.Length > TestLegacyExporter.GetMaxPath(), Is.True);
|
||||
exportItemAndAssert(item, exportStorage, expectedName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExportFileWithSuperLongNameMultipleTimesTest()
|
||||
{
|
||||
var exportStorage = storage?.GetStorageForDirectory(@"exports");
|
||||
var exportStorage = storage.GetStorageForDirectory(@"exports");
|
||||
|
||||
const string fullname = "some file with super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name";
|
||||
const string fullname =
|
||||
"some file with super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name";
|
||||
|
||||
int expectedLength = TestLegacyExporter.GetMaxPath() - (legacyExporter?.GetExtension().Length ?? 0);
|
||||
int expectedLength = TestLegacyExporter.GetMaxPath() - (legacyExporter.GetExtension().Length);
|
||||
string expectedName = fullname.Remove(expectedLength);
|
||||
|
||||
var item = new TestPathInfo(fullname);
|
||||
|
||||
Assert.That(item.FileName.Length > TestLegacyExporter.GetMaxPath(), Is.True);
|
||||
Assert.That(item.Filename.Length > TestLegacyExporter.GetMaxPath(), Is.True);
|
||||
|
||||
//Export multiple times
|
||||
for (int i = 0; i < 10; i++)
|
||||
exportItemAndAssert(item, exportStorage, expectedName);
|
||||
}
|
||||
|
||||
private void exportItemAndAssert(IHasNamedFiles item, Storage? exportStorage, string expectedName)
|
||||
private void exportItemAndAssert(IHasNamedFiles item, Storage exportStorage, string expectedName)
|
||||
{
|
||||
Assert.DoesNotThrow(() => legacyExporter?.Export(item));
|
||||
Assert.That(exportStorage?.Exists($"{expectedName}{legacyExporter?.GetExtension()}"), Is.True);
|
||||
Assert.DoesNotThrow(() => legacyExporter.Export(item));
|
||||
Assert.That(exportStorage.Exists($"{expectedName}{legacyExporter.GetExtension()}"), Is.True);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void CleanupAfterTest()
|
||||
public void TearDown()
|
||||
{
|
||||
storage?.Dispose();
|
||||
if (storage.IsNotNull())
|
||||
storage.Dispose();
|
||||
}
|
||||
|
||||
private class TestPathInfo : IHasNamedFiles
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string Filename { get; }
|
||||
|
||||
public TestPathInfo(string fileName) => FileName = fileName;
|
||||
public IEnumerable<INamedFileUsage> Files { get; } = new List<INamedFileUsage>();
|
||||
|
||||
public IEnumerable<INamedFileUsage> Files { get; set; } = new List<INamedFileUsage>();
|
||||
public TestPathInfo(string filename)
|
||||
{
|
||||
Filename = filename;
|
||||
}
|
||||
|
||||
public override string ToString() => FileName;
|
||||
public override string ToString() => Filename;
|
||||
}
|
||||
|
||||
private class TestLegacyExporter : LegacyExporter<IHasNamedFiles>
|
||||
|
Loading…
Reference in New Issue
Block a user