RangeBaseTests.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // -----------------------------------------------------------------------
  2. // <copyright file="RangeBaseTests.cs" company="Steven Kirk">
  3. // Copyright 2015 MIT Licence. See licence.md for more information.
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace Perspex.Controls.UnitTests.Primitives
  7. {
  8. using System;
  9. using Perspex.Controls.Primitives;
  10. using Xunit;
  11. public class RangeBaseTests
  12. {
  13. [Fact]
  14. public void Maximum_Should_Be_Coerced_To_Minimum()
  15. {
  16. var target = new TestRange
  17. {
  18. Minimum = 100,
  19. Maximum = 50,
  20. };
  21. Assert.Equal(100, target.Minimum);
  22. Assert.Equal(100, target.Maximum);
  23. }
  24. [Fact]
  25. public void Value_Should_Be_Coerced_To_Range()
  26. {
  27. var target = new TestRange
  28. {
  29. Minimum = 0,
  30. Maximum = 50,
  31. Value = 100,
  32. };
  33. Assert.Equal(0, target.Minimum);
  34. Assert.Equal(50, target.Maximum);
  35. Assert.Equal(50, target.Value);
  36. }
  37. [Fact]
  38. public void Changing_Minimum_Should_Coerce_Value_And_Maximum()
  39. {
  40. var target = new TestRange
  41. {
  42. Minimum = 0,
  43. Maximum = 100,
  44. Value = 50,
  45. };
  46. target.Minimum = 200;
  47. Assert.Equal(200, target.Minimum);
  48. Assert.Equal(200, target.Maximum);
  49. Assert.Equal(200, target.Value);
  50. }
  51. [Fact]
  52. public void Changing_Maximum_Should_Coerce_Value()
  53. {
  54. var target = new TestRange
  55. {
  56. Minimum = 0,
  57. Maximum = 100,
  58. Value = 100,
  59. };
  60. target.Maximum = 50;
  61. Assert.Equal(0, target.Minimum);
  62. Assert.Equal(50, target.Maximum);
  63. Assert.Equal(50, target.Value);
  64. }
  65. [Fact]
  66. public void Properties_Should_Not_Accept_Nan_And_Inifinity()
  67. {
  68. var target = new TestRange();
  69. Assert.Throws<ArgumentException>(() => target.Minimum = double.NaN);
  70. Assert.Throws<ArgumentException>(() => target.Minimum = double.PositiveInfinity);
  71. Assert.Throws<ArgumentException>(() => target.Minimum = double.NegativeInfinity);
  72. Assert.Throws<ArgumentException>(() => target.Maximum = double.NaN);
  73. Assert.Throws<ArgumentException>(() => target.Maximum = double.PositiveInfinity);
  74. Assert.Throws<ArgumentException>(() => target.Maximum = double.NegativeInfinity);
  75. Assert.Throws<ArgumentException>(() => target.Value = double.NaN);
  76. Assert.Throws<ArgumentException>(() => target.Value = double.PositiveInfinity);
  77. Assert.Throws<ArgumentException>(() => target.Value = double.NegativeInfinity);
  78. }
  79. private class TestRange : RangeBase
  80. {
  81. }
  82. }
  83. }