1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 10:32:55 +08:00
osu-lazer/osu.Game.Tests/Mods/SettingsSourceAttributeTest.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.9 KiB
C#
Raw Normal View History

2021-02-27 21:46:48 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-02-27 21:46:48 +08:00
using System.Linq;
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
2021-02-27 21:46:48 +08:00
using osu.Game.Configuration;
using osu.Game.Overlays.Settings;
2021-02-27 21:46:48 +08:00
namespace osu.Game.Tests.Mods
{
[TestFixture]
public class SettingsSourceAttributeTest
{
[Test]
public void TestOrdering()
{
var objectWithSettings = new ClassWithSettings();
var orderedSettings = objectWithSettings.GetOrderedSettingsSourceProperties().ToArray();
2021-02-27 22:14:25 +08:00
Assert.That(orderedSettings, Has.Length.EqualTo(4));
2021-02-27 21:57:37 +08:00
Assert.That(orderedSettings[0].Item2.Name, Is.EqualTo(nameof(ClassWithSettings.FirstSetting)));
Assert.That(orderedSettings[1].Item2.Name, Is.EqualTo(nameof(ClassWithSettings.SecondSetting)));
Assert.That(orderedSettings[2].Item2.Name, Is.EqualTo(nameof(ClassWithSettings.ThirdSetting)));
2021-02-27 22:14:25 +08:00
Assert.That(orderedSettings[3].Item2.Name, Is.EqualTo(nameof(ClassWithSettings.UnorderedSetting)));
2021-02-27 21:46:48 +08:00
}
[Test]
public void TestCustomControl()
{
var objectWithCustomSettingControl = new ClassWithCustomSettingControl();
var settings = objectWithCustomSettingControl.CreateSettingsControls().ToArray();
Assert.That(settings, Has.Length.EqualTo(1));
Assert.That(settings[0], Is.TypeOf<CustomSettingsControl>());
}
2021-02-27 21:46:48 +08:00
private class ClassWithSettings
{
2021-02-27 22:14:25 +08:00
[SettingSource("Unordered setting", "Should be last")]
public BindableFloat UnorderedSetting { get; set; } = new BindableFloat();
2021-02-27 21:46:48 +08:00
[SettingSource("Second setting", "Another description", 2)]
public BindableBool SecondSetting { get; set; } = new BindableBool();
[SettingSource("First setting", "A description", 1)]
public BindableDouble FirstSetting { get; set; } = new BindableDouble();
[SettingSource("Third setting", "Yet another description", 3)]
public BindableInt ThirdSetting { get; set; } = new BindableInt();
}
private class ClassWithCustomSettingControl
{
[SettingSource("Custom setting", "Should be a custom control", SettingControlType = typeof(CustomSettingsControl))]
public BindableInt UnorderedSetting { get; set; } = new BindableInt();
}
private class CustomSettingsControl : SettingsItem<int>
{
protected override Drawable CreateControl() => new CustomControl();
private class CustomControl : Drawable, IHasCurrentValue<int>
{
public Bindable<int> Current { get; set; } = new Bindable<int>();
}
}
2021-02-27 21:46:48 +08:00
}
}