Xamarin.Forms/Xamarin.Forms.Core.UnitTests/EntryUnitTests.cs

175 строки
3.1 KiB
C#
Исходник Постоянная ссылка Обычный вид История

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;
entry.TextChanged += (sender, args) =>
{
2016-03-22 23:02:25 +03:00
signaled = true;
Assert.AreEqual(value, args.NewTextValue);
2016-03-22 23:02:25 +03:00
};
entry.SetValue(Entry.TextProperty, value);
2016-03-22 23:02:25 +03:00
Assert.IsTrue(signaled, "ValueChanged did not fire");
2016-03-22 23:02:25 +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
{
var entry = new Entry
{
2016-03-22 23:02:25 +03:00
Text = initial
};
string oldValue = null;
string newValue = null;
Entry entryFromSender = null;
entry.TextChanged += (s, e) =>
{
2016-03-22 23:02:25 +03:00
entryFromSender = (Entry)s;
oldValue = e.OldTextValue;
newValue = e.NewTextValue;
};
entry.Text = final;
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
}
[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
{
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;
entry.SetBinding(Entry.ReturnCommandProperty, "Command");
entry.BindingContext = null;
entry.Completed += (s, e) =>
{
result = true;
};
entry.SendCompleted();
Assert.True(result == isEnabled ? true : false);
}
[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
}
}