[Core] Fixed invocation of the IButtonController methods when IsEnabled is false (#1410)

* Fixed invocation of the IButtonController methods when IsEnabled is false

* Fixed Testes
This commit is contained in:
workgroupengineering 2018-01-05 17:25:41 +01:00 коммит произвёл Rui Marinho
Родитель 14937b6252
Коммит f8566492da
2 изменённых файлов: 53 добавлений и 13 удалений

Просмотреть файл

@ -35,42 +35,57 @@ namespace Xamarin.Forms.Core.UnitTests
}
[Test]
public void TestClickedvent ()
[TestCase(true)]
[TestCase(false)]
public void TestClickedvent (bool isEnabled)
{
var view = new Button ();
var view = new Button()
{
IsEnabled= isEnabled,
};
bool activated = false;
view.Clicked += (sender, e) => activated = true;
((IButtonController) view).SendClicked ();
Assert.True (activated);
Assert.True (activated == isEnabled ? true : false);
}
[Test]
public void TestPressedEvent ()
[TestCase(true)]
[TestCase(false)]
public void TestPressedEvent (bool isEnabled)
{
var view = new Button();
var view = new Button()
{
IsEnabled = isEnabled,
};
bool pressed = false;
view.Pressed += (sender, e) => pressed = true;
((IButtonController)view).SendPressed();
Assert.True(pressed);
Assert.True(pressed == isEnabled ? true : false);
}
[Test]
public void TestReleasedEvent ()
[TestCase(true)]
[TestCase(false)]
public void TestReleasedEvent (bool isEnabled)
{
var view = new Button();
var view = new Button()
{
IsEnabled = isEnabled,
};
bool released = false;
view.Released += (sender, e) => released = true;
((IButtonController)view).SendReleased();
Assert.True(released);
Assert.True(released == isEnabled ? true : false);
}
protected override Button CreateSource()
@ -220,6 +235,22 @@ namespace Xamarin.Forms.Core.UnitTests
Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString(""));
}
[Test]
public void ButtonClickWhenCommandCanExecuteFalse()
{
bool invoked = false;
var button = new Button()
{
Command = new Command(() => invoked = true
, () => false),
};
(button as IButtonController)
?.SendClicked();
Assert.False(invoked);
}
private void AssertButtonContentLayoutsEqual(Button.ButtonContentLayout layout1, object layout2)
{
var bcl = (Button.ButtonContentLayout)layout2;

Просмотреть файл

@ -113,20 +113,29 @@ namespace Xamarin.Forms
[EditorBrowsable(EditorBrowsableState.Never)]
public void SendClicked()
{
Command?.Execute(CommandParameter);
Clicked?.Invoke(this, EventArgs.Empty);
if (IsEnabled == true)
{
Command?.Execute(CommandParameter);
Clicked?.Invoke(this, EventArgs.Empty);
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void SendPressed()
{
Pressed?.Invoke(this, EventArgs.Empty);
if (IsEnabled == true)
{
Pressed?.Invoke(this, EventArgs.Empty);
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void SendReleased()
{
Released?.Invoke(this, EventArgs.Empty);
if (IsEnabled == true)
{
Released?.Invoke(this, EventArgs.Empty);
}
}
public FontAttributes FontAttributes