Merge pull request #8386 from microsoft/dev/crutkas/fxCopColorPickerUnitTests

FxCop to UnitTests for ColorPicker
This commit is contained in:
Clint Rutkas 2020-12-07 14:44:46 -08:00 committed by GitHub
commit 292939c4a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 12 deletions

View File

@ -8,7 +8,7 @@ using System.Globalization;
using ColorPicker.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTest_ColorPickerUI.Helpers
namespace Microsoft.ColorPicker.UnitTests
{
/// <summary>
/// Test class to test <see cref="ColorConverter"/>
@ -184,9 +184,16 @@ namespace UnitTest_ColorPickerUI.Helpers
[DataRow("7E7EB8", 240.5, 013.5, 057.0)]
public void ColorRGBtoHSITest(string hexValue, double hue, double saturation, double intensity)
{
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber);
if (string.IsNullOrWhiteSpace(hexValue))
{
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 result = ColorHelper.ConvertToHSIColor(color);
@ -225,9 +232,16 @@ namespace UnitTest_ColorPickerUI.Helpers
[DataRow("7E7EB8", 240, 049, 028)]
public void ColorRGBtoHWBTest(string hexValue, double hue, double whiteness, double blackness)
{
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber);
if (string.IsNullOrWhiteSpace(hexValue))
{
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 result = ColorHelper.ConvertToHWBColor(color);
@ -266,9 +280,16 @@ namespace UnitTest_ColorPickerUI.Helpers
[DataRow("7E7EB8", "B0", 049, 028)]
public void ColorRGBtoNColTest(string hexValue, string hue, double whiteness, double blackness)
{
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber);
if (string.IsNullOrWhiteSpace(hexValue))
{
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 result = ColorHelper.ConvertToNaturalColor(color);
@ -300,7 +321,10 @@ namespace UnitTest_ColorPickerUI.Helpers
{
_ = ColorHelper.ConvertToCMYKColor(color);
}
#pragma warning disable CA1031 // Do not catch general exception types
// intentionally trying to catch
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
{
exception = ex;
}

View File

@ -7,7 +7,7 @@ using ColorPicker.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTest_ColorPickerUI.Helpers
namespace Microsoft.ColorPicker.UnitTests
{
[TestClass]
public class ColorRepresentationHelperTest

View File

@ -3,13 +3,14 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ProjectGuid>{090CD7B7-3B0C-4D1D-BC98-83EB5D799BC1}</ProjectGuid>
<RootNamespace>UnitTest_ColorPickerUI</RootNamespace>
<RootNamespace>Microsoft.ColorPicker.UnitTests</RootNamespace>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>8.0</LangVersion>
<OutputType>Library</OutputType>
<PlatformTarget>x64</PlatformTarget>
<Platforms>x64</Platforms>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -23,6 +24,10 @@
</PropertyGroup>
<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="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>