mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Merge pull request #8386 from microsoft/dev/crutkas/fxCopColorPickerUnitTests
FxCop to UnitTests for ColorPicker
This commit is contained in:
@@ -8,7 +8,7 @@ using System.Globalization;
|
|||||||
using ColorPicker.Helpers;
|
using ColorPicker.Helpers;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
namespace UnitTest_ColorPickerUI.Helpers
|
namespace Microsoft.ColorPicker.UnitTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test class to test <see cref="ColorConverter"/>
|
/// Test class to test <see cref="ColorConverter"/>
|
||||||
@@ -184,9 +184,16 @@ namespace UnitTest_ColorPickerUI.Helpers
|
|||||||
[DataRow("7E7EB8", 240.5, 013.5, 057.0)]
|
[DataRow("7E7EB8", 240.5, 013.5, 057.0)]
|
||||||
public void ColorRGBtoHSITest(string hexValue, double hue, double saturation, double intensity)
|
public void ColorRGBtoHSITest(string hexValue, double hue, double saturation, double intensity)
|
||||||
{
|
{
|
||||||
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber);
|
if (string.IsNullOrWhiteSpace(hexValue))
|
||||||
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber);
|
{
|
||||||
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber);
|
Assert.IsNotNull(hexValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.IsTrue(hexValue.Length >= 6);
|
||||||
|
|
||||||
|
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
var color = Color.FromArgb(255, red, green, blue);
|
var color = Color.FromArgb(255, red, green, blue);
|
||||||
var result = ColorHelper.ConvertToHSIColor(color);
|
var result = ColorHelper.ConvertToHSIColor(color);
|
||||||
@@ -225,9 +232,16 @@ namespace UnitTest_ColorPickerUI.Helpers
|
|||||||
[DataRow("7E7EB8", 240, 049, 028)]
|
[DataRow("7E7EB8", 240, 049, 028)]
|
||||||
public void ColorRGBtoHWBTest(string hexValue, double hue, double whiteness, double blackness)
|
public void ColorRGBtoHWBTest(string hexValue, double hue, double whiteness, double blackness)
|
||||||
{
|
{
|
||||||
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber);
|
if (string.IsNullOrWhiteSpace(hexValue))
|
||||||
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber);
|
{
|
||||||
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber);
|
Assert.IsNotNull(hexValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.IsTrue(hexValue.Length >= 6);
|
||||||
|
|
||||||
|
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
var color = Color.FromArgb(255, red, green, blue);
|
var color = Color.FromArgb(255, red, green, blue);
|
||||||
var result = ColorHelper.ConvertToHWBColor(color);
|
var result = ColorHelper.ConvertToHWBColor(color);
|
||||||
@@ -266,9 +280,16 @@ namespace UnitTest_ColorPickerUI.Helpers
|
|||||||
[DataRow("7E7EB8", "B0", 049, 028)]
|
[DataRow("7E7EB8", "B0", 049, 028)]
|
||||||
public void ColorRGBtoNColTest(string hexValue, string hue, double whiteness, double blackness)
|
public void ColorRGBtoNColTest(string hexValue, string hue, double whiteness, double blackness)
|
||||||
{
|
{
|
||||||
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber);
|
if (string.IsNullOrWhiteSpace(hexValue))
|
||||||
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber);
|
{
|
||||||
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber);
|
Assert.IsNotNull(hexValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.IsTrue(hexValue.Length >= 6);
|
||||||
|
|
||||||
|
var red = int.Parse( hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
var color = Color.FromArgb(255, red, green, blue);
|
var color = Color.FromArgb(255, red, green, blue);
|
||||||
var result = ColorHelper.ConvertToNaturalColor(color);
|
var result = ColorHelper.ConvertToNaturalColor(color);
|
||||||
@@ -300,7 +321,10 @@ namespace UnitTest_ColorPickerUI.Helpers
|
|||||||
{
|
{
|
||||||
_ = ColorHelper.ConvertToCMYKColor(color);
|
_ = ColorHelper.ConvertToCMYKColor(color);
|
||||||
}
|
}
|
||||||
|
#pragma warning disable CA1031 // Do not catch general exception types
|
||||||
|
// intentionally trying to catch
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
#pragma warning restore CA1031 // Do not catch general exception types
|
||||||
{
|
{
|
||||||
exception = ex;
|
exception = ex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using ColorPicker.Helpers;
|
|||||||
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
namespace UnitTest_ColorPickerUI.Helpers
|
namespace Microsoft.ColorPicker.UnitTests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class ColorRepresentationHelperTest
|
public class ColorRepresentationHelperTest
|
||||||
|
|||||||
@@ -3,13 +3,14 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<ProjectGuid>{090CD7B7-3B0C-4D1D-BC98-83EB5D799BC1}</ProjectGuid>
|
<ProjectGuid>{090CD7B7-3B0C-4D1D-BC98-83EB5D799BC1}</ProjectGuid>
|
||||||
<RootNamespace>UnitTest_ColorPickerUI</RootNamespace>
|
<RootNamespace>Microsoft.ColorPicker.UnitTests</RootNamespace>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>8.0</LangVersion>
|
<LangVersion>8.0</LangVersion>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<Platforms>x64</Platforms>
|
<Platforms>x64</Platforms>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@@ -23,6 +24,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||||
<PackageReference Include="coverlet.collector" Version="1.3.0">
|
<PackageReference Include="coverlet.collector" Version="1.3.0">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|||||||
Reference in New Issue
Block a user