Skip to content

Commit

Permalink
tests: unit tests added and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoBaSs84 committed Jul 27, 2024
1 parent f60ed86 commit d19a320
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BB84.ExtensionsTests;
public sealed partial class ColorExtensionsTests
{
[DataTestMethod]
[DynamicData(nameof(GetArgbTestData), DynamicDataSourceType.Method)]
[DynamicData(nameof(GetArgbHexData), DynamicDataSourceType.Method)]
public void FromARGBHexStringTest(Color expected, string value)
=> Assert.AreEqual(expected.ToArgb(), value.FromARGBHexString().ToArgb());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Drawing;

using BB84.Extensions;

namespace BB84.ExtensionsTests;

public sealed partial class ColorExtensionsTests
{
[DataTestMethod]
[DynamicData(nameof(GetArgbByteData), DynamicDataSourceType.Method)]
public void FromArgbByteArrayTest(Color expected, byte[] value)
=> Assert.AreEqual(expected.ToArgb(), value.FromArgbByteArray().ToArgb());

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void FromArgbByteArrayExceptionTest()
=> Array.Empty<byte>().FromArgbByteArray();

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BB84.ExtensionsTests;
public sealed partial class ColorExtensionsTests
{
[DataTestMethod]
[DynamicData(nameof(GetRgbTestData), DynamicDataSourceType.Method)]
[DynamicData(nameof(GetRgbHexData), DynamicDataSourceType.Method)]
public void FromRGBHexStringTest(Color expected, string value)
=> Assert.AreEqual(expected.ToArgb(), value.FromRGBHexString().ToArgb());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Drawing;

using BB84.Extensions;

namespace BB84.ExtensionsTests;

public sealed partial class ColorExtensionsTests
{
[DataTestMethod]
[DynamicData(nameof(GetRgbByteData), DynamicDataSourceType.Method)]
public void FromRgbByteArrayTest(Color expected, byte[] value)
=> Assert.AreEqual(expected.ToArgb(), value.FromRgbByteArray().ToArgb());

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void FromRgbByteArrayExceptionTest()
=> Array.Empty<byte>().FromRgbByteArray();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BB84.ExtensionsTests;
public sealed partial class ColorExtensionsTests
{
[DataTestMethod]
[DynamicData(nameof(GetArgbTestData), DynamicDataSourceType.Method)]
[DynamicData(nameof(GetArgbHexData), DynamicDataSourceType.Method)]
public void ToARGBHexStringTest(Color value, string expected)
=> Assert.AreEqual(expected, value.ToARGBHexString());
}
13 changes: 13 additions & 0 deletions tests/BB84.ExtensionsTests/ColorExtensionsTests.ToArgbByteArray.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Drawing;

using BB84.Extensions;

namespace BB84.ExtensionsTests;

public sealed partial class ColorExtensionsTests
{
[DataTestMethod]
[DynamicData(nameof(GetArgbByteData), DynamicDataSourceType.Method)]
public void ToArgbByteArrayTest(Color value, byte[] excpected)
=> Assert.IsTrue(excpected.SequenceEqual(value.ToArgbByteArray()));
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BB84.ExtensionsTests;
public sealed partial class ColorExtensionsTests
{
[DataTestMethod]
[DynamicData(nameof(GetRgbTestData), DynamicDataSourceType.Method)]
[DynamicData(nameof(GetRgbHexData), DynamicDataSourceType.Method)]
public void ToRGBHexStringTest(Color value, string expected)
=> Assert.AreEqual(expected, value.ToRGBHexString());
}
13 changes: 13 additions & 0 deletions tests/BB84.ExtensionsTests/ColorExtensionsTests.ToRgbByteArray.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Drawing;

using BB84.Extensions;

namespace BB84.ExtensionsTests;

public sealed partial class ColorExtensionsTests
{
[DataTestMethod]
[DynamicData(nameof(GetRgbByteData), DynamicDataSourceType.Method)]
public void ToRgbByteArrayTest(Color value, byte[] expected)
=> Assert.IsTrue(expected.SequenceEqual(value.ToRgbByteArray()));
}
22 changes: 20 additions & 2 deletions tests/BB84.ExtensionsTests/ColorExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ namespace BB84.ExtensionsTests;
[TestClass]
public sealed partial class ColorExtensionsTests
{
public static IEnumerable<object[]> GetArgbTestData()
public static IEnumerable<object[]> GetArgbByteData()
{
yield return new object[] { Color.White, new byte[] { 255, 255, 255, 255 } };
yield return new object[] { Color.Black, new byte[] { 0, 0, 0, 255 } };
yield return new object[] { Color.Red, new byte[] { 0, 0, 255, 255 } };
yield return new object[] { Color.Lime, new byte[] { 0, 255, 0, 255 } };
yield return new object[] { Color.Blue, new byte[] { 255, 0, 0, 255 } };
}

public static IEnumerable<object[]> GetArgbHexData()
{
yield return new object[] { Color.White, "#FFFFFFFF" };
yield return new object[] { Color.Black, "#FF000000" };
Expand All @@ -14,7 +23,16 @@ public static IEnumerable<object[]> GetArgbTestData()
yield return new object[] { Color.Blue, "#FF0000FF" };
}

public static IEnumerable<object[]> GetRgbTestData()
public static IEnumerable<object[]> GetRgbByteData()
{
yield return new object[] { Color.White, new byte[] { 255, 255, 255 } };
yield return new object[] { Color.Black, new byte[] { 0, 0, 0 } };
yield return new object[] { Color.Red, new byte[] { 0, 0, 255 } };
yield return new object[] { Color.Lime, new byte[] { 0, 255, 0 } };
yield return new object[] { Color.Blue, new byte[] { 255, 0, 0 } };
}

public static IEnumerable<object[]> GetRgbHexData()
{
yield return new object[] { Color.White, "#FFFFFF" };
yield return new object[] { Color.Black, "#000000" };
Expand Down

0 comments on commit d19a320

Please sign in to comment.