RangeBaseTests.cs 2.8 KB

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