Skip to content

A Swiss Army knife for developers.

Clean-up some code and added unit tests

Etienne Baudouxe4b67edcbee8
diff --git a/src/dev/impl/DevToys/Core/Threading/AsyncLazy.cs b/src/dev/impl/DevToys/Core/Threading/AsyncLazy.cs
index 62a046b47..ade978bfb 100644
--- a/src/dev/impl/DevToys/Core/Threading/AsyncLazy.cs
+++ b/src/dev/impl/DevToys/Core/Threading/AsyncLazy.cs
@@ -3,12 +3,17 @@
using System;
using System.Threading;
using System.Threading.Tasks;
+using DevToys.Shared.Core;
namespace DevToys.Core.Threading
{
internal sealed class AsyncLazy<T>
{
- private static Func<Task<T>> FromFuncT(Func<T> valueFunc) => () => Task.FromResult(valueFunc());
+ private static Func<Task<T>> FromFuncT(Func<T> valueFunc)
+ {
+ Arguments.NotNull(valueFunc, nameof(valueFunc));
+ return () => Task.FromResult(valueFunc());
+ }
private readonly Lazy<Task<T>> _innerLazy;
@@ -49,9 +54,9 @@ namespace DevToys.Core.Threading
_innerLazy = new Lazy<Task<T>>(valueFactory, mode);
}
- public async Task<T> GetValueAsync()
+ public Task<T> GetValueAsync()
{
- return IsValueCreated ? await _innerLazy.Value : _innerLazy.Value.Result;
+ return IsValueCreated ? Task.FromResult(_innerLazy.Value.Result) : _innerLazy.Value;
}
}
}
diff --git a/src/dev/impl/DevToys/Core/TitleBar.cs b/src/dev/impl/DevToys/Core/TitleBar.cs
index 6d8b9084b..9f7f1f8a2 100644
--- a/src/dev/impl/DevToys/Core/TitleBar.cs
+++ b/src/dev/impl/DevToys/Core/TitleBar.cs
@@ -46,6 +46,7 @@ namespace DevToys.Core
{
_settingsProvider = settingsProvider;
_themeListener = themeListener;
+ _themeListener.ThemeChanged += ThemeListener_ThemeChanged;
}
public Task SetupTitleBarAsync()
@@ -56,6 +57,14 @@ namespace DevToys.Core
});
}
+ private void ThemeListener_ThemeChanged(object sender, System.EventArgs e)
+ {
+ ThreadHelper.RunOnUIThreadAsync(() =>
+ {
+ ApplyThemeForTitleBarButtons();
+ });
+ }
+
private void SetupTitleBar(CoreApplicationViewTitleBar coreTitleBar)
{
ThreadHelper.ThrowIfNotOnUIThread();
diff --git a/src/dev/impl/DevToys/DevToys.csproj b/src/dev/impl/DevToys/DevToys.csproj
index 373fc44da..fa3b108e8 100644
--- a/src/dev/impl/DevToys/DevToys.csproj
+++ b/src/dev/impl/DevToys/DevToys.csproj
@@ -360,10 +360,8 @@
<Compile Include="UI\Converters\EnumToThicknessConverter.cs" />
<Compile Include="UI\Converters\InvertedBooleanConverter.cs" />
<Compile Include="UI\Converters\NullToBooleanConverter.cs" />
- <Compile Include="UI\Extensions\Axis.cs" />
<Compile Include="UI\Extensions\HighlighterExtension.cs" />
<Compile Include="UI\Extensions\IsCompactOverlayModeTrigger.cs" />
- <Compile Include="UI\Extensions\ScrollViewerExtensions.cs" />
<Compile Include="ViewModels\MainPageViewModel.cs" />
<Compile Include="ViewModels\Tools\Settings\SettingsToolProvider.cs" />
<Compile Include="ViewModels\Tools\Settings\SettingsToolViewModel.cs" />
diff --git a/src/dev/impl/DevToys/Models/NoResultFoundMockToolProvider.cs b/src/dev/impl/DevToys/Models/NoResultFoundMockToolProvider.cs
index ed70a07c7..ee89d6b63 100644
--- a/src/dev/impl/DevToys/Models/NoResultFoundMockToolProvider.cs
+++ b/src/dev/impl/DevToys/Models/NoResultFoundMockToolProvider.cs
@@ -29,7 +29,6 @@ namespace DevToys.Models
public IToolViewModel CreateTool()
{
- // TODO: Show a page indicating "No results match your search".
throw new NotSupportedException();
}
}
diff --git a/src/dev/impl/DevToys/UI/Extensions/Axis.cs b/src/dev/impl/DevToys/UI/Extensions/Axis.cs
deleted file mode 100644
index f2a724356..000000000
--- a/src/dev/impl/DevToys/UI/Extensions/Axis.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-#nullable enable
-
-namespace DevToys.UI.Extensions
-{
- /// <summary>
- /// Indicates an axis in the 2D space
- /// </summary>
- internal enum Axis
- {
- /// <summary>
- /// The X axis (horizontal)
- /// </summary>
- X,
-
- /// <summary>
- /// The Y axis (vertical)
- /// </summary>
- Y
- }
-}
diff --git a/src/dev/impl/DevToys/UI/Extensions/ScrollViewerExtensions.cs b/src/dev/impl/DevToys/UI/Extensions/ScrollViewerExtensions.cs
deleted file mode 100644
index 31e5866fc..000000000
--- a/src/dev/impl/DevToys/UI/Extensions/ScrollViewerExtensions.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-#nullable enable
-
-using Windows.UI.Composition;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Hosting;
-
-namespace DevToys.UI.Extensions
-{
- internal static class ScrollViewerExtensions
- {
- internal static ExpressionAnimation StartExpressionAnimation(
- this ScrollViewer scrollViewer,
- UIElement target,
- Axis axis)
- {
- return scrollViewer.StartExpressionAnimation(target, sourceAxis: axis, targetAxis: axis);
- }
-
- internal static ExpressionAnimation StartExpressionAnimation(
- this ScrollViewer scrollViewer,
- UIElement target,
- Axis sourceAxis,
- Axis targetAxis)
- {
- CompositionPropertySet scrollSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer);
-
- ExpressionAnimation animation = scrollSet.Compositor.CreateExpressionAnimation($"{nameof(scrollViewer)}.{nameof(UIElement.Translation)}.{sourceAxis}");
- animation.SetReferenceParameter(nameof(scrollViewer), scrollSet);
-
- Visual visual = ElementCompositionPreview.GetElementVisual(target);
- visual.StartAnimation($"{nameof(Visual.Offset)}.{targetAxis}", animation);
-
- return animation;
- }
- }
-}
diff --git a/src/dev/impl/DevToys/UI/MainMenuNavigationViewMenuItemSelector.cs b/src/dev/impl/DevToys/UI/MainMenuNavigationViewMenuItemSelector.cs
index aecfbdd7b..bb1a9bb6f 100644
--- a/src/dev/impl/DevToys/UI/MainMenuNavigationViewMenuItemSelector.cs
+++ b/src/dev/impl/DevToys/UI/MainMenuNavigationViewMenuItemSelector.cs
@@ -20,7 +20,7 @@ namespace DevToys.UI
{
return ToolProvider;
}
- else if (item is Microsoft.UI.Xaml.Controls.NavigationViewItemSeparator navigationViewItemSeparator)
+ else if (item is Microsoft.UI.Xaml.Controls.NavigationViewItemSeparator)
{
return Separator;
}
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/AllTools/AllToolsToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/AllTools/AllToolsToolViewModel.cs
index b2ec96e87..63ccf3efe 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/AllTools/AllToolsToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/AllTools/AllToolsToolViewModel.cs
@@ -20,11 +20,11 @@ namespace DevToys.ViewModels.AllTools
ToolProviders
= toolProviderFactory
.GetAllTools()
- .Where(tool => tool.ChildrenTools.Count == 0 && tool.Metadata.MenuPlacement != MenuPlacement.Header)
- .OrderBy(tool => tool.Metadata.MenuPlacement)
- .ThenBy(tool => tool.ToolProvider.MenuDisplayName)
- .ThenBy(tool => tool.Metadata.Order ?? int.MaxValue)
- .ThenBy(item => item.Metadata.Name)
+ .Where(tool => tool.ChildrenTools.Count == 0 && tool.Metadata.MenuPlacement != MenuPlacement.Header) // Don't show tool groups and tools displayed in the menu header.
+ .OrderBy(tool => tool.Metadata.MenuPlacement) // Show first items from the Body, then the Footer of the menu.
+ .ThenBy(tool => tool.ToolProvider.MenuDisplayName) // Order items alphabetically
+ .ThenBy(tool => tool.Metadata.Order ?? int.MaxValue) // Then by defined order.
+ .ThenBy(item => item.Metadata.Name) // Then by internal name
.Select(tool => tool.ToolProvider)
.ToList();
}
diff --git a/src/tests/DevToys.Tests/Core/Threading/AsyncLazyTests.cs b/src/tests/DevToys.Tests/Core/Threading/AsyncLazyTests.cs
new file mode 100644
index 000000000..8e2a97124
--- /dev/null
+++ b/src/tests/DevToys.Tests/Core/Threading/AsyncLazyTests.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Threading.Tasks;
+using DevToys.Core.Threading;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace DevToys.Tests.Core.Threading
+{
+ [TestClass]
+ public class AsyncLazyTests
+ {
+ [TestMethod]
+ public async Task AccurateResultAsync()
+ {
+ var expected = new TestClass(5);
+ var lazy = new AsyncLazy<TestClass>(async () =>
+ {
+ await Task.Yield();
+ return expected;
+ });
+
+ TestClass actual = await lazy.GetValueAsync();
+ Assert.AreSame(expected, actual);
+ }
+
+ [TestMethod]
+ public async Task IsValueCreatedAsync()
+ {
+ var tcs = new TaskCompletionSource<bool>();
+ var lazy = new AsyncLazy<TestClass>(async () =>
+ {
+ await tcs.Task;
+ return new TestClass(5);
+ });
+
+ Assert.IsFalse(lazy.IsValueCreated);
+ Task<TestClass> resultTask = lazy.GetValueAsync();
+ Assert.IsFalse(lazy.IsValueCreated);
+ tcs.SetResult(true);
+ await resultTask;
+ Assert.IsTrue(lazy.IsValueCreated);
+ Assert.AreEqual(5, (await resultTask).Value);
+ }
+
+ [TestMethod]
+ public void BadArguments()
+ {
+ Assert.ThrowsException<ArgumentNullException>(() => new AsyncLazy<object>(null));
+ }
+
+ public class TestClass
+ {
+ public int Value { get; }
+
+ public TestClass(int value)
+ {
+ Value = value;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj is TestClass other)
+ {
+ return Value == other.Value;
+ }
+
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return Value;
+ }
+ }
+ }
+}
diff --git a/src/tests/DevToys.Tests/Core/Threading/TaskCompletionNotifierTests.cs b/src/tests/DevToys.Tests/Core/Threading/TaskCompletionNotifierTests.cs
new file mode 100644
index 000000000..ca91f2bca
--- /dev/null
+++ b/src/tests/DevToys.Tests/Core/Threading/TaskCompletionNotifierTests.cs
@@ -0,0 +1,96 @@
+using System;
+using System.Threading.Tasks;
+using DevToys.Core.Threading;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace DevToys.Tests.Core.Threading
+{
+ [TestClass]
+ public class TaskCompletionNotifierTests
+ {
+ [TestMethod]
+ public async Task TaskCompletionNotifierFaultedAsync()
+ {
+ var tcs = new TaskCompletionSource<bool>();
+ var tcn
+ = new TaskCompletionNotifier<int>(
+ async () =>
+ {
+ await tcs.Task;
+ throw new Exception("Task faulted!");
+ });
+
+ Assert.IsFalse(tcn.IsFaulted);
+ Assert.IsFalse(tcn.IsCanceled);
+ Assert.IsFalse(tcn.IsSuccessfullyCompleted);
+ Assert.IsFalse(tcn.IsCompleted);
+
+ tcs.TrySetResult(true);
+ await Task.Delay(100);
+
+ Assert.IsTrue(tcn.IsFaulted);
+ Assert.IsFalse(tcn.IsCanceled);
+ Assert.IsFalse(tcn.IsSuccessfullyCompleted);
+ Assert.IsTrue(tcn.IsCompleted);
+ }
+
+ [TestMethod]
+ public async Task TaskCompletionNotifierCanceledAsync()
+ {
+ var tcs = new TaskCompletionSource<bool>();
+ var tcn
+ = new TaskCompletionNotifier<int>(
+ async () =>
+ {
+ await tcs.Task;
+ throw new OperationCanceledException("Task canceled!");
+ });
+
+ Assert.IsFalse(tcn.IsFaulted);
+ Assert.IsFalse(tcn.IsCanceled);
+ Assert.IsFalse(tcn.IsSuccessfullyCompleted);
+ Assert.IsFalse(tcn.IsCompleted);
+
+ tcs.TrySetResult(true);
+ await Task.Delay(100);
+
+ Assert.IsFalse(tcn.IsFaulted);
+ Assert.IsTrue(tcn.IsCanceled);
+ Assert.IsFalse(tcn.IsSuccessfullyCompleted);
+ Assert.IsTrue(tcn.IsCompleted);
+ }
+
+ [TestMethod]
+ public async Task TaskCompletionNotifierSuccessfulAsync()
+ {
+ var tcs = new TaskCompletionSource<bool>();
+ var tcn
+ = new TaskCompletionNotifier<int>(
+ async () =>
+ {
+ await tcs.Task;
+ return 5;
+ });
+
+ Assert.IsFalse(tcn.IsFaulted);
+ Assert.IsFalse(tcn.IsCanceled);
+ Assert.IsFalse(tcn.IsSuccessfullyCompleted);
+ Assert.IsFalse(tcn.IsCompleted);
+
+ tcs.TrySetResult(true);
+ await Task.Delay(100);
+
+ Assert.IsFalse(tcn.IsFaulted);
+ Assert.IsFalse(tcn.IsCanceled);
+ Assert.IsTrue(tcn.IsSuccessfullyCompleted);
+ Assert.IsTrue(tcn.IsCompleted);
+ Assert.AreEqual(5, tcn.Result);
+ }
+
+ [TestMethod]
+ public void BadArguments()
+ {
+ Assert.ThrowsException<ArgumentNullException>(() => new TaskCompletionNotifier<int>(null));
+ }
+ }
+}
diff --git a/src/tests/DevToys.Tests/DevToys.Tests.csproj b/src/tests/DevToys.Tests/DevToys.Tests.csproj
index 9d4d9d9e4..2c36a509a 100644
--- a/src/tests/DevToys.Tests/DevToys.Tests.csproj
+++ b/src/tests/DevToys.Tests/DevToys.Tests.csproj
@@ -45,6 +45,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Core\Formatter\BaseNumberFormatterTests.cs" />
+ <Compile Include="Core\Threading\AsyncLazyTests.cs" />
+ <Compile Include="Core\Threading\TaskCompletionNotifierTests.cs" />
<Compile Include="Helpers\YamlHelperTests.cs" />
<Compile Include="Helpers\JsonHelperTests.cs" />
<Compile Include="MefBaseTest.cs" />
@@ -97,6 +99,7 @@
<Name>DevToys.Shared</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/src/tests/DevToys.Tests/Providers/IToolProviderFactoryTest.cs b/src/tests/DevToys.Tests/Providers/IToolProviderFactoryTest.cs
index 707113aa2..9e695fd0f 100644
--- a/src/tests/DevToys.Tests/Providers/IToolProviderFactoryTest.cs
+++ b/src/tests/DevToys.Tests/Providers/IToolProviderFactoryTest.cs
@@ -34,5 +34,29 @@ namespace DevToys.Tests.Providers
}
});
}
+
+ [TestMethod]
+ public async Task ToolTree()
+ {
+ await ThreadHelper.RunOnUIThreadAsync(async () =>
+ {
+ System.Collections.Generic.IEnumerable<MatchedToolProvider> result = await ExportProvider.Import<IToolProviderFactory>().GetToolsTreeAsync();
+
+ Assert.IsTrue(result.Count() > 0);
+ Assert.IsTrue(result.First().ChildrenTools.Count > 0);
+ });
+ }
+
+ [TestMethod]
+ public async Task ChildrenTool()
+ {
+ await ThreadHelper.RunOnUIThreadAsync(async () =>
+ {
+ System.Collections.Generic.IEnumerable<MatchedToolProvider> result = await ExportProvider.Import<IToolProviderFactory>().GetToolsTreeAsync();
+ System.Collections.Generic.IEnumerable<IToolProvider> result2 = ExportProvider.Import<IToolProviderFactory>().GetAllChildrenTools(result.First().ToolProvider);
+
+ Assert.IsTrue(result2.Count() > 0);
+ });
+ }
}
}
diff --git a/src/tests/DevToys.Tests/UI/ConvertersTests.cs b/src/tests/DevToys.Tests/UI/ConvertersTests.cs
index c644745d7..1fa79faf1 100644
--- a/src/tests/DevToys.Tests/UI/ConvertersTests.cs
+++ b/src/tests/DevToys.Tests/UI/ConvertersTests.cs
@@ -8,6 +8,71 @@ namespace DevToys.Tests.UI
[TestClass]
public class ConvertersTests
{
+ [TestMethod]
+ public void BooleanToDoubleConverterTest()
+ {
+ var converter = new BooleanToDoubleConverter
+ {
+ ValueOnTrue = 1.0,
+ ValueOnFalse = 2.0
+ };
+
+ Assert.AreEqual(1.0, converter.Convert(true, typeof(double), null, null));
+ Assert.AreEqual(2.0, converter.Convert(false, typeof(double), null, null));
+ }
+
+ [TestMethod]
+ public void BooleanToGridLengthConverterTest()
+ {
+ var converter = new BooleanToGridLengthConverter
+ {
+ GridLengthOnTrue = GridLength.Auto,
+ GridLengthOnFalse = new GridLength(123)
+ };
+
+ Assert.AreEqual(GridLength.Auto, converter.Convert(true, typeof(GridLength), null, null));
+ Assert.AreEqual(new GridLength(123), converter.Convert(false, typeof(GridLength), null, null));
+ }
+
+ [TestMethod]
+ public void BooleanToIntegerConverterTest()
+ {
+ var converter = new BooleanToIntegerConverter
+ {
+ ValueOnTrue = 1,
+ ValueOnFalse = 2
+ };
+
+ Assert.AreEqual(1, converter.Convert(true, typeof(int), null, null));
+ Assert.AreEqual(2, converter.Convert(false, typeof(int), null, null));
+ }
+
+ [TestMethod]
+ public void BooleanToScrollModeConverterTest()
+ {
+ var converter = new BooleanToScrollModeConverter
+ {
+ ScrollModeOnTrue = ScrollMode.Enabled,
+ ScrollModeOnFalse = ScrollMode.Disabled
+ };
+
+ Assert.AreEqual(ScrollMode.Enabled, converter.Convert(true, typeof(ScrollMode), null, null));
+ Assert.AreEqual(ScrollMode.Disabled, converter.Convert(false, typeof(ScrollMode), null, null));
+ }
+
+ [TestMethod]
+ public void BooleanToTextWrappingConverterTest()
+ {
+ var converter = new BooleanToTextWrappingConverter
+ {
+ TextWrappingOnTrue = TextWrapping.NoWrap,
+ TextWrappingOnFalse = TextWrapping.Wrap
+ };
+
+ Assert.AreEqual(TextWrapping.NoWrap, converter.Convert(true, typeof(TextWrapping), null, null));
+ Assert.AreEqual(TextWrapping.Wrap, converter.Convert(false, typeof(TextWrapping), null, null));
+ }
+
[TestMethod]
public void BooleanToVisibilityConverterTest()
{
@@ -25,6 +90,55 @@ namespace DevToys.Tests.UI
Assert.AreEqual(Visibility.Visible, converter.Convert(false, typeof(Visibility), null, null));
}
+ [TestMethod]
+ public void DoublrToGridLengthConverterTest()
+ {
+ var converter = new DoubleToGridLengthConverter();
+
+ Assert.AreEqual(new GridLength(2.0), converter.Convert(2.0, typeof(GridLength), null, null));
+ }
+
+ [TestMethod]
+ public void EnumToBooleanConverterTest()
+ {
+ var converter = new EnumToBooleanConverter();
+
+ Assert.IsFalse((bool)converter.Convert(null, null, "foo", null));
+ Assert.IsFalse((bool)converter.Convert(AppBarClosedDisplayMode.Compact, null, null, null));
+ Assert.IsFalse((bool)converter.Convert("foo", null, "foo", null));
+
+ Assert.IsTrue((bool)converter.Convert(AppBarClosedDisplayMode.Compact, null, "Compact", null));
+ Assert.IsFalse((bool)converter.Convert(AppBarClosedDisplayMode.Compact, null, "Test", null));
+
+ Assert.AreEqual(AppBarClosedDisplayMode.Compact, converter.ConvertBack(true, typeof(AppBarClosedDisplayMode), "Compact", null));
+ }
+
+ [TestMethod]
+ public void EnumToThicknessConverterTest()
+ {
+ var converter = new EnumToThicknessConverter
+ {
+ ThicknessOnEnumDetected = new Thickness(10),
+ ThicknessOnEnumNotDetected = new Thickness(0)
+ };
+
+ Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(null, null, "foo", null));
+ Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, null, null));
+ Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert("foo", null, "foo", null));
+
+ Assert.AreEqual(converter.ThicknessOnEnumDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, "Compact", null));
+ Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, "Test", null));
+ }
+
+ [TestMethod]
+ public void InvertedBooleanConverterTest()
+ {
+ var converter = new InvertedBooleanConverter();
+
+ Assert.IsFalse((bool)converter.Convert(true, typeof(bool), null, null));
+ Assert.IsTrue((bool)converter.Convert(false, typeof(bool), null, null));
+ }
+
[TestMethod]
public void NullToBooleanConverterTest()
{
@@ -53,35 +167,20 @@ namespace DevToys.Tests.UI
}
[TestMethod]
- public void EnumToThicknessConverterTest()
+ public void NullToVisibilityConverterTest()
{
- var converter = new EnumToThicknessConverter
+ var converter = new NullToVisibilityConverter
{
- ThicknessOnEnumDetected = new Thickness(10),
- ThicknessOnEnumNotDetected = new Thickness(0)
+ IsInverted = false
};
- Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(null, null, "foo", null));
- Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, null, null));
- Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert("foo", null, "foo", null));
-
- Assert.AreEqual(converter.ThicknessOnEnumDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, "Compact", null));
- Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, "Test", null));
- }
+ Assert.AreEqual(Visibility.Visible, (Visibility)converter.Convert(null, typeof(bool), null, null));
+ Assert.AreEqual(Visibility.Collapsed, (Visibility)converter.Convert(1, typeof(bool), null, null));
- [TestMethod]
- public void EnumToBooleanConverterTest()
- {
- var converter = new EnumToBooleanConverter();
-
- Assert.IsFalse((bool)converter.Convert(null, null, "foo", null));
- Assert.IsFalse((bool)converter.Convert(AppBarClosedDisplayMode.Compact, null, null, null));
- Assert.IsFalse((bool)converter.Convert("foo", null, "foo", null));
-
- Assert.IsTrue((bool)converter.Convert(AppBarClosedDisplayMode.Compact, null, "Compact", null));
- Assert.IsFalse((bool)converter.Convert(AppBarClosedDisplayMode.Compact, null, "Test", null));
+ converter.IsInverted = true;
- Assert.AreEqual(AppBarClosedDisplayMode.Compact, converter.ConvertBack(true, typeof(AppBarClosedDisplayMode), "Compact", null));
+ Assert.AreEqual(Visibility.Collapsed, (Visibility)converter.Convert(null, typeof(bool), null, null));
+ Assert.AreEqual(Visibility.Visible, (Visibility)converter.Convert(1, typeof(bool), null, null));
}
}
}