-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stam
authored and
Stam
committed
Sep 8, 2023
1 parent
e25ab05
commit 0a9cb43
Showing
4 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tests/SoulSplitter.Tests/UI/Converters/BoolToVisibilityConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// This file is part of the SoulSplitter distribution (https://github.com/FrankvdStam/SoulSplitter). | ||
// Copyright (c) 2022 Frank van der Stam. | ||
// https://github.com/FrankvdStam/SoulSplitter/blob/main/LICENSE | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, version 3. | ||
// | ||
// This program is distributed in the hope that it will be useful, but | ||
// WITHOUT ANY WARRANTY without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using SoulSplitter.UI.Converters; | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace SoulSplitter.Tests.UI.Converters | ||
{ | ||
[TestClass] | ||
public class BoolToVisibilityConverterTests | ||
{ | ||
[TestMethod] | ||
public void Convert_Happy_Flow() | ||
{ | ||
var converter = new BoolToVisibilityConverter(); | ||
Assert.AreEqual(Visibility.Visible, converter.Convert(true)); | ||
Assert.AreEqual(Visibility.Collapsed, converter.Convert(false)); | ||
} | ||
|
||
[TestMethod] | ||
public void Convert_Exception() | ||
{ | ||
var converter = new BoolToVisibilityConverter(); | ||
Assert.ThrowsException<NotSupportedException>(() => converter.Convert("test")); | ||
} | ||
|
||
[TestMethod] | ||
public void ConvertBack_Exception() | ||
{ | ||
var converter = new BoolToVisibilityConverter(); | ||
Assert.ThrowsException<NotSupportedException>(() => converter.ConvertBack(Visibility.Visible)); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/SoulSplitter.Tests/UI/Converters/ColorToBrushConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This file is part of the SoulSplitter distribution (https://github.com/FrankvdStam/SoulSplitter). | ||
// Copyright (c) 2022 Frank van der Stam. | ||
// https://github.com/FrankvdStam/SoulSplitter/blob/main/LICENSE | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, version 3. | ||
// | ||
// This program is distributed in the hope that it will be useful, but | ||
// WITHOUT ANY WARRANTY without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using SoulSplitter.UI.Converters; | ||
using System.Windows; | ||
using System.Windows.Media; | ||
|
||
namespace SoulSplitter.Tests.UI.Converters | ||
{ | ||
[TestClass] | ||
public class ColorToBrushConverterTests | ||
{ | ||
[TestMethod] | ||
public void Convert_Happy_Flow() | ||
{ | ||
var converter = new ColorToBrushConverter(); | ||
var color = new System.Windows.Media.Color | ||
{ | ||
A = 1, | ||
R = 2, | ||
G = 3, | ||
B = 4, | ||
}; | ||
|
||
var brush = converter.Convert(color); | ||
Assert.IsInstanceOfType<SolidColorBrush>(brush); | ||
Assert.AreEqual("#01020304", ((SolidColorBrush)brush).Color.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void Convert_Exception() | ||
{ | ||
var converter = new ColorToBrushConverter(); | ||
Assert.ThrowsException<NotSupportedException>(() => converter.Convert("test")); | ||
} | ||
|
||
[TestMethod] | ||
public void ConvertBack_Exception() | ||
{ | ||
var converter = new BoolToVisibilityConverter(); | ||
Assert.ThrowsException<NotSupportedException>(() => converter.ConvertBack(new SolidColorBrush())); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/SoulSplitter.Tests/UI/Converters/ConverterExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// This file is part of the SoulSplitter distribution (https://github.com/FrankvdStam/SoulSplitter). | ||
// Copyright (c) 2022 Frank van der Stam. | ||
// https://github.com/FrankvdStam/SoulSplitter/blob/main/LICENSE | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, version 3. | ||
// | ||
// This program is distributed in the hope that it will be useful, but | ||
// WITHOUT ANY WARRANTY without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using System.Windows.Data; | ||
|
||
namespace SoulSplitter.Tests.UI.Converters | ||
{ | ||
internal static class ConverterExtensions | ||
{ | ||
/// <summary> | ||
/// Calls IValueConverter.Convert, fills in some standard values for all parameters | ||
/// </summary> | ||
public static object Convert(this IValueConverter converter, object value) | ||
{ | ||
return converter.Convert(value, typeof(ConverterExtensions), null, Thread.CurrentThread.CurrentCulture); | ||
} | ||
|
||
/// <summary> | ||
/// Calls IValueConverter.ConvertBack, fills in some standard values for all parameters | ||
/// </summary> | ||
public static object ConvertBack(this IValueConverter converter, object value) | ||
{ | ||
return converter.ConvertBack(value, typeof(ConverterExtensions), null, Thread.CurrentThread.CurrentCulture); | ||
} | ||
} | ||
} |