132 行
5.5 KiB
C#
132 行
5.5 KiB
C#
using System.Globalization;
|
|
using YukkuriMovieMaker.Plugin;
|
|
using YukkuriMovieMaker.Plugin.Brush;
|
|
using YukkuriMovieMaker.Plugin.Shape;
|
|
using YukkuriMovieMaker.Plugin.Tachie;
|
|
using YukkuriMovieMaker.Plugin.Transition;
|
|
using YukkuriMovieMaker.Plugin.Voice;
|
|
|
|
namespace UndoTree.Tests;
|
|
|
|
[Collection("Settings")]
|
|
public sealed class UndoTreeParameterNamesTests
|
|
{
|
|
static void With(IPlugin[] plugins, string culture, Action body)
|
|
{
|
|
var previousPlugins = UndoTreeNames.LoadedPlugins;
|
|
var previousCulture = CultureInfo.CurrentUICulture;
|
|
UndoTreeNames.LoadedPlugins = () => plugins;
|
|
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(culture);
|
|
try
|
|
{
|
|
body();
|
|
}
|
|
finally
|
|
{
|
|
UndoTreeNames.LoadedPlugins = previousPlugins;
|
|
CultureInfo.CurrentUICulture = previousCulture;
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("ja-JP", "ローソク足の図形パラメータ")]
|
|
[InlineData("en-US", "Candlestick shape parameters")]
|
|
public void AParameterOfAnotherPluginIsNamedAfterItsPluginAndItsKind(string culture, string expected)
|
|
{
|
|
With([new Foreign.CandlestickShapePlugin()], culture, () =>
|
|
Assert.Equal(expected, UndoTreeNames.OfType(typeof(Foreign.CandlestickShapeParameter), CultureInfo.GetCultureInfo(culture))));
|
|
}
|
|
|
|
[Fact]
|
|
public void WithoutAPluginOfTheSameKindInTheSameAssemblyTheTypeNameIsShown()
|
|
{
|
|
With([], "ja-JP", () =>
|
|
Assert.Equal(nameof(Foreign.CandlestickShapeParameter), UndoTreeNames.OfType(typeof(Foreign.CandlestickShapeParameter))));
|
|
With([new Foreign.ForeignOtherPlugin()], "ja-JP", () =>
|
|
Assert.Equal(nameof(Foreign.CandlestickShapeParameter), UndoTreeNames.OfType(typeof(Foreign.CandlestickShapeParameter))));
|
|
}
|
|
|
|
[Fact]
|
|
public void APluginOfAnotherAssemblyIsNotTakenForThePluginOfTheParameter()
|
|
{
|
|
var hostPlugin = (IPlugin)Activator.CreateInstance(typeof(YukkuriMovieMaker.Project.Scenes).Assembly.GetType("YukkuriMovieMaker.Shape.CircleShapePlugin")!)!;
|
|
Assert.IsAssignableFrom<IShapePlugin>(hostPlugin);
|
|
|
|
With([hostPlugin], "ja-JP", () =>
|
|
Assert.Equal(nameof(Foreign.CandlestickShapeParameter), UndoTreeNames.OfType(typeof(Foreign.CandlestickShapeParameter))));
|
|
}
|
|
|
|
[Fact]
|
|
public void AmongSeveralPluginsTheOneWithTheLongestCommonStartOfTheNameIsChosen()
|
|
{
|
|
With([new Foreign.WaveShapePlugin(), new Foreign.CandlestickShapePlugin()], "ja-JP", () =>
|
|
{
|
|
var japanese = CultureInfo.GetCultureInfo("ja-JP");
|
|
|
|
Assert.Equal("ローソク足の図形パラメータ", UndoTreeNames.OfType(typeof(Foreign.CandlestickShapeParameter), japanese));
|
|
Assert.Equal("うねりの図形パラメータ", UndoTreeNames.OfType(typeof(Foreign.WaveShapeParameter), japanese));
|
|
Assert.Equal(nameof(Foreign.OrphanShapeParameter), UndoTreeNames.OfType(typeof(Foreign.OrphanShapeParameter), japanese));
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void WhenTwoPluginsMatchEquallyNoneIsChosen()
|
|
{
|
|
With([new Foreign.WaveShapePlugin(), new Foreign.WaveformShapePlugin()], "ja-JP", () =>
|
|
Assert.Equal(nameof(Foreign.WaveXShapeParameter), UndoTreeNames.OfType(typeof(Foreign.WaveXShapeParameter))));
|
|
}
|
|
|
|
[Fact]
|
|
public void APluginWhoseNameCannotBeReadIsIgnored()
|
|
{
|
|
With([new Foreign.BrokenShapePlugin()], "ja-JP", () =>
|
|
Assert.Equal(nameof(Foreign.CandlestickShapeParameter), UndoTreeNames.OfType(typeof(Foreign.CandlestickShapeParameter))));
|
|
}
|
|
|
|
[Fact]
|
|
public void ThePluginNameReachesTheLabelOfAChange()
|
|
{
|
|
With([new Foreign.CandlestickShapePlugin()], "en-US", () =>
|
|
{
|
|
var (manager, _) = Histories.NewDocument();
|
|
var parameter = new Foreign.CandlestickShapeParameter();
|
|
manager.Subscribe(parameter);
|
|
Histories.Edit(manager, () => parameter.Width = 3);
|
|
|
|
var info = UndoRedoCommandView.Read(UndoRedoManagerReader.Create(manager)!.CommandsOf(UndoRedoManagerReader.Create(manager)!.Undo[^1]).Single()).Describe();
|
|
|
|
Assert.Equal("Candlestick shape parameters", info.TargetLabel);
|
|
Assert.Equal("Candlestick shape parameters / Width", info.Text);
|
|
});
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(typeof(ShapeParameterBase), "ShapeParameterOf")]
|
|
[InlineData(typeof(AudioSpectrumParameterBase), "AudioSpectrumParameterOf")]
|
|
[InlineData(typeof(BrushParameterBase), "BrushParameterOf")]
|
|
[InlineData(typeof(TransitionParameterBase), "TransitionParameterOf")]
|
|
[InlineData(typeof(VoiceParameterBase), "VoiceParameterOf")]
|
|
[InlineData(typeof(TachieCharacterParameterBase), "TachieCharacterParameterOf")]
|
|
[InlineData(typeof(TachieFaceParameterBase), "TachieFaceParameterOf")]
|
|
[InlineData(typeof(TachieItemParameterBase), "TachieItemParameterOf")]
|
|
[InlineData(typeof(Document), null)]
|
|
public void AParameterIsAssignedToItsKind(Type type, string? key)
|
|
{
|
|
Assert.Equal(key, UndoTreeNames.FamilyKeyOf(type));
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(TextsTests.Cultures), MemberType = typeof(TextsTests))]
|
|
public void EveryKindHasATemplateWithThePluginNameInEveryLanguage(string culture)
|
|
{
|
|
var cultureInfo = CultureInfo.GetCultureInfo(culture);
|
|
|
|
Assert.All(UndoTreeNames.FamilyKeys, key =>
|
|
{
|
|
var template = Texts.ResourceManager.GetString(key, cultureInfo);
|
|
Assert.False(string.IsNullOrEmpty(template));
|
|
Assert.Contains("{0}", template);
|
|
});
|
|
}
|
|
}
|