2016-03-22 23:02:25 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace Xamarin.Forms.Core.UnitTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class SliderUnitTests : BaseTestFixture
|
|
|
|
{
|
|
|
|
[Test]
|
2020-09-29 13:15:44 +03:00
|
|
|
public void TestConstructor()
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2020-09-29 13:15:44 +03:00
|
|
|
var slider = new Slider(20, 200, 50);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
2020-09-29 13:15:44 +03:00
|
|
|
Assert.AreEqual(20, slider.Minimum);
|
|
|
|
Assert.AreEqual(200, slider.Maximum);
|
|
|
|
Assert.AreEqual(50, slider.Value);
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-09-29 13:15:44 +03:00
|
|
|
public void TestInvalidConstructor()
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2020-09-29 13:15:44 +03:00
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => new Slider(10, 5, 10));
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-09-29 13:15:44 +03:00
|
|
|
public void TestConstructorClamping()
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2020-09-29 13:15:44 +03:00
|
|
|
Slider slider = new Slider(50, 100, 0);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
2020-09-29 13:15:44 +03:00
|
|
|
Assert.AreEqual(50, slider.Value);
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-09-29 13:15:44 +03:00
|
|
|
public void TestMinValueClamp()
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2020-09-29 13:15:44 +03:00
|
|
|
Slider slider = new Slider(0, 100, 0);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
slider.Minimum = 10;
|
|
|
|
|
2020-09-29 13:15:44 +03:00
|
|
|
Assert.AreEqual(10, slider.Value);
|
|
|
|
Assert.AreEqual(10, slider.Minimum);
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-09-29 13:15:44 +03:00
|
|
|
public void TestMaxValueClamp()
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2020-09-29 13:15:44 +03:00
|
|
|
Slider slider = new Slider(0, 100, 100);
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
slider.Maximum = 10;
|
2020-09-29 13:15:44 +03:00
|
|
|
|
|
|
|
Assert.AreEqual(10, slider.Value);
|
|
|
|
Assert.AreEqual(10, slider.Maximum);
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-09-29 13:15:44 +03:00
|
|
|
public void TestInvalidMaxValue()
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2020-09-29 13:15:44 +03:00
|
|
|
var slider = new Slider();
|
|
|
|
Assert.Throws<ArgumentException>(() => slider.Maximum = slider.Minimum - 1);
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-09-29 13:15:44 +03:00
|
|
|
public void TestInvalidMinValue()
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2020-09-29 13:15:44 +03:00
|
|
|
var slider = new Slider();
|
|
|
|
Assert.Throws<ArgumentException>(() => slider.Minimum = slider.Maximum + 1);
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-09-29 13:15:44 +03:00
|
|
|
public void TestValueChanged()
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2020-09-29 13:15:44 +03:00
|
|
|
var slider = new Slider();
|
2016-03-22 23:02:25 +03:00
|
|
|
var changed = false;
|
|
|
|
|
|
|
|
slider.ValueChanged += (sender, arg) => changed = true;
|
|
|
|
|
|
|
|
slider.Value += 1;
|
|
|
|
|
2020-09-29 13:15:44 +03:00
|
|
|
Assert.True(changed);
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
2020-09-29 13:15:44 +03:00
|
|
|
[TestCase(0.0, 1.0)]
|
|
|
|
[TestCase(1.0, 0.5)]
|
|
|
|
public void SliderValueChangedEventArgs(double initialValue, double finalValue)
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2020-09-29 13:15:44 +03:00
|
|
|
var slider = new Slider
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
Minimum = 0.0,
|
|
|
|
Maximum = 1.0,
|
|
|
|
Value = initialValue
|
|
|
|
};
|
|
|
|
|
|
|
|
Slider sliderFromSender = null;
|
|
|
|
double oldValue = 0.0;
|
|
|
|
double newValue = 0.0;
|
|
|
|
|
2020-09-29 13:15:44 +03:00
|
|
|
slider.ValueChanged += (s, e) =>
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
sliderFromSender = (Slider)s;
|
|
|
|
oldValue = e.OldValue;
|
|
|
|
newValue = e.NewValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
slider.Value = finalValue;
|
|
|
|
|
2020-09-29 13:15:44 +03:00
|
|
|
Assert.AreEqual(slider, sliderFromSender);
|
|
|
|
Assert.AreEqual(initialValue, oldValue);
|
|
|
|
Assert.AreEqual(finalValue, newValue);
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
2018-12-04 22:08:13 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDragStarted()
|
|
|
|
{
|
|
|
|
var slider = new Slider();
|
|
|
|
var started = false;
|
|
|
|
|
|
|
|
slider.DragStarted += (sender, arg) => started = true;
|
|
|
|
((ISliderController)slider).SendDragStarted();
|
|
|
|
|
2020-09-29 13:15:44 +03:00
|
|
|
Assert.True(started);
|
2018-12-04 22:08:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDragCompleted()
|
|
|
|
{
|
|
|
|
var slider = new Slider();
|
|
|
|
var completed = false;
|
|
|
|
|
|
|
|
slider.DragCompleted += (sender, arg) => completed = true;
|
|
|
|
((ISliderController)slider).SendDragCompleted();
|
|
|
|
|
|
|
|
Assert.True(completed);
|
|
|
|
}
|
2020-09-29 13:15:44 +03:00
|
|
|
}
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|