ColorExtensionsTests.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) Craftwork Games. All rights reserved.
  2. // Licensed under the MIT license.
  3. // See LICENSE file in the project root for full license information.
  4. using Microsoft.Xna.Framework;
  5. namespace MonoGame.Extended.Tests;
  6. public class ColorExtensionsTests
  7. {
  8. public class ToHex
  9. {
  10. [Fact]
  11. public void Color_Transparent_ReturnsCorrectHex()
  12. {
  13. Color transparent = new Color(0, 0, 0, 0);
  14. string hex = transparent.ToHex();
  15. Assert.Equal("#00000000", hex);
  16. }
  17. [Fact]
  18. public void Color_White_ReturnsCorrectHex()
  19. {
  20. Color white = new Color(255, 255, 255);
  21. string hex = white.ToHex();
  22. Assert.Equal("#ffffffff", hex);
  23. }
  24. [Fact]
  25. public void Color_Black_ReturnsCorrectHex()
  26. {
  27. Color black = new Color(0, 0, 0);
  28. string hex = black.ToHex();
  29. Assert.Equal("#000000ff", hex);
  30. }
  31. [Fact]
  32. public void Color_Red_ReturnsCorrectHex()
  33. {
  34. Color red = new Color(255, 0, 0);
  35. string hex = red.ToHex();
  36. Assert.Equal("#ff0000ff", hex);
  37. }
  38. [Fact]
  39. public void Color_Green_ReturnsCorrectHex()
  40. {
  41. Color green = new Color(0, 255, 0);
  42. string hex = green.ToHex();
  43. Assert.Equal("#00ff00ff", hex);
  44. }
  45. [Fact]
  46. public void Color_Blue_ReturnsCorrectHex()
  47. {
  48. Color blue = new Color(0, 0, 255);
  49. string hex = blue.ToHex();
  50. Assert.Equal("#0000ffff", hex);
  51. }
  52. [Fact]
  53. public void Color_ReturnsCorrectHex()
  54. {
  55. Color color = new Color(170, 187, 204, 128);
  56. string hex = color.ToHex();
  57. Assert.Equal("#aabbcc80", hex);
  58. }
  59. }
  60. }