2016-03-22 23:02:25 +03:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace Xamarin.Forms.Core.UnitTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class EntryUnitTests : BaseTestFixture
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void ValueChangedFromSetValue()
|
|
|
|
{
|
|
|
|
var entry = new Entry();
|
|
|
|
|
|
|
|
const string value = "Foo";
|
|
|
|
|
|
|
|
bool signaled = false;
|
2018-08-31 20:20:30 +03:00
|
|
|
entry.TextChanged += (sender, args) =>
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
signaled = true;
|
2018-08-31 20:20:30 +03:00
|
|
|
Assert.AreEqual(value, args.NewTextValue);
|
2016-03-22 23:02:25 +03:00
|
|
|
};
|
|
|
|
|
2018-08-31 20:20:30 +03:00
|
|
|
entry.SetValue(Entry.TextProperty, value);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
2018-08-31 20:20:30 +03:00
|
|
|
Assert.IsTrue(signaled, "ValueChanged did not fire");
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
2018-08-31 20:20:30 +03:00
|
|
|
[TestCase(null, "foo")]
|
|
|
|
[TestCase("foo", "bar")]
|
|
|
|
[TestCase("foo", null)]
|
|
|
|
public void ValueChangedArgs(string initial, string final)
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2018-08-31 20:20:30 +03:00
|
|
|
var entry = new Entry
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
Text = initial
|
|
|
|
};
|
|
|
|
|
|
|
|
string oldValue = null;
|
|
|
|
string newValue = null;
|
|
|
|
|
|
|
|
Entry entryFromSender = null;
|
|
|
|
|
2018-08-31 20:20:30 +03:00
|
|
|
entry.TextChanged += (s, e) =>
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
entryFromSender = (Entry)s;
|
|
|
|
oldValue = e.OldTextValue;
|
|
|
|
newValue = e.NewTextValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
entry.Text = final;
|
|
|
|
|
2018-08-31 20:20:30 +03:00
|
|
|
Assert.AreEqual(entry, entryFromSender);
|
|
|
|
Assert.AreEqual(initial, oldValue);
|
|
|
|
Assert.AreEqual(final, newValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestCase(1)]
|
|
|
|
[TestCase(0)]
|
|
|
|
[TestCase(9999)]
|
|
|
|
public void CursorPositionValid(int val)
|
|
|
|
{
|
|
|
|
var entry = new Entry
|
|
|
|
{
|
|
|
|
CursorPosition = val
|
|
|
|
};
|
|
|
|
|
|
|
|
var target = entry.CursorPosition;
|
|
|
|
|
|
|
|
Assert.AreEqual(target, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CursorPositionInvalid()
|
|
|
|
{
|
|
|
|
Assert.Throws<System.ArgumentException>(() =>
|
|
|
|
{
|
|
|
|
var entry = new Entry
|
|
|
|
{
|
|
|
|
CursorPosition = -1
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(1)]
|
|
|
|
[TestCase(0)]
|
|
|
|
[TestCase(9999)]
|
|
|
|
public void SelectionLengthValid(int val)
|
|
|
|
{
|
|
|
|
var entry = new Entry
|
|
|
|
{
|
|
|
|
SelectionLength = val
|
|
|
|
};
|
|
|
|
|
|
|
|
var target = entry.SelectionLength;
|
|
|
|
|
|
|
|
Assert.AreEqual(target, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SelectionLengthInvalid()
|
|
|
|
{
|
|
|
|
Assert.Throws<System.ArgumentException>(() =>
|
|
|
|
{
|
|
|
|
var entry = new Entry
|
|
|
|
{
|
|
|
|
SelectionLength = -1
|
|
|
|
};
|
|
|
|
});
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
2018-03-15 13:29:08 +03:00
|
|
|
|
|
|
|
[TestCase(true)]
|
|
|
|
[TestCase(false)]
|
|
|
|
public void ReturnTypeCommand(bool isEnabled)
|
|
|
|
{
|
|
|
|
var entry = new Entry()
|
|
|
|
{
|
|
|
|
IsEnabled = isEnabled,
|
|
|
|
};
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
|
2020-09-29 13:15:44 +03:00
|
|
|
var bindingContext = new
|
|
|
|
{
|
2018-03-15 13:29:08 +03:00
|
|
|
Command = new Command(() => { result = true; }, () => true)
|
|
|
|
};
|
|
|
|
|
|
|
|
entry.SetBinding(Entry.ReturnCommandProperty, "Command");
|
|
|
|
entry.BindingContext = bindingContext;
|
|
|
|
|
|
|
|
entry.SendCompleted();
|
|
|
|
|
|
|
|
Assert.True(result == isEnabled ? true : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(true)]
|
|
|
|
[TestCase(false)]
|
|
|
|
public void ReturnTypeCommandNullTestIsEnabled(bool isEnabled)
|
|
|
|
{
|
|
|
|
var entry = new Entry()
|
|
|
|
{
|
|
|
|
IsEnabled = isEnabled,
|
|
|
|
};
|
|
|
|
|
|
|
|
bool result = false;
|
2018-08-31 20:20:30 +03:00
|
|
|
|
2018-03-15 13:29:08 +03:00
|
|
|
entry.SetBinding(Entry.ReturnCommandProperty, "Command");
|
|
|
|
entry.BindingContext = null;
|
2018-08-31 20:20:30 +03:00
|
|
|
entry.Completed += (s, e) =>
|
|
|
|
{
|
2018-03-15 13:29:08 +03:00
|
|
|
result = true;
|
|
|
|
};
|
|
|
|
entry.SendCompleted();
|
|
|
|
|
|
|
|
Assert.True(result == isEnabled ? true : false);
|
|
|
|
}
|
2019-01-10 19:21:29 +03:00
|
|
|
|
|
|
|
[TestCase(true)]
|
|
|
|
public void IsReadOnlyTest(bool isReadOnly)
|
|
|
|
{
|
|
|
|
Entry entry = new Entry();
|
|
|
|
entry.SetValue(InputView.IsReadOnlyProperty, isReadOnly);
|
|
|
|
Assert.AreEqual(isReadOnly, entry.IsReadOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void IsReadOnlyDefaultValueTest()
|
|
|
|
{
|
|
|
|
Entry entry = new Entry();
|
|
|
|
Assert.AreEqual(entry.IsReadOnly, false);
|
|
|
|
}
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
}
|