1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 20:22:55 +08:00

Make more tests use the custom mod classes

For safety purposes... In implementing the previous tests, I found that
using mod.Object.GetType() can lead to bad assertions since the same
ModProxy class is used for all mocked classes.
This commit is contained in:
smoogipoo 2021-02-02 18:33:12 +09:00
parent 1df412a03c
commit 9955e02898

View File

@ -14,37 +14,37 @@ namespace osu.Game.Tests.Mods
[Test] [Test]
public void TestModIsCompatibleByItself() public void TestModIsCompatibleByItself()
{ {
var mod = new Mock<Mod>(); var mod = new Mock<CustomMod1>();
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod.Object })); Assert.That(ModUtils.CheckCompatibleSet(new[] { mod.Object }));
} }
[Test] [Test]
public void TestIncompatibleThroughTopLevel() public void TestIncompatibleThroughTopLevel()
{ {
var mod1 = new Mock<Mod>(); var mod1 = new Mock<CustomMod1>();
var mod2 = new Mock<Mod>(); var mod2 = new Mock<CustomMod2>();
mod1.Setup(m => m.IncompatibleMods).Returns(new[] { mod2.Object.GetType() }); mod1.Setup(m => m.IncompatibleMods).Returns(new[] { mod2.Object.GetType() });
// Test both orderings. // Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod1.Object, mod2.Object }), Is.False); Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.False);
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod2.Object, mod1.Object }), Is.False); Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.False);
} }
[Test] [Test]
public void TestMultiModIncompatibleWithTopLevel() public void TestMultiModIncompatibleWithTopLevel()
{ {
var mod1 = new Mock<Mod>(); var mod1 = new Mock<CustomMod1>();
// The nested mod. // The nested mod.
var mod2 = new Mock<Mod>(); var mod2 = new Mock<CustomMod2>();
mod2.Setup(m => m.IncompatibleMods).Returns(new[] { mod1.Object.GetType() }); mod2.Setup(m => m.IncompatibleMods).Returns(new[] { mod1.Object.GetType() });
var multiMod = new MultiMod(new MultiMod(mod2.Object)); var multiMod = new MultiMod(new MultiMod(mod2.Object));
// Test both orderings. // Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new[] { multiMod, mod1.Object }), Is.False); Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { multiMod, mod1.Object }), Is.False);
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod1.Object, multiMod }), Is.False); Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, multiMod }), Is.False);
} }
[Test] [Test]
@ -65,37 +65,37 @@ namespace osu.Game.Tests.Mods
[Test] [Test]
public void TestCompatibleMods() public void TestCompatibleMods()
{ {
var mod1 = new Mock<Mod>(); var mod1 = new Mock<CustomMod1>();
var mod2 = new Mock<Mod>(); var mod2 = new Mock<CustomMod2>();
// Test both orderings. // Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod1.Object, mod2.Object }), Is.True); Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.True);
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod2.Object, mod1.Object }), Is.True); Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.True);
} }
[Test] [Test]
public void TestIncompatibleThroughBaseType() public void TestIncompatibleThroughBaseType()
{ {
var mod1 = new Mock<Mod>(); var mod1 = new Mock<CustomMod1>();
var mod2 = new Mock<Mod>(); var mod2 = new Mock<CustomMod2>();
mod2.Setup(m => m.IncompatibleMods).Returns(new[] { mod1.Object.GetType().BaseType }); mod2.Setup(m => m.IncompatibleMods).Returns(new[] { typeof(Mod) });
// Test both orderings. // Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod1.Object, mod2.Object }), Is.False); Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.False);
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod2.Object, mod1.Object }), Is.False); Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.False);
} }
[Test] [Test]
public void TestAllowedThroughMostDerivedType() public void TestAllowedThroughMostDerivedType()
{ {
var mod = new Mock<Mod>(); var mod = new Mock<CustomMod1>();
Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { mod.Object.GetType() })); Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { mod.Object.GetType() }));
} }
[Test] [Test]
public void TestNotAllowedThroughBaseType() public void TestNotAllowedThroughBaseType()
{ {
var mod = new Mock<Mod>(); var mod = new Mock<CustomMod1>();
Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { typeof(Mod) }), Is.False); Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { typeof(Mod) }), Is.False);
} }