由于Windows 8.1应用程序不支持多值转换器,因此我选择使用依赖项属性。但是后来,当我测试转换器并实例化它时,我收到了这个错误:
有谁知道如何测试这种转换器?
以下是源代码的最简单版本:
[TestClass]
public class ConverterWithDependencyPropertyTests
{
[TestMethod]
public void UnitTest()
{
var converter = new BinCodeToBinQuantityConverter();
}
}
答案 0 :(得分:0)
最后,我可以这样做:
[TestMethod]
public async Task Converter_With_Dependency_Property_Test()
{
var expectedResult = 3;
var valueConverted = 0;
await ExecuteOnUIThread(() =>
{
_converterWithDependencyProperty = new ConverterWithDependencyProperty();
_converterWithDependencyProperty.DependencyProperty = _dummyValue;
valueConverted = (int)_converterWithDependencyProperty.Convert(_dummyValueToConvert, typeof(int), null, null);
});
Assert.AreEqual(expectedResult, valueConverted);
}
public static IAsyncAction ExecuteOnUIThread(DispatchedHandler action)
{
return CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, action);
}