A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

97 lines
3.0 KiB

// -----------------------------------------------------------------------
// <copyright file="RangeBaseTests.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls.UnitTests.Primitives
{
using System;
using Perspex.Controls.Primitives;
using Xunit;
public class RangeBaseTests
{
[Fact]
public void Maximum_Should_Be_Coerced_To_Minimum()
{
var target = new TestRange
{
Minimum = 100,
Maximum = 50,
};
Assert.Equal(100, target.Minimum);
Assert.Equal(100, target.Maximum);
}
[Fact]
public void Value_Should_Be_Coerced_To_Range()
{
var target = new TestRange
{
Minimum = 0,
Maximum = 50,
Value = 100,
};
Assert.Equal(0, target.Minimum);
Assert.Equal(50, target.Maximum);
Assert.Equal(50, target.Value);
}
[Fact]
public void Changing_Minimum_Should_Coerce_Value_And_Maximum()
{
var target = new TestRange
{
Minimum = 0,
Maximum = 100,
Value = 50,
};
target.Minimum = 200;
Assert.Equal(200, target.Minimum);
Assert.Equal(200, target.Maximum);
Assert.Equal(200, target.Value);
}
[Fact]
public void Changing_Maximum_Should_Coerce_Value()
{
var target = new TestRange
{
Minimum = 0,
Maximum = 100,
Value = 100,
};
target.Maximum = 50;
Assert.Equal(0, target.Minimum);
Assert.Equal(50, target.Maximum);
Assert.Equal(50, target.Value);
}
[Fact]
public void Properties_Should_Not_Accept_Nan_And_Inifinity()
{
var target = new TestRange();
Assert.Throws<ArgumentException>(() => target.Minimum = double.NaN);
Assert.Throws<ArgumentException>(() => target.Minimum = double.PositiveInfinity);
Assert.Throws<ArgumentException>(() => target.Minimum = double.NegativeInfinity);
Assert.Throws<ArgumentException>(() => target.Maximum = double.NaN);
Assert.Throws<ArgumentException>(() => target.Maximum = double.PositiveInfinity);
Assert.Throws<ArgumentException>(() => target.Maximum = double.NegativeInfinity);
Assert.Throws<ArgumentException>(() => target.Value = double.NaN);
Assert.Throws<ArgumentException>(() => target.Value = double.PositiveInfinity);
Assert.Throws<ArgumentException>(() => target.Value = double.NegativeInfinity);
}
private class TestRange : RangeBase
{
}
}
}